Skip to content

Commit

Permalink
temp squash
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Dec 9, 2024
1 parent e30f40e commit 276f7f9
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 122 deletions.
39 changes: 19 additions & 20 deletions llarp/handlers/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ namespace llarp::handlers
update_and_publish_localcc(get_current_client_intros(), _srv_records);
}

// static std::atomic<bool> testnet_trigger = false;
static std::atomic<bool> testnet_trigger = false;

void SessionEndpoint::start_tickers()
{
Expand All @@ -155,25 +155,24 @@ namespace llarp::handlers
},
true);

// if (not testnet_trigger)
// {
// testnet_trigger = true;

// _router.loop()->call_later(10s, [this]() {
// try
// {
// RouterID cpk{oxenc::from_base32z("u3w71idt3i4ysq33bwdc7hdqgitb76bds3d3e8x4qkug56ga3ouo")};
// 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");
// });
// }
// catch (const std::exception& e)
// {
// log::critical(logcat, "Failed to parse client netaddr: {}", e.what());
// }
// });
// }
if (not testnet_trigger)
{
testnet_trigger = true;

_router.loop()->call_later(10s, [this]() {
try
{
RouterID cpk{oxenc::from_base32z("o53kmmkwbmqrh5pmrg8irptixqdt5xwafgmwuxa7u7gigxic58ro")};
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"); });
}
catch (const std::exception& e)
{
log::critical(logcat, "Failed to parse client netaddr: {}", e.what());
}
});
}
}
else
log::info(logcat, "SessionEndpoint configured to NOT publish ClientContact...");
Expand Down
196 changes: 100 additions & 96 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ namespace llarp
void LinkManager::start_tickers()
{
log::debug(logcat, "Starting gossip ticker...");
_gossip_ticker = _router.loop()->call_every(
_router._gossip_interval, [this]() { regenerate_and_gossip_rc(); }, true);
_gossip_ticker = _router.loop()->call_every(_router._gossip_interval, [this]() { regenerate_and_gossip_rc(); });
}

LinkManager::LinkManager(Router& r)
Expand Down Expand Up @@ -317,7 +316,7 @@ namespace llarp
make_static_secret(_router.identity()),
[this](oxen::quic::connection_interface& ci) { return on_conn_open(ci); },
[this](oxen::quic::connection_interface& ci, uint64_t ec) { return on_conn_closed(ci, ec); },
[this](oxen::quic::dgram_interface&, bstring dgram) { handle_path_data_message(std::move(dgram)); },
[this](oxen::quic::dgram_interface&, bstring dgram) { return handle_path_data_message(std::move(dgram)); },
is_service_node() ? alpns::SERVICE_INBOUND : alpns::CLIENT_INBOUND,
is_service_node() ? alpns::SERVICE_OUTBOUND : alpns::CLIENT_OUTBOUND,
oxen::quic::opt::enable_datagrams{});
Expand Down Expand Up @@ -1498,132 +1497,137 @@ namespace llarp
return _handle_path_control(std::move(m));
}

void LinkManager::handle_path_data_message(bstring message)
void LinkManager::handle_path_data_message(bstring data)
{
HopID hop_id;
std::string payload;
SymmNonce nonce;

try
{
std::tie(hop_id, nonce, payload) = ONION::deserialize_hop(oxenc::bt_dict_consumer{message});
}
catch (const std::exception& e)
{
log::warning(logcat, "Exception: {}", e.what());
return;
}
_router.loop()->call([this, message = std::move(data)]() {
HopID hop_id;
std::string payload;
SymmNonce nonce;

if (!_is_service_node)
{
auto path = _router.path_context()->get_path(hop_id);

if (not path)
try
{
log::warning(logcat, "Client received path data with unknown rxID: {}", hop_id);
std::tie(hop_id, nonce, payload) = ONION::deserialize_hop(oxenc::bt_dict_consumer{message});
}
catch (const std::exception& e)
{
log::warning(logcat, "Exception: {}", e.what());
return;
}

log::info(logcat, "Received path data for local client: {}", buffer_printer{payload});

for (auto& hop : path->hops)
if (!_is_service_node)
{
nonce = crypto::onion(
reinterpret_cast<unsigned char*>(payload.data()),
payload.size(),
hop.kx.shared_secret,
nonce,
hop.kx.xor_nonce);
auto path = _router.path_context()->get_path(hop_id);

log::trace(logcat, "xchacha20 -> {}", buffer_printer{payload});
}
if (not path)
{
log::warning(logcat, "Client received path data with unknown rxID: {}", hop_id);
return;
}

NetworkAddress sender;
bstring data;
log::info(logcat, "Received path data for local client: {}", buffer_printer{payload});

try
{
oxenc::bt_dict_consumer btdc{payload};
std::tie(sender, data) = PATH::DATA::deserialize(btdc);
for (auto& hop : path->hops)
{
nonce = crypto::onion(
reinterpret_cast<unsigned char*>(payload.data()),
payload.size(),
hop.kx.shared_secret,
nonce,
hop.kx.xor_nonce);

log::trace(logcat, "xchacha20 -> {}", buffer_printer{payload});
}

NetworkAddress sender;
bstring data;

if (auto session = _router.session_endpoint()->get_session(sender))
try
{
session->recv_path_data_message(std::move(data));
oxenc::bt_dict_consumer btdc{payload};
std::tie(sender, data) = PATH::DATA::deserialize(btdc);

if (auto session = _router.session_endpoint()->get_session(sender))
{
session->recv_path_data_message(std::move(data));
}
else
{
log::warning(logcat, "Could not find session (remote:{}) to relay path data message!", sender);
}
}
else
catch (const std::exception& e)
{
log::warning(logcat, "Could not find session (remote:{}) to relay path data message!", sender);
log::warning(logcat, "Exception: {}", e.what());
}
return;
}
catch (const std::exception& e)

log::debug(logcat, "Received path data for local relay: {}", buffer_printer{payload});

auto hop = _router.path_context()->get_transit_hop(hop_id);

if (not hop)
{
log::warning(logcat, "Exception: {}", e.what());
log::warning(logcat, "Received path data with unknown next hop (ID: {})", hop_id);
return;
}
return;
}

log::debug(logcat, "Received path data for local relay: {}", buffer_printer{payload});

auto hop = _router.path_context()->get_transit_hop(hop_id);
auto onion_nonce = nonce ^ hop->kx.xor_nonce;

if (not hop)
{
log::warning(logcat, "Received path data with unknown next hop (ID: {})", hop_id);
return;
}
crypto::onion(
reinterpret_cast<unsigned char*>(payload.data()),
payload.size(),
hop->kx.shared_secret,
onion_nonce,
hop->kx.xor_nonce);

auto onion_nonce = nonce ^ hop->kx.xor_nonce;
RouterID next_router;
std::string new_payload;

crypto::onion(
reinterpret_cast<unsigned char*>(payload.data()),
payload.size(),
hop->kx.shared_secret,
onion_nonce,
hop->kx.xor_nonce);
// 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});

RouterID next_router;
std::string new_payload;
// HopID ihid;
// std::string intermediate;

// 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});
try
{
std::tie(hop_id, payload) = PATH::DATA::deserialize_intermediate(oxenc::bt_dict_consumer{payload});
}
catch (const std::exception& e)
{
log::warning(
logcat, "Path data intermediate payload exception: {}: {}", e.what(), buffer_printer{payload});
return;
}

HopID ihid;
std::string intermediate;
// log::debug(logcat, "Inbound path rxid:{}, outbound path txid:{}", hop_id, ihid);

try
{
std::tie(ihid, intermediate) = PATH::DATA::deserialize_intermediate(oxenc::bt_dict_consumer{payload});
}
catch (const std::exception& e)
{
log::warning(
logcat, "Path data intermediate payload exception: {}: {}", e.what(), buffer_printer{payload});
return;
}
hop = _router.path_context()->get_transit_hop(hop_id);

hop = _router.path_context()->get_transit_hop(ihid);
if (not hop)
{
log::warning(logcat, "We are bridge node for path data message with unknown txID: {}", hop_id);
return;
}

if (not hop)
{
log::warning(logcat, "We are bridge node for path data message with unknown rxID: {}", ihid);
return;
// payload = std::move(intermediate);
log::debug(logcat, "Bridging path data message on hop: {}", hop->to_string());
}

payload = std::move(intermediate);
log::debug(logcat, "Bridging path data message on hop: {}", hop->to_string());
}
// if not terminal hop, relay datagram onwards
auto hop_is_rx = hop->rxid() == hop_id;

// if not terminal hop, relay datagram onwards
auto hop_is_rx = hop->rxid() == hop_id;
const auto& next_id = hop_is_rx ? hop->txid() : hop->rxid();
next_router = hop_is_rx ? hop->upstream() : hop->downstream();

const auto& next_id = hop_is_rx ? hop->txid() : hop->rxid();
next_router = hop_is_rx ? hop->upstream() : hop->downstream();
new_payload = ONION::serialize_hop(next_id.to_view(), onion_nonce, std::move(payload));

new_payload = ONION::serialize_hop(next_id.to_view(), onion_nonce, std::move(payload));

send_data_message(next_router, std::move(new_payload));
send_data_message(next_router, std::move(new_payload));
});
}

void LinkManager::handle_path_request(oxen::quic::message m, std::string payload)
Expand Down
6 changes: 3 additions & 3 deletions llarp/path/path.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ namespace llarp

bool send_path_data_message(std::string body);

std::string make_path_message(std::string payload);

bool is_established() const { return _established; }

bool is_ready(std::chrono::milliseconds now = llarp::time_now_ms()) const;
Expand Down Expand Up @@ -165,9 +167,7 @@ namespace llarp
std::string to_string() const;
static constexpr bool to_string_formattable = true;

private:
std::string make_path_message(std::string payload);

protected:
void populate_internals(const std::vector<RemoteRC>& _hops);

/// call obtained exit hooks
Expand Down
4 changes: 2 additions & 2 deletions llarp/router/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ namespace llarp
// inline constexpr size_t INTROSET_STORAGE_REDUNDANCY{(INTROSET_RELAY_REDUNDANCY * INTROSET_REQS_PER_RELAY)};

// TESTNET: these constants are shortened for testing purposes
inline constexpr std::chrono::milliseconds TESTNET_GOSSIP_INTERVAL{10min};
inline constexpr std::chrono::milliseconds RC_UPDATE_INTERVAL{10min};
inline constexpr std::chrono::milliseconds TESTNET_GOSSIP_INTERVAL{5min};
inline constexpr std::chrono::milliseconds RC_UPDATE_INTERVAL{5min};
inline constexpr std::chrono::milliseconds INITIAL_ATTEMPT_INTERVAL{30s};
// as we advance towards full mesh, we try to connect to this number per tick
inline constexpr int FULL_MESH_ITERATION{1};
Expand Down
3 changes: 2 additions & 1 deletion llarp/session/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ namespace llarp::session
auto inner_payload = PATH::DATA::serialize(std::move(data), _r.local_rid());
auto intermediate_payload =
PATH::DATA::serialize_intermediate(std::move(inner_payload), _current_path->intro.pivot_txid);
return _current_path->send_path_data_message(std::move(intermediate_payload));
return _r.send_data_message(
_current_path->upstream_rid(), _current_path->make_path_message(std::move(intermediate_payload)));
}

void BaseSession::recv_path_data_message(bstring body)
Expand Down

0 comments on commit 276f7f9

Please sign in to comment.