0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-07-05 10:08:36 +02:00

modules/console: Add fed send command.

This commit is contained in:
Jason Volk 2018-04-06 21:58:37 -07:00
parent 99d04c310a
commit 124102bf2f

View file

@ -2101,6 +2101,93 @@ console_cmd__fed__head(opt &out, const string_view &line)
return true;
}
bool
console_cmd__fed__send(opt &out, const string_view &line)
{
const params param{line, " ",
{
"remote", "event_id",
}};
const net::hostport remote
{
param.at(0)
};
const m::event::id &event_id
{
param.at(2)
};
const m::event::fetch event
{
event_id
};
thread_local char pdubuf[64_KiB];
const json::value pdu
{
json::stringify(mutable_buffer{pdubuf}, event)
};
const vector_view<const json::value> pdus
{
&pdu, &pdu + 1
};
const auto txn
{
m::txn::create(pdus)
};
thread_local char idbuf[128];
const auto txnid
{
m::txn::create_id(idbuf, txn)
};
const unique_buffer<mutable_buffer> bufs
{
16_KiB
};
m::v1::send::opts opts;
opts.remote = remote;
m::v1::send request
{
txnid, const_buffer{txn}, bufs, std::move(opts)
};
request.wait(seconds(30));
const auto code
{
request.get()
};
const json::object response
{
request
};
const m::v1::send::response resp
{
response
};
resp.for_each_pdu([&]
(const m::event::id &event_id, const json::object &error)
{
out << remote << " ->" << txnid << " " << event_id << " ";
if(empty(error))
out << http::status(code) << std::endl;
else
out << string_view{error} << std::endl;
});
return true;
}
bool
console_cmd__fed__sync(opt &out, const string_view &line)
{