Skip to content

Commit

Permalink
part-time squash
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Dec 9, 2024
1 parent 276f7f9 commit 836933a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
2 changes: 1 addition & 1 deletion llarp/handlers/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"); });
Expand Down
64 changes: 41 additions & 23 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)](
Expand Down Expand Up @@ -1581,21 +1584,22 @@ namespace llarp
onion_nonce,
hop->kx.xor_nonce);

RouterID next_router;
std::string new_payload;
std::optional<std::pair<RouterID, HopID>> 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)
{
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)
{
Expand All @@ -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));
});
}

Expand Down
12 changes: 12 additions & 0 deletions llarp/path/transit_hop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ namespace llarp::path
return std::move(btdp).str();
}

std::optional<std::pair<RouterID, HopID>> TransitHop::next_id(const HopID& h) const
{
std::optional<std::pair<RouterID, HopID>> ret = std::nullopt;

if (h == _rxid)
ret = {_upstream, _txid};
else if (h == _txid)
ret = {_downstream, _rxid};

return ret;
}

nlohmann::json TransitHop::ExtractStatus() const
{
return {
Expand Down
2 changes: 2 additions & 0 deletions llarp/path/transit_hop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace llarp
HopID txid() { return _txid; }
const HopID& txid() const { return _txid; }

std::optional<std::pair<RouterID, HopID>> next_id(const HopID& h) const;

bool operator<(const TransitHop& other) const
{
return std::tie(_txid, _rxid, _upstream, _downstream)
Expand Down

0 comments on commit 836933a

Please sign in to comment.