diff --git a/llarp/handlers/session.cpp b/llarp/handlers/session.cpp index 1ae18d223b..184d557ad3 100644 --- a/llarp/handlers/session.cpp +++ b/llarp/handlers/session.cpp @@ -162,7 +162,7 @@ namespace llarp::handlers _router.loop()->call_later(10s, [this]() { try { - RouterID cpk{oxenc::from_base32z("o53kmmkwbmqrh5pmrg8irptixqdt5xwafgmwuxa7u7gigxic58ro")}; + RouterID cpk{oxenc::from_base32z("6e9wdnd4cj3j3rgc9ze8ctxqj4z976tmu8osbzwgabruabb4u1ky")}; log::info(logcat, "Beginning session init to client: {}", cpk.to_network_address(false)); _initiate_session( NetworkAddress::from_pubkey(cpk, true), [](ip_v) { log::critical(logcat, "FUCK YEAH"); }); diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index 15185d3728..65c2a088ba 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -1440,15 +1440,18 @@ namespace llarp hop->to_string(), buffer_printer{*inner_body}); - auto hop_is_rx = hop->rxid() == hop_id; + auto next_ids = hop->next_id(hop_id); - const auto& next_id = hop_is_rx ? hop->txid() : hop->rxid(); - const auto& next_router = hop_is_rx ? hop->upstream() : hop->downstream(); + if (not next_ids) + { + log::error(logcat, "Failed to query hop ({}) for next ids (input: {})", hop->to_string(), hop_id); + return m.respond(messages::ERROR_RESPONSE, true); + } - std::string new_payload = ONION::serialize_hop(next_id.to_view(), onion_nonce, std::move(payload)); + std::string new_payload = ONION::serialize_hop(next_ids->second.to_view(), onion_nonce, std::move(payload)); send_control_message( - next_router, + next_ids->first, "path_control", std::move(new_payload), [hop_weak = hop->weak_from_this(), hop_id, prev_message = std::move(m)]( @@ -1581,8 +1584,8 @@ namespace llarp onion_nonce, hop->kx.xor_nonce); - RouterID next_router; - std::string new_payload; + std::optional> next_ids = std::nullopt; + std::string next_payload; // if terminal hop, pass to the correct path expecting to receive this message if (hop->terminal_hop) @@ -1590,12 +1593,13 @@ namespace llarp log::debug( logcat, "We are terminal hop for path data: {}: {}", hop->to_string(), buffer_printer{payload}); - // HopID ihid; - // std::string intermediate; + HopID ihid; + std::string intermediate; try { - std::tie(hop_id, payload) = PATH::DATA::deserialize_intermediate(oxenc::bt_dict_consumer{payload}); + std::tie(ihid, intermediate) = + PATH::DATA::deserialize_intermediate(oxenc::bt_dict_consumer{payload}); } catch (const std::exception& e) { @@ -1604,29 +1608,43 @@ namespace llarp return; } - // log::debug(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid); + log::debug(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid); - hop = _router.path_context()->get_transit_hop(hop_id); + auto next_hop = _router.path_context()->get_transit_hop(ihid); - if (not hop) + if (not next_hop) { - log::warning(logcat, "We are bridge node for path data message with unknown txID: {}", hop_id); + log::warning(logcat, "We are bridge node for path data message with unknown txID: {}", ihid); return; } - // payload = std::move(intermediate); - log::debug(logcat, "Bridging path data message on hop: {}", hop->to_string()); - } + log::debug(logcat, "Bridging path data message on hop: {}", next_hop->to_string()); - // if not terminal hop, relay datagram onwards - auto hop_is_rx = hop->rxid() == hop_id; + next_ids = next_hop->next_id(ihid); - const auto& next_id = hop_is_rx ? hop->txid() : hop->rxid(); - next_router = hop_is_rx ? hop->upstream() : hop->downstream(); + if (not next_ids) + { + log::error( + logcat, "Failed to query hop ({}) for next ids (input: {})", next_hop->to_string(), hop_id); + return; + } - new_payload = ONION::serialize_hop(next_id.to_view(), onion_nonce, std::move(payload)); + next_payload = ONION::serialize_hop(next_ids->second.to_view(), onion_nonce, std::move(intermediate)); + } + else + { + next_ids = hop->next_id(hop_id); + + if (not next_ids) + { + log::error(logcat, "Failed to query hop ({}) for next ids (input: {})", hop->to_string(), hop_id); + return; + } + + next_payload = ONION::serialize_hop(next_ids->second.to_view(), onion_nonce, std::move(payload)); + } - send_data_message(next_router, std::move(new_payload)); + send_data_message(next_ids->first, std::move(next_payload)); }); } diff --git a/llarp/path/transit_hop.cpp b/llarp/path/transit_hop.cpp index 38a2db76b8..9f7879e1e3 100644 --- a/llarp/path/transit_hop.cpp +++ b/llarp/path/transit_hop.cpp @@ -57,6 +57,18 @@ namespace llarp::path return std::move(btdp).str(); } + std::optional> TransitHop::next_id(const HopID& h) const + { + std::optional> ret = std::nullopt; + + if (h == _rxid) + ret = {_upstream, _txid}; + else if (h == _txid) + ret = {_downstream, _rxid}; + + return ret; + } + nlohmann::json TransitHop::ExtractStatus() const { return { diff --git a/llarp/path/transit_hop.hpp b/llarp/path/transit_hop.hpp index 54a13cacfe..07d82b24a5 100644 --- a/llarp/path/transit_hop.hpp +++ b/llarp/path/transit_hop.hpp @@ -51,6 +51,8 @@ namespace llarp HopID txid() { return _txid; } const HopID& txid() const { return _txid; } + std::optional> next_id(const HopID& h) const; + bool operator<(const TransitHop& other) const { return std::tie(_txid, _rxid, _upstream, _downstream)