mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
llarp::Context uses AbstractRouter now
This commit is contained in:
parent
13a9f65520
commit
89ae60cfab
|
@ -18,7 +18,7 @@ namespace llarp
|
||||||
struct Config;
|
struct Config;
|
||||||
struct Crypto;
|
struct Crypto;
|
||||||
class Logic;
|
class Logic;
|
||||||
struct Router;
|
struct AbstractRouter;
|
||||||
struct RouterContact;
|
struct RouterContact;
|
||||||
|
|
||||||
struct Context
|
struct Context
|
||||||
|
@ -28,7 +28,7 @@ namespace llarp
|
||||||
int num_nethreads = 1;
|
int num_nethreads = 1;
|
||||||
bool singleThreaded = false;
|
bool singleThreaded = false;
|
||||||
std::unique_ptr< llarp::Crypto > crypto;
|
std::unique_ptr< llarp::Crypto > crypto;
|
||||||
std::unique_ptr< llarp::Router > router;
|
std::unique_ptr< llarp::AbstractRouter > router;
|
||||||
std::unique_ptr< llarp_threadpool > worker;
|
std::unique_ptr< llarp_threadpool > worker;
|
||||||
std::unique_ptr< llarp::Logic > logic;
|
std::unique_ptr< llarp::Logic > logic;
|
||||||
std::unique_ptr< llarp::Config > config;
|
std::unique_ptr< llarp::Config > config;
|
||||||
|
|
|
@ -97,7 +97,8 @@ namespace llarp
|
||||||
Context::LoadDatabase()
|
Context::LoadDatabase()
|
||||||
{
|
{
|
||||||
crypto = std::make_unique< sodium::CryptoLibSodium >();
|
crypto = std::make_unique< sodium::CryptoLibSodium >();
|
||||||
nodedb = std::make_unique< llarp_nodedb >(crypto.get(), router->disk);
|
nodedb =
|
||||||
|
std::make_unique< llarp_nodedb >(crypto.get(), router->diskworker());
|
||||||
|
|
||||||
if(!llarp_nodedb::ensure_dir(nodedb_dir.c_str()))
|
if(!llarp_nodedb::ensure_dir(nodedb_dir.c_str()))
|
||||||
{
|
{
|
||||||
|
@ -360,7 +361,7 @@ extern "C"
|
||||||
llarp_main_inject_vpn_fd(struct llarp_main *ptr, int fd)
|
llarp_main_inject_vpn_fd(struct llarp_main *ptr, int fd)
|
||||||
{
|
{
|
||||||
llarp::handlers::TunEndpoint *tun =
|
llarp::handlers::TunEndpoint *tun =
|
||||||
ptr->ctx->router->hiddenServiceContext.getFirstTun();
|
ptr->ctx->router->hiddenServiceContext().getFirstTun();
|
||||||
if(!tun)
|
if(!tun)
|
||||||
return;
|
return;
|
||||||
if(!tun->Promise)
|
if(!tun->Promise)
|
||||||
|
@ -507,15 +508,15 @@ extern "C"
|
||||||
main_router_prefetch(struct llarp_main *ptr,
|
main_router_prefetch(struct llarp_main *ptr,
|
||||||
const llarp::service::Address &addr)
|
const llarp::service::Address &addr)
|
||||||
{
|
{
|
||||||
auto *endpoint = &ptr->ctx->router->hiddenServiceContext;
|
auto &endpoint = ptr->ctx->router->hiddenServiceContext();
|
||||||
return endpoint->Prefetch(addr);
|
return endpoint.Prefetch(addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
llarp::handlers::TunEndpoint *
|
llarp::handlers::TunEndpoint *
|
||||||
main_router_getFirstTunEndpoint(struct llarp_main *ptr)
|
main_router_getFirstTunEndpoint(struct llarp_main *ptr)
|
||||||
{
|
{
|
||||||
if(ptr && ptr->ctx && ptr->ctx->router)
|
if(ptr && ptr->ctx && ptr->ctx->router)
|
||||||
return ptr->ctx->router->hiddenServiceContext.getFirstTun();
|
return ptr->ctx->router->hiddenServiceContext().getFirstTun();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,15 +524,13 @@ extern "C"
|
||||||
main_router_endpoint_iterator(
|
main_router_endpoint_iterator(
|
||||||
struct llarp_main *ptr, struct llarp::service::Context::endpoint_iter &i)
|
struct llarp_main *ptr, struct llarp::service::Context::endpoint_iter &i)
|
||||||
{
|
{
|
||||||
auto *context = &ptr->ctx->router->hiddenServiceContext;
|
return ptr->ctx->router->hiddenServiceContext().iterate(i);
|
||||||
return context->iterate(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
llarp_tun_io *
|
llarp_tun_io *
|
||||||
main_router_getRange(struct llarp_main *ptr)
|
main_router_getRange(struct llarp_main *ptr)
|
||||||
{
|
{
|
||||||
auto *context = &ptr->ctx->router->hiddenServiceContext;
|
return ptr->ctx->router->hiddenServiceContext().getRange();
|
||||||
return context->getRange();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
|
@ -13,8 +13,9 @@ struct llarp_threadpool;
|
||||||
|
|
||||||
namespace llarp
|
namespace llarp
|
||||||
{
|
{
|
||||||
struct Crypto;
|
|
||||||
class Logic;
|
class Logic;
|
||||||
|
struct Config;
|
||||||
|
struct Crypto;
|
||||||
struct RouterContact;
|
struct RouterContact;
|
||||||
struct RouterID;
|
struct RouterID;
|
||||||
struct ILinkMessage;
|
struct ILinkMessage;
|
||||||
|
@ -39,6 +40,10 @@ namespace llarp
|
||||||
struct IMessageHandler;
|
struct IMessageHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace service {
|
||||||
|
struct Context;
|
||||||
|
}
|
||||||
|
|
||||||
struct AbstractRouter : public util::IStateful
|
struct AbstractRouter : public util::IStateful
|
||||||
{
|
{
|
||||||
virtual void
|
virtual void
|
||||||
|
@ -90,15 +95,41 @@ namespace llarp
|
||||||
virtual llarp_threadpool *
|
virtual llarp_threadpool *
|
||||||
diskworker() = 0;
|
diskworker() = 0;
|
||||||
|
|
||||||
|
virtual service::Context &
|
||||||
|
hiddenServiceContext() = 0;
|
||||||
|
|
||||||
|
virtual const service::Context &
|
||||||
|
hiddenServiceContext() const = 0;
|
||||||
|
|
||||||
virtual bool
|
virtual bool
|
||||||
Sign(Signature &sig, const llarp_buffer_t &buf) const = 0;
|
Sign(Signature &sig, const llarp_buffer_t &buf) const = 0;
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
Configure(Config *conf) = 0;
|
||||||
|
|
||||||
|
virtual bool
|
||||||
|
Run(struct llarp_nodedb *nodedb) = 0;
|
||||||
|
|
||||||
|
/// stop running the router logic gracefully
|
||||||
|
virtual void
|
||||||
|
Stop() = 0;
|
||||||
|
|
||||||
virtual const byte_t *
|
virtual const byte_t *
|
||||||
pubkey() const = 0;
|
pubkey() const = 0;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
OnConnectTimeout(ILinkSession *session) = 0;
|
OnConnectTimeout(ILinkSession *session) = 0;
|
||||||
|
|
||||||
|
/// inject configuration and reconfigure router
|
||||||
|
virtual bool
|
||||||
|
Reconfigure(Config *conf) = 0;
|
||||||
|
|
||||||
|
/// validate new configuration against old one
|
||||||
|
/// return true on 100% valid
|
||||||
|
/// return false if not 100% valid
|
||||||
|
virtual bool
|
||||||
|
ValidateConfig(Config *conf) const = 0;
|
||||||
|
|
||||||
/// called by link when a remote session has no more sessions open
|
/// called by link when a remote session has no more sessions open
|
||||||
virtual void
|
virtual void
|
||||||
SessionClosed(RouterID remote) = 0;
|
SessionClosed(RouterID remote) = 0;
|
||||||
|
|
|
@ -210,7 +210,7 @@ namespace llarp
|
||||||
, _exitContext(this)
|
, _exitContext(this)
|
||||||
, _dht(llarp_dht_context_new(this))
|
, _dht(llarp_dht_context_new(this))
|
||||||
, inbound_link_msg_parser(this)
|
, inbound_link_msg_parser(this)
|
||||||
, hiddenServiceContext(this)
|
, _hiddenServiceContext(this)
|
||||||
{
|
{
|
||||||
// set rational defaults
|
// set rational defaults
|
||||||
this->ip4addr.sin_family = AF_INET;
|
this->ip4addr.sin_family = AF_INET;
|
||||||
|
@ -234,7 +234,7 @@ namespace llarp
|
||||||
Router::ExtractStatus() const
|
Router::ExtractStatus() const
|
||||||
{
|
{
|
||||||
util::StatusObject obj{{"dht", _dht->impl->ExtractStatus()},
|
util::StatusObject obj{{"dht", _dht->impl->ExtractStatus()},
|
||||||
{"services", hiddenServiceContext.ExtractStatus()},
|
{"services", _hiddenServiceContext.ExtractStatus()},
|
||||||
{"exit", _exitContext.ExtractStatus()}};
|
{"exit", _exitContext.ExtractStatus()}};
|
||||||
std::vector< util::StatusObject > ob_links, ib_links;
|
std::vector< util::StatusObject > ob_links, ib_links;
|
||||||
std::transform(inboundLinks.begin(), inboundLinks.end(),
|
std::transform(inboundLinks.begin(), inboundLinks.end(),
|
||||||
|
@ -1087,7 +1087,7 @@ namespace llarp
|
||||||
if(inboundLinks.size() == 0)
|
if(inboundLinks.size() == 0)
|
||||||
{
|
{
|
||||||
paths.BuildPaths(now);
|
paths.BuildPaths(now);
|
||||||
hiddenServiceContext.Tick(now);
|
_hiddenServiceContext.Tick(now);
|
||||||
}
|
}
|
||||||
if(NumberOfConnectedRouters() < minConnectedRouters)
|
if(NumberOfConnectedRouters() < minConnectedRouters)
|
||||||
{
|
{
|
||||||
|
@ -1433,7 +1433,7 @@ namespace llarp
|
||||||
}
|
}
|
||||||
|
|
||||||
LogInfo("starting hidden service context...");
|
LogInfo("starting hidden service context...");
|
||||||
if(!hiddenServiceContext.StartAll())
|
if(!hiddenServiceContext().StartAll())
|
||||||
{
|
{
|
||||||
LogError("Failed to start hidden service context");
|
LogError("Failed to start hidden service context");
|
||||||
return false;
|
return false;
|
||||||
|
@ -1503,7 +1503,7 @@ namespace llarp
|
||||||
{
|
{
|
||||||
// auto detect if we have any pre-defined endpoints
|
// auto detect if we have any pre-defined endpoints
|
||||||
// no if we have a endpoints
|
// no if we have a endpoints
|
||||||
if(hiddenServiceContext.hasEndpoints())
|
if(hiddenServiceContext().hasEndpoints())
|
||||||
{
|
{
|
||||||
LogInfo("Auto mode detected and we have endpoints");
|
LogInfo("Auto mode detected and we have endpoints");
|
||||||
netConfig.emplace("enabled", "false");
|
netConfig.emplace("enabled", "false");
|
||||||
|
@ -1557,7 +1557,7 @@ namespace llarp
|
||||||
|
|
||||||
_stopping.store(true);
|
_stopping.store(true);
|
||||||
LogInfo("stopping router");
|
LogInfo("stopping router");
|
||||||
hiddenServiceContext.StopAll();
|
hiddenServiceContext().StopAll();
|
||||||
_exitContext.Stop();
|
_exitContext.Stop();
|
||||||
if(rpcServer)
|
if(rpcServer)
|
||||||
rpcServer->Stop();
|
rpcServer->Stop();
|
||||||
|
@ -1727,7 +1727,7 @@ namespace llarp
|
||||||
++itr;
|
++itr;
|
||||||
}
|
}
|
||||||
// add endpoint
|
// add endpoint
|
||||||
return hiddenServiceContext.AddDefaultEndpoint(netConfig);
|
return hiddenServiceContext().AddDefaultEndpoint(netConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1748,7 +1748,7 @@ namespace llarp
|
||||||
service::Config::section_t filteredConfig;
|
service::Config::section_t filteredConfig;
|
||||||
mergeHiddenServiceConfig(config.second, filteredConfig.second);
|
mergeHiddenServiceConfig(config.second, filteredConfig.second);
|
||||||
filteredConfig.first = config.first;
|
filteredConfig.first = config.first;
|
||||||
if(!hiddenServiceContext.AddEndpoint(filteredConfig))
|
if(!hiddenServiceContext().AddEndpoint(filteredConfig))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -225,7 +225,19 @@ namespace llarp
|
||||||
InboundMessageParser inbound_link_msg_parser;
|
InboundMessageParser inbound_link_msg_parser;
|
||||||
routing::InboundMessageParser inbound_routing_msg_parser;
|
routing::InboundMessageParser inbound_routing_msg_parser;
|
||||||
|
|
||||||
service::Context hiddenServiceContext;
|
service::Context _hiddenServiceContext;
|
||||||
|
|
||||||
|
service::Context &
|
||||||
|
hiddenServiceContext() override
|
||||||
|
{
|
||||||
|
return _hiddenServiceContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
const service::Context &
|
||||||
|
hiddenServiceContext() const override
|
||||||
|
{
|
||||||
|
return _hiddenServiceContext;
|
||||||
|
}
|
||||||
|
|
||||||
using NetConfig_t = std::unordered_multimap< std::string, std::string >;
|
using NetConfig_t = std::unordered_multimap< std::string, std::string >;
|
||||||
|
|
||||||
|
@ -341,17 +353,17 @@ namespace llarp
|
||||||
AddHiddenService(const service::Config::section_t &config);
|
AddHiddenService(const service::Config::section_t &config);
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Configure(Config *conf);
|
Configure(Config *conf) override;
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Ready();
|
Ready();
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Run(struct llarp_nodedb *nodedb);
|
Run(struct llarp_nodedb *nodedb) override;
|
||||||
|
|
||||||
/// stop running the router logic gracefully
|
/// stop running the router logic gracefully
|
||||||
void
|
void
|
||||||
Stop();
|
Stop() override;
|
||||||
|
|
||||||
/// close all sessions and shutdown all links
|
/// close all sessions and shutdown all links
|
||||||
void
|
void
|
||||||
|
@ -389,13 +401,13 @@ namespace llarp
|
||||||
|
|
||||||
/// inject configuration and reconfigure router
|
/// inject configuration and reconfigure router
|
||||||
bool
|
bool
|
||||||
Reconfigure(Config *conf);
|
Reconfigure(Config *conf) override;
|
||||||
|
|
||||||
/// validate new configuration against old one
|
/// validate new configuration against old one
|
||||||
/// return true on 100% valid
|
/// return true on 100% valid
|
||||||
/// return false if not 100% valid
|
/// return false if not 100% valid
|
||||||
bool
|
bool
|
||||||
ValidateConfig(Config *conf) const;
|
ValidateConfig(Config *conf) const override;
|
||||||
|
|
||||||
/// send to remote router or queue for sending
|
/// send to remote router or queue for sending
|
||||||
/// returns false on overflow
|
/// returns false on overflow
|
||||||
|
|
Loading…
Reference in a new issue