diff --git a/llarp/crypto/crypto.cpp b/llarp/crypto/crypto.cpp index 0e01813040..89843b6dfd 100644 --- a/llarp/crypto/crypto.cpp +++ b/llarp/crypto/crypto.cpp @@ -238,7 +238,7 @@ namespace llarp SharedSecret& secret, const SymmNonce& nonce, const RouterID& remote, - old_uspan payload) + std::span payload) { // derive shared key if (!crypto::dh_client(secret, remote, shared_key, nonce)) @@ -262,7 +262,7 @@ namespace llarp SharedSecret& shared, const PubKey& remote, const SymmNonce& nonce, - old_uspan encrypted) + std::span encrypted) { // derive shared secret using shared secret and our secret key (and nonce) if (!crypto::dh_server(shared, remote, local_sk, nonce)) diff --git a/llarp/crypto/crypto.hpp b/llarp/crypto/crypto.hpp index 0c4c9f6e15..5a35ffc396 100644 --- a/llarp/crypto/crypto.hpp +++ b/llarp/crypto/crypto.hpp @@ -68,7 +68,7 @@ namespace llarp SharedSecret& secret, const SymmNonce& nonce, const RouterID& remote, - old_uspan payload); + std::span payload); // void derive_encrypt_outer_wrapping( // const Ed25519SecretKey& shared_key, @@ -85,7 +85,7 @@ namespace llarp SharedSecret& shared, const PubKey& remote, const SymmNonce& nonce, - old_uspan encrypted); + std::span encrypted); std::array make_scalar(const PubKey& k, uint64_t domain); diff --git a/llarp/crypto/types.cpp b/llarp/crypto/types.cpp index 4984a2cb62..80cd8ab916 100644 --- a/llarp/crypto/types.cpp +++ b/llarp/crypto/types.cpp @@ -145,14 +145,14 @@ namespace llarp throw std::runtime_error{"Server DH failed -- should this even ever happen?"}; } - void shared_kx_data::encrypt(old_uspan data) + void shared_kx_data::encrypt(std::span data) { if (!crypto::xchacha20(data.data(), data.size(), shared_secret, nonce)) throw std::runtime_error{"xchacha20 encryption failed -- should this even ever happen?"}; } // identical methods, separated for clarity of use/logging for now - void shared_kx_data::decrypt(old_uspan data) + void shared_kx_data::decrypt(std::span data) { if (!crypto::xchacha20(data.data(), data.size(), shared_secret, nonce)) throw std::runtime_error{"xchacha20 decryption failed -- should this even ever happen?"}; diff --git a/llarp/crypto/types.hpp b/llarp/crypto/types.hpp index 6857e6b5d8..382c891af9 100644 --- a/llarp/crypto/types.hpp +++ b/llarp/crypto/types.hpp @@ -67,13 +67,13 @@ namespace llarp explicit Ed25519PrivateData(const AlignedBuffer<64>& key_and_hash) : AlignedBuffer<64>(key_and_hash) {} // Returns writeable access to the 32-byte Ed25519 Private Scalar - old_uspan scalar() { return {data(), 32}; } + std::span scalar() { return {data(), 32}; } // Returns readable access to the 32-byte Ed25519 Private Scalar - const_uspan scalar() const { return {data(), 32}; } + uspan scalar() const { return {data(), 32}; } // Returns writeable access to the 32-byte Ed25519 Signing Hash - old_uspan signing_hash() { return {data() + 32, 32}; } + std::span signing_hash() { return {data() + 32, 32}; } // Returns readable access to the 32-byte Ed25519 Signing Hash - const_uspan signing_hash() const { return {data() + 32, 32}; } + uspan signing_hash() const { return {data() + 32, 32}; } PubKey to_pubkey() const; @@ -125,9 +125,9 @@ namespace llarp void server_dh(const Ed25519SecretKey& local_sk); - void encrypt(old_uspan data); + void encrypt(std::span data); - void decrypt(old_uspan enc); + void decrypt(std::span enc); }; } // namespace llarp diff --git a/llarp/dns/message.cpp b/llarp/dns/message.cpp index 22a7caba69..2f48e0937f 100644 --- a/llarp/dns/message.cpp +++ b/llarp/dns/message.cpp @@ -46,7 +46,7 @@ namespace llarp::dns return true; } - bool MessageHeader::decode(std::span b) + bool MessageHeader::decode(std::span b) { std::memcpy(_data.data(), b.data(), sizeof(_data)); for (auto& d : _data) diff --git a/llarp/dns/message.hpp b/llarp/dns/message.hpp index e489111edb..7492d8836b 100644 --- a/llarp/dns/message.hpp +++ b/llarp/dns/message.hpp @@ -39,7 +39,7 @@ namespace llarp bool Decode(llarp_buffer_t* buf) override; - bool decode(std::span b) override; + bool decode(std::span b) override; nlohmann::json ToJSON() const override; @@ -80,7 +80,7 @@ namespace llarp bool Decode(llarp_buffer_t* buf) override; - bool decode(std::span /* b */) override { return {}; }; // TODO: + bool decode(std::span /* b */) override { return {}; }; // TODO: // Wrapper around Encode that encodes into a new buffer and returns it std::vector to_buffer() const; diff --git a/llarp/dns/question.hpp b/llarp/dns/question.hpp index a087d2afb9..43bb674efd 100644 --- a/llarp/dns/question.hpp +++ b/llarp/dns/question.hpp @@ -21,7 +21,7 @@ namespace llarp::dns bool Decode(llarp_buffer_t* buf) override; - bool decode(std::span /* b */) override { return {}; } + bool decode(std::span /* b */) override { return {}; } std::string to_string() const; diff --git a/llarp/dns/rr.hpp b/llarp/dns/rr.hpp index be7e5488b0..e2b3e2e8af 100644 --- a/llarp/dns/rr.hpp +++ b/llarp/dns/rr.hpp @@ -25,7 +25,7 @@ namespace llarp::dns bool Decode(llarp_buffer_t* buf) override; - bool decode(std::span /* b */) override { return {}; }; + bool decode(std::span /* b */) override { return {}; }; nlohmann::json ToJSON() const override; diff --git a/llarp/dns/serialize.hpp b/llarp/dns/serialize.hpp index 5020d2b2bf..d6505b0115 100644 --- a/llarp/dns/serialize.hpp +++ b/llarp/dns/serialize.hpp @@ -19,7 +19,7 @@ namespace llarp::dns /// decode entity from buffer virtual bool Decode(llarp_buffer_t* buf) = 0; - virtual bool decode(std::span b) = 0; + virtual bool decode(std::span b) = 0; /// convert this whatever into json virtual nlohmann::json ToJSON() const = 0; diff --git a/llarp/handlers/session.cpp b/llarp/handlers/session.cpp index ab59cde7a6..e561a0b10c 100644 --- a/llarp/handlers/session.cpp +++ b/llarp/handlers/session.cpp @@ -137,7 +137,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() { @@ -152,25 +152,24 @@ namespace llarp::handlers }, true); - // if (not testnet_trigger) - // { - // testnet_trigger = true; - - // _router.loop()->call_later(5s, [this]() { - // try - // { - // RouterID cpk{oxenc::from_base32z("4g96taie3et7dbkumk5x6rycskaxxsgjeiunpe61469z1gsbfkuo")}; - // 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(5s, [this]() { + try + { + RouterID cpk{oxenc::from_base32z("acit6x8kwxdehpkzrpunw5nb8mf4w5u8tn3ojmxit9rpnhhhp81y")}; + 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..."); @@ -630,7 +629,11 @@ namespace llarp::handlers if (auto maybe_ip = _router.tun_endpoint()->map_session_to_local_ip(session->remote())) { log::info( - logcat, "TUN device successfully routing session to remote: {}", session->remote()); + logcat, + "TUN device successfully routing session (remote: {}) via local ip: {}", + session->remote(), + std::holds_alternative(*maybe_ip) ? std::get(*maybe_ip).to_string() + : std::get(*maybe_ip).to_string()); return hook(*maybe_ip); } diff --git a/llarp/handlers/tun.hpp b/llarp/handlers/tun.hpp index 5992813593..f33d4f090b 100644 --- a/llarp/handlers/tun.hpp +++ b/llarp/handlers/tun.hpp @@ -144,15 +144,6 @@ namespace llarp::handlers void start_poller(); - // protected: - struct WritePacket - { - uint64_t seqno; - IPPacket pkt; - - bool operator>(const WritePacket& other) const { return seqno > other.seqno; } - }; - // Stores assigned IP's for each session in/out of this lokinet instance // - Reserved local addresses is directly pre-loaded from config // - Persisting address map is directly pre-loaded from config diff --git a/llarp/link/link_manager.cpp b/llarp/link/link_manager.cpp index 858f4d4adf..e21ba885be 100644 --- a/llarp/link/link_manager.cpp +++ b/llarp/link/link_manager.cpp @@ -24,7 +24,7 @@ namespace llarp { static auto logcat = llarp::log::Cat("lquic"); - static constexpr auto static_shared_key = "Lokinet static shared secret key"_usv; + static constexpr auto static_shared_key = "Lokinet static shared secret key"_usp; static static_secret make_static_secret(const Ed25519SecretKey& sk) { diff --git a/llarp/messages/exit.hpp b/llarp/messages/exit.hpp index f288fdf09f..f911b501f3 100644 --- a/llarp/messages/exit.hpp +++ b/llarp/messages/exit.hpp @@ -9,9 +9,7 @@ namespace llarp { /* TODO: - - ADD PUBKEY FIELD OR AT LEAST SEE WHY LINKMANAGER::HANDLE_OBTAIN_EXIT() LOOKS FOR ONE - - - change these parameters to ustringviews and ustrings where needed after bumping oxenc + - change these parameters to uspans where needed after bumping oxenc - change std::string sig(64, '\0') --> std::array sig */ diff --git a/llarp/util/buffer.hpp b/llarp/util/buffer.hpp index fbf7593cc6..ba0b98dd11 100644 --- a/llarp/util/buffer.hpp +++ b/llarp/util/buffer.hpp @@ -21,74 +21,27 @@ namespace llarp { - using const_cspan = oxenc::const_span; - using const_uspan = oxenc::const_span; - using const_span = oxenc::const_span; - - using old_cspan = std::span; - using old_uspan = std::span; - using old_bspan = std::span; + using cspan = oxenc::const_span; + using uspan = oxenc::const_span; + using span = oxenc::const_span; using ustring = std::basic_string; using ustring_view = std::basic_string_view; using bstring = std::basic_string; using bstring_view = std::basic_string_view; - namespace detail - { - template - struct bsv_literal - { - consteval bsv_literal(const char (&s)[N]) - { - for (size_t i = 0; i < N; i++) - str[i] = static_cast(s[i]); - } - std::byte str[N]; // we keep the null on the end, in case you pass .data() to a C func - using size = std::integral_constant; - }; - template - struct usv_literal - { - consteval usv_literal(const char (&s)[N]) - { - for (size_t i = 0; i < N; i++) - str[i] = static_cast(s[i]); - } - unsigned char str[N]; // we keep the null on the end, in case you pass .data() to a C func - using size = std::integral_constant; - }; - } // namespace detail - inline ustring operator""_us(const char* str, size_t len) noexcept { return {reinterpret_cast(str), len}; } - template - constexpr ustring_view operator""_usv() noexcept - { - return {UStr.str, decltype(UStr)::size::value}; - } - - template - constexpr bstring_view operator""_bsv() - { - return {BStr.str, decltype(BStr)::size::value}; - } - - inline bstring operator""_bs(const char* str, size_t len) noexcept - { - return {reinterpret_cast(str), len}; - } - // Helper function to switch between string_view and ustring_view inline ustring_view to_usv(std::string_view v) { return {reinterpret_cast(v.data()), v.size()}; } template - inline old_uspan to_uspan(std::basic_string& v) + inline std::span to_uspan(std::basic_string& v) { - return old_uspan{reinterpret_cast(v.data()), v.size()}; + return std::span{reinterpret_cast(v.data()), v.size()}; } } // namespace llarp