diff --git a/llarp/exit/session.hpp b/llarp/exit/session.hpp index b70d34bcd..fd36ce3da 100644 --- a/llarp/exit/session.hpp +++ b/llarp/exit/session.hpp @@ -32,6 +32,13 @@ namespace llarp util::StatusObject ExtractStatus() const override; + bool + ShouldBundleRC() const override + { + // TODO: make configurable + return false; + } + void HandlePathDied(llarp::path::Path* p) override; diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index 196159725..33f5c3e86 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -54,6 +54,7 @@ namespace llarp // current hop auto& hop = ctx->path->hops[ctx->idx]; auto& frame = ctx->LRCM.frames[ctx->idx]; + // generate key ctx->crypto->encryption_keygen(hop.commkey); hop.nonce.Randomize(); @@ -80,8 +81,9 @@ namespace llarp else { hop.upstream = ctx->path->hops[ctx->idx].rc.pubkey; - record.nextRC = - std::make_unique< RouterContact >(ctx->path->hops[ctx->idx].rc); + if(ctx->pathset->ShouldBundleRC()) + record.nextRC = + std::make_unique< RouterContact >(ctx->path->hops[ctx->idx].rc); } // build record diff --git a/llarp/path/pathbuilder.hpp b/llarp/path/pathbuilder.hpp index 87dc6d4b1..cd787a899 100644 --- a/llarp/path/pathbuilder.hpp +++ b/llarp/path/pathbuilder.hpp @@ -48,6 +48,10 @@ namespace llarp virtual bool ShouldBuildMore(llarp_time_t now) const override; + /// should we bundle RCs in builds? + virtual bool + ShouldBundleRC() const = 0; + /// return true if we hit our soft limit for building paths too fast bool BuildCooldownHit(llarp_time_t now) const; diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index c564ddb9f..2073db199 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -390,7 +390,7 @@ namespace llarp EnsureEncryptionKey(); bool - ConnectionToRouterAllowed(const RouterID &router) const; + ConnectionToRouterAllowed(const RouterID &router) const override; bool SaveRC(); diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 9175b09c2..73f6c8c78 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -12,7 +12,7 @@ #include #include #include - +#include #include namespace llarp @@ -57,6 +57,10 @@ namespace llarp if(val > 0) m_MinPathLatency = val; } + if(k == "bundle-rc") + { + m_BundleRC = IsTrueValue(v.c_str()); + } return true; } @@ -812,6 +816,12 @@ namespace llarp self->m_IsolatedLogic); } + bool + Endpoint::ShouldBundleRC() const + { + return m_BundleRC; + } + void Endpoint::PutNewOutboundContext(const llarp::service::IntroSet& introset) { diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index b80f9364c..7d10c96c1 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -214,6 +214,9 @@ namespace llarp using PendingBufferQueue = std::queue< PendingBuffer >; + bool + ShouldBundleRC() const override; + struct SendContext { SendContext(const ServiceInfo& ident, const Introduction& intro, @@ -280,6 +283,12 @@ namespace llarp util::StatusObject ExtractStatus() const override; + bool + ShouldBundleRC() const override + { + return m_Endpoint->ShouldBundleRC(); + } + bool Stop() override; @@ -494,6 +503,7 @@ namespace llarp std::string m_Keyfile; std::string m_Name; std::string m_NetNS; + bool m_BundleRC = false; using PendingTraffic = std::unordered_map< Address, PendingBufferQueue, Address::Hash >;