0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

modules/federation/send: Simplify error handling (related 3a696636df).

modules/federation/send: Preliminary setup for error transcription in response.
This commit is contained in:
Jason Volk 2020-03-26 10:28:05 -07:00
parent 6cc7ec3be8
commit 106dd18a86

View file

@ -59,7 +59,6 @@ handle_edu(client &client,
const m::resource::request::object<m::txn> &request, const m::resource::request::object<m::txn> &request,
const string_view &txn_id, const string_view &txn_id,
const m::edu &edu) const m::edu &edu)
try
{ {
m::event event; m::event event;
json::get<"origin"_>(event) = request.origin; json::get<"origin"_>(event) = request.origin;
@ -69,6 +68,8 @@ try
json::get<"depth"_>(event) = json::undefined_number; json::get<"depth"_>(event) = json::undefined_number;
m::vm::opts vmopts; m::vm::opts vmopts;
vmopts.nothrows = -1U;
vmopts.nothrows &= ~m::vm::fault::INTERRUPT;
vmopts.node_id = request.origin; vmopts.node_id = request.origin;
vmopts.txn_id = txn_id; vmopts.txn_id = txn_id;
vmopts.edu = true; vmopts.edu = true;
@ -79,20 +80,6 @@ try
event, vmopts event, vmopts
}; };
} }
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::derror
{
m::log, "%s :%s EDU :%s",
txn_id,
request.origin,
e.what(),
};
}
void void
handle_pdus(client &client, handle_pdus(client &client,
@ -115,6 +102,47 @@ handle_pdus(client &client,
}; };
} }
json::object
handle_txn(client &client,
const m::resource::request::object<m::txn> &request,
const string_view &txn_id,
unique_mutable_buffer &buf)
try
{
const auto &pdus
{
json::get<"pdus"_>(request)
};
const auto &edus
{
json::get<"edus"_>(request)
};
handle_pdus(client, request, txn_id, pdus);
for(const json::object &edu : edus)
handle_edu(client, request, txn_id, edu);
return json::empty_object;
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::critical
{
m::log, "Unhandled error processing txn '%s' from '%s' :%s",
txn_id,
request.origin,
e.what(),
};
throw;
}
m::resource::response m::resource::response
handle_put(client &client, handle_put(client &client,
const m::resource::request::object<m::txn> &request) const m::resource::request::object<m::txn> &request)
@ -136,24 +164,15 @@ handle_put(client &client,
json::at<"origin"_>(request) json::at<"origin"_>(request)
}; };
const json::array &edus char rembuf[64];
{
json::get<"edus"_>(request)
};
const json::array &pdus
{
json::get<"pdus"_>(request)
};
log::debug log::debug
{ {
m::log, "%s :%s | %s --> edus:%zu pdus:%zu", m::log, "%s :%s | %s --> edus:%zu pdus:%zu",
txn_id, txn_id,
origin, origin,
string(remote(client)), string(rembuf, remote(client)),
edus.count(), json::get<"edus"_>(request).count(),
pdus.count(), json::get<"pdus"_>(request).count(),
}; };
if(origin && origin != request.origin) if(origin && origin != request.origin)
@ -182,7 +201,6 @@ handle_put(client &client,
(const auto &eval) (const auto &eval)
{ {
assert(eval.opts); assert(eval.opts);
const bool match_node const bool match_node
{ {
eval.opts->node_id == request.origin eval.opts->node_id == request.origin
@ -211,14 +229,16 @@ handle_put(client &client,
client, http::TOO_MANY_REQUESTS client, http::TOO_MANY_REQUESTS
}; };
handle_pdus(client, request, txn_id, pdus); // Lazy-allocated response buffer; only for error transcription
unique_mutable_buffer response_buffer;
for(const json::object &edu : edus) const json::object &response
handle_edu(client, request, txn_id, edu); {
handle_txn(client, request, txn_id, response_buffer)
};
return m::resource::response return m::resource::response
{ {
client, http::OK client, response
}; };
} }