From 276f7f9d33f35dceeb3231f342be017b0b106cf6 Mon Sep 17 00:00:00 2001 From: dr7ana Date: Mon, 9 Dec 2024 12:07:26 -0800 Subject: [PATCH] temp squash --- llarp/handlers/session.cpp | 39 ++++--- llarp/link/link_manager.cpp | 196 ++++++++++++++++++------------------ llarp/path/path.hpp | 6 +- llarp/router/router.hpp | 4 +- llarp/session/session.cpp | 3 +- 5 files changed, 126 insertions(+), 122 deletions(-) diff --git a/llarp/handlers/session.cpp b/llarp/handlers/session.cpp index 3f221bc2f1..1ae18d223b 100644 --- a/llarp/handlers/session.cpp +++ b/llarp/handlers/session.cpp @@ -140,7 +140,7 @@ namespace llarp::handlers update_and_publish_localcc(get_current_client_intros(), _srv_records); } - // static std::atomic testnet_trigger = false; + static std::atomic testnet_trigger = false; void SessionEndpoint::start_tickers() { @@ -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..."); diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index f01187ebd3..15185d3728 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -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) @@ -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{}); @@ -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(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(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(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(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) diff --git a/llarp/path/path.hpp b/llarp/path/path.hpp index 7c8d03a71f..78a87d3c25 100644 --- a/llarp/path/path.hpp +++ b/llarp/path/path.hpp @@ -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; @@ -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& _hops); /// call obtained exit hooks diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 24295afba7..02b29d3979 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -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}; diff --git a/llarp/session/session.cpp b/llarp/session/session.cpp index e79f80d721..43f1200fe0 100644 --- a/llarp/session/session.cpp +++ b/llarp/session/session.cpp @@ -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)