0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-05-29 00:03:45 +02:00

ircd:Ⓜ️:feds: Refactor interface into opcode ABI.

This commit is contained in:
Jason Volk 2019-04-18 05:16:21 -07:00
parent 08cd894cd0
commit bc922724cd
5 changed files with 75 additions and 116 deletions

View file

@ -20,23 +20,22 @@
/// until it returns. The return value is the for_each-protocol result based on your
/// closure (if the closure ever returns false, the function also returns false).
///
/// The closure is invoke asynchronously as results come in. If the closure
/// The closure is invoked asynchronously as results come in. If the closure
/// returns false, the interface function will return immediately and all
/// pending requests will go out of scope and may be cancelled as per
/// ircd::server decides.
namespace ircd::m::feds
{
enum class op :uint8_t;
struct opts;
struct result;
struct acquire;
using closure = std::function<bool (const result &)>;
};
bool head(const opts &, const closure &);
bool auth(const opts &, const closure &);
bool event(const opts &, const closure &);
bool state(const opts &, const closure &);
bool backfill(const opts &, const closure &);
bool version(const opts &, const closure &);
bool perspective(const opts &, const closure &);
struct ircd::m::feds::acquire
{
acquire(const opts &, const closure &);
};
struct ircd::m::feds::result
@ -50,6 +49,7 @@ struct ircd::m::feds::result
struct ircd::m::feds::opts
{
enum op op {(enum op)0};
milliseconds timeout {20000L};
m::room::id room_id;
m::event::id event_id;
@ -57,3 +57,16 @@ struct ircd::m::feds::opts
string_view arg[4]; // misc argv
uint64_t argi[4]; // misc integer argv
};
enum class ircd::m::feds::op
:uint8_t
{
noop,
head,
auth ,
event,
state,
backfill,
version,
keys,
};

View file

@ -1175,102 +1175,17 @@ ircd::m::app::exists(const string_view &id)
// m/feds.h
//
bool
ircd::m::feds::perspective(const opts &o,
const closure &c)
ircd::m::feds::acquire::acquire(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::perspective"
"federation_federation", "ircd::m::feds::execute"
};
return call(o, c);
}
bool
ircd::m::feds::version(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::version"
};
return call(o, c);
}
bool
ircd::m::feds::state(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::state"
};
return call(o, c);
}
bool
ircd::m::feds::backfill(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::backfill"
};
return call(o, c);
}
bool
ircd::m::feds::event(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::event"
};
return call(o, c);
}
bool
ircd::m::feds::auth(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::auth"
};
return call(o, c);
}
bool
ircd::m::feds::head(const opts &o,
const closure &c)
{
using prototype = bool (const opts &, const closure &);
static mods::import<prototype> call
{
"federation_federation", "ircd::m::feds::head"
};
return call(o, c);
call(o, c);
}
///////////////////////////////////////////////////////////////////////////////

View file

@ -10149,8 +10149,10 @@ console_cmd__feds__version(opt &out, const string_view &line)
};
m::feds::opts opts;
opts.op = m::feds::op::version;
opts.room_id = room_id;
m::feds::version(opts, [&out](const auto &result)
m::feds::acquire(opts, [&out]
(const auto &result)
{
out << (result.eptr? '-' : '+')
<< " "
@ -10223,12 +10225,13 @@ console_cmd__feds__state(opt &out, const string_view &line)
}};
m::feds::opts opts;
opts.op = m::feds::op::state;
opts.timeout = out.timeout;
opts.event_id = event_id;
opts.room_id = room_id;
opts.arg[0] = "ids";
m::feds::state(opts, closure);
m::feds::acquire(opts, closure);
for(auto &p : grid)
{
@ -10273,9 +10276,10 @@ console_cmd__feds__event(opt &out, const string_view &line)
}
m::feds::opts opts;
opts.op = m::feds::op::event;
opts.room_id = room_id;
opts.event_id = event_id;
m::feds::event(opts, [&out](const auto &result)
m::feds::acquire(opts, [&out](const auto &result)
{
out << (result.eptr? '-': empty(result.object)? '?': '+')
<< " "
@ -10314,10 +10318,11 @@ console_cmd__feds__head(opt &out, const string_view &line)
};
m::feds::opts opts;
opts.op = m::feds::op::head;
opts.room_id = room_id;
opts.user_id = user_id;
opts.timeout = out.timeout;
m::feds::head(opts, [&out](const auto &result)
m::feds::acquire(opts, [&out](const auto &result)
{
if(result.eptr)
{
@ -10376,9 +10381,10 @@ console_cmd__feds__auth(opt &out, const string_view &line)
};
m::feds::opts opts;
opts.op = m::feds::op::auth;
opts.room_id = room_id;
opts.event_id = event_id;
m::feds::auth(opts, [&out](const auto &result)
m::feds::acquire(opts, [&out](const auto &result)
{
if(result.eptr)
return true;
@ -10512,11 +10518,12 @@ console_cmd__feds__perspective(opt &out, const string_view &line)
};
m::feds::opts opts;
opts.op = m::feds::op::keys;
opts.timeout = out.timeout;
opts.room_id = room_id;
opts.arg[0] = server_key.first;
opts.arg[1] = server_key.second;
m::feds::perspective(opts, [&out](const auto &result)
m::feds::acquire(opts, [&out](const auto &result)
{
out << std::setw(32) << trunc(result.origin, 32) << " :";
@ -10572,10 +10579,11 @@ console_cmd__feds__backfill(opt &out, const string_view &line)
std::set<string_view> origins;
m::feds::opts opts;
opts.op = m::feds::op::backfill;
opts.room_id = room_id;
opts.event_id = event_id;
opts.argi[0] = limit;
m::feds::backfill(opts, [&grid, &origins]
m::feds::acquire(opts, [&grid, &origins]
(const auto &result)
{
if(result.eptr)

View file

@ -28,6 +28,16 @@ namespace ircd::m::feds
template<class T>
static std::list<request<T>>
creator(const opts &, const std::function<T (request<T> &, const string_view &origin)> &);
static bool head(const opts &, const closure &);
static bool auth(const opts &, const closure &);
static bool event(const opts &, const closure &);
static bool state(const opts &, const closure &);
static bool backfill(const opts &, const closure &);
static bool version(const opts &, const closure &);
static bool keys(const opts &, const closure &);
bool execute(const opts &opts, const closure &closure);
}
template<class T>
@ -60,8 +70,27 @@ struct ircd::m::feds::request
bool
IRCD_MODULE_EXPORT
ircd::m::feds::perspective(const opts &opts,
const closure &closure)
ircd::m::feds::execute(const opts &opts,
const closure &closure)
{
switch(opts.op)
{
case op::head: return head(opts, closure);
case op::auth: return auth(opts, closure);
case op::event: return event(opts, closure);
case op::state: return state(opts, closure);
case op::backfill: return backfill(opts, closure);
case op::version: return version(opts, closure);
case op::keys: return keys(opts, closure);
case op::noop: break;
}
return true;
}
bool
ircd::m::feds::keys(const opts &opts,
const closure &closure)
{
const auto make_request{[&opts]
(auto &request, const auto &origin)
@ -93,7 +122,6 @@ ircd::m::feds::perspective(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::version(const opts &opts,
const closure &closure)
{
@ -122,7 +150,6 @@ ircd::m::feds::version(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::backfill(const opts &opts,
const closure &closure)
{
@ -153,7 +180,6 @@ ircd::m::feds::backfill(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::state(const opts &opts,
const closure &closure)
{
@ -184,7 +210,6 @@ ircd::m::feds::state(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::event(const opts &opts,
const closure &closure)
{
@ -213,7 +238,6 @@ ircd::m::feds::event(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::auth(const opts &opts,
const closure &closure)
{
@ -242,7 +266,6 @@ ircd::m::feds::auth(const opts &opts,
}
bool
IRCD_MODULE_EXPORT
ircd::m::feds::head(const opts &opts,
const closure &closure)
{

View file

@ -205,10 +205,10 @@ ircd::m::fetch::headfill(const room &room)
};
m::feds::opts opts;
opts.op = m::feds::op::head;
opts.room_id = room.room_id;
opts.user_id = user_id;
m::feds::head(opts, [&room]
m::feds::acquire(opts, [&room]
(const auto &result)
{
handle_headfill(room, result);
@ -266,11 +266,11 @@ IRCD_MODULE_EXPORT
ircd::m::fetch::backfill(const room &room)
{
m::feds::opts opts;
opts.op = m::feds::op::backfill;
opts.room_id = room.room_id;
opts.event_id = room.event_id;
opts.argi[0] = 4;
m::feds::backfill(opts, [&room]
m::feds::acquire(opts, [&room]
(const auto &result)
{
handle_backfill(room, result);