No fetch only throw

pull/2228/head
dr7ana 5 months ago
parent 5469c9beb0
commit e331f0b31f

@ -960,7 +960,7 @@ namespace llarp
LinkManager::fetch_router_ids( LinkManager::fetch_router_ids(
const RouterID& via, std::string payload, std::function<void(oxen::quic::message m)> func) const RouterID& via, std::string payload, std::function<void(oxen::quic::message m)> func)
{ {
send_control_message(via, "fetch_router_ids"s, std::move(payload), std::move(func)); send_control_message(via, "fetch_rids"s, std::move(payload), std::move(func));
} }
void void
@ -974,8 +974,7 @@ namespace llarp
try try
{ {
oxenc::bt_dict_consumer btdc{m.body()}; oxenc::bt_dict_consumer btdc{m.body()};
source = RouterID{btdc.require<ustring_view>("source")};
source.from_string(btdc.require<std::string_view>("source"));
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
@ -993,7 +992,7 @@ namespace llarp
log::critical(logcat, "Relaying FetchRID request to intended target RID:{}", source); log::critical(logcat, "Relaying FetchRID request to intended target RID:{}", source);
send_control_message( send_control_message(
source, source,
"fetch_router_ids"s, "fetch_rids"s,
m.body_str(), m.body_str(),
[source_rid = std::move(source), original = std::move(m)](oxen::quic::message m) mutable { [source_rid = std::move(source), original = std::move(m)](oxen::quic::message m) mutable {
original.respond(m.body_str(), m.is_error()); original.respond(m.body_str(), m.is_error());

@ -105,9 +105,18 @@ namespace llarp
inline static std::string inline static std::string
serialize(const RouterID& source) serialize(const RouterID& source)
{ {
// serialize_response is a bit weird here, and perhaps could have a sister function oxenc::bt_dict_producer btdp;
// with the same purpose but as a request, but...it works.
return messages::serialize_response({{"source", source.ToView()}}); try
{
btdp.append("source", source.ToView());
}
catch (...)
{
log::error(link_cat, "Error: FetchRIDMessage failed to bt encode contents!");
}
return std::move(btdp).str();
} }
} // namespace FetchRIDMessage } // namespace FetchRIDMessage

@ -233,8 +233,13 @@ namespace llarp
// if we are not bootstrapping, we should check the rc's against the ones we currently hold // if we are not bootstrapping, we should check the rc's against the ones we currently hold
if (not _using_bootstrap_fallback) if (not _using_bootstrap_fallback)
{ {
if (not process_fetched_rcs(rcs)) log::critical(logcat, "Checking returned RCs against locally held...");
return false;
auto success = process_fetched_rcs(rcs);
log::critical(
logcat, "RCs returned by FetchRC {} by trust model", success ? "approved" : "rejected");
return success;
} }
while (!rcs.empty()) while (!rcs.empty())
@ -383,10 +388,10 @@ namespace llarp
_router.link_manager().fetch_rcs( _router.link_manager().fetch_rcs(
src, src,
FetchRCMessage::serialize(_router.last_rc_fetch, needed), FetchRCMessage::serialize(_router.last_rc_fetch, needed),
[this, src, initial](oxen::quic::message m) mutable { [this, source = src, initial](oxen::quic::message m) mutable {
if (m.timed_out) if (m.timed_out)
{ {
log::critical(logcat, "RC fetch to {} timed out!", src); log::critical(logcat, "RC fetch to {} timed out!", source);
fetch_rcs_result(initial, m.timed_out); fetch_rcs_result(initial, m.timed_out);
return; return;
} }
@ -397,7 +402,7 @@ namespace llarp
if (m.is_error()) if (m.is_error())
{ {
auto reason = btdc.require<std::string_view>(messages::STATUS_KEY); auto reason = btdc.require<std::string_view>(messages::STATUS_KEY);
log::critical(logcat, "RC fetch to {} returned error: {}", src, reason); log::critical(logcat, "RC fetch to {} returned error: {}", source, reason);
fetch_rcs_result(initial, m.is_error()); fetch_rcs_result(initial, m.is_error());
return; return;
} }
@ -414,7 +419,8 @@ namespace llarp
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
log::critical(logcat, "Failed to parse RC fetch response from {}: {}", src, e.what()); log::critical(
logcat, "Failed to parse RC fetch response from {}: {}", source, e.what());
fetch_rcs_result(initial, true); fetch_rcs_result(initial, true);
return; return;
} }
@ -454,11 +460,11 @@ namespace llarp
_router.link_manager().fetch_router_ids( _router.link_manager().fetch_router_ids(
src, src,
FetchRIDMessage::serialize(target), FetchRIDMessage::serialize(target),
[this, src, target, initial](oxen::quic::message m) mutable { [this, source = src, target, initial](oxen::quic::message m) mutable {
if (m.is_error()) if (m.is_error())
{ {
auto err = "RID fetch from {} via {} {}"_format( auto err = "RID fetch from {} via {} {}"_format(
src, target, m.timed_out ? "timed out" : "failed"); target, source, m.timed_out ? "timed out" : "failed");
log::critical(link_cat, err); log::critical(link_cat, err);
ingest_rid_fetch_responses(target); ingest_rid_fetch_responses(target);
fetch_rids_result(initial); fetch_rids_result(initial);
@ -472,10 +478,10 @@ namespace llarp
btdc.required("routers"); btdc.required("routers");
auto router_id_strings = btdc.consume_list<std::vector<ustring>>(); auto router_id_strings = btdc.consume_list<std::vector<ustring>>();
btdc.require_signature("signature", [&src](ustring_view msg, ustring_view sig) { btdc.require_signature("signature", [&source](ustring_view msg, ustring_view sig) {
if (sig.size() != 64) if (sig.size() != 64)
throw std::runtime_error{"Invalid signature: not 64 bytes"}; throw std::runtime_error{"Invalid signature: not 64 bytes"};
if (not crypto::verify(src, msg, sig)) if (not crypto::verify(source, msg, sig))
throw std::runtime_error{ throw std::runtime_error{
"Failed to verify signature for fetch RouterIDs response."}; "Failed to verify signature for fetch RouterIDs response."};
}); });
@ -487,7 +493,7 @@ namespace llarp
if (s.size() != RouterID::SIZE) if (s.size() != RouterID::SIZE)
{ {
log::critical( log::critical(
link_cat, "RID fetch from {} via {} returned bad RouterID", target, src); link_cat, "RID fetch from {} via {} returned bad RouterID", target, source);
ingest_rid_fetch_responses(target); ingest_rid_fetch_responses(target);
fetch_rids_result(initial); fetch_rids_result(initial);
return; return;
@ -677,7 +683,8 @@ namespace llarp
rc, rc,
BootstrapFetchMessage::serialize( BootstrapFetchMessage::serialize(
is_snode ? std::make_optional(_router.router_contact) : std::nullopt, num_needed), is_snode ? std::make_optional(_router.router_contact) : std::nullopt, num_needed),
[this, is_snode = _router.is_service_node()](oxen::quic::message m) mutable { [this, is_snode = _router.is_service_node(), src = rc.router_id()](
oxen::quic::message m) mutable {
log::critical(logcat, "Received response to BootstrapRC fetch request..."); log::critical(logcat, "Received response to BootstrapRC fetch request...");
if (not m) if (not m)
@ -685,7 +692,7 @@ namespace llarp
log::warning( log::warning(
logcat, logcat,
"BootstrapRC fetch request to {} failed (error {}/{})", "BootstrapRC fetch request to {} failed (error {}/{})",
fetch_source, src,
bootstrap_attempts, bootstrap_attempts,
MAX_BOOTSTRAP_FETCH_ATTEMPTS); MAX_BOOTSTRAP_FETCH_ATTEMPTS);
fallback_to_bootstrap(); fallback_to_bootstrap();
@ -714,7 +721,7 @@ namespace llarp
log::warning( log::warning(
logcat, logcat,
"Failed to parse BootstrapRC fetch response from {} (error {}/{}): {}", "Failed to parse BootstrapRC fetch response from {} (error {}/{}): {}",
fetch_source, src,
bootstrap_attempts, bootstrap_attempts,
MAX_BOOTSTRAP_FETCH_ATTEMPTS, MAX_BOOTSTRAP_FETCH_ATTEMPTS,
e.what()); e.what());
@ -725,7 +732,7 @@ namespace llarp
log::critical( log::critical(
logcat, logcat,
"BootstrapRC fetch response from {} returned {}/{} needed RCs", "BootstrapRC fetch response from {} returned {}/{} needed RCs",
fetch_source, src,
num, num,
MIN_ACTIVE_RCS); MIN_ACTIVE_RCS);

@ -24,6 +24,9 @@ namespace llarp
RouterID(ustring_view data) : PubKey(data.data()) RouterID(ustring_view data) : PubKey(data.data())
{} {}
RouterID(std::string_view data) : RouterID(to_usv(data))
{}
util::StatusObject util::StatusObject
ExtractStatus() const; ExtractStatus() const;

Loading…
Cancel
Save