2018-04-28 03:02:42 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
2019-04-11 14:29:59 +02:00
|
|
|
namespace ircd::m::feds
|
2018-04-28 03:02:42 +02:00
|
|
|
{
|
2019-04-19 01:23:03 +02:00
|
|
|
struct request_base;
|
2019-04-19 03:24:12 +02:00
|
|
|
template<class T> struct request;
|
|
|
|
using request_list = std::list<std::unique_ptr<request_base>>;
|
|
|
|
template<class T> using create_closure = std::function<T (request<T> &, const string_view &origin)>;
|
2019-04-19 01:23:03 +02:00
|
|
|
|
2019-07-24 07:38:09 +02:00
|
|
|
template<class T> static request_list for_one(const string_view &origin, const opts &, const closure &, const create_closure<T> &);
|
|
|
|
template<class T> static request_list for_each_in_room(const opts &, const closure &, const create_closure<T> &);
|
2019-04-19 06:23:00 +02:00
|
|
|
|
|
|
|
static bool call_user(const closure &closure, const result &result);
|
2019-04-19 03:24:12 +02:00
|
|
|
static bool handler(request_list &, const milliseconds &, const closure &);
|
2019-04-12 09:09:32 +02:00
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
static request_list head(const opts &, const closure &);
|
|
|
|
static request_list auth(const opts &, const closure &);
|
|
|
|
static request_list event(const opts &, const closure &);
|
|
|
|
static request_list state(const opts &, const closure &);
|
|
|
|
static request_list backfill(const opts &, const closure &);
|
|
|
|
static request_list version(const opts &, const closure &);
|
|
|
|
static request_list keys(const opts &, const closure &);
|
2019-06-23 04:13:40 +02:00
|
|
|
static request_list send(const opts &, const closure &);
|
2018-04-30 14:43:56 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 01:23:03 +02:00
|
|
|
//
|
|
|
|
// request_base
|
|
|
|
//
|
|
|
|
|
|
|
|
/// Polymorphic non-template base
|
|
|
|
struct ircd::m::feds::request_base
|
|
|
|
{
|
|
|
|
const feds::opts *opts {nullptr};
|
2019-04-19 03:24:12 +02:00
|
|
|
char origin[256];
|
2019-04-19 01:23:03 +02:00
|
|
|
|
|
|
|
request_base(const feds::opts &opts)
|
|
|
|
:opts{&opts}
|
|
|
|
{}
|
|
|
|
|
|
|
|
request_base() = default;
|
|
|
|
virtual ~request_base() noexcept;
|
|
|
|
};
|
|
|
|
|
|
|
|
ircd::m::feds::request_base::~request_base()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// request
|
|
|
|
//
|
|
|
|
|
2019-04-11 14:29:59 +02:00
|
|
|
template<class T>
|
|
|
|
struct ircd::m::feds::request
|
2019-04-19 01:23:03 +02:00
|
|
|
:request_base
|
|
|
|
,T
|
2018-04-30 14:43:56 +02:00
|
|
|
{
|
2019-04-11 14:29:59 +02:00
|
|
|
char buf[8_KiB];
|
2018-04-30 14:43:56 +02:00
|
|
|
|
2019-04-19 01:23:03 +02:00
|
|
|
request(const feds::opts &opts, const std::function<T (request &)> &closure)
|
|
|
|
:request_base{opts}
|
|
|
|
,T(closure(*this))
|
2019-04-12 09:31:07 +02:00
|
|
|
{}
|
|
|
|
|
2019-04-11 14:29:59 +02:00
|
|
|
request(request &&) = delete;
|
|
|
|
request(const request &) = delete;
|
2020-07-20 05:35:22 +02:00
|
|
|
~request() noexcept;
|
2019-04-19 01:23:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
ircd::m::feds::request<T>::~request()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
if(this->valid())
|
2019-04-17 02:56:11 +02:00
|
|
|
{
|
2019-04-19 01:23:03 +02:00
|
|
|
server::cancel(*this);
|
|
|
|
this->wait();
|
2019-04-17 02:56:11 +02:00
|
|
|
}
|
2019-04-19 01:23:03 +02:00
|
|
|
}
|
2018-04-28 03:02:42 +02:00
|
|
|
|
2019-04-12 09:31:07 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// m/feds.h
|
|
|
|
//
|
2018-05-05 12:23:56 +02:00
|
|
|
|
2019-09-26 21:16:22 +02:00
|
|
|
ircd::m::feds::execute::execute(const vector_view<const opts> &optsv,
|
|
|
|
const closure &closure)
|
|
|
|
:boolean{true}
|
2019-04-18 14:16:21 +02:00
|
|
|
{
|
2019-04-19 03:24:12 +02:00
|
|
|
request_list list;
|
2019-04-19 00:25:01 +02:00
|
|
|
for(const auto &opts : optsv) switch(opts.op)
|
2019-04-18 14:16:21 +02:00
|
|
|
{
|
2019-04-19 03:24:12 +02:00
|
|
|
case op::head:
|
|
|
|
list.splice(list.end(), head(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::auth:
|
|
|
|
list.splice(list.end(), auth(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::event:
|
|
|
|
list.splice(list.end(), event(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::state:
|
|
|
|
list.splice(list.end(), state(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::backfill:
|
|
|
|
list.splice(list.end(), backfill(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::version:
|
|
|
|
list.splice(list.end(), version(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case op::keys:
|
|
|
|
list.splice(list.end(), keys(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
2019-06-23 04:13:40 +02:00
|
|
|
case op::send:
|
|
|
|
list.splice(list.end(), send(opts, closure));
|
|
|
|
continue;
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
case op::noop:
|
|
|
|
continue;
|
2019-04-18 14:16:21 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
milliseconds timeout {0};
|
|
|
|
for(const auto &opts : optsv)
|
2020-03-04 19:39:14 +01:00
|
|
|
timeout = std::max(opts.timeout, timeout);
|
2019-04-19 03:24:12 +02:00
|
|
|
|
2019-09-26 21:16:22 +02:00
|
|
|
this->boolean::val = handler(list, timeout, closure);
|
2019-04-18 14:16:21 +02:00
|
|
|
}
|
|
|
|
|
2019-06-23 04:13:40 +02:00
|
|
|
ircd::m::feds::request_list
|
|
|
|
ircd::m::feds::send(const opts &opts,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::send::opts v1opts;
|
2019-06-23 04:13:40 +02:00
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
|
|
|
strlcpy{request.origin, origin}
|
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::send
|
2019-06-23 04:13:40 +02:00
|
|
|
{
|
|
|
|
opts.arg[0], opts.arg[1], request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::send>(opts, closure, make_request);
|
2019-06-23 04:13:40 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-18 14:16:21 +02:00
|
|
|
ircd::m::feds::keys(const opts &opts,
|
|
|
|
const closure &closure)
|
2019-04-12 09:53:32 +02:00
|
|
|
{
|
2019-07-23 04:48:59 +02:00
|
|
|
const auto make_request{[&opts]
|
2019-04-12 09:53:32 +02:00
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::key::query::opts v1opts;
|
2019-04-12 09:53:32 +02:00
|
|
|
v1opts.dynamic = false;
|
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
2019-04-15 23:28:05 +02:00
|
|
|
strlcpy{request.origin, origin}
|
2019-04-12 09:53:32 +02:00
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
const m::fed::key::server_key server_key
|
2019-04-12 09:53:32 +02:00
|
|
|
{
|
|
|
|
opts.arg[0], opts.arg[1]
|
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::key::query
|
2019-04-12 09:53:32 +02:00
|
|
|
{
|
|
|
|
{&server_key, 1}, request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2019-07-23 04:48:59 +02:00
|
|
|
return opts.room_id?
|
2020-03-06 04:35:20 +01:00
|
|
|
for_each_in_room<m::fed::key::query>(opts, closure, make_request):
|
|
|
|
for_one<m::fed::key::query>(opts.arg[0], opts, closure, make_request);
|
2019-04-12 09:53:32 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-12 09:09:32 +02:00
|
|
|
ircd::m::feds::version(const opts &opts,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
static const auto make_request{[]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::version::opts opts;
|
2019-04-12 09:09:32 +02:00
|
|
|
opts.dynamic = false;
|
|
|
|
opts.remote = string_view
|
|
|
|
{
|
2019-04-15 23:28:05 +02:00
|
|
|
strlcpy{request.origin, origin}
|
2019-04-12 09:09:32 +02:00
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::version
|
2019-04-12 09:09:32 +02:00
|
|
|
{
|
|
|
|
request.buf, std::move(opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::version>(opts, closure, make_request);
|
2019-04-12 09:09:32 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-12 10:53:57 +02:00
|
|
|
ircd::m::feds::backfill(const opts &opts,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::backfill::opts v1opts;
|
2019-04-12 10:53:57 +02:00
|
|
|
v1opts.event_id = opts.event_id;
|
|
|
|
v1opts.limit = opts.argi[0];
|
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
2019-04-15 23:28:05 +02:00
|
|
|
strlcpy{request.origin, origin}
|
2019-04-12 10:53:57 +02:00
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::backfill
|
2019-04-12 10:53:57 +02:00
|
|
|
{
|
|
|
|
opts.room_id, request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::backfill>(opts, closure, make_request);
|
2019-04-12 10:53:57 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-11 14:29:59 +02:00
|
|
|
ircd::m::feds::state(const opts &opts,
|
|
|
|
const closure &closure)
|
2018-05-05 12:23:56 +02:00
|
|
|
{
|
2019-04-11 14:29:59 +02:00
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::state::opts v1opts;
|
2019-04-12 09:52:29 +02:00
|
|
|
v1opts.ids_only = opts.arg[0] == "ids";
|
2019-04-11 14:29:59 +02:00
|
|
|
v1opts.event_id = opts.event_id;
|
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
|
|
|
strlcpy{request.origin, origin}
|
|
|
|
};
|
2018-05-05 12:23:56 +02:00
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::state
|
2019-04-11 14:29:59 +02:00
|
|
|
{
|
|
|
|
opts.room_id, request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
2018-05-05 12:23:56 +02:00
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::state>(opts, closure, make_request);
|
2018-05-05 12:23:56 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-12 09:16:27 +02:00
|
|
|
ircd::m::feds::event(const opts &opts,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::event::opts v1opts;
|
2019-04-12 09:16:27 +02:00
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
2019-04-15 23:28:05 +02:00
|
|
|
strlcpy{request.origin, origin}
|
2019-04-12 09:16:27 +02:00
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::event
|
2019-04-12 09:16:27 +02:00
|
|
|
{
|
|
|
|
opts.event_id, request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::event>(opts, closure, make_request);
|
2019-04-12 09:16:27 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-18 13:07:21 +02:00
|
|
|
ircd::m::feds::auth(const opts &opts,
|
|
|
|
const closure &closure)
|
|
|
|
{
|
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::event_auth::opts v1opts;
|
2019-04-18 13:07:21 +02:00
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
|
|
|
strlcpy{request.origin, origin}
|
|
|
|
};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::event_auth
|
2019-04-18 13:07:21 +02:00
|
|
|
{
|
2019-04-19 06:53:07 +02:00
|
|
|
opts.room_id, opts.event_id, request.buf, std::move(v1opts)
|
2019-04-18 13:07:21 +02:00
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::event_auth>(opts, closure, make_request);
|
2019-04-18 13:07:21 +02:00
|
|
|
}
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::request_list
|
2019-04-11 14:29:59 +02:00
|
|
|
ircd::m::feds::head(const opts &opts,
|
|
|
|
const closure &closure)
|
2018-05-05 12:23:56 +02:00
|
|
|
{
|
2019-04-11 14:29:59 +02:00
|
|
|
const auto make_request{[&opts]
|
|
|
|
(auto &request, const auto &origin)
|
2018-05-05 12:23:56 +02:00
|
|
|
{
|
2020-03-06 04:35:20 +01:00
|
|
|
m::fed::make_join::opts v1opts;
|
2019-04-11 14:29:59 +02:00
|
|
|
v1opts.remote = string_view
|
|
|
|
{
|
|
|
|
strlcpy{request.origin, origin}
|
|
|
|
};
|
2018-05-05 12:23:56 +02:00
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return m::fed::make_join
|
2019-04-11 14:29:59 +02:00
|
|
|
{
|
|
|
|
opts.room_id, opts.user_id, request.buf, std::move(v1opts)
|
|
|
|
};
|
|
|
|
}};
|
|
|
|
|
2020-03-06 04:35:20 +01:00
|
|
|
return for_each_in_room<m::fed::make_join>(opts, closure, make_request);
|
2018-04-28 03:02:42 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 09:31:07 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// (internal)
|
|
|
|
//
|
|
|
|
|
|
|
|
bool
|
2019-04-19 03:24:12 +02:00
|
|
|
ircd::m::feds::handler(request_list &reqs,
|
|
|
|
const milliseconds &timeout,
|
|
|
|
const closure &closure)
|
2019-04-12 09:31:07 +02:00
|
|
|
{
|
|
|
|
const auto when
|
|
|
|
{
|
2019-09-23 05:02:23 +02:00
|
|
|
now<system_point>() + timeout
|
2019-04-12 09:31:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
while(!reqs.empty())
|
|
|
|
{
|
2019-04-19 01:23:03 +02:00
|
|
|
static const auto dereferencer{[]
|
2019-04-19 03:24:12 +02:00
|
|
|
(auto &iterator) -> server::request &
|
2019-04-19 01:23:03 +02:00
|
|
|
{
|
2019-04-19 03:24:12 +02:00
|
|
|
return dynamic_cast<server::request &>(**iterator);
|
2019-04-19 01:23:03 +02:00
|
|
|
}};
|
|
|
|
|
2019-04-12 09:31:07 +02:00
|
|
|
auto next
|
|
|
|
{
|
2019-04-19 01:23:03 +02:00
|
|
|
ctx::when_any(begin(reqs), end(reqs), dereferencer)
|
2019-04-12 09:31:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
if(!next.wait_until(when, std::nothrow))
|
|
|
|
break;
|
|
|
|
|
|
|
|
const auto it
|
|
|
|
{
|
|
|
|
next.get()
|
|
|
|
};
|
|
|
|
|
2019-04-18 08:02:33 +02:00
|
|
|
assert(it != end(reqs));
|
2019-04-19 06:23:00 +02:00
|
|
|
const unwind remove{[&reqs, &it]
|
|
|
|
{
|
|
|
|
reqs.erase(it);
|
|
|
|
}};
|
2019-04-19 01:23:03 +02:00
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
request_base &req(**it);
|
|
|
|
server::request &sreq(dynamic_cast<server::request &>(req)); try
|
2019-04-12 09:31:07 +02:00
|
|
|
{
|
2019-04-19 03:24:12 +02:00
|
|
|
const auto code{sreq.get()};
|
|
|
|
const json::array &array{sreq.in.content};
|
|
|
|
const json::object &object{sreq.in.content};
|
2019-04-19 06:23:00 +02:00
|
|
|
const result result
|
|
|
|
{
|
|
|
|
req.opts, req.origin, {}, object, array
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!call_user(closure, result))
|
2019-04-12 09:31:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
catch(const std::exception &)
|
|
|
|
{
|
2019-04-19 06:23:00 +02:00
|
|
|
if(!req.opts->closure_errors && !req.opts->nothrow_closure_retval)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!req.opts->closure_errors)
|
|
|
|
continue;
|
|
|
|
|
2019-04-12 09:31:07 +02:00
|
|
|
const ctx::exception_handler eptr;
|
2019-04-18 08:02:33 +02:00
|
|
|
const std::exception_ptr &eptr_(eptr);
|
2019-04-19 06:23:00 +02:00
|
|
|
const result result
|
|
|
|
{
|
|
|
|
req.opts, req.origin, eptr_
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!call_user(closure, result))
|
2019-04-12 09:31:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-19 03:24:12 +02:00
|
|
|
|
2019-04-19 06:23:00 +02:00
|
|
|
bool
|
|
|
|
ircd::m::feds::call_user(const closure &closure,
|
|
|
|
const result &result)
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return closure(result);
|
|
|
|
}
|
|
|
|
catch(const std::exception &)
|
|
|
|
{
|
|
|
|
assert(result.request);
|
|
|
|
if(result.request->nothrow_closure)
|
|
|
|
return result.request->nothrow_closure_retval;
|
|
|
|
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
template<class T>
|
|
|
|
ircd::m::feds::request_list
|
2019-07-23 03:48:21 +02:00
|
|
|
ircd::m::feds::for_each_in_room(const opts &opts,
|
2019-07-24 07:38:09 +02:00
|
|
|
const feds::closure &closure,
|
|
|
|
const std::function<T (request<T> &, const string_view &origin)> &create_closure)
|
2019-04-19 03:24:12 +02:00
|
|
|
{
|
2019-07-23 03:48:21 +02:00
|
|
|
request_list ret;
|
|
|
|
if(!opts.room_id)
|
|
|
|
return ret;
|
|
|
|
|
2019-04-19 03:24:12 +02:00
|
|
|
const m::room::origins origins
|
|
|
|
{
|
|
|
|
opts.room_id
|
|
|
|
};
|
|
|
|
|
2019-07-24 07:38:09 +02:00
|
|
|
origins.for_each([&opts, &ret, &closure, &create_closure]
|
2019-04-19 03:24:12 +02:00
|
|
|
(const string_view &origin)
|
|
|
|
{
|
2019-08-14 10:51:38 +02:00
|
|
|
if(opts.exclude_myself && my_host(origin))
|
|
|
|
return;
|
|
|
|
|
2020-04-07 22:15:47 +02:00
|
|
|
const auto errant
|
2019-04-19 03:24:12 +02:00
|
|
|
{
|
2020-04-26 04:52:24 +02:00
|
|
|
fed::errant(origin)
|
2019-07-24 07:38:09 +02:00
|
|
|
};
|
|
|
|
|
2020-04-07 22:15:47 +02:00
|
|
|
if(opts.closure_cached_errors || !errant) try
|
2019-07-24 07:38:09 +02:00
|
|
|
{
|
|
|
|
ret.emplace_back(std::make_unique<request<T>>(opts, [&create_closure, &origin]
|
2019-04-19 03:24:12 +02:00
|
|
|
(auto &request)
|
|
|
|
{
|
2019-07-24 07:38:09 +02:00
|
|
|
return create_closure(request, origin);
|
2019-04-19 03:24:12 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
catch(const std::exception &)
|
|
|
|
{
|
2019-07-24 07:38:09 +02:00
|
|
|
if(!opts.closure_cached_errors)
|
|
|
|
return;
|
|
|
|
|
|
|
|
feds::result result;
|
|
|
|
result.request = &opts;
|
|
|
|
result.origin = origin;
|
|
|
|
result.eptr = std::current_exception();
|
|
|
|
const ctx::exception_handler eh;
|
|
|
|
m::feds::call_user(closure, result);
|
2019-04-19 03:24:12 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2019-07-23 04:48:59 +02:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
ircd::m::feds::request_list
|
|
|
|
ircd::m::feds::for_one(const string_view &origin,
|
|
|
|
const opts &opts,
|
2019-07-24 07:38:09 +02:00
|
|
|
const feds::closure &closure,
|
|
|
|
const std::function<T (request<T> &, const string_view &origin)> &create_closure)
|
2019-07-23 04:48:59 +02:00
|
|
|
{
|
|
|
|
request_list ret;
|
2019-08-14 10:51:38 +02:00
|
|
|
if(opts.exclude_myself && my_host(origin))
|
|
|
|
return ret;
|
|
|
|
|
2020-04-07 22:15:47 +02:00
|
|
|
const auto errant
|
2019-07-23 04:48:59 +02:00
|
|
|
{
|
2020-04-26 04:52:24 +02:00
|
|
|
fed::errant(origin)
|
2019-07-24 07:38:09 +02:00
|
|
|
};
|
|
|
|
|
2020-04-07 22:15:47 +02:00
|
|
|
if(opts.closure_cached_errors || !errant) try
|
2019-07-24 07:38:09 +02:00
|
|
|
{
|
|
|
|
ret.emplace_back(std::make_unique<request<T>>(opts, [&create_closure, &origin]
|
2019-07-23 04:48:59 +02:00
|
|
|
(auto &request)
|
|
|
|
{
|
2019-07-24 07:38:09 +02:00
|
|
|
return create_closure(request, origin);
|
2019-07-23 04:48:59 +02:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
catch(const std::exception &e)
|
|
|
|
{
|
2019-07-24 07:38:09 +02:00
|
|
|
if(!opts.closure_cached_errors)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
feds::result result;
|
|
|
|
result.request = &opts;
|
|
|
|
result.origin = origin;
|
|
|
|
result.eptr = std::current_exception();
|
|
|
|
const ctx::exception_handler eh;
|
|
|
|
m::feds::call_user(closure, result);
|
2019-07-23 04:48:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|