From 124102bf2f4a32a4459def6dd2887af845263c54 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 6 Apr 2018 21:58:37 -0700 Subject: [PATCH] modules/console: Add fed send command. --- modules/console.cc | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/modules/console.cc b/modules/console.cc index 7ba8463bf..c1486d87a 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 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 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) {