tooling::HiveRouter

HiveRouter is a subclass of Router which overrides specific behavior in order to perform testing-related functions. More...

#include <hive_router.hpp>

Inherits from llarp::Router, llarp::AbstractRouter, std::enable_shared_from_this< AbstractRouter >

Public Functions

Name
HiveRouter(llarp::EventLoop_ptr loop, std::shared_ptr< llarp::vpn::Platform > vpnPlatform, RouterHive * hive)
virtual ~HiveRouter() =default
virtual bool disableGossipingRC_TestingOnly() override
Override logic to prevent base Router class from gossiping its RC.
void disableGossiping()
void enableGossiping()

Protected Functions

Name
virtual void HandleRouterEvent(RouterEventPtr event) const override
Virtual function to handle RouterEvent.

Protected Attributes

Name
bool m_disableGossiping
RouterHive * m_hive

Additional inherited members

Public Types inherited from llarp::Router

Name
using std::chrono::steady_clock Clock_t
using Clock_t::time_point TimePoint_t

Public Functions inherited from llarp::Router

Name
virtual path::BuildLimiter & pathBuildLimiter() override
virtual const llarp::net::Platform & Net() const override
virtual llarp_dht_context * dht() const override
virtual std::optional< std::variant< nuint32_t, nuint128_t > > OurPublicIP() const override
get what our real public ip is if we can know it
virtual const std::shared_ptr< NodeDB > & nodedb() const override
virtual const path::PathContext & pathContext() const override
virtual path::PathContext & pathContext() override
virtual const RouterContact & rc() const override
virtual void TearDown() override
Issue immediate teardown of all resources.
virtual void ModifyOurRC(std::function< std::optional< RouterContact >(RouterContact)> modify) override
modify our rc modify returns nullopt if unmodified otherwise it returns the new rc to be sigend and published out
virtual void SetRouterWhitelist(const std::vector< RouterID > & whitelist, const std::vector< RouterID > & greylist, const std::vector< RouterID > & unfundedlist) override
set router's service node whitelist
virtual std::unordered_set< RouterID > GetRouterWhitelist() const override
virtual exit::Context & exitContext() override
virtual const std::shared_ptr< KeyManager > & keyManager() const override
virtual const SecretKey & identity() const override
virtual const SecretKey & encryption() const override
virtual Profiling & routerProfiling() override
virtual const EventLoop_ptr & loop() const override
virtual vpn::Platform * GetVPNPlatform() const override
virtual void QueueWork(std::function< void(void)> ) override
call function in crypto worker
virtual void QueueDiskIO(std::function< void(void)> ) override
call function in disk io thread
bool LooksDecommissioned() const
return true if we look like we are a decommissioned service node
bool LooksFunded() const
return true if we look like we are a registered, fully-staked service node (either active or decommissioned).
bool LooksRegistered() const
return true if we a registered service node; not that this only requires a partial stake, and does not imply that this service node is active or fully funded.
bool ShouldTestOtherRouters() const
return true if we look like we are allowed and able to test other routers
virtual llarp_time_t Uptime() const override
returns milliseconds since started
virtual bool Sign(Signature & sig, const llarp_buffer_t & buf) const override
virtual service::Context & hiddenServiceContext() override
virtual const service::Context & hiddenServiceContext() const override
virtual void SetDownHook(std::function< void(void)> hook) override
virtual bool LooksAlive() const override
virtual const std::shared_ptr< RoutePoker > & routePoker() const override
virtual void TriggerPump() override
Trigger a pump of low level links. Idempotent.
void PumpLL()
virtual std::string status_line() override
virtual IOutboundMessageHandler & outboundMessageHandler() override
virtual IOutboundSessionMaker & outboundSessionMaker() override
virtual ILinkManager & linkManager() override
virtual I_RCLookupHandler & rcLookupHandler() override
virtual int OutboundUDPSocket() const override
virtual void GossipRCIfNeeded(const RouterContact rc) override
gossip an rc if required
Router(EventLoop_ptr loop, std::shared_ptr< vpn::Platform > vpnPlatform)
~Router() override
virtual bool HandleRecvLinkMessageBuffer(ILinkSession * from, const llarp_buffer_t & msg) override
void InitInboundLinks()
void InitOutboundLinks()
virtual bool GetRandomGoodRouter(RouterID & r) override
bool InitServiceNode()
initialize us as a service node return true on success
virtual bool IsRunning() const override
virtual bool IsServiceNode() const override
return true if we are running in service node mode
virtual std::optional< std::string > OxendErrorState() const override
Called to determine if we're in a bad state (which gets reported to our oxend) that should prevent uptime proofs from going out to the network (so that the error state gets noticed).
void Close()
virtual bool Configure(std::shared_ptr< Config > conf, bool isSNode, std::shared_ptr< NodeDB > nodedb) override
virtual void Freeze() override
indicate we are about to sleep for a while
virtual void Thaw() override
thaw from long sleep or network changed event
virtual bool Run() override
virtual void Stop() override
stop running the router logic gracefully
virtual void Die() override
non graceful stop router
void StopLinks()
close all sessions and shutdown all links
virtual void PersistSessionUntil(const RouterID & remote, llarp_time_t until) override
bool EnsureIdentity()
bool EnsureEncryptionKey()
virtual bool SessionToRouterAllowed(const RouterID & router) const override
virtual bool PathToRouterAllowed(const RouterID & router) const override
void HandleSaveRC() const
bool SaveRC()
virtual bool HasClientExit() const override
return true if we are a client with an exit configured
virtual const byte_t * pubkey() const override
void try_connect(fs::path rcfile)
virtual bool TryConnectAsync(RouterContact rc, uint16_t tries) override
virtual bool SendToOrQueue(const RouterID & remote, const ILinkMessage & msg, SendStatusHandler handler) override
send to remote router or queue for sending returns false on overflow returns true on successful queue NOT threadsafe MUST be called in the logic thread
virtual void ForEachPeer(std::function< void(const ILinkSession *, bool)> visit, bool randomize =false) const override
visit each connected link session
void ForEachPeer(std::function< void(ILinkSession *)> visit)
virtual bool IsBootstrapNode(RouterID ) const override
virtual bool CheckRenegotiateValid(RouterContact newRc, RouterContact oldRC) override
check if newRc matches oldRC and update local rc for this remote contact if valid returns true on valid and updated returns false otherwise
virtual void SessionClosed(RouterID remote) override
called by link when a remote session has no more sessions open
void ConnectionTimedOut(ILinkSession * session)
called by link when an unestablished connection times out
bool ConnectionEstablished(ILinkSession * session, bool inbound)
called by link when session is fully established
void Tick()
call internal router ticker
virtual llarp_time_t Now() const override
returns system clock milliseconds since epoch
virtual bool ParseRoutingMessageBuffer(const llarp_buffer_t & buf, routing::IMessageHandler * h, const PathID_t & rxid) override
parse a routing message in a buffer and handle it with a handler if successful parsing return true on parse and handle success otherwise return false
virtual void ConnectToRandomRouters(int N) override
connect to N random routers
virtual size_t NumberOfConnectedRouters() const override
count the number of unique service nodes connected via pubkey
virtual size_t NumberOfConnectedClients() const override
count the number of unique clients connected by pubkey
virtual bool GetRandomConnectedRouter(RouterContact & result) const override
virtual void HandleDHTLookupForExplore(RouterID remote, const std::vector< RouterContact > & results) override
virtual void LookupRouter(RouterID remote, RouterLookupHandler resultHandler) override
lookup router by pubkey if we are a service node this is done direct otherwise it's done via path
virtual bool HasSessionTo(const RouterID & router) const override
return true if we have at least 1 session to this router in either direction
virtual std::string ShortName() const override
virtual uint32_t NextPathBuildNumber() override
void AfterStopLinks()
void AfterStopIssued()
virtual std::shared_ptr< Config > GetConfig() const override

Public Attributes inherited from llarp::Router

Name
llarp_time_t _lastPump
bool ready
fs::path transport_keyfile
fs::path ident_keyfile
fs::path encryption_keyfile
fs::path our_rc_file
bool m_UseFileLogging
RouterContact _rc
bool whitelistRouters
should we obey the service node whitelist?
path::BuildLimiter m_PathBuildLimiter
std::shared_ptr< EventLoopWakeup > m_Pump
std::unique_ptr< EventLoopWork > m_CurrentEvLoopWork
std::shared_ptr< EventLoopWakeup > m_LoopWorkPumper
std::optional< SockAddr > _ourAddress
EventLoop_ptr _loop
std::shared_ptr< vpn::Platform > _vpnPlatform
path::PathContext paths
exit::Context _exitContext
SecretKey _identity
SecretKey _encryption
llarp_dht_context * _dht
std::shared_ptr< NodeDB > _nodedb
llarp_time_t _startedAt
llarp_time_t rcRegenInterval
how often do we resign our RC? milliseconds.
bool sendPadding
LinkMessageParser inbound_link_msg_parser
routing::InboundMessageParser inbound_routing_msg_parser
service::Context _hiddenServiceContext
llarp_time_t _lastTick
std::function< void(void)> _onDown
BootstrapList bootstrapRCList
bootstrap RCs
std::shared_ptr< RoutePoker > m_RoutePoker
const llarp_time_t _randomStartDelay
Profiling _routerProfiling
fs::path _profilesFile
OutboundMessageHandler _outboundMessageHandler
OutboundSessionMaker _outboundSessionMaker
LinkManager _linkManager
RCLookupHandler _rcLookupHandler
RCGossiper _rcGossiper
TimePoint_t m_NextExploreAt
std::shared_ptr< Config > m_Config
int m_OutboundUDPSocket

Public Functions inherited from llarp::AbstractRouter

Name
virtual ~AbstractRouter() =default
virtual bool HandleRecvLinkMessageBuffer(ILinkSession * from, const llarp_buffer_t & msg) =0
virtual const net::Platform & Net() const =0
virtual vpn::Platform * GetVPNPlatform() const =0
virtual llarp_dht_context * dht() const =0
virtual const std::shared_ptr< NodeDB > & nodedb() const =0
virtual const path::PathContext & pathContext() const =0
virtual path::PathContext & pathContext() =0
virtual const RouterContact & rc() const =0
virtual void ModifyOurRC(std::function< std::optional< RouterContact >(RouterContact)> modify) =0
modify our rc modify returns nullopt if unmodified otherwise it returns the new rc to be sigend and published out
virtual exit::Context & exitContext() =0
virtual const std::shared_ptr< KeyManager > & keyManager() const =0
virtual const SecretKey & identity() const =0
virtual const SecretKey & encryption() const =0
virtual Profiling & routerProfiling() =0
virtual const EventLoop_ptr & loop() const =0
virtual void QueueWork(std::function< void(void)> ) =0
call function in crypto worker
virtual void QueueDiskIO(std::function< void(void)> ) =0
call function in disk io thread
virtual std::shared_ptr< Config > GetConfig() const
virtual service::Context & hiddenServiceContext() =0
virtual const service::Context & hiddenServiceContext() const =0
virtual IOutboundMessageHandler & outboundMessageHandler() =0
virtual IOutboundSessionMaker & outboundSessionMaker() =0
virtual ILinkManager & linkManager() =0
virtual const std::shared_ptr< RoutePoker > & routePoker() const =0
virtual I_RCLookupHandler & rcLookupHandler() =0
virtual bool Sign(Signature & sig, const llarp_buffer_t & buf) const =0
virtual bool Configure(std::shared_ptr< Config > conf, bool isSNode, std::shared_ptr< NodeDB > nodedb) =0
virtual bool IsServiceNode() const =0
virtual std::optional< std::string > OxendErrorState() const =0
Called to determine if we're in a bad state (which gets reported to our oxend) that should prevent uptime proofs from going out to the network (so that the error state gets noticed).
virtual bool Run() =0
virtual bool IsRunning() const =0
virtual bool LooksAlive() const =0
virtual void Stop() =0
stop running the router logic gracefully
virtual void Freeze() =0
indicate we are about to sleep for a while
virtual void Thaw() =0
thaw from long sleep or network changed event
virtual void Die() =0
non gracefully stop the router
virtual void TriggerPump() =0
Trigger a pump of low level links. Idempotent.
virtual bool IsBootstrapNode(RouterID r) const =0
virtual void TearDown() =0
Issue immediate teardown of all resources.
virtual const byte_t * pubkey() const =0
virtual std::optional< std::variant< nuint32_t, nuint128_t > > OurPublicIP() const =0
get what our real public ip is if we can know it
virtual void ConnectToRandomRouters(int N) =0
connect to N random routers
virtual bool TryConnectAsync(RouterContact rc, uint16_t tries) =0
virtual void SessionClosed(RouterID remote) =0
called by link when a remote session has no more sessions open
virtual llarp_time_t Now() const =0
returns system clock milliseconds since epoch
virtual llarp_time_t Uptime() const =0
returns milliseconds since started
virtual bool GetRandomGoodRouter(RouterID & r) =0
virtual bool SendToOrQueue(const RouterID & remote, const ILinkMessage & msg, SendStatusHandler handler =nullptr) =0
virtual void PersistSessionUntil(const RouterID & remote, llarp_time_t until) =0
virtual bool ParseRoutingMessageBuffer(const llarp_buffer_t & buf, routing::IMessageHandler * h, const PathID_t & rxid) =0
virtual size_t NumberOfConnectedRouters() const =0
count the number of service nodes we are connected to
virtual size_t NumberOfConnectedClients() const =0
count the number of clients that are connected to us
virtual bool GetRandomConnectedRouter(RouterContact & result) const =0
virtual void HandleDHTLookupForExplore(RouterID remote, const std::vector< RouterContact > & results) =0
virtual void SetDownHook(std::function< void(void)> )
virtual void LookupRouter(RouterID remote, RouterLookupHandler resultHandler) =0
lookup router by pubkey if we are a service node this is done direct otherwise it's done via path
virtual bool CheckRenegotiateValid(RouterContact newRc, RouterContact oldRC) =0
check if newRc matches oldRC and update local rc for this remote contact if valid returns true on valid and updated returns false otherwise
virtual void SetRouterWhitelist(const std::vector< RouterID > & whitelist, const std::vector< RouterID > & greylist, const std::vector< RouterID > & unfundedlist) =0
set router's service node whitelist
virtual std::unordered_set< RouterID > GetRouterWhitelist() const =0
virtual void ForEachPeer(std::function< void(const ILinkSession *, bool)> visit, bool randomize) const =0
visit each connected link session
virtual bool SessionToRouterAllowed(const RouterID & router) const =0
virtual bool PathToRouterAllowed(const RouterID & router) const =0
virtual bool HasClientExit() const
return true if we have an exit as a client
virtual path::BuildLimiter & pathBuildLimiter() =0
virtual bool HasSessionTo(const RouterID & router) const =0
return true if we have at least 1 session to this router in either direction
virtual uint32_t NextPathBuildNumber() =0
virtual std::string ShortName() const =0
virtual void GossipRCIfNeeded(const RouterContact rc) =0
gossip an rc if required
virtual std::string status_line() =0
template <class EventType ,class... Params>
void
NotifyRouterEvent(Params &&... args) const
Templated convenience function to generate a RouterHive event and delegate to non-templated (and overridable) function for handling.
virtual int OutboundUDPSocket() const

Detailed Description

struct tooling::HiveRouter;

HiveRouter is a subclass of Router which overrides specific behavior in order to perform testing-related functions.

It exists largely to prevent this behavior (which may often be "dangerous") from leaking into release code.

Public Functions Documentation

function HiveRouter

explicit HiveRouter(
    llarp::EventLoop_ptr loop,
    std::shared_ptr< llarp::vpn::Platform > vpnPlatform,
    RouterHive * hive
)

function ~HiveRouter

virtual ~HiveRouter() =default

function disableGossipingRC_TestingOnly

virtual bool disableGossipingRC_TestingOnly() override

Override logic to prevent base Router class from gossiping its RC.

Reimplements: llarp::Router::disableGossipingRC_TestingOnly

function disableGossiping

void disableGossiping()

function enableGossiping

void enableGossiping()

Protected Functions Documentation

function HandleRouterEvent

virtual void HandleRouterEvent(
    RouterEventPtr event
) const override

Virtual function to handle RouterEvent.

Reimplements: llarp::Router::HandleRouterEvent

HiveRouter overrides this in order to inject the event. The default implementation in Router simply logs it.

Protected Attributes Documentation

variable m_disableGossiping

bool m_disableGossiping = false;

variable m_hive

RouterHive * m_hive = nullptr;

Updated on 2026-01-10 at 22:49:45 +0000