2019-02-11 19:45:42 +00:00
|
|
|
#ifndef LLARP_ABSTRACT_ROUTER_HPP
|
|
|
|
#define LLARP_ABSTRACT_ROUTER_HPP
|
|
|
|
|
2019-12-06 18:21:14 +00:00
|
|
|
#include <config/key_manager.hpp>
|
|
|
|
#include <memory>
|
2019-02-11 19:45:42 +00:00
|
|
|
#include <util/types.hpp>
|
2019-02-15 22:19:19 +00:00
|
|
|
#include <util/status.hpp>
|
2019-06-04 18:31:17 +00:00
|
|
|
#include <router/i_outbound_message_handler.hpp>
|
2019-02-11 19:45:42 +00:00
|
|
|
#include <vector>
|
2019-04-08 12:01:52 +00:00
|
|
|
#include <ev/ev.h>
|
2019-05-03 13:15:03 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <router_contact.hpp>
|
2019-02-11 19:45:42 +00:00
|
|
|
|
|
|
|
struct llarp_buffer_t;
|
|
|
|
struct llarp_dht_context;
|
|
|
|
struct llarp_nodedb;
|
|
|
|
struct llarp_threadpool;
|
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
class Logic;
|
2019-02-22 16:21:05 +00:00
|
|
|
struct Config;
|
2019-02-11 19:45:42 +00:00
|
|
|
struct RouterID;
|
|
|
|
struct ILinkMessage;
|
|
|
|
struct ILinkSession;
|
|
|
|
struct PathID_t;
|
|
|
|
struct Profiling;
|
|
|
|
struct SecretKey;
|
|
|
|
struct Signature;
|
2019-06-26 21:39:29 +00:00
|
|
|
struct IOutboundMessageHandler;
|
|
|
|
struct IOutboundSessionMaker;
|
|
|
|
struct ILinkManager;
|
|
|
|
struct I_RCLookupHandler;
|
2019-02-11 19:45:42 +00:00
|
|
|
|
|
|
|
namespace exit
|
|
|
|
{
|
|
|
|
struct Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace path
|
|
|
|
{
|
|
|
|
struct PathContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace routing
|
|
|
|
{
|
|
|
|
struct IMessageHandler;
|
|
|
|
}
|
|
|
|
|
2019-02-22 17:18:54 +00:00
|
|
|
namespace service
|
|
|
|
{
|
2019-02-22 16:21:05 +00:00
|
|
|
struct Context;
|
|
|
|
}
|
|
|
|
|
2019-05-18 18:46:49 +00:00
|
|
|
namespace thread
|
|
|
|
{
|
|
|
|
class ThreadPool;
|
|
|
|
}
|
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
struct AbstractRouter
|
2019-02-11 19:45:42 +00:00
|
|
|
{
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual ~AbstractRouter() = default;
|
2019-02-11 19:45:42 +00:00
|
|
|
|
|
|
|
virtual bool
|
|
|
|
HandleRecvLinkMessageBuffer(ILinkSession *from,
|
|
|
|
const llarp_buffer_t &msg) = 0;
|
|
|
|
|
2019-05-22 16:20:50 +00:00
|
|
|
virtual std::shared_ptr< Logic >
|
2019-02-11 19:45:42 +00:00
|
|
|
logic() const = 0;
|
|
|
|
|
|
|
|
virtual llarp_dht_context *
|
|
|
|
dht() const = 0;
|
|
|
|
|
|
|
|
virtual llarp_nodedb *
|
|
|
|
nodedb() const = 0;
|
|
|
|
|
|
|
|
virtual const path::PathContext &
|
|
|
|
pathContext() const = 0;
|
|
|
|
|
|
|
|
virtual path::PathContext &
|
|
|
|
pathContext() = 0;
|
|
|
|
|
|
|
|
virtual const RouterContact &
|
|
|
|
rc() const = 0;
|
|
|
|
|
|
|
|
virtual exit::Context &
|
|
|
|
exitContext() = 0;
|
|
|
|
|
2019-12-06 18:21:14 +00:00
|
|
|
virtual std::shared_ptr< KeyManager >
|
|
|
|
keyManager() const = 0;
|
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual const SecretKey &
|
|
|
|
identity() const = 0;
|
|
|
|
|
|
|
|
virtual const SecretKey &
|
|
|
|
encryption() const = 0;
|
|
|
|
|
|
|
|
virtual Profiling &
|
|
|
|
routerProfiling() = 0;
|
|
|
|
|
2019-04-08 12:01:52 +00:00
|
|
|
virtual llarp_ev_loop_ptr
|
2019-02-11 19:45:42 +00:00
|
|
|
netloop() const = 0;
|
|
|
|
|
2019-07-09 13:47:24 +00:00
|
|
|
virtual std::shared_ptr< thread::ThreadPool >
|
2019-02-11 19:45:42 +00:00
|
|
|
threadpool() = 0;
|
|
|
|
|
2019-07-09 13:47:24 +00:00
|
|
|
virtual std::shared_ptr< thread::ThreadPool >
|
2019-02-11 19:45:42 +00:00
|
|
|
diskworker() = 0;
|
|
|
|
|
2019-02-22 16:21:05 +00:00
|
|
|
virtual service::Context &
|
|
|
|
hiddenServiceContext() = 0;
|
|
|
|
|
|
|
|
virtual const service::Context &
|
|
|
|
hiddenServiceContext() const = 0;
|
|
|
|
|
2019-06-26 21:39:29 +00:00
|
|
|
virtual IOutboundMessageHandler &
|
|
|
|
outboundMessageHandler() = 0;
|
|
|
|
|
|
|
|
virtual IOutboundSessionMaker &
|
|
|
|
outboundSessionMaker() = 0;
|
|
|
|
|
|
|
|
virtual ILinkManager &
|
|
|
|
linkManager() = 0;
|
|
|
|
|
|
|
|
virtual I_RCLookupHandler &
|
|
|
|
rcLookupHandler() = 0;
|
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual bool
|
|
|
|
Sign(Signature &sig, const llarp_buffer_t &buf) const = 0;
|
|
|
|
|
2019-02-22 16:21:05 +00:00
|
|
|
virtual bool
|
2019-06-26 21:39:29 +00:00
|
|
|
Configure(Config *conf, llarp_nodedb *nodedb) = 0;
|
2019-02-22 16:21:05 +00:00
|
|
|
|
2020-01-06 23:13:23 +00:00
|
|
|
virtual bool
|
|
|
|
IsServiceNode() const = 0;
|
|
|
|
|
2019-02-22 16:21:05 +00:00
|
|
|
virtual bool
|
2019-10-04 09:10:55 +00:00
|
|
|
StartJsonRpc() = 0;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
Run() = 0;
|
2019-02-22 16:21:05 +00:00
|
|
|
|
2019-10-09 13:08:38 +00:00
|
|
|
virtual bool
|
|
|
|
IsRunning() const = 0;
|
|
|
|
|
2019-12-07 19:58:19 +00:00
|
|
|
virtual bool
|
|
|
|
LooksAlive() const = 0;
|
|
|
|
|
2019-02-22 16:21:05 +00:00
|
|
|
/// stop running the router logic gracefully
|
|
|
|
virtual void
|
|
|
|
Stop() = 0;
|
|
|
|
|
2019-04-30 16:07:17 +00:00
|
|
|
/// pump low level links
|
|
|
|
virtual void
|
|
|
|
PumpLL() = 0;
|
|
|
|
|
2019-04-03 19:05:44 +00:00
|
|
|
virtual bool
|
|
|
|
IsBootstrapNode(RouterID r) const = 0;
|
2019-04-08 12:01:52 +00:00
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual const byte_t *
|
|
|
|
pubkey() const = 0;
|
|
|
|
|
2019-02-20 12:09:18 +00:00
|
|
|
/// connect to N random routers
|
|
|
|
virtual void
|
|
|
|
ConnectToRandomRouters(int N) = 0;
|
2019-02-22 16:21:05 +00:00
|
|
|
/// inject configuration and reconfigure router
|
|
|
|
virtual bool
|
|
|
|
Reconfigure(Config *conf) = 0;
|
|
|
|
|
2019-05-03 13:15:03 +00:00
|
|
|
virtual bool
|
|
|
|
TryConnectAsync(RouterContact rc, uint16_t tries) = 0;
|
|
|
|
|
2019-02-22 16:21:05 +00:00
|
|
|
/// validate new configuration against old one
|
|
|
|
/// return true on 100% valid
|
|
|
|
/// return false if not 100% valid
|
|
|
|
virtual bool
|
|
|
|
ValidateConfig(Config *conf) const = 0;
|
2019-02-20 12:09:18 +00:00
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
/// called by link when a remote session has no more sessions open
|
|
|
|
virtual void
|
|
|
|
SessionClosed(RouterID remote) = 0;
|
|
|
|
|
2019-04-22 12:25:25 +00:00
|
|
|
/// returns system clock milliseconds since epoch
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual llarp_time_t
|
|
|
|
Now() const = 0;
|
|
|
|
|
2019-04-22 12:25:25 +00:00
|
|
|
/// returns milliseconds since started
|
|
|
|
virtual llarp_time_t
|
|
|
|
Uptime() const = 0;
|
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual bool
|
|
|
|
GetRandomGoodRouter(RouterID &r) = 0;
|
|
|
|
|
|
|
|
virtual bool
|
2019-06-04 18:31:17 +00:00
|
|
|
SendToOrQueue(const RouterID &remote, const ILinkMessage *msg,
|
|
|
|
SendStatusHandler handler = nullptr) = 0;
|
2019-02-11 19:45:42 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2019-05-09 15:36:39 +00:00
|
|
|
/// count the number of service nodes we are connected to
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual size_t
|
|
|
|
NumberOfConnectedRouters() const = 0;
|
|
|
|
|
2019-05-09 15:36:39 +00:00
|
|
|
/// count the number of clients that are connected to us
|
|
|
|
virtual size_t
|
|
|
|
NumberOfConnectedClients() const = 0;
|
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
virtual bool
|
|
|
|
GetRandomConnectedRouter(RouterContact &result) const = 0;
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
HandleDHTLookupForExplore(RouterID remote,
|
|
|
|
const std::vector< RouterContact > &results) = 0;
|
|
|
|
|
2019-03-31 15:09:59 +00:00
|
|
|
/// lookup router by pubkey
|
|
|
|
/// if we are a service node this is done direct otherwise it's done via
|
|
|
|
/// path
|
|
|
|
virtual void
|
2019-05-03 13:15:03 +00:00
|
|
|
LookupRouter(RouterID remote, RouterLookupHandler resultHandler) = 0;
|
2019-03-31 15:09:59 +00:00
|
|
|
|
2019-02-11 19:45:42 +00:00
|
|
|
/// 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 bool
|
|
|
|
CheckRenegotiateValid(RouterContact newRc, RouterContact oldRC) = 0;
|
2019-02-15 22:19:19 +00:00
|
|
|
|
|
|
|
/// set router's service node whitelist
|
2019-02-18 19:44:41 +00:00
|
|
|
virtual void
|
|
|
|
SetRouterWhitelist(const std::vector< RouterID > &routers) = 0;
|
2019-02-15 22:19:19 +00:00
|
|
|
|
2019-02-18 19:44:41 +00:00
|
|
|
/// visit each connected link session
|
2019-02-15 22:19:19 +00:00
|
|
|
virtual void
|
2019-04-08 12:01:52 +00:00
|
|
|
ForEachPeer(std::function< void(const ILinkSession *, bool) > visit,
|
|
|
|
bool randomize) const = 0;
|
2019-04-17 19:05:54 +00:00
|
|
|
|
|
|
|
virtual bool
|
|
|
|
ConnectionToRouterAllowed(const RouterID &router) const = 0;
|
2019-04-19 15:10:26 +00:00
|
|
|
|
2019-05-28 11:35:26 +00:00
|
|
|
/// return true if we have at least 1 session to this router in either
|
|
|
|
/// direction
|
2019-05-27 19:01:09 +00:00
|
|
|
virtual bool
|
2019-05-28 11:35:26 +00:00
|
|
|
HasSessionTo(const RouterID &router) const = 0;
|
2019-05-27 19:01:09 +00:00
|
|
|
|
2019-04-19 15:10:26 +00:00
|
|
|
virtual util::StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2019-05-28 11:35:26 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
EnsureRouter(RouterID router, RouterLookupHandler handler);
|
2019-02-11 19:45:42 +00:00
|
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|