clang format.......

pull/1184/head
Thomas Winget 4 years ago
parent 695784b2b6
commit 84a1d7dbcc

@ -20,7 +20,7 @@ struct llarp_main;
namespace tooling namespace tooling
{ {
struct RouterHive; struct RouterHive;
} // namespace tooling } // namespace tooling
#endif #endif
namespace llarp namespace llarp
@ -39,7 +39,7 @@ namespace llarp
struct Context struct Context
{ {
/// get context from main pointer /// get context from main pointer
static std::shared_ptr<Context> static std::shared_ptr< Context >
Get(llarp_main *); Get(llarp_main *);
Context() = default; Context() = default;
@ -97,7 +97,7 @@ namespace llarp
#ifdef LOKINET_HIVE #ifdef LOKINET_HIVE
void void
InjectHive(tooling::RouterHive* hive); InjectHive(tooling::RouterHive *hive);
#endif #endif
private: private:

@ -13,7 +13,6 @@
#include <vector> #include <vector>
#include <unordered_set> #include <unordered_set>
struct llarp_config; struct llarp_config;
namespace llarp namespace llarp
{ {
@ -259,7 +258,7 @@ namespace llarp
bool bool
LoadFromStr(string_view str); LoadFromStr(string_view str);
llarp_config * llarp_config*
Copy() const; Copy() const;
}; };

@ -303,7 +303,7 @@ namespace llarp
#ifdef LOKINET_HIVE #ifdef LOKINET_HIVE
void void
Context::InjectHive(tooling::RouterHive* hive) Context::InjectHive(tooling::RouterHive *hive)
{ {
router->hive = hive; router->hive = hive;
} }
@ -332,11 +332,11 @@ namespace llarp
llarp_config * llarp_config *
Config::Copy() const Config::Copy() const
{ {
llarp_config * ptr = new llarp_config(); llarp_config *ptr = new llarp_config();
ptr->impl = *this; ptr->impl = *this;
return ptr; return ptr;
} }
} } // namespace llarp
extern "C" extern "C"
{ {
@ -560,8 +560,7 @@ llarp_main::llarp_main(llarp_config *conf)
namespace llarp namespace llarp
{ {
std::shared_ptr< Context >
std::shared_ptr<Context>
Context::Get(llarp_main *m) Context::Get(llarp_main *m)
{ {
if(m == nullptr || m->ctx == nullptr) if(m == nullptr || m->ctx == nullptr)

@ -24,12 +24,11 @@ namespace llarp
llarp_dht_context *ctx, llarp_dht_context *ctx,
std::vector< std::unique_ptr< IMessage > > & /*replies*/) const std::vector< std::unique_ptr< IMessage > > & /*replies*/) const
{ {
auto &dht = *ctx->impl; auto &dht = *ctx->impl;
auto *router = dht.GetRouter(); auto *router = dht.GetRouter();
auto ev = std::make_unique<tooling::GotIntroReceivedEvent>( auto ev = std::make_unique< tooling::GotIntroReceivedEvent >(
router->pubkey(), router->pubkey(), Key_t(From.data()),
Key_t(From.data()),
(found.size() > 0 ? found[0] : llarp::service::EncryptedIntroSet{}), (found.size() > 0 ? found[0] : llarp::service::EncryptedIntroSet{}),
txid); txid);
router->NotifyRouterEvent(std::move(ev)); router->NotifyRouterEvent(std::move(ev));

@ -125,11 +125,13 @@ namespace llarp
{ {
if(not dht.GetRouter()->rcLookupHandler().CheckRC(rc)) if(not dht.GetRouter()->rcLookupHandler().CheckRC(rc))
return false; return false;
if(txid == 0) // txid == 0 on gossip if(txid == 0) // txid == 0 on gossip
{ {
LogWarn("Received Gossiped RC, generating RCGossipReceivedEvent"); LogWarn("Received Gossiped RC, generating RCGossipReceivedEvent");
auto *router = dht.GetRouter(); auto *router = dht.GetRouter();
tooling::RouterEventPtr event = std::make_unique<tooling::RCGossipReceivedEvent>(router->pubkey(), rc); tooling::RouterEventPtr event =
std::make_unique< tooling::RCGossipReceivedEvent >(
router->pubkey(), rc);
router->NotifyRouterEvent(std::move(event)); router->NotifyRouterEvent(std::move(event));
router->GossipRCIfNeeded(rc); router->GossipRCIfNeeded(rc);
} }

@ -58,12 +58,14 @@ namespace llarp
llarp_dht_context *ctx, llarp_dht_context *ctx,
std::vector< std::unique_ptr< IMessage > > &replies) const std::vector< std::unique_ptr< IMessage > > &replies) const
{ {
const auto now = ctx->impl->Now(); const auto now = ctx->impl->Now();
const llarp::dht::Key_t addr(introset.derivedSigningKey); const llarp::dht::Key_t addr(introset.derivedSigningKey);
const auto keyStr = addr.ToHex(); const auto keyStr = addr.ToHex();
auto router = ctx->impl->GetRouter(); auto router = ctx->impl->GetRouter();
auto ev = std::make_unique<tooling::PubIntroReceivedEvent>(router->pubkey(), Key_t(relayed ? router->pubkey() : From.data()), addr, txID, relayOrder); auto ev = std::make_unique< tooling::PubIntroReceivedEvent >(
router->pubkey(), Key_t(relayed ? router->pubkey() : From.data()),
addr, txID, relayOrder);
router->NotifyRouterEvent(std::move(ev)); router->NotifyRouterEvent(std::move(ev));
auto &dht = *ctx->impl; auto &dht = *ctx->impl;

@ -783,14 +783,16 @@ namespace libuv
#endif #endif
m_LogicCaller.data = this; m_LogicCaller.data = this;
int err; int err;
if ((err = uv_async_init(&m_Impl, &m_LogicCaller, [](uv_async_t* h) { if((err = uv_async_init(&m_Impl, &m_LogicCaller,
Loop* l = static_cast< Loop* >(h->data); [](uv_async_t* h) {
while(not l->m_LogicCalls.empty()) Loop* l = static_cast< Loop* >(h->data);
{ while(not l->m_LogicCalls.empty())
auto f = l->m_LogicCalls.popFront(); {
f(); auto f = l->m_LogicCalls.popFront();
} f();
})) != 0) }
}))
!= 0)
{ {
llarp::LogError("Libuv uv_async_init returned error: ", uv_strerror(err)); llarp::LogError("Libuv uv_async_init returned error: ", uv_strerror(err));
return false; return false;

@ -11,7 +11,6 @@ namespace llarp
: public llarp::service::Endpoint, : public llarp::service::Endpoint,
public std::enable_shared_from_this< NullEndpoint > public std::enable_shared_from_this< NullEndpoint >
{ {
NullEndpoint(const std::string &name, AbstractRouter *r, NullEndpoint(const std::string &name, AbstractRouter *r,
llarp::service::Context *parent) llarp::service::Context *parent)
: llarp::service::Endpoint(name, r, parent) : llarp::service::Endpoint(name, r, parent)

@ -419,7 +419,7 @@ namespace llarp
// TODO: check if we really want to accept it // TODO: check if we really want to accept it
self->hop->started = now; self->hop->started = now;
auto event = std::make_unique<tooling::PathRequestReceivedEvent>( auto event = std::make_unique< tooling::PathRequestReceivedEvent >(
self->context->Router()->pubkey(), self->hop); self->context->Router()->pubkey(), self->hop);
self->context->Router()->NotifyRouterEvent(std::move(event)); self->context->Router()->NotifyRouterEvent(std::move(event));

@ -29,7 +29,8 @@ namespace llarp
PathID_t pathid; PathID_t pathid;
LRSM_AsyncHandler(std::array< EncryptedFrame, 8 > _frames, uint64_t _status, LRSM_AsyncHandler(std::array< EncryptedFrame, 8 > _frames, uint64_t _status,
HopHandler_ptr _path, AbstractRouter* _router, const PathID_t& pathid) HopHandler_ptr _path, AbstractRouter* _router,
const PathID_t& pathid)
: frames(std::move(_frames)) : frames(std::move(_frames))
, status(_status) , status(_status)
, path(std::move(_path)) , path(std::move(_path))
@ -43,7 +44,8 @@ namespace llarp
void void
handle() handle()
{ {
auto ev = std::make_unique<tooling::PathStatusReceivedEvent>(router->pubkey(), pathid, status); auto ev = std::make_unique< tooling::PathStatusReceivedEvent >(
router->pubkey(), pathid, status);
router->NotifyRouterEvent(std::move(ev)); router->NotifyRouterEvent(std::move(ev));
path->HandleLRSM(status, frames, router); path->HandleLRSM(status, frames, router);
@ -146,8 +148,8 @@ namespace llarp
return false; return false;
} }
auto handler = auto handler = std::make_shared< LRSM_AsyncHandler >(frames, status, path,
std::make_shared< LRSM_AsyncHandler >(frames, status, path, router, pathid); router, pathid);
handler->queue_handle(); handler->queue_handle();

@ -132,7 +132,9 @@ namespace llarp
{ {
if(!ctx->pathset->IsStopped()) if(!ctx->pathset->IsStopped())
{ {
tooling::RouterEventPtr event = std::make_unique<tooling::PathAttemptEvent>(ctx->router->pubkey(), ctx->path); tooling::RouterEventPtr event =
std::make_unique< tooling::PathAttemptEvent >(ctx->router->pubkey(),
ctx->path);
ctx->router->NotifyRouterEvent(std::move(event)); ctx->router->NotifyRouterEvent(std::move(event));
const RouterID remote = ctx->path->Upstream(); const RouterID remote = ctx->path->Upstream();
@ -450,7 +452,6 @@ namespace llarp
std::move(path_shortName)); std::move(path_shortName));
LogInfo(Name(), " build ", path->ShortName(), ": ", path->HopsString()); LogInfo(Name(), " build ", path->ShortName(), ": ", path->HopsString());
path->SetBuildResultHook( path->SetBuildResultHook(
[self](Path_ptr p) { self->HandlePathBuilt(p); }); [self](Path_ptr p) { self->HandlePathBuilt(p); });
ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(), ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(),

@ -20,7 +20,7 @@ struct llarp_threadpool;
namespace tooling namespace tooling
{ {
struct RouterHive; struct RouterHive;
} // namespace tooling } // namespace tooling
namespace llarp namespace llarp
{ {
@ -65,9 +65,8 @@ namespace llarp
struct AbstractRouter struct AbstractRouter
{ {
#ifdef LOKINET_HIVE #ifdef LOKINET_HIVE
tooling::RouterHive* hive; tooling::RouterHive *hive;
#endif #endif
virtual ~AbstractRouter() = default; virtual ~AbstractRouter() = default;

@ -21,18 +21,19 @@ namespace llarp
} }
void void
RCGossiper::Init(ILinkManager* l, const RouterID& ourID, AbstractRouter* router) RCGossiper::Init(ILinkManager* l, const RouterID& ourID,
AbstractRouter* router)
{ {
m_OurRouterID = ourID; m_OurRouterID = ourID;
m_LinkManager = l; m_LinkManager = l;
m_router = router; m_router = router;
} }
bool bool
RCGossiper::ShouldGossipOurRC(Time_t now) const RCGossiper::ShouldGossipOurRC(Time_t now) const
{ {
bool should = now >= (m_LastGossipedOurRC + GossipOurRCInterval); bool should = now >= (m_LastGossipedOurRC + GossipOurRCInterval);
LogWarn("ShouldGossipOurRC: ", should); LogWarn("ShouldGossipOurRC: ", should);
return should; return should;
} }
@ -98,7 +99,9 @@ LogWarn("ShouldGossipOurRC: ", should);
return; return;
msg.resize(buf.cur - buf.base); msg.resize(buf.cur - buf.base);
tooling::RouterEventPtr event = std::make_unique<tooling::RCGossipSentEvent>(m_router->pubkey(), rc); tooling::RouterEventPtr event =
std::make_unique< tooling::RCGossipSentEvent >(m_router->pubkey(),
rc);
m_router->NotifyRouterEvent(std::move(event)); m_router->NotifyRouterEvent(std::move(event));
// send message // send message

@ -28,7 +28,7 @@ namespace llarp
IsOurRC(const RouterContact &rc) const override; IsOurRC(const RouterContact &rc) const override;
void void
Init(ILinkManager *, const RouterID &, AbstractRouter*); Init(ILinkManager *, const RouterID &, AbstractRouter *);
private: private:
RouterID m_OurRouterID; RouterID m_OurRouterID;

@ -59,7 +59,8 @@ namespace llarp
, inbound_link_msg_parser(this) , inbound_link_msg_parser(this)
, _hiddenServiceContext(this) , _hiddenServiceContext(this)
#ifdef LOKINET_HIVE #ifdef LOKINET_HIVE
, _randomStartDelay(std::chrono::milliseconds((llarp::randint() % 1250) + 2000)) , _randomStartDelay(
std::chrono::milliseconds((llarp::randint() % 1250) + 2000))
#else #else
, _randomStartDelay(std::chrono::seconds((llarp::randint() % 30) + 10)) , _randomStartDelay(std::chrono::seconds((llarp::randint() % 30) + 10))
#endif #endif
@ -482,7 +483,8 @@ namespace llarp
llarp::LogError("invalid key for strict-connect: ", val); llarp::LogError("invalid key for strict-connect: ", val);
} }
llarp::LogWarn("Bootstrap routers list size: ", conf->bootstrap.routers.size()); llarp::LogWarn("Bootstrap routers list size: ",
conf->bootstrap.routers.size());
std::vector< std::string > configRouters = conf->connect.routers; std::vector< std::string > configRouters = conf->connect.routers;
configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(), configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(),
conf->bootstrap.routers.end()); conf->bootstrap.routers.end());

@ -46,7 +46,7 @@
namespace tooling namespace tooling
{ {
struct RouterHive; struct RouterHive;
} // namespace tooling } // namespace tooling
namespace llarp namespace llarp
{ {
@ -228,7 +228,6 @@ namespace llarp
return _hiddenServiceContext; return _hiddenServiceContext;
} }
llarp_time_t _lastTick = 0s; llarp_time_t _lastTick = 0s;
bool bool

@ -39,7 +39,7 @@ namespace llarp
{ {
} }
explicit Address(const std::string & str) : AlignedBuffer<32>() explicit Address(const std::string& str) : AlignedBuffer< 32 >()
{ {
if(not FromString(str)) if(not FromString(str))
throw std::runtime_error("invalid address"); throw std::runtime_error("invalid address");

@ -192,9 +192,8 @@ namespace llarp
return nullptr; return nullptr;
} }
void void
Context::InjectEndpoint(std::string name, std::shared_ptr<Endpoint> ep) Context::InjectEndpoint(std::string name, std::shared_ptr< Endpoint > ep)
{ {
ep->LoadKeyFile(); ep->LoadKeyFile();
if(ep->Start()) if(ep->Start())

@ -48,7 +48,7 @@ namespace llarp
/// inject endpoint instance /// inject endpoint instance
void void
InjectEndpoint(std::string name, std::shared_ptr<Endpoint> ep); InjectEndpoint(std::string name, std::shared_ptr< Endpoint > ep);
/// stop and remove an endpoint by name /// stop and remove an endpoint by name
/// return false if we don't have the hidden service with that name /// return false if we don't have the hidden service with that name
@ -58,7 +58,7 @@ namespace llarp
Endpoint_ptr Endpoint_ptr
GetEndpointByName(const std::string &name); GetEndpointByName(const std::string &name);
Endpoint_ptr Endpoint_ptr
GetDefault() GetDefault()
{ {
return GetEndpointByName("default"); return GetEndpointByName("default");

@ -199,17 +199,19 @@ namespace llarp
// prefetch addrs // prefetch addrs
for(const auto& addr : m_state->m_PrefetchAddrs) for(const auto& addr : m_state->m_PrefetchAddrs)
{ {
EnsurePathToService( EnsurePathToService(
addr, [](Address, OutboundContext* ctx) { addr,
#ifdef LOKINET_HIVE [](Address, OutboundContext* ctx) {
std::vector<byte_t> discard; #ifdef LOKINET_HIVE
discard.resize(128); std::vector< byte_t > discard;
ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard), eProtocolControl); discard.resize(128);
#else ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard),
(void)ctx; eProtocolControl);
#endif #else
}, 10s); (void)ctx;
#endif
},
10s);
} }
// deregister dead sessions // deregister dead sessions
@ -477,7 +479,10 @@ namespace llarp
{ {
for(size_t i = 0; i < llarp::dht::IntroSetRequestsPerRelay; ++i) for(size_t i = 0; i < llarp::dht::IntroSetRequestsPerRelay; ++i)
{ {
auto ev = std::make_unique<tooling::PubIntroSentEvent>(r->pubkey(), llarp::dht::Key_t{introset.derivedSigningKey.as_array()}, RouterID(path->hops[path->hops.size()-1].rc.pubkey), published); auto ev = std::make_unique< tooling::PubIntroSentEvent >(
r->pubkey(),
llarp::dht::Key_t{introset.derivedSigningKey.as_array()},
RouterID(path->hops[path->hops.size() - 1].rc.pubkey), published);
r->NotifyRouterEvent(std::move(ev)); r->NotifyRouterEvent(std::move(ev));
if(PublishIntroSetVia(introset, r, path, published)) if(PublishIntroSetVia(introset, r, path, published))
published++; published++;

@ -369,14 +369,13 @@ namespace llarp
const std::set< RouterID >& const std::set< RouterID >&
SnodeBlacklist() const; SnodeBlacklist() const;
bool bool
SendToServiceOrQueue(const service::Address& addr, SendToServiceOrQueue(const service::Address& addr,
const llarp_buffer_t& payload, ProtocolType t); const llarp_buffer_t& payload, ProtocolType t);
bool bool
SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& payload); SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& payload);
protected: protected:
/// parent context that owns this endpoint /// parent context that owns this endpoint
Context* const context; Context* const context;

@ -1,41 +1,49 @@
#include "dht_event.hpp" #include "dht_event.hpp"
#include "service/intro_set.hpp" #include "service/intro_set.hpp"
namespace tooling namespace tooling
{ {
PubIntroReceivedEvent::PubIntroReceivedEvent(const llarp::RouterID & ourRouter, const llarp::dht::Key_t & from, const llarp::dht::Key_t & location, uint64_t txid, uint64_t relayOrder) : PubIntroReceivedEvent::PubIntroReceivedEvent(
RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true), const llarp::RouterID& ourRouter, const llarp::dht::Key_t& from,
From(from), const llarp::dht::Key_t& location, uint64_t txid, uint64_t relayOrder)
IntrosetLocation(location), : RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true)
RelayOrder(relayOrder), , From(from)
TxID(txid) , IntrosetLocation(location)
{} , RelayOrder(relayOrder)
, TxID(txid)
{
}
PubIntroSentEvent::PubIntroSentEvent(const llarp::RouterID & ourRouter, const llarp::dht::Key_t & introsetPubkey, const llarp::RouterID& relay, uint64_t relayIndex) PubIntroSentEvent::PubIntroSentEvent(const llarp::RouterID& ourRouter,
: RouterEvent("DHT: PubIntroSentEvent", ourRouter, false) const llarp::dht::Key_t& introsetPubkey,
, introsetPubkey(introsetPubkey) const llarp::RouterID& relay,
, relay(relay) uint64_t relayIndex)
, relayIndex(relayIndex) : RouterEvent("DHT: PubIntroSentEvent", ourRouter, false)
, introsetPubkey(introsetPubkey)
, relay(relay)
, relayIndex(relayIndex)
{ {
} }
std::string std::string
PubIntroSentEvent::ToString() const PubIntroSentEvent::ToString() const
{ {
return RouterEvent::ToString() + " ---- introset pubkey: " + introsetPubkey.ShortHex() + ", relay: " + relay.ShortString() + ", relayIndex: " + std::to_string(relayIndex); return RouterEvent::ToString() + " ---- introset pubkey: "
+ introsetPubkey.ShortHex() + ", relay: " + relay.ShortString()
+ ", relayIndex: " + std::to_string(relayIndex);
} }
std::string PubIntroReceivedEvent::ToString() const std::string
PubIntroReceivedEvent::ToString() const
{ {
return RouterEvent::ToString() + "from " + From.ShortHex() + " location=" + IntrosetLocation.ShortHex() + " order=" + std::to_string(RelayOrder) + " txid=" + std::to_string(TxID); return RouterEvent::ToString() + "from " + From.ShortHex() + " location="
+ IntrosetLocation.ShortHex() + " order=" + std::to_string(RelayOrder)
+ " txid=" + std::to_string(TxID);
} }
GotIntroReceivedEvent::GotIntroReceivedEvent( GotIntroReceivedEvent::GotIntroReceivedEvent(
const llarp::RouterID& ourRouter_, const llarp::RouterID& ourRouter_, const llarp::dht::Key_t& from_,
const llarp::dht::Key_t& from_, const llarp::service::EncryptedIntroSet& introset_, uint64_t txid_)
const llarp::service::EncryptedIntroSet & introset_,
uint64_t txid_)
: RouterEvent("DHT:: GotIntroReceivedEvent", ourRouter_, true) : RouterEvent("DHT:: GotIntroReceivedEvent", ourRouter_, true)
, From(from_) , From(from_)
, Introset(introset_) , Introset(introset_)
@ -43,9 +51,12 @@ namespace tooling
{ {
} }
std::string GotIntroReceivedEvent::ToString() const std::string
GotIntroReceivedEvent::ToString() const
{ {
return RouterEvent::ToString() + "from " + From.ShortHex() + " location=" + Introset.derivedSigningKey.ShortHex() + " order=" + std::to_string(RelayOrder) + " txid=" + std::to_string(TxID); return RouterEvent::ToString() + "from " + From.ShortHex()
+ " location=" + Introset.derivedSigningKey.ShortHex() + " order="
+ std::to_string(RelayOrder) + " txid=" + std::to_string(TxID);
} }
} } // namespace tooling

@ -6,10 +6,11 @@
namespace tooling namespace tooling
{ {
struct PubIntroSentEvent : public RouterEvent struct PubIntroSentEvent : public RouterEvent
{ {
PubIntroSentEvent(const llarp::RouterID & ourRouter, const llarp::dht::Key_t & introsetPubkey, const llarp::RouterID& relay, uint64_t relayIndex); PubIntroSentEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& introsetPubkey,
const llarp::RouterID& relay, uint64_t relayIndex);
llarp::dht::Key_t introsetPubkey; llarp::dht::Key_t introsetPubkey;
@ -17,34 +18,40 @@ namespace tooling
uint64_t relayIndex; uint64_t relayIndex;
std::string ToString() const override; std::string
ToString() const override;
}; };
struct PubIntroReceivedEvent : public RouterEvent struct PubIntroReceivedEvent : public RouterEvent
{ {
PubIntroReceivedEvent(const llarp::RouterID & ourRouter, const llarp::dht::Key_t & from, const llarp::dht::Key_t & location, uint64_t txid, uint64_t relayOrder); PubIntroReceivedEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t& from,
const llarp::dht::Key_t& location, uint64_t txid,
uint64_t relayOrder);
llarp::dht::Key_t From; llarp::dht::Key_t From;
llarp::dht::Key_t IntrosetLocation; llarp::dht::Key_t IntrosetLocation;
uint64_t RelayOrder; uint64_t RelayOrder;
uint64_t TxID; uint64_t TxID;
std::string ToString() const override; std::string
ToString() const override;
}; };
struct GotIntroReceivedEvent : public RouterEvent struct GotIntroReceivedEvent : public RouterEvent
{ {
// TODO: thought: why not just use the original message object here? // TODO: thought: why not just use the original message object here?
// TODO: question: what ties this to the actual logic that knows an event occurred? // TODO: question: what ties this to the actual logic that knows an event
GotIntroReceivedEvent( // occurred?
const llarp::RouterID & ourRouter, GotIntroReceivedEvent(const llarp::RouterID& ourRouter,
const llarp::dht::Key_t & from, const llarp::dht::Key_t& from,
const llarp::service::EncryptedIntroSet & introset, const llarp::service::EncryptedIntroSet& introset,
uint64_t txid); uint64_t txid);
llarp::dht::Key_t From; llarp::dht::Key_t From;
llarp::service::EncryptedIntroSet Introset; llarp::service::EncryptedIntroSet Introset;
uint64_t RelayOrder; uint64_t RelayOrder;
uint64_t TxID; uint64_t TxID;
std::string ToString() const override; std::string
ToString() const override;
}; };
} } // namespace tooling

@ -5,11 +5,12 @@
namespace tooling namespace tooling
{ {
PathAttemptEvent::PathAttemptEvent(
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path) const llarp::RouterID& routerID,
: RouterEvent("PathAttemptEvent", routerID, false) std::shared_ptr< const llarp::path::Path > path)
, hops(path->hops) : RouterEvent("PathAttemptEvent", routerID, false)
, pathid(path->hops[0].rxID) , hops(path->hops)
, pathid(path->hops[0].rxID)
{ {
} }
@ -20,14 +21,14 @@ namespace tooling
result += "---- ["; result += "---- [";
size_t i = 0; size_t i = 0;
for (const auto& hop : hops) for(const auto& hop : hops)
{ {
i++; i++;
result += llarp::RouterID(hop.rc.pubkey).ShortString(); result += llarp::RouterID(hop.rc.pubkey).ShortString();
result += "]"; result += "]";
if (i != hops.size()) if(i != hops.size())
{ {
result += " -> ["; result += " -> [";
} }
@ -36,16 +37,17 @@ namespace tooling
return result; return result;
} }
PathRequestReceivedEvent::PathRequestReceivedEvent(
PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop) const llarp::RouterID& routerID,
: RouterEvent("PathRequestReceivedEvent", routerID, true) std::shared_ptr< const llarp::path::TransitHop > hop)
, prevHop(hop->info.downstream) : RouterEvent("PathRequestReceivedEvent", routerID, true)
, nextHop(hop->info.upstream) , prevHop(hop->info.downstream)
, txid(hop->info.txID) , nextHop(hop->info.upstream)
, rxid(hop->info.rxID) , txid(hop->info.txID)
, rxid(hop->info.rxID)
{ {
isEndpoint = false; isEndpoint = false;
if (routerID == nextHop) if(routerID == nextHop)
{ {
isEndpoint = true; isEndpoint = true;
} }
@ -61,7 +63,7 @@ namespace tooling
result += routerID.ShortString(); result += routerID.ShortString();
result += "] -> ["; result += "] -> [";
if (isEndpoint) if(isEndpoint)
{ {
result += "nowhere]"; result += "nowhere]";
} }
@ -74,10 +76,12 @@ namespace tooling
return result; return result;
} }
PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status) PathStatusReceivedEvent::PathStatusReceivedEvent(
: RouterEvent("PathStatusReceivedEvent", routerID, true) const llarp::RouterID& routerID, const llarp::PathID_t rxid,
, rxid(rxid) uint64_t status)
, status(status) : RouterEvent("PathStatusReceivedEvent", routerID, true)
, rxid(rxid)
, status(status)
{ {
} }
@ -91,4 +95,4 @@ namespace tooling
return result; return result;
} }
} // namespace tooling } // namespace tooling

@ -4,23 +4,27 @@
namespace tooling namespace tooling
{ {
struct PathAttemptEvent : public RouterEvent struct PathAttemptEvent : public RouterEvent
{ {
PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path); PathAttemptEvent(const llarp::RouterID& routerID,
std::shared_ptr< const llarp::path::Path > path);
std::string ToString() const override; std::string
ToString() const override;
std::vector<llarp::path::PathHopConfig> hops; std::vector< llarp::path::PathHopConfig > hops;
llarp::PathID_t pathid; llarp::PathID_t pathid;
}; };
struct PathRequestReceivedEvent : public RouterEvent struct PathRequestReceivedEvent : public RouterEvent
{ {
PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop); PathRequestReceivedEvent(
const llarp::RouterID& routerID,
std::shared_ptr< const llarp::path::TransitHop > hop);
std::string ToString() const override; std::string
ToString() const override;
llarp::RouterID prevHop; llarp::RouterID prevHop;
llarp::RouterID nextHop; llarp::RouterID nextHop;
@ -33,13 +37,15 @@ namespace tooling
struct PathStatusReceivedEvent : public RouterEvent struct PathStatusReceivedEvent : public RouterEvent
{ {
PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status); PathStatusReceivedEvent(const llarp::RouterID& routerID,
const llarp::PathID_t rxid, uint64_t status);
std::string ToString() const override; std::string
ToString() const override;
llarp::PathID_t rxid; llarp::PathID_t rxid;
uint64_t status; uint64_t status;
}; };
} // namespace tooling } // namespace tooling

@ -2,16 +2,17 @@
namespace tooling namespace tooling
{ {
RCGossipReceivedEvent::RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc) RCGossipReceivedEvent::RCGossipReceivedEvent(const llarp::RouterID& routerID,
: RouterEvent("RCGossipReceivedEvent", routerID, true) const llarp::RouterContact& rc)
, rc(rc) : RouterEvent("RCGossipReceivedEvent", routerID, true), rc(rc)
{ {
} }
std::string std::string
RCGossipReceivedEvent::ToString() const RCGossipReceivedEvent::ToString() const
{ {
return RouterEvent::ToString() + " ---- other RouterID: " + llarp::RouterID(rc.pubkey).ShortString(); return RouterEvent::ToString()
+ " ---- other RouterID: " + llarp::RouterID(rc.pubkey).ShortString();
} }
std::string std::string
@ -20,17 +21,17 @@ namespace tooling
return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
} }
RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID,
RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc) const llarp::RouterContact& rc)
: RouterEvent("RCGossipSentEvent", routerID, true) : RouterEvent("RCGossipSentEvent", routerID, true), rc(rc)
, rc(rc)
{ {
} }
std::string std::string
RCGossipSentEvent::ToString() const RCGossipSentEvent::ToString() const
{ {
return RouterEvent::ToString() + " ---- sending RC for RouterID: " + llarp::RouterID(rc.pubkey).ShortString(); return RouterEvent::ToString() + " ---- sending RC for RouterID: "
+ llarp::RouterID(rc.pubkey).ShortString();
} }
std::string std::string
@ -39,5 +40,4 @@ namespace tooling
return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); return RouterEvent::ToString() + " ---- RC: " + rc.ToString();
} }
} // namespace tooling } // namespace tooling

@ -6,7 +6,8 @@ namespace tooling
{ {
struct RCGossipReceivedEvent : public RouterEvent struct RCGossipReceivedEvent : public RouterEvent
{ {
RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc); RCGossipReceivedEvent(const llarp::RouterID& routerID,
const llarp::RouterContact& rc);
std::string std::string
ToString() const override; ToString() const override;
@ -19,7 +20,8 @@ namespace tooling
struct RCGossipSentEvent : public RouterEvent struct RCGossipSentEvent : public RouterEvent
{ {
RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc); RCGossipSentEvent(const llarp::RouterID& routerID,
const llarp::RouterContact& rc);
std::string std::string
ToString() const override; ToString() const override;
@ -30,5 +32,4 @@ namespace tooling
llarp::RouterContact rc; llarp::RouterContact rc;
}; };
} // namespace tooling } // namespace tooling

@ -2,9 +2,9 @@
namespace tooling namespace tooling
{ {
RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID,
RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered) bool triggered)
: eventType(eventType), routerID(routerID), triggered(triggered) : eventType(eventType), routerID(routerID), triggered(triggered)
{ {
} }
@ -19,4 +19,4 @@ namespace tooling
return result; return result;
} }
} // namespace tooling } // namespace tooling

@ -8,7 +8,6 @@
namespace llarp namespace llarp
{ {
struct PathID_t; struct PathID_t;
namespace path namespace path
@ -18,23 +17,23 @@ namespace llarp
struct TransitHop; struct TransitHop;
} // namespace llarp::path } // namespace path
} // namespace llarp
} // namespace llarp
namespace tooling namespace tooling
{ {
struct RouterHive; struct RouterHive;
struct RouterEvent struct RouterEvent
{ {
RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered); RouterEvent(std::string eventType, llarp::RouterID routerID,
bool triggered);
virtual ~RouterEvent() = default; virtual ~RouterEvent() = default;
virtual std::string ToString() const; virtual std::string
ToString() const;
const std::string eventType; const std::string eventType;
@ -43,6 +42,6 @@ namespace tooling
bool triggered = false; bool triggered = false;
}; };
using RouterEventPtr = std::unique_ptr<RouterEvent>; using RouterEventPtr = std::unique_ptr< RouterEvent >;
} // namespace tooling } // namespace tooling

@ -13,7 +13,8 @@ using namespace std::chrono_literals;
namespace tooling namespace tooling
{ {
void void
RouterHive::AddRouter(const std::shared_ptr<llarp::Config> & config, std::vector<llarp_main *> *routers) RouterHive::AddRouter(const std::shared_ptr< llarp::Config >& config,
std::vector< llarp_main* >* routers)
{ {
llarp_main* ctx = llarp_main_init_from_config(config->Copy()); llarp_main* ctx = llarp_main_init_from_config(config->Copy());
if(llarp_main_setup(ctx) == 0) if(llarp_main_setup(ctx) == 0)
@ -24,24 +25,24 @@ namespace tooling
} }
void void
RouterHive::AddRelay(const std::shared_ptr<llarp::Config> & config) RouterHive::AddRelay(const std::shared_ptr< llarp::Config >& config)
{ {
AddRouter(config, &relays); AddRouter(config, &relays);
} }
void void
RouterHive::AddClient(const std::shared_ptr<llarp::Config> & config) RouterHive::AddClient(const std::shared_ptr< llarp::Config >& config)
{ {
AddRouter(config, &clients); AddRouter(config, &clients);
} }
void void
RouterHive::StartRouters(std::vector<llarp_main *> *routers) RouterHive::StartRouters(std::vector< llarp_main* >* routers)
{ {
for (llarp_main* ctx : *routers) for(llarp_main* ctx : *routers)
{ {
routerMainThreads.emplace_back([ctx](){ routerMainThreads.emplace_back([ctx]() {
llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false}); llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false});
}); });
std::this_thread::sleep_for(2ms); std::this_thread::sleep_for(2ms);
} }
@ -62,26 +63,25 @@ namespace tooling
void void
RouterHive::StopRouters() RouterHive::StopRouters()
{ {
llarp::LogInfo("Signalling all routers to stop"); llarp::LogInfo("Signalling all routers to stop");
for (llarp_main* ctx : relays) for(llarp_main* ctx : relays)
{ {
llarp_main_signal(ctx, 2 /* SIGINT */); llarp_main_signal(ctx, 2 /* SIGINT */);
} }
for (llarp_main* ctx : clients) for(llarp_main* ctx : clients)
{ {
llarp_main_signal(ctx, 2 /* SIGINT */); llarp_main_signal(ctx, 2 /* SIGINT */);
} }
llarp::LogInfo("Waiting on routers to be stopped"); llarp::LogInfo("Waiting on routers to be stopped");
for (llarp_main* ctx : relays) for(llarp_main* ctx : relays)
{ {
while(llarp_main_is_running(ctx)) while(llarp_main_is_running(ctx))
{ {
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);
} }
} }
for (llarp_main* ctx : clients) for(llarp_main* ctx : clients)
{ {
while(llarp_main_is_running(ctx)) while(llarp_main_is_running(ctx))
{ {
@ -90,9 +90,9 @@ namespace tooling
} }
llarp::LogInfo("Joining all router threads"); llarp::LogInfo("Joining all router threads");
for (auto& thread : routerMainThreads) for(auto& thread : routerMainThreads)
{ {
while (not thread.joinable()) while(not thread.joinable())
{ {
std::this_thread::sleep_for(500ms); std::this_thread::sleep_for(500ms);
} }
@ -105,7 +105,7 @@ namespace tooling
void void
RouterHive::NotifyEvent(RouterEventPtr event) RouterHive::NotifyEvent(RouterEventPtr event)
{ {
std::lock_guard<std::mutex> guard{eventQueueMutex}; std::lock_guard< std::mutex > guard{eventQueueMutex};
eventQueue.push_back(std::move(event)); eventQueue.push_back(std::move(event));
} }
@ -113,9 +113,9 @@ namespace tooling
RouterEventPtr RouterEventPtr
RouterHive::GetNextEvent() RouterHive::GetNextEvent()
{ {
std::lock_guard<std::mutex> guard{eventQueueMutex}; std::lock_guard< std::mutex > guard{eventQueueMutex};
if (not eventQueue.empty()) if(not eventQueue.empty())
{ {
auto ptr = std::move(eventQueue.front()); auto ptr = std::move(eventQueue.front());
eventQueue.pop_front(); eventQueue.pop_front();
@ -124,13 +124,13 @@ namespace tooling
return nullptr; return nullptr;
} }
std::deque<RouterEventPtr> std::deque< RouterEventPtr >
RouterHive::GetAllEvents() RouterHive::GetAllEvents()
{ {
std::lock_guard<std::mutex> guard{eventQueueMutex}; std::lock_guard< std::mutex > guard{eventQueueMutex};
std::deque<RouterEventPtr> events; std::deque< RouterEventPtr > events;
if (not eventQueue.empty()) if(not eventQueue.empty())
{ {
eventQueue.swap(events); eventQueue.swap(events);
} }
@ -138,16 +138,15 @@ namespace tooling
} }
void void
RouterHive::VisitRouter(llarp_main *router, std::function<void(Context_ptr)> visit) RouterHive::VisitRouter(llarp_main* router,
std::function< void(Context_ptr) > visit)
{ {
auto ctx = llarp::Context::Get(router); auto ctx = llarp::Context::Get(router);
LogicCall(ctx->logic, [visit, ctx]() { LogicCall(ctx->logic, [visit, ctx]() { visit(ctx); });
visit(ctx);
});
} }
void void
RouterHive::VisitRelay(size_t index, std::function<void(Context_ptr)> visit) RouterHive::VisitRelay(size_t index, std::function< void(Context_ptr) > visit)
{ {
if(index >= relays.size()) if(index >= relays.size())
{ {
@ -158,7 +157,8 @@ namespace tooling
} }
void void
RouterHive::VisitClient(size_t index, std::function<void(Context_ptr)> visit) RouterHive::VisitClient(size_t index,
std::function< void(Context_ptr) > visit)
{ {
if(index >= clients.size()) if(index >= clients.size())
{ {
@ -168,35 +168,35 @@ namespace tooling
VisitRouter(clients[index], visit); VisitRouter(clients[index], visit);
} }
std::vector<size_t> std::vector< size_t >
RouterHive::RelayConnectedRelays() RouterHive::RelayConnectedRelays()
{ {
std::vector<size_t> results; std::vector< size_t > results;
results.resize(relays.size()); results.resize(relays.size());
std::mutex results_lock; std::mutex results_lock;
size_t i=0; size_t i = 0;
size_t done_count = 0; size_t done_count = 0;
for (auto relay : relays) for(auto relay : relays)
{ {
auto ctx = llarp::Context::Get(relay); auto ctx = llarp::Context::Get(relay);
LogicCall(ctx->logic, [&, i, ctx]() { LogicCall(ctx->logic, [&, i, ctx]() {
size_t count = ctx->router->NumberOfConnectedRouters(); size_t count = ctx->router->NumberOfConnectedRouters();
std::lock_guard<std::mutex> guard{results_lock}; std::lock_guard< std::mutex > guard{results_lock};
results[i] = count; results[i] = count;
done_count++; done_count++;
}); });
i++; i++;
} }
while (true) while(true)
{ {
size_t read_done_count = 0; size_t read_done_count = 0;
{ {
std::lock_guard<std::mutex> guard{results_lock}; std::lock_guard< std::mutex > guard{results_lock};
read_done_count = done_count; read_done_count = done_count;
} }
if (read_done_count == relays.size()) if(read_done_count == relays.size())
break; break;
std::this_thread::sleep_for(100ms); std::this_thread::sleep_for(100ms);
@ -204,35 +204,35 @@ namespace tooling
return results; return results;
} }
std::vector<llarp::RouterContact> std::vector< llarp::RouterContact >
RouterHive::GetRelayRCs() RouterHive::GetRelayRCs()
{ {
std::vector<llarp::RouterContact> results; std::vector< llarp::RouterContact > results;
results.resize(relays.size()); results.resize(relays.size());
std::mutex results_lock; std::mutex results_lock;
size_t i=0; size_t i = 0;
size_t done_count = 0; size_t done_count = 0;
for (auto relay : relays) for(auto relay : relays)
{ {
auto ctx = llarp::Context::Get(relay); auto ctx = llarp::Context::Get(relay);
LogicCall(ctx->logic, [&, i, ctx]() { LogicCall(ctx->logic, [&, i, ctx]() {
llarp::RouterContact rc = ctx->router->rc(); llarp::RouterContact rc = ctx->router->rc();
std::lock_guard<std::mutex> guard{results_lock}; std::lock_guard< std::mutex > guard{results_lock};
results[i] = std::move(rc); results[i] = std::move(rc);
done_count++; done_count++;
}); });
i++; i++;
} }
while (true) while(true)
{ {
size_t read_done_count = 0; size_t read_done_count = 0;
{ {
std::lock_guard<std::mutex> guard{results_lock}; std::lock_guard< std::mutex > guard{results_lock};
read_done_count = done_count; read_done_count = done_count;
} }
if (read_done_count == relays.size()) if(read_done_count == relays.size())
break; break;
std::this_thread::sleep_for(100ms); std::this_thread::sleep_for(100ms);
@ -240,4 +240,4 @@ namespace tooling
return results; return results;
} }
} // namespace tooling } // namespace tooling

@ -20,39 +20,38 @@ namespace llarp
namespace tooling namespace tooling
{ {
struct RouterHive struct RouterHive
{ {
using Context_ptr = std::shared_ptr<llarp::Context>; using Context_ptr = std::shared_ptr< llarp::Context >;
private:
private:
void void
StartRouters(std::vector<llarp_main *> *routers); StartRouters(std::vector< llarp_main * > *routers);
void void
AddRouter(const std::shared_ptr<llarp::Config> & config, std::vector<llarp_main *> *routers); AddRouter(const std::shared_ptr< llarp::Config > &config,
std::vector< llarp_main * > *routers);
/// safely visit router /// safely visit router
void void
VisitRouter(llarp_main *router, std::function<void(Context_ptr)> visit); VisitRouter(llarp_main *router, std::function< void(Context_ptr) > visit);
/// safely visit relay at index N /// safely visit relay at index N
void void
VisitRelay(size_t index, std::function<void(Context_ptr)> visit); VisitRelay(size_t index, std::function< void(Context_ptr) > visit);
/// safely visit client at index N /// safely visit client at index N
void void
VisitClient(size_t index, std::function<void(Context_ptr)> visit); VisitClient(size_t index, std::function< void(Context_ptr) > visit);
public: public:
RouterHive() = default; RouterHive() = default;
void void
AddRelay(const std::shared_ptr<llarp::Config> & conf); AddRelay(const std::shared_ptr< llarp::Config > &conf);
void void
AddClient(const std::shared_ptr<llarp::Config> & conf); AddClient(const std::shared_ptr< llarp::Config > &conf);
void void
StartRelays(); StartRelays();
@ -69,11 +68,11 @@ namespace tooling
RouterEventPtr RouterEventPtr
GetNextEvent(); GetNextEvent();
std::deque<RouterEventPtr> std::deque< RouterEventPtr >
GetAllEvents(); GetAllEvents();
void void
ForEachRelay(std::function<void(Context_ptr)> visit) ForEachRelay(std::function< void(Context_ptr) > visit)
{ {
for(size_t idx = 0; idx < relays.size(); ++idx) for(size_t idx = 0; idx < relays.size(); ++idx)
{ {
@ -82,7 +81,7 @@ namespace tooling
} }
void void
ForEachClient(std::function<void(Context_ptr)> visit) ForEachClient(std::function< void(Context_ptr) > visit)
{ {
for(size_t idx = 0; idx < clients.size(); ++idx) for(size_t idx = 0; idx < clients.size(); ++idx)
{ {
@ -92,25 +91,25 @@ namespace tooling
/// safely visit every router context /// safely visit every router context
void void
ForEachRouter(std::function<void(Context_ptr)> visit) ForEachRouter(std::function< void(Context_ptr) > visit)
{ {
ForEachRelay(visit); ForEachRelay(visit);
ForEachClient(visit); ForEachClient(visit);
} }
std::vector<size_t> std::vector< size_t >
RelayConnectedRelays(); RelayConnectedRelays();
std::vector<llarp::RouterContact> std::vector< llarp::RouterContact >
GetRelayRCs(); GetRelayRCs();
std::vector<llarp_main *> relays; std::vector< llarp_main * > relays;
std::vector<llarp_main *> clients; std::vector< llarp_main * > clients;
std::vector<std::thread> routerMainThreads; std::vector< std::thread > routerMainThreads;
std::mutex eventQueueMutex; std::mutex eventQueueMutex;
std::deque<RouterEventPtr> eventQueue; std::deque< RouterEventPtr > eventQueue;
}; };
} // namespace tooling } // namespace tooling

@ -396,13 +396,15 @@ namespace llarp
{ {
uint32_t generation = 0; uint32_t generation = 0;
uint32_t index = 0; uint32_t index = 0;
bool secondTry = false; bool secondTry = false;
bool success = false; bool success = false;
for(;;) for(;;)
{ {
success = m_manager.reservePopIndex(generation, index) == QueueReturn::Success; success = m_manager.reservePopIndex(generation, index)
== QueueReturn::Success;
if (secondTry || success) break; if(secondTry || success)
break;
m_waitingPoppers.fetch_add(1, std::memory_order_relaxed); m_waitingPoppers.fetch_add(1, std::memory_order_relaxed);
@ -415,7 +417,7 @@ namespace llarp
m_waitingPoppers.fetch_sub(1, std::memory_order_relaxed); m_waitingPoppers.fetch_sub(1, std::memory_order_relaxed);
} }
if (success) if(success)
{ {
QueuePopGuard< Type > popGuard(*this, generation, index); QueuePopGuard< Type > popGuard(*this, generation, index);
return Type(std::move(m_data[index])); return Type(std::move(m_data[index]));

@ -11,26 +11,31 @@ namespace py = pybind11;
namespace pybind11 namespace pybind11
{ {
namespace detail namespace detail
{ {
template < typename Key, typename Value, typename Hash, typename Equal,
template <typename Key, typename Value, typename Hash, typename Equal, typename Alloc> struct type_caster<std::unordered_multimap<Key, Value, Hash, Equal, Alloc>> typename Alloc >
: map_caster<std::unordered_multimap<Key, Value, Hash, Equal, Alloc>, Key, Value> { }; struct type_caster<
std::unordered_multimap< Key, Value, Hash, Equal, Alloc > >
: map_caster< std::unordered_multimap< Key, Value, Hash, Equal, Alloc >,
template<typename T> Key, Value >
struct type_caster<nonstd::optional<T>> {
: public optional_caster<nonstd::optional<T>> {}; };
/* template < typename T >
template <typename CharT, class Traits> struct type_caster< nonstd::optional< T > >
struct type_caster<simple_string_view> : public optional_caster< nonstd::optional< T > >
: string_caster<simple_string_view, true> {}; {
*/ };
} // namespace pybind11::detail /*
} // namespace pybind11 template <typename CharT, class Traits>
struct type_caster<simple_string_view>
: string_caster<simple_string_view, true> {};
*/
} // namespace detail
} // namespace pybind11
namespace llarp namespace llarp
{ {
@ -47,32 +52,32 @@ namespace llarp
RouterContact_Init(py::module &mod); RouterContact_Init(py::module &mod);
void void
Config_Init(py::module & mod); Config_Init(py::module &mod);
void void
PathTypes_Init(py::module & mod); PathTypes_Init(py::module &mod);
namespace dht namespace dht
{ {
void void
DHTTypes_Init(py::module& mod); DHTTypes_Init(py::module &mod);
} }
namespace path namespace path
{ {
void void
PathHopConfig_Init(py::module & mod); PathHopConfig_Init(py::module &mod);
} }
namespace handlers namespace handlers
{ {
void void
PyHandler_Init(py::module & mod); PyHandler_Init(py::module &mod);
} }
namespace service namespace service
{ {
void void
Address_Init(py::module &mod); Address_Init(py::module &mod);
} }
@ -81,8 +86,8 @@ namespace llarp
namespace tooling namespace tooling
{ {
void void
RouterHive_Init(py::module & mod); RouterHive_Init(py::module &mod);
void void
RouterEvent_Init(py::module & mod); RouterEvent_Init(py::module &mod);
} } // namespace tooling

@ -12,108 +12,111 @@ namespace llarp
} }
void void
Config_Init(py::module & mod) Config_Init(py::module &mod)
{ {
using Config_ptr = std::shared_ptr<Config>; using Config_ptr = std::shared_ptr< Config >;
py::class_<Config, Config_ptr>(mod, "Config") py::class_< Config, Config_ptr >(mod, "Config")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("router", &Config::router) .def_readwrite("router", &Config::router)
.def_readwrite("network", &Config::network) .def_readwrite("network", &Config::network)
.def_readwrite("connect", &Config::connect) .def_readwrite("connect", &Config::connect)
.def_readwrite("netdb", &Config::netdb) .def_readwrite("netdb", &Config::netdb)
.def_readwrite("dns", &Config::dns) .def_readwrite("dns", &Config::dns)
.def_readwrite("links", &Config::links) .def_readwrite("links", &Config::links)
.def_readwrite("services", &Config::services) .def_readwrite("services", &Config::services)
.def_readwrite("system", &Config::system) .def_readwrite("system", &Config::system)
.def_readwrite("api", &Config::api) .def_readwrite("api", &Config::api)
.def_readwrite("lokid", &Config::lokid) .def_readwrite("lokid", &Config::lokid)
.def_readwrite("bootstrap", &Config::bootstrap) .def_readwrite("bootstrap", &Config::bootstrap)
.def_readwrite("logging", &Config::logging) .def_readwrite("logging", &Config::logging)
.def("LoadFile", &Config::Load); .def("LoadFile", &Config::Load);
py::class_<RouterConfig>(mod, "RouterConfig") py::class_< RouterConfig >(mod, "RouterConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("minConnectedRouters", &RouterConfig::m_minConnectedRouters) .def_readwrite("minConnectedRouters",
.def_readwrite("maxConnectedRouters", &RouterConfig::m_maxConnectedRouters) &RouterConfig::m_minConnectedRouters)
.def_readwrite("netid", &RouterConfig::m_netId) .def_readwrite("maxConnectedRouters",
.def_readwrite("nickname", &RouterConfig::m_nickname) &RouterConfig::m_maxConnectedRouters)
.def_readwrite("encryptionKeyfile", &RouterConfig::m_encryptionKeyfile) .def_readwrite("netid", &RouterConfig::m_netId)
.def_readwrite("ourRcFile", &RouterConfig::m_ourRcFile) .def_readwrite("nickname", &RouterConfig::m_nickname)
.def_readwrite("transportKeyfile", &RouterConfig::m_transportKeyfile) .def_readwrite("encryptionKeyfile", &RouterConfig::m_encryptionKeyfile)
.def_readwrite("identKeyfile", &RouterConfig::m_identKeyfile) .def_readwrite("ourRcFile", &RouterConfig::m_ourRcFile)
.def_readwrite("blockBogons", &RouterConfig::m_blockBogons) .def_readwrite("transportKeyfile", &RouterConfig::m_transportKeyfile)
.def_readwrite("publicOverride", &RouterConfig::m_publicOverride) .def_readwrite("identKeyfile", &RouterConfig::m_identKeyfile)
.def_readwrite("ip4addr", &RouterConfig::m_ip4addr) .def_readwrite("blockBogons", &RouterConfig::m_blockBogons)
.def("overrideAddress", [](RouterConfig & self, std::string ip, std::string port) { .def_readwrite("publicOverride", &RouterConfig::m_publicOverride)
self.fromSection("public-ip", ip); .def_readwrite("ip4addr", &RouterConfig::m_ip4addr)
self.fromSection("public-port", port); .def("overrideAddress",
}) [](RouterConfig &self, std::string ip, std::string port) {
.def_readwrite("workerThreads", &RouterConfig::m_workerThreads) self.fromSection("public-ip", ip);
.def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads) self.fromSection("public-port", port);
.def_readwrite("JobQueueSize", &RouterConfig::m_JobQueueSize) })
.def_readwrite("DefaultLinkProto", &RouterConfig::m_DefaultLinkProto); .def_readwrite("workerThreads", &RouterConfig::m_workerThreads)
.def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads)
py::class_<NetworkConfig>(mod, "NetworkConfig") .def_readwrite("JobQueueSize", &RouterConfig::m_JobQueueSize)
.def(py::init<>()) .def_readwrite("DefaultLinkProto", &RouterConfig::m_DefaultLinkProto);
.def_readwrite("enableProfiling", &NetworkConfig::m_enableProfiling)
.def_readwrite("routerProfilesFile", &NetworkConfig::m_routerProfilesFile) py::class_< NetworkConfig >(mod, "NetworkConfig")
.def_readwrite("strictConnect", &NetworkConfig::m_strictConnect) .def(py::init<>())
.def_readwrite("netConfig", &NetworkConfig::m_netConfig); .def_readwrite("enableProfiling", &NetworkConfig::m_enableProfiling)
.def_readwrite("routerProfilesFile",
py::class_<ConnectConfig>(mod, "ConnectConfig") &NetworkConfig::m_routerProfilesFile)
.def(py::init<>()) .def_readwrite("strictConnect", &NetworkConfig::m_strictConnect)
.def_readwrite("routers", &ConnectConfig::routers); .def_readwrite("netConfig", &NetworkConfig::m_netConfig);
py::class_<NetdbConfig>(mod, "NetdbConfig") py::class_< ConnectConfig >(mod, "ConnectConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("nodedbDir", &NetdbConfig::m_nodedbDir); .def_readwrite("routers", &ConnectConfig::routers);
py::class_<DnsConfig>(mod, "DnsConfig") py::class_< NetdbConfig >(mod, "NetdbConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("netConfig", &DnsConfig::netConfig); .def_readwrite("nodedbDir", &NetdbConfig::m_nodedbDir);
py::class_<LinksConfig>(mod, "LinksConfig") py::class_< DnsConfig >(mod, "DnsConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("OutboundLink", &LinksConfig::m_OutboundLink) .def_readwrite("netConfig", &DnsConfig::netConfig);
.def_readwrite("InboundLinks", &LinksConfig::m_InboundLinks);
py::class_< LinksConfig >(mod, "LinksConfig")
py::class_<ServicesConfig>(mod, "ServicesConfig") .def(py::init<>())
.def(py::init<>()) .def_readwrite("OutboundLink", &LinksConfig::m_OutboundLink)
.def_readwrite("services", &ServicesConfig::services); .def_readwrite("InboundLinks", &LinksConfig::m_InboundLinks);
py::class_<SystemConfig>(mod, "SystemConfig") py::class_< ServicesConfig >(mod, "ServicesConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("pidfile", &SystemConfig::pidfile); .def_readwrite("services", &ServicesConfig::services);
py::class_<ApiConfig>(mod, "ApiConfig") py::class_< SystemConfig >(mod, "SystemConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("enableRPCServer", &ApiConfig::m_enableRPCServer) .def_readwrite("pidfile", &SystemConfig::pidfile);
.def_readwrite("rpcBindAddr", &ApiConfig::m_rpcBindAddr);
py::class_< ApiConfig >(mod, "ApiConfig")
py::class_<LokidConfig>(mod, "LokidConfig") .def(py::init<>())
.def(py::init<>()) .def_readwrite("enableRPCServer", &ApiConfig::m_enableRPCServer)
.def_readwrite("usingSNSeed", &LokidConfig::usingSNSeed) .def_readwrite("rpcBindAddr", &ApiConfig::m_rpcBindAddr);
.def_readwrite("whitelistRouters", &LokidConfig::whitelistRouters)
.def_readwrite("ident_keyfile", &LokidConfig::ident_keyfile) py::class_< LokidConfig >(mod, "LokidConfig")
.def_readwrite("lokidRPCAddr", &LokidConfig::lokidRPCAddr) .def(py::init<>())
.def_readwrite("lokidRPCUser", &LokidConfig::lokidRPCUser) .def_readwrite("usingSNSeed", &LokidConfig::usingSNSeed)
.def_readwrite("lokidRPCPassword", &LokidConfig::lokidRPCPassword); .def_readwrite("whitelistRouters", &LokidConfig::whitelistRouters)
.def_readwrite("ident_keyfile", &LokidConfig::ident_keyfile)
py::class_<BootstrapConfig>(mod, "BootstrapConfig") .def_readwrite("lokidRPCAddr", &LokidConfig::lokidRPCAddr)
.def(py::init<>()) .def_readwrite("lokidRPCUser", &LokidConfig::lokidRPCUser)
.def_readwrite("routers", &BootstrapConfig::routers); .def_readwrite("lokidRPCPassword", &LokidConfig::lokidRPCPassword);
py::class_<LoggingConfig>(mod, "LoggingConfig") py::class_< BootstrapConfig >(mod, "BootstrapConfig")
.def(py::init<>()) .def(py::init<>())
.def_readwrite("LogJSON", &LoggingConfig::m_LogJSON) .def_readwrite("routers", &BootstrapConfig::routers);
.def_readwrite("LogFile", &LoggingConfig::m_LogFile);
py::class_< LoggingConfig >(mod, "LoggingConfig")
py::class_<sockaddr_in>(mod, "sockaddr_in") .def(py::init<>())
.def_readwrite("sin_family", &sockaddr_in::sin_family) .def_readwrite("LogJSON", &LoggingConfig::m_LogJSON)
.def_readwrite("sin_port", &sockaddr_in::sin_port) .def_readwrite("LogFile", &LoggingConfig::m_LogFile);
.def_readwrite("sin_addr", &sockaddr_in::sin_addr);
py::class_< sockaddr_in >(mod, "sockaddr_in")
py::class_<in_addr>(mod, "in_addr") .def_readwrite("sin_family", &sockaddr_in::sin_family)
.def("set", &in_addr_set); .def_readwrite("sin_port", &sockaddr_in::sin_port)
.def_readwrite("sin_addr", &sockaddr_in::sin_addr);
py::class_< in_addr >(mod, "in_addr").def("set", &in_addr_set);
} }
} } // namespace llarp

@ -15,25 +15,31 @@ namespace llarp
[](Context_ptr self) -> int { [](Context_ptr self) -> int {
return self->Run(llarp_main_runtime_opts{}); return self->Run(llarp_main_runtime_opts{});
}) })
.def("Stop", [](Context_ptr self) { .def("Stop", [](Context_ptr self) { self->CloseAsync(); })
self->CloseAsync();
})
.def("IsUp", &Context::IsUp) .def("IsUp", &Context::IsUp)
.def("IsRelay", [](Context_ptr self) -> bool { .def("IsRelay",
return self->router->IsServiceNode(); [](Context_ptr self) -> bool {
}) return self->router->IsServiceNode();
})
.def("LooksAlive", &Context::LooksAlive) .def("LooksAlive", &Context::LooksAlive)
.def("Configure", &Context::Configure) .def("Configure", &Context::Configure)
.def("TrySendPacket", [](Context_ptr self, std::string from, service::Address to, std::string pkt) { .def("TrySendPacket",
auto ep = self->router->hiddenServiceContext().GetEndpointByName(from); [](Context_ptr self, std::string from, service::Address to,
std::vector<byte_t> buf; std::string pkt) {
buf.resize(pkt.size()); auto ep =
std::copy_n(pkt.c_str(), pkt.size(), buf.data()); self->router->hiddenServiceContext().GetEndpointByName(from);
return ep and ep->SendToServiceOrQueue(to, std::move(buf), service::eProtocolControl); std::vector< byte_t > buf;
}) buf.resize(pkt.size());
.def("AddEndpoint", [](Context_ptr self, handlers::PythonEndpoint_ptr ep) { std::copy_n(pkt.c_str(), pkt.size(), buf.data());
self->router->hiddenServiceContext().InjectEndpoint(ep->OurName, ep); return ep
}) and ep->SendToServiceOrQueue(to, std::move(buf),
service::eProtocolControl);
})
.def("AddEndpoint",
[](Context_ptr self, handlers::PythonEndpoint_ptr ep) {
self->router->hiddenServiceContext().InjectEndpoint(ep->OurName,
ep);
})
.def("CallSafe", &Context::CallSafe); .def("CallSafe", &Context::CallSafe);
} }
} // namespace llarp } // namespace llarp

@ -11,16 +11,17 @@ namespace llarp
DHTTypes_Init(py::module& mod) DHTTypes_Init(py::module& mod)
{ {
py::class_< Key_t >(mod, "DHTKey") py::class_< Key_t >(mod, "DHTKey")
.def(py::self == py::self) .def(py::self == py::self)
.def(py::self < py::self) .def(py::self < py::self)
.def(py::self ^ py::self) .def(py::self ^ py::self)
.def("distance", [](const Key_t* const lhs, const Key_t* const rhs) { .def("distance",
return *lhs ^ *rhs; [](const Key_t* const lhs, const Key_t* const rhs) {
}) return *lhs ^ *rhs;
.def("ShortString", [](const Key_t* const key) { })
return llarp::RouterID(key->as_array()).ShortString(); .def("ShortString", [](const Key_t* const key) {
}); return llarp::RouterID(key->as_array()).ShortString();
});
} }
} // namespace llarp::dht } // namespace dht
} // namespace llarp } // namespace llarp

@ -1,18 +1,18 @@
#include "llarp/handlers/pyhandler.hpp" #include "llarp/handlers/pyhandler.hpp"
namespace llarp namespace llarp
{ {
namespace handlers namespace handlers
{ {
void void
PyHandler_Init(py::module & mod) PyHandler_Init(py::module& mod)
{ {
py::class_<PythonEndpoint, PythonEndpoint_ptr >(mod, "Endpoint") py::class_< PythonEndpoint, PythonEndpoint_ptr >(mod, "Endpoint")
.def(py::init<std::string, Context_ptr>()) .def(py::init< std::string, Context_ptr >())
.def("SendTo", &PythonEndpoint::SendPacket) .def("SendTo", &PythonEndpoint::SendPacket)
.def("OurAddress", &PythonEndpoint::GetOurAddress) .def("OurAddress", &PythonEndpoint::GetOurAddress)
.def_readwrite("GotPacket", &PythonEndpoint::handlePacket); .def_readwrite("GotPacket", &PythonEndpoint::handlePacket);
} }
} // namespace handlers } // namespace handlers
} } // namespace llarp

@ -1,41 +1,43 @@
#pragma once #pragma once
#include "common.hpp" #include "common.hpp"
#include "llarp.hpp" #include "llarp.hpp"
#include "service/context.hpp" #include "service/context.hpp"
#include "service/endpoint.hpp" #include "service/endpoint.hpp"
#include "router/abstractrouter.hpp" #include "router/abstractrouter.hpp"
namespace llarp namespace llarp
{ {
namespace handlers namespace handlers
{ {
using Context_ptr = std::shared_ptr<llarp::Context>; using Context_ptr = std::shared_ptr< llarp::Context >;
struct PythonEndpoint final struct PythonEndpoint final
: public llarp::service::Endpoint, : public llarp::service::Endpoint,
public std::enable_shared_from_this< PythonEndpoint > public std::enable_shared_from_this< PythonEndpoint >
{ {
PythonEndpoint(std::string name, Context_ptr routerContext) PythonEndpoint(std::string name, Context_ptr routerContext)
: llarp::service::Endpoint(name, routerContext->router.get(), &routerContext->router->hiddenServiceContext()) : llarp::service::Endpoint(
name, routerContext->router.get(),
&routerContext->router->hiddenServiceContext())
, OurName(name) , OurName(name)
{ {
} }
const std::string OurName; const std::string OurName;
bool bool
HandleInboundPacket(const service::ConvoTag tag, const llarp_buffer_t & pktbuf, HandleInboundPacket(const service::ConvoTag tag,
const llarp_buffer_t& pktbuf,
service::ProtocolType proto) override service::ProtocolType proto) override
{ {
if(handlePacket) if(handlePacket)
{ {
AlignedBuffer<32> addr; AlignedBuffer< 32 > addr;
bool isSnode = false; bool isSnode = false;
if(not GetEndpointWithConvoTag(tag, addr, isSnode)) if(not GetEndpointWithConvoTag(tag, addr, isSnode))
return false; return false;
if(isSnode) if(isSnode)
return true; return true;
std::vector<byte_t> pkt; std::vector< byte_t > pkt;
pkt.resize(pktbuf.sz); pkt.resize(pktbuf.sz);
std::copy_n(pktbuf.base, pktbuf.sz, pkt.data()); std::copy_n(pktbuf.base, pktbuf.sz, pkt.data());
handlePacket(service::Address(addr), std::move(pkt), proto); handlePacket(service::Address(addr), std::move(pkt), proto);
@ -55,25 +57,29 @@ namespace handlers
return false; return false;
} }
using PacketHandler_t = std::function<void(service::Address, std::vector<byte_t>, service::ProtocolType)>; using PacketHandler_t = std::function< void(
service::Address, std::vector< byte_t >, service::ProtocolType) >;
PacketHandler_t handlePacket; PacketHandler_t handlePacket;
void void
SendPacket(service::Address remote, std::vector<byte_t> pkt, service::ProtocolType proto) SendPacket(service::Address remote, std::vector< byte_t > pkt,
service::ProtocolType proto)
{ {
LogicCall(m_router->logic(), [remote, pkt, proto, self=shared_from_this()]() { LogicCall(m_router->logic(),
self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt), proto); [remote, pkt, proto, self = shared_from_this()]() {
}); self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt),
proto);
});
} }
std::string std::string
GetOurAddress() const GetOurAddress() const
{ {
return m_Identity.pub.Addr().ToString(); return m_Identity.pub.Addr().ToString();
} }
}; };
using PythonEndpoint_ptr = std::shared_ptr<PythonEndpoint>; using PythonEndpoint_ptr = std::shared_ptr< PythonEndpoint >;
} } // namespace handlers
} } // namespace llarp

@ -6,24 +6,24 @@ namespace llarp
namespace path namespace path
{ {
void void
PathHopConfig_Init(py::module & mod) PathHopConfig_Init(py::module &mod)
{ {
auto str_func = [](PathHopConfig *hop) { auto str_func = [](PathHopConfig *hop) {
std::string s = "Hop: ["; std::string s = "Hop: [";
s += RouterID(hop->rc.pubkey).ShortString(); s += RouterID(hop->rc.pubkey).ShortString();
s += "] -> ["; s += "] -> [";
s += hop->upstream.ShortString(); s += hop->upstream.ShortString();
s += "]"; s += "]";
return s; return s;
}; };
py::class_< PathHopConfig >(mod, "PathHopConfig") py::class_< PathHopConfig >(mod, "PathHopConfig")
.def_readonly("rc", &PathHopConfig::rc) .def_readonly("rc", &PathHopConfig::rc)
.def_readonly("upstreamRouter", &PathHopConfig::upstream) .def_readonly("upstreamRouter", &PathHopConfig::upstream)
.def_readonly("txid", &PathHopConfig::txID) .def_readonly("txid", &PathHopConfig::txID)
.def_readonly("rxid", &PathHopConfig::rxID) .def_readonly("rxid", &PathHopConfig::rxID)
.def("ToString", str_func) .def("ToString", str_func)
.def("__str__", str_func) .def("__str__", str_func)
.def("__repr__", str_func); .def("__repr__", str_func);
} }
} // namespace llarp::path } // namespace path
} // namespace llarp } // namespace llarp

@ -6,13 +6,13 @@
namespace llarp namespace llarp
{ {
void void
PathTypes_Init(py::module & mod) PathTypes_Init(py::module& mod)
{ {
py::class_< PathID_t >(mod, "PathID") py::class_< PathID_t >(mod, "PathID")
.def(py::self == py::self) .def(py::self == py::self)
.def("ShortHex", &PathID_t::ShortHex) .def("ShortHex", &PathID_t::ShortHex)
.def("__str__", &PathID_t::ShortHex) .def("__str__", &PathID_t::ShortHex)
.def("__repr__", &PathID_t::ShortHex); .def("__repr__", &PathID_t::ShortHex);
} }
} // namespace llarp } // namespace llarp

@ -9,12 +9,16 @@ namespace llarp
{ {
py::class_< RouterContact >(mod, "RouterContact") py::class_< RouterContact >(mod, "RouterContact")
.def(py::init<>()) .def(py::init<>())
.def_property_readonly("routerID", [](const RouterContact* const rc) -> llarp::RouterID { .def_property_readonly(
return llarp::RouterID(rc->pubkey); "routerID",
}) [](const RouterContact* const rc) -> llarp::RouterID {
.def_property_readonly("AsDHTKey", [](const RouterContact* const rc) -> llarp::dht::Key_t { return llarp::RouterID(rc->pubkey);
return llarp::dht::Key_t{rc->pubkey.as_array()}; })
}) .def_property_readonly(
"AsDHTKey",
[](const RouterContact* const rc) -> llarp::dht::Key_t {
return llarp::dht::Key_t{rc->pubkey.as_array()};
})
.def("ReadFile", &RouterContact::Read) .def("ReadFile", &RouterContact::Read)
.def("WriteFile", &RouterContact::Write) .def("WriteFile", &RouterContact::Write)
.def("ToString", &RouterContact::ToString) .def("ToString", &RouterContact::ToString)

@ -5,9 +5,9 @@
namespace llarp namespace llarp
{ {
void void
RouterID_Init(py::module & mod) RouterID_Init(py::module& mod)
{ {
py::class_<RouterID>(mod, "RouterID") py::class_< RouterID >(mod, "RouterID")
.def("FromHex", .def("FromHex",
[](RouterID* r, const std::string& hex) -> bool { [](RouterID* r, const std::string& hex) -> bool {
return HexDecode(hex.c_str(), r->data(), r->size()); return HexDecode(hex.c_str(), r->data(), r->size());
@ -15,8 +15,9 @@ namespace llarp
.def("__repr__", &RouterID::ToString) .def("__repr__", &RouterID::ToString)
.def("__str__", &RouterID::ToString) .def("__str__", &RouterID::ToString)
.def("ShortString", &RouterID::ShortString) .def("ShortString", &RouterID::ShortString)
.def("__eq__", [](const RouterID* const lhs, const RouterID* const rhs) { .def("__eq__",
return *lhs == *rhs; [](const RouterID* const lhs, const RouterID* const rhs) {
}); return *lhs == *rhs;
});
} }
} } // namespace llarp

@ -5,14 +5,14 @@ namespace llarp
{ {
namespace service namespace service
{ {
void void
Address_Init(py::module & mod) Address_Init(py::module& mod)
{ {
py::class_<Address>(mod, "ServiceAddress") py::class_< Address >(mod, "ServiceAddress")
.def(py::init<std::string>()) .def(py::init< std::string >())
.def("__str__", [](const Address & addr) -> std::string { .def("__str__", [](const Address& addr) -> std::string {
return addr.ToString(); return addr.ToString();
}); });
} }
} } // namespace service
} } // namespace llarp

@ -12,55 +12,61 @@
namespace tooling namespace tooling
{ {
void void
RouterEvent_Init(py::module & mod) RouterEvent_Init(py::module& mod)
{ {
py::class_<RouterEvent>(mod, "RouterEvent") py::class_< RouterEvent >(mod, "RouterEvent")
.def("__repr__", &RouterEvent::ToString) .def("__repr__", &RouterEvent::ToString)
.def("__str__", &RouterEvent::ToString) .def("__str__", &RouterEvent::ToString)
.def_readonly("routerID", &RouterEvent::routerID) .def_readonly("routerID", &RouterEvent::routerID)
.def_readonly("triggered", &RouterEvent::triggered); .def_readonly("triggered", &RouterEvent::triggered);
py::class_<PathAttemptEvent, RouterEvent>(mod, "PathAttemptEvent") py::class_< PathAttemptEvent, RouterEvent >(mod, "PathAttemptEvent")
.def_readonly("hops", &PathAttemptEvent::hops); .def_readonly("hops", &PathAttemptEvent::hops);
py::class_<PathRequestReceivedEvent, RouterEvent>(mod, "PathRequestReceivedEvent") py::class_< PathRequestReceivedEvent, RouterEvent >(
.def_readonly("prevHop", &PathRequestReceivedEvent::prevHop) mod, "PathRequestReceivedEvent")
.def_readonly("nextHop", &PathRequestReceivedEvent::nextHop) .def_readonly("prevHop", &PathRequestReceivedEvent::prevHop)
.def_readonly("txid", &PathRequestReceivedEvent::txid) .def_readonly("nextHop", &PathRequestReceivedEvent::nextHop)
.def_readonly("rxid", &PathRequestReceivedEvent::rxid) .def_readonly("txid", &PathRequestReceivedEvent::txid)
.def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint); .def_readonly("rxid", &PathRequestReceivedEvent::rxid)
.def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint);
py::class_<PathStatusReceivedEvent, RouterEvent>(mod, "PathStatusReceivedEvent") py::class_< PathStatusReceivedEvent, RouterEvent >(
.def_readonly("rxid", &PathStatusReceivedEvent::rxid) mod, "PathStatusReceivedEvent")
.def_readonly("status", &PathStatusReceivedEvent::rxid) .def_readonly("rxid", &PathStatusReceivedEvent::rxid)
.def_property_readonly("Successful", [](const PathStatusReceivedEvent* const ev) { .def_readonly("status", &PathStatusReceivedEvent::rxid)
return ev->status == llarp::LR_StatusRecord::SUCCESS; .def_property_readonly(
}); "Successful", [](const PathStatusReceivedEvent* const ev) {
return ev->status == llarp::LR_StatusRecord::SUCCESS;
});
py::class_<PubIntroSentEvent, RouterEvent>(mod, "DhtPubIntroSentEvent") py::class_< PubIntroSentEvent, RouterEvent >(mod, "DhtPubIntroSentEvent")
.def_readonly("introsetPubkey", &PubIntroSentEvent::introsetPubkey) .def_readonly("introsetPubkey", &PubIntroSentEvent::introsetPubkey)
.def_readonly("relay", &PubIntroSentEvent::relay) .def_readonly("relay", &PubIntroSentEvent::relay)
.def_readonly("relayIndex", &PubIntroSentEvent::relayIndex); .def_readonly("relayIndex", &PubIntroSentEvent::relayIndex);
py::class_<PubIntroReceivedEvent, RouterEvent>(mod, "DhtPubIntroReceivedEvent") py::class_< PubIntroReceivedEvent, RouterEvent >(mod,
.def_readonly("from", &PubIntroReceivedEvent::From) "DhtPubIntroReceivedEvent")
.def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation) .def_readonly("from", &PubIntroReceivedEvent::From)
.def_readonly("relayOrder", &PubIntroReceivedEvent::RelayOrder) .def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation)
.def_readonly("txid", &PubIntroReceivedEvent::TxID); .def_readonly("relayOrder", &PubIntroReceivedEvent::RelayOrder)
.def_readonly("txid", &PubIntroReceivedEvent::TxID);
py::class_<GotIntroReceivedEvent, RouterEvent>(mod, "DhtGotIntroReceivedEvent") py::class_< GotIntroReceivedEvent, RouterEvent >(mod,
.def_readonly("from", &GotIntroReceivedEvent::From) "DhtGotIntroReceivedEvent")
.def_readonly("location", &GotIntroReceivedEvent::Introset) .def_readonly("from", &GotIntroReceivedEvent::From)
.def_readonly("relayOrder", &GotIntroReceivedEvent::RelayOrder) .def_readonly("location", &GotIntroReceivedEvent::Introset)
.def_readonly("txid", &GotIntroReceivedEvent::TxID); .def_readonly("relayOrder", &GotIntroReceivedEvent::RelayOrder)
.def_readonly("txid", &GotIntroReceivedEvent::TxID);
py::class_<RCGossipReceivedEvent, RouterEvent>(mod, "RCGossipReceivedEvent") py::class_< RCGossipReceivedEvent, RouterEvent >(mod,
.def_readonly("rc", &RCGossipReceivedEvent::rc) "RCGossipReceivedEvent")
.def("LongString", &RCGossipReceivedEvent::LongString); .def_readonly("rc", &RCGossipReceivedEvent::rc)
.def("LongString", &RCGossipReceivedEvent::LongString);
py::class_<RCGossipSentEvent, RouterEvent>(mod, "RCGossipSentEvent") py::class_< RCGossipSentEvent, RouterEvent >(mod, "RCGossipSentEvent")
.def_readonly("rc", &RCGossipSentEvent::rc) .def_readonly("rc", &RCGossipSentEvent::rc)
.def("LongString", &RCGossipSentEvent::LongString); .def("LongString", &RCGossipSentEvent::LongString);
} }
} // namespace tooling } // namespace tooling

@ -24,6 +24,5 @@ namespace tooling
.def("GetAllEvents", &RouterHive::GetAllEvents) .def("GetAllEvents", &RouterHive::GetAllEvents)
.def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays) .def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays)
.def("GetRelayRCs", &RouterHive::GetRelayRCs); .def("GetRelayRCs", &RouterHive::GetRelayRCs);
} }
} } // namespace tooling

@ -15,8 +15,5 @@ PYBIND11_MODULE(pyllarp, m)
llarp::path::PathHopConfig_Init(m); llarp::path::PathHopConfig_Init(m);
llarp::handlers::PyHandler_Init(m); llarp::handlers::PyHandler_Init(m);
llarp::service::Address_Init(m); llarp::service::Address_Init(m);
m.def("EnableDebug", []() { m.def("EnableDebug", []() { llarp::SetLogLevel(llarp::eLogDebug); });
llarp::SetLogLevel(llarp::eLogDebug);
});
} }

Loading…
Cancel
Save