llarp::Context uses AbstractRouter now

pull/339/head
Michael 5 years ago
parent 13a9f65520
commit 89ae60cfab
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C

@ -18,7 +18,7 @@ namespace llarp
struct Config;
struct Crypto;
class Logic;
struct Router;
struct AbstractRouter;
struct RouterContact;
struct Context
@ -28,7 +28,7 @@ namespace llarp
int num_nethreads = 1;
bool singleThreaded = false;
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::Logic > logic;
std::unique_ptr< llarp::Config > config;

@ -97,7 +97,8 @@ namespace llarp
Context::LoadDatabase()
{
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()))
{
@ -360,7 +361,7 @@ extern "C"
llarp_main_inject_vpn_fd(struct llarp_main *ptr, int fd)
{
llarp::handlers::TunEndpoint *tun =
ptr->ctx->router->hiddenServiceContext.getFirstTun();
ptr->ctx->router->hiddenServiceContext().getFirstTun();
if(!tun)
return;
if(!tun->Promise)
@ -507,15 +508,15 @@ extern "C"
main_router_prefetch(struct llarp_main *ptr,
const llarp::service::Address &addr)
{
auto *endpoint = &ptr->ctx->router->hiddenServiceContext;
return endpoint->Prefetch(addr);
auto &endpoint = ptr->ctx->router->hiddenServiceContext();
return endpoint.Prefetch(addr);
}
llarp::handlers::TunEndpoint *
main_router_getFirstTunEndpoint(struct llarp_main *ptr)
{
if(ptr && ptr->ctx && ptr->ctx->router)
return ptr->ctx->router->hiddenServiceContext.getFirstTun();
return ptr->ctx->router->hiddenServiceContext().getFirstTun();
return nullptr;
}
@ -523,15 +524,13 @@ extern "C"
main_router_endpoint_iterator(
struct llarp_main *ptr, struct llarp::service::Context::endpoint_iter &i)
{
auto *context = &ptr->ctx->router->hiddenServiceContext;
return context->iterate(i);
return ptr->ctx->router->hiddenServiceContext().iterate(i);
}
llarp_tun_io *
main_router_getRange(struct llarp_main *ptr)
{
auto *context = &ptr->ctx->router->hiddenServiceContext;
return context->getRange();
return ptr->ctx->router->hiddenServiceContext().getRange();
}
const char *

@ -13,8 +13,9 @@ struct llarp_threadpool;
namespace llarp
{
struct Crypto;
class Logic;
struct Config;
struct Crypto;
struct RouterContact;
struct RouterID;
struct ILinkMessage;
@ -39,6 +40,10 @@ namespace llarp
struct IMessageHandler;
}
namespace service {
struct Context;
}
struct AbstractRouter : public util::IStateful
{
virtual void
@ -90,15 +95,41 @@ namespace llarp
virtual llarp_threadpool *
diskworker() = 0;
virtual service::Context &
hiddenServiceContext() = 0;
virtual const service::Context &
hiddenServiceContext() const = 0;
virtual bool
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 *
pubkey() const = 0;
virtual void
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
virtual void
SessionClosed(RouterID remote) = 0;

@ -210,7 +210,7 @@ namespace llarp
, _exitContext(this)
, _dht(llarp_dht_context_new(this))
, inbound_link_msg_parser(this)
, hiddenServiceContext(this)
, _hiddenServiceContext(this)
{
// set rational defaults
this->ip4addr.sin_family = AF_INET;
@ -234,7 +234,7 @@ namespace llarp
Router::ExtractStatus() const
{
util::StatusObject obj{{"dht", _dht->impl->ExtractStatus()},
{"services", hiddenServiceContext.ExtractStatus()},
{"services", _hiddenServiceContext.ExtractStatus()},
{"exit", _exitContext.ExtractStatus()}};
std::vector< util::StatusObject > ob_links, ib_links;
std::transform(inboundLinks.begin(), inboundLinks.end(),
@ -1087,7 +1087,7 @@ namespace llarp
if(inboundLinks.size() == 0)
{
paths.BuildPaths(now);
hiddenServiceContext.Tick(now);
_hiddenServiceContext.Tick(now);
}
if(NumberOfConnectedRouters() < minConnectedRouters)
{
@ -1433,7 +1433,7 @@ namespace llarp
}
LogInfo("starting hidden service context...");
if(!hiddenServiceContext.StartAll())
if(!hiddenServiceContext().StartAll())
{
LogError("Failed to start hidden service context");
return false;
@ -1503,7 +1503,7 @@ namespace llarp
{
// auto detect if we have any pre-defined endpoints
// no if we have a endpoints
if(hiddenServiceContext.hasEndpoints())
if(hiddenServiceContext().hasEndpoints())
{
LogInfo("Auto mode detected and we have endpoints");
netConfig.emplace("enabled", "false");
@ -1557,7 +1557,7 @@ namespace llarp
_stopping.store(true);
LogInfo("stopping router");
hiddenServiceContext.StopAll();
hiddenServiceContext().StopAll();
_exitContext.Stop();
if(rpcServer)
rpcServer->Stop();
@ -1727,7 +1727,7 @@ namespace llarp
++itr;
}
// add endpoint
return hiddenServiceContext.AddDefaultEndpoint(netConfig);
return hiddenServiceContext().AddDefaultEndpoint(netConfig);
}
bool
@ -1748,7 +1748,7 @@ namespace llarp
service::Config::section_t filteredConfig;
mergeHiddenServiceConfig(config.second, filteredConfig.second);
filteredConfig.first = config.first;
if(!hiddenServiceContext.AddEndpoint(filteredConfig))
if(!hiddenServiceContext().AddEndpoint(filteredConfig))
return false;
}
return true;

@ -225,7 +225,19 @@ namespace llarp
InboundMessageParser inbound_link_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 >;
@ -341,17 +353,17 @@ namespace llarp
AddHiddenService(const service::Config::section_t &config);
bool
Configure(Config *conf);
Configure(Config *conf) override;
bool
Ready();
bool
Run(struct llarp_nodedb *nodedb);
Run(struct llarp_nodedb *nodedb) override;
/// stop running the router logic gracefully
void
Stop();
Stop() override;
/// close all sessions and shutdown all links
void
@ -389,13 +401,13 @@ namespace llarp
/// inject configuration and reconfigure router
bool
Reconfigure(Config *conf);
Reconfigure(Config *conf) override;
/// validate new configuration against old one
/// return true on 100% valid
/// return false if not 100% valid
bool
ValidateConfig(Config *conf) const;
ValidateConfig(Config *conf) const override;
/// send to remote router or queue for sending
/// returns false on overflow

Loading…
Cancel
Save