0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd:Ⓜ️:feds: Add send operation to feds suite.

modules/console: Update console for feds resend.
This commit is contained in:
Jason Volk 2019-06-22 19:13:40 -07:00
parent 7dffdf12e0
commit 53ea7b8658
3 changed files with 69 additions and 11 deletions

View file

@ -100,4 +100,5 @@ enum class ircd::m::feds::op
backfill,
version,
keys,
send,
};

View file

@ -11297,7 +11297,7 @@ console_cmd__feds__backfill(opt &out, const string_view &line)
}
bool
console_cmd__feds__resend(opt &out, const string_view &line)
console_cmd__feds__send(opt &out, const string_view &line)
{
const params param{line, " ",
{
@ -11314,19 +11314,49 @@ console_cmd__feds__resend(opt &out, const string_view &line)
event_id
};
m::vm::opts opts;
opts.replays = true;
opts.conforming = false;
opts.fetch = false;
opts.eval = false;
opts.write = false;
opts.effects = false;
opts.notify = true;
m::vm::eval
const json::value event_json
{
m::event{event}, opts
event.source
};
const m::txn::array pduv
{
&event_json, 1
};
const std::string content
{
m::txn::create(pduv)
};
char txnidbuf[64];
const auto txnid
{
m::txn::create_id(txnidbuf, content)
};
m::feds::opts opts;
opts.op = m::feds::op::send;
opts.room_id = at<"room_id"_>(event);
opts.arg[0] = txnid;
opts.arg[1] = content;
m::feds::acquire(opts, [&out]
(const auto &result)
{
out << (result.eptr? '-' : '+')
<< " "
<< std::setw(40) << std::left << result.origin
<< " ";
if(result.eptr)
out << what(result.eptr);
else
out << string_view{result.object};
out << std::endl;
return true;
});
return true;
}

View file

@ -35,6 +35,7 @@ namespace ircd::m::feds
static request_list backfill(const opts &, const closure &);
static request_list version(const opts &, const closure &);
static request_list keys(const opts &, const closure &);
static request_list send(const opts &, const closure &);
bool execute(const vector_view<const opts> &opts, const closure &closure);
}
@ -135,6 +136,10 @@ ircd::m::feds::execute(const vector_view<const opts> &optsv,
list.splice(list.end(), keys(opts, closure));
continue;
case op::send:
list.splice(list.end(), send(opts, closure));
continue;
case op::noop:
continue;
}
@ -147,6 +152,28 @@ ircd::m::feds::execute(const vector_view<const opts> &optsv,
return handler(list, timeout, closure);
}
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)
{
m::v1::send::opts v1opts;
v1opts.remote = string_view
{
strlcpy{request.origin, origin}
};
return m::v1::send
{
opts.arg[0], opts.arg[1], request.buf, std::move(v1opts)
};
}};
return creator<m::v1::send>(opts, make_request);
}
ircd::m::feds::request_list
ircd::m::feds::keys(const opts &opts,
const closure &closure)