llarp::AbstractRouter

Inherits from std::enable_shared_from_this< AbstractRouter >

Inherited by llarp::Router

Public Functions

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

Protected Functions

Name
virtual void HandleRouterEvent(tooling::RouterEventPtr event) const =0
Virtual function to handle RouterEvent.

Public Functions Documentation

function ~AbstractRouter

virtual ~AbstractRouter() =default

function HandleRecvLinkMessageBuffer

virtual bool HandleRecvLinkMessageBuffer(
    ILinkSession * from,
    const llarp_buffer_t & msg
) =0

Reimplemented by: llarp::Router::HandleRecvLinkMessageBuffer

function Net

virtual const net::Platform & Net() const =0

Reimplemented by: llarp::Router::Net

function GetVPNPlatform

virtual vpn::Platform * GetVPNPlatform() const =0

Reimplemented by: llarp::Router::GetVPNPlatform

function dht

virtual llarp_dht_context * dht() const =0

Reimplemented by: llarp::Router::dht

function nodedb

virtual const std::shared_ptr< NodeDB > & nodedb() const =0

Reimplemented by: llarp::Router::nodedb

function pathContext

virtual const path::PathContext & pathContext() const =0

Reimplemented by: llarp::Router::pathContext

function pathContext

virtual path::PathContext & pathContext() =0

Reimplemented by: llarp::Router::pathContext

function rc

virtual const RouterContact & rc() const =0

Reimplemented by: llarp::Router::rc

function ModifyOurRC

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

Reimplemented by: llarp::Router::ModifyOurRC

function exitContext

virtual exit::Context & exitContext() =0

Reimplemented by: llarp::Router::exitContext

function keyManager

virtual const std::shared_ptr< KeyManager > & keyManager() const =0

Reimplemented by: llarp::Router::keyManager

function identity

virtual const SecretKey & identity() const =0

Reimplemented by: llarp::Router::identity

function encryption

virtual const SecretKey & encryption() const =0

Reimplemented by: llarp::Router::encryption

function routerProfiling

virtual Profiling & routerProfiling() =0

Reimplemented by: llarp::Router::routerProfiling

function loop

virtual const EventLoop_ptr & loop() const =0

Reimplemented by: llarp::Router::loop

function QueueWork

virtual void QueueWork(
    std::function< void(void)> 
) =0

call function in crypto worker

Reimplemented by: llarp::Router::QueueWork

function QueueDiskIO

virtual void QueueDiskIO(
    std::function< void(void)> 
) =0

call function in disk io thread

Reimplemented by: llarp::Router::QueueDiskIO

function GetConfig

inline virtual std::shared_ptr< Config > GetConfig() const

Reimplemented by: llarp::Router::GetConfig

function hiddenServiceContext

virtual service::Context & hiddenServiceContext() =0

Reimplemented by: llarp::Router::hiddenServiceContext

function hiddenServiceContext

virtual const service::Context & hiddenServiceContext() const =0

Reimplemented by: llarp::Router::hiddenServiceContext

function outboundMessageHandler

virtual IOutboundMessageHandler & outboundMessageHandler() =0

Reimplemented by: llarp::Router::outboundMessageHandler

function outboundSessionMaker

virtual IOutboundSessionMaker & outboundSessionMaker() =0

Reimplemented by: llarp::Router::outboundSessionMaker

function linkManager

virtual ILinkManager & linkManager() =0

Reimplemented by: llarp::Router::linkManager

function routePoker

virtual const std::shared_ptr< RoutePoker > & routePoker() const =0

Reimplemented by: llarp::Router::routePoker

function rcLookupHandler

virtual I_RCLookupHandler & rcLookupHandler() =0

Reimplemented by: llarp::Router::rcLookupHandler

function Sign

virtual bool Sign(
    Signature & sig,
    const llarp_buffer_t & buf
) const =0

Reimplemented by: llarp::Router::Sign

function Configure

virtual bool Configure(
    std::shared_ptr< Config > conf,
    bool isSNode,
    std::shared_ptr< NodeDB > nodedb
) =0

Reimplemented by: llarp::Router::Configure

function IsServiceNode

virtual bool IsServiceNode() const =0

Reimplemented by: llarp::Router::IsServiceNode

function OxendErrorState

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).

Reimplemented by: llarp::Router::OxendErrorState

Currently this means we require a decent number of peers whenever we are fully staked (active or decommed).

function Run

virtual bool Run() =0

Reimplemented by: llarp::Router::Run

function IsRunning

virtual bool IsRunning() const =0

Reimplemented by: llarp::Router::IsRunning

function LooksAlive

virtual bool LooksAlive() const =0

Reimplemented by: llarp::Router::LooksAlive

function Stop

virtual void Stop() =0

stop running the router logic gracefully

Reimplemented by: llarp::Router::Stop

function Freeze

virtual void Freeze() =0

indicate we are about to sleep for a while

Reimplemented by: llarp::Router::Freeze

function Thaw

virtual void Thaw() =0

thaw from long sleep or network changed event

Reimplemented by: llarp::Router::Thaw

function Die

virtual void Die() =0

non gracefully stop the router

Reimplemented by: llarp::Router::Die

function TriggerPump

virtual void TriggerPump() =0

Trigger a pump of low level links. Idempotent.

Reimplemented by: llarp::Router::TriggerPump

function IsBootstrapNode

virtual bool IsBootstrapNode(
    RouterID r
) const =0

Reimplemented by: llarp::Router::IsBootstrapNode

function TearDown

virtual void TearDown() =0

Issue immediate teardown of all resources.

Reimplemented by: llarp::Router::TearDown

function pubkey

virtual const byte_t * pubkey() const =0

Reimplemented by: llarp::Router::pubkey

function OurPublicIP

virtual std::optional< std::variant< nuint32_t, nuint128_t > > OurPublicIP() const =0

get what our real public ip is if we can know it

Reimplemented by: llarp::Router::OurPublicIP

function ConnectToRandomRouters

virtual void ConnectToRandomRouters(
    int N
) =0

connect to N random routers

Reimplemented by: llarp::Router::ConnectToRandomRouters

function TryConnectAsync

virtual bool TryConnectAsync(
    RouterContact rc,
    uint16_t tries
) =0

Reimplemented by: llarp::Router::TryConnectAsync

function SessionClosed

virtual void SessionClosed(
    RouterID remote
) =0

called by link when a remote session has no more sessions open

Reimplemented by: llarp::Router::SessionClosed

function Now

virtual llarp_time_t Now() const =0

returns system clock milliseconds since epoch

Reimplemented by: llarp::Router::Now

function Uptime

virtual llarp_time_t Uptime() const =0

returns milliseconds since started

Reimplemented by: llarp::Router::Uptime

function GetRandomGoodRouter

virtual bool GetRandomGoodRouter(
    RouterID & r
) =0

Reimplemented by: llarp::Router::GetRandomGoodRouter

function SendToOrQueue

virtual bool SendToOrQueue(
    const RouterID & remote,
    const ILinkMessage & msg,
    SendStatusHandler handler =nullptr
) =0

Reimplemented by: llarp::Router::SendToOrQueue

function PersistSessionUntil

virtual void PersistSessionUntil(
    const RouterID & remote,
    llarp_time_t until
) =0

Reimplemented by: llarp::Router::PersistSessionUntil

function ParseRoutingMessageBuffer

virtual bool ParseRoutingMessageBuffer(
    const llarp_buffer_t & buf,
    routing::IMessageHandler * h,
    const PathID_t & rxid
) =0

Reimplemented by: llarp::Router::ParseRoutingMessageBuffer

function NumberOfConnectedRouters

virtual size_t NumberOfConnectedRouters() const =0

count the number of service nodes we are connected to

Reimplemented by: llarp::Router::NumberOfConnectedRouters

function NumberOfConnectedClients

virtual size_t NumberOfConnectedClients() const =0

count the number of clients that are connected to us

Reimplemented by: llarp::Router::NumberOfConnectedClients

function GetRandomConnectedRouter

virtual bool GetRandomConnectedRouter(
    RouterContact & result
) const =0

Reimplemented by: llarp::Router::GetRandomConnectedRouter

function HandleDHTLookupForExplore

virtual void HandleDHTLookupForExplore(
    RouterID remote,
    const std::vector< RouterContact > & results
) =0

Reimplemented by: llarp::Router::HandleDHTLookupForExplore

function SetDownHook

inline virtual void SetDownHook(
    std::function< void(void)> 
)

Reimplemented by: llarp::Router::SetDownHook

function LookupRouter

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

Reimplemented by: llarp::Router::LookupRouter

function CheckRenegotiateValid

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

Reimplemented by: llarp::Router::CheckRenegotiateValid

function SetRouterWhitelist

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

Reimplemented by: llarp::Router::SetRouterWhitelist

function GetRouterWhitelist

virtual std::unordered_set< RouterID > GetRouterWhitelist() const =0

Reimplemented by: llarp::Router::GetRouterWhitelist

function ForEachPeer

virtual void ForEachPeer(
    std::function< void(const ILinkSession *, bool)> visit,
    bool randomize
) const =0

visit each connected link session

Reimplemented by: llarp::Router::ForEachPeer

function SessionToRouterAllowed

virtual bool SessionToRouterAllowed(
    const RouterID & router
) const =0

Reimplemented by: llarp::Router::SessionToRouterAllowed

function PathToRouterAllowed

virtual bool PathToRouterAllowed(
    const RouterID & router
) const =0

Reimplemented by: llarp::Router::PathToRouterAllowed

function HasClientExit

inline virtual bool HasClientExit() const

return true if we have an exit as a client

Reimplemented by: llarp::Router::HasClientExit

function pathBuildLimiter

virtual path::BuildLimiter & pathBuildLimiter() =0

Reimplemented by: llarp::Router::pathBuildLimiter

function HasSessionTo

virtual bool HasSessionTo(
    const RouterID & router
) const =0

return true if we have at least 1 session to this router in either direction

Reimplemented by: llarp::Router::HasSessionTo

function NextPathBuildNumber

virtual uint32_t NextPathBuildNumber() =0

Reimplemented by: llarp::Router::NextPathBuildNumber

function ShortName

virtual std::string ShortName() const =0

Reimplemented by: llarp::Router::ShortName

function GossipRCIfNeeded

virtual void GossipRCIfNeeded(
    const RouterContact rc
) =0

gossip an rc if required

Reimplemented by: llarp::Router::GossipRCIfNeeded

function status_line

virtual std::string status_line() =0

Reimplemented by: llarp::Router::status_line

function NotifyRouterEvent

template <class EventType ,
class... Params>
inline void NotifyRouterEvent(
    Params &&... args
) const

Templated convenience function to generate a RouterHive event and delegate to non-templated (and overridable) function for handling.

function OutboundUDPSocket

inline virtual int OutboundUDPSocket() const

Reimplemented by: llarp::Router::OutboundUDPSocket

Protected Functions Documentation

function HandleRouterEvent

virtual void HandleRouterEvent(
    tooling::RouterEventPtr event
) const =0

Virtual function to handle RouterEvent.

Reimplemented by: tooling::HiveRouter::HandleRouterEvent, llarp::Router::HandleRouterEvent

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


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