From 84a1d7dbcc45665e3db7ac82af82deeadadfd420 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Fri, 6 Mar 2020 20:20:11 -0500 Subject: [PATCH] clang format....... --- include/llarp.hpp | 6 +- llarp/config/config.hpp | 3 +- llarp/context.cpp | 11 +- llarp/dht/messages/gotintro.cpp | 7 +- llarp/dht/messages/gotrouter.cpp | 8 +- llarp/dht/messages/pubintro.cpp | 6 +- llarp/ev/ev_libuv.cpp | 18 ++- llarp/handlers/null.hpp | 1 - llarp/messages/relay_commit.cpp | 2 +- llarp/messages/relay_status.cpp | 10 +- llarp/path/pathbuilder.cpp | 5 +- llarp/router/abstractrouter.hpp | 5 +- llarp/router/rc_gossiper.cpp | 11 +- llarp/router/rc_gossiper.hpp | 2 +- llarp/router/router.cpp | 6 +- llarp/router/router.hpp | 3 +- llarp/service/address.hpp | 2 +- llarp/service/context.cpp | 3 +- llarp/service/context.hpp | 4 +- llarp/service/endpoint.cpp | 29 ++-- llarp/service/endpoint.hpp | 5 +- llarp/tooling/dht_event.cpp | 59 +++++--- llarp/tooling/dht_event.hpp | 37 +++-- llarp/tooling/path_event.cpp | 46 +++--- llarp/tooling/path_event.hpp | 24 +-- llarp/tooling/rc_event.cpp | 22 +-- llarp/tooling/rc_event.hpp | 9 +- llarp/tooling/router_event.cpp | 8 +- llarp/tooling/router_event.hpp | 17 +-- llarp/tooling/router_hive.cpp | 88 +++++------ llarp/tooling/router_hive.hpp | 45 +++--- llarp/util/thread/queue.hpp | 12 +- pybind/common.hpp | 65 ++++---- pybind/llarp/config.cpp | 209 +++++++++++++------------- pybind/llarp/context.cpp | 38 +++-- pybind/llarp/dht/dht_types.cpp | 23 +-- pybind/llarp/handlers/pyhandler.cpp | 22 +-- pybind/llarp/handlers/pyhandler.hpp | 46 +++--- pybind/llarp/path/path_hop_config.cpp | 32 ++-- pybind/llarp/path/path_types.cpp | 10 +- pybind/llarp/router_contact.cpp | 16 +- pybind/llarp/router_id.cpp | 13 +- pybind/llarp/service/address.cpp | 18 +-- pybind/llarp/tooling/router_event.cpp | 88 ++++++----- pybind/llarp/tooling/router_hive.cpp | 3 +- pybind/module.cpp | 5 +- 46 files changed, 585 insertions(+), 517 deletions(-) diff --git a/include/llarp.hpp b/include/llarp.hpp index af5af3bcc..ca136a65e 100644 --- a/include/llarp.hpp +++ b/include/llarp.hpp @@ -20,7 +20,7 @@ struct llarp_main; namespace tooling { struct RouterHive; -} // namespace tooling +} // namespace tooling #endif namespace llarp @@ -39,7 +39,7 @@ namespace llarp struct Context { /// get context from main pointer - static std::shared_ptr + static std::shared_ptr< Context > Get(llarp_main *); Context() = default; @@ -97,7 +97,7 @@ namespace llarp #ifdef LOKINET_HIVE void - InjectHive(tooling::RouterHive* hive); + InjectHive(tooling::RouterHive *hive); #endif private: diff --git a/llarp/config/config.hpp b/llarp/config/config.hpp index a6975eaa9..1a9a9563a 100644 --- a/llarp/config/config.hpp +++ b/llarp/config/config.hpp @@ -13,7 +13,6 @@ #include #include - struct llarp_config; namespace llarp { @@ -259,7 +258,7 @@ namespace llarp bool LoadFromStr(string_view str); - llarp_config * + llarp_config* Copy() const; }; diff --git a/llarp/context.cpp b/llarp/context.cpp index cbbc29991..ca31bc15f 100644 --- a/llarp/context.cpp +++ b/llarp/context.cpp @@ -303,7 +303,7 @@ namespace llarp #ifdef LOKINET_HIVE void - Context::InjectHive(tooling::RouterHive* hive) + Context::InjectHive(tooling::RouterHive *hive) { router->hive = hive; } @@ -332,11 +332,11 @@ namespace llarp llarp_config * Config::Copy() const { - llarp_config * ptr = new llarp_config(); - ptr->impl = *this; + llarp_config *ptr = new llarp_config(); + ptr->impl = *this; return ptr; } -} +} // namespace llarp extern "C" { @@ -560,8 +560,7 @@ llarp_main::llarp_main(llarp_config *conf) namespace llarp { - - std::shared_ptr + std::shared_ptr< Context > Context::Get(llarp_main *m) { if(m == nullptr || m->ctx == nullptr) diff --git a/llarp/dht/messages/gotintro.cpp b/llarp/dht/messages/gotintro.cpp index a5e4ab9ab..5982dd8e5 100644 --- a/llarp/dht/messages/gotintro.cpp +++ b/llarp/dht/messages/gotintro.cpp @@ -24,12 +24,11 @@ namespace llarp llarp_dht_context *ctx, std::vector< std::unique_ptr< IMessage > > & /*replies*/) const { - auto &dht = *ctx->impl; + auto &dht = *ctx->impl; auto *router = dht.GetRouter(); - auto ev = std::make_unique( - router->pubkey(), - Key_t(From.data()), + auto ev = std::make_unique< tooling::GotIntroReceivedEvent >( + router->pubkey(), Key_t(From.data()), (found.size() > 0 ? found[0] : llarp::service::EncryptedIntroSet{}), txid); router->NotifyRouterEvent(std::move(ev)); diff --git a/llarp/dht/messages/gotrouter.cpp b/llarp/dht/messages/gotrouter.cpp index 61c86af61..f61935dcc 100644 --- a/llarp/dht/messages/gotrouter.cpp +++ b/llarp/dht/messages/gotrouter.cpp @@ -125,11 +125,13 @@ namespace llarp { if(not dht.GetRouter()->rcLookupHandler().CheckRC(rc)) 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(); - tooling::RouterEventPtr event = std::make_unique(router->pubkey(), rc); + tooling::RouterEventPtr event = + std::make_unique< tooling::RCGossipReceivedEvent >( + router->pubkey(), rc); router->NotifyRouterEvent(std::move(event)); router->GossipRCIfNeeded(rc); } diff --git a/llarp/dht/messages/pubintro.cpp b/llarp/dht/messages/pubintro.cpp index 0ba6519c7..9557f1701 100644 --- a/llarp/dht/messages/pubintro.cpp +++ b/llarp/dht/messages/pubintro.cpp @@ -58,12 +58,14 @@ namespace llarp llarp_dht_context *ctx, 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 auto keyStr = addr.ToHex(); auto router = ctx->impl->GetRouter(); - auto ev = std::make_unique(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)); auto &dht = *ctx->impl; diff --git a/llarp/ev/ev_libuv.cpp b/llarp/ev/ev_libuv.cpp index 97371e9c3..c9aad3153 100644 --- a/llarp/ev/ev_libuv.cpp +++ b/llarp/ev/ev_libuv.cpp @@ -783,14 +783,16 @@ namespace libuv #endif m_LogicCaller.data = this; int err; - if ((err = uv_async_init(&m_Impl, &m_LogicCaller, [](uv_async_t* h) { - Loop* l = static_cast< Loop* >(h->data); - while(not l->m_LogicCalls.empty()) - { - auto f = l->m_LogicCalls.popFront(); - f(); - } - })) != 0) + if((err = uv_async_init(&m_Impl, &m_LogicCaller, + [](uv_async_t* h) { + Loop* l = static_cast< Loop* >(h->data); + while(not l->m_LogicCalls.empty()) + { + auto f = l->m_LogicCalls.popFront(); + f(); + } + })) + != 0) { llarp::LogError("Libuv uv_async_init returned error: ", uv_strerror(err)); return false; diff --git a/llarp/handlers/null.hpp b/llarp/handlers/null.hpp index c54a52338..5f25c8545 100644 --- a/llarp/handlers/null.hpp +++ b/llarp/handlers/null.hpp @@ -11,7 +11,6 @@ namespace llarp : public llarp::service::Endpoint, public std::enable_shared_from_this< NullEndpoint > { - NullEndpoint(const std::string &name, AbstractRouter *r, llarp::service::Context *parent) : llarp::service::Endpoint(name, r, parent) diff --git a/llarp/messages/relay_commit.cpp b/llarp/messages/relay_commit.cpp index 5685687fb..16a7776d1 100644 --- a/llarp/messages/relay_commit.cpp +++ b/llarp/messages/relay_commit.cpp @@ -419,7 +419,7 @@ namespace llarp // TODO: check if we really want to accept it self->hop->started = now; - auto event = std::make_unique( + auto event = std::make_unique< tooling::PathRequestReceivedEvent >( self->context->Router()->pubkey(), self->hop); self->context->Router()->NotifyRouterEvent(std::move(event)); diff --git a/llarp/messages/relay_status.cpp b/llarp/messages/relay_status.cpp index 829085ace..b8238a386 100644 --- a/llarp/messages/relay_status.cpp +++ b/llarp/messages/relay_status.cpp @@ -29,7 +29,8 @@ namespace llarp PathID_t pathid; 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)) , status(_status) , path(std::move(_path)) @@ -43,7 +44,8 @@ namespace llarp void handle() { - auto ev = std::make_unique(router->pubkey(), pathid, status); + auto ev = std::make_unique< tooling::PathStatusReceivedEvent >( + router->pubkey(), pathid, status); router->NotifyRouterEvent(std::move(ev)); path->HandleLRSM(status, frames, router); @@ -146,8 +148,8 @@ namespace llarp return false; } - auto handler = - std::make_shared< LRSM_AsyncHandler >(frames, status, path, router, pathid); + auto handler = std::make_shared< LRSM_AsyncHandler >(frames, status, path, + router, pathid); handler->queue_handle(); diff --git a/llarp/path/pathbuilder.cpp b/llarp/path/pathbuilder.cpp index d98fb9ca0..2539675e2 100644 --- a/llarp/path/pathbuilder.cpp +++ b/llarp/path/pathbuilder.cpp @@ -132,7 +132,9 @@ namespace llarp { if(!ctx->pathset->IsStopped()) { - tooling::RouterEventPtr event = std::make_unique(ctx->router->pubkey(), ctx->path); + tooling::RouterEventPtr event = + std::make_unique< tooling::PathAttemptEvent >(ctx->router->pubkey(), + ctx->path); ctx->router->NotifyRouterEvent(std::move(event)); const RouterID remote = ctx->path->Upstream(); @@ -450,7 +452,6 @@ namespace llarp std::move(path_shortName)); LogInfo(Name(), " build ", path->ShortName(), ": ", path->HopsString()); - path->SetBuildResultHook( [self](Path_ptr p) { self->HandlePathBuilt(p); }); ctx->AsyncGenerateKeys(path, m_router->logic(), m_router->threadpool(), diff --git a/llarp/router/abstractrouter.hpp b/llarp/router/abstractrouter.hpp index 742d3c55f..475536283 100644 --- a/llarp/router/abstractrouter.hpp +++ b/llarp/router/abstractrouter.hpp @@ -20,7 +20,7 @@ struct llarp_threadpool; namespace tooling { struct RouterHive; -} // namespace tooling +} // namespace tooling namespace llarp { @@ -65,9 +65,8 @@ namespace llarp struct AbstractRouter { - #ifdef LOKINET_HIVE - tooling::RouterHive* hive; + tooling::RouterHive *hive; #endif virtual ~AbstractRouter() = default; diff --git a/llarp/router/rc_gossiper.cpp b/llarp/router/rc_gossiper.cpp index 6c126ce96..4c11258ee 100644 --- a/llarp/router/rc_gossiper.cpp +++ b/llarp/router/rc_gossiper.cpp @@ -21,18 +21,19 @@ namespace llarp } void - RCGossiper::Init(ILinkManager* l, const RouterID& ourID, AbstractRouter* router) + RCGossiper::Init(ILinkManager* l, const RouterID& ourID, + AbstractRouter* router) { m_OurRouterID = ourID; m_LinkManager = l; - m_router = router; + m_router = router; } bool RCGossiper::ShouldGossipOurRC(Time_t now) const { bool should = now >= (m_LastGossipedOurRC + GossipOurRCInterval); -LogWarn("ShouldGossipOurRC: ", should); + LogWarn("ShouldGossipOurRC: ", should); return should; } @@ -98,7 +99,9 @@ LogWarn("ShouldGossipOurRC: ", should); return; msg.resize(buf.cur - buf.base); - tooling::RouterEventPtr event = std::make_unique(m_router->pubkey(), rc); + tooling::RouterEventPtr event = + std::make_unique< tooling::RCGossipSentEvent >(m_router->pubkey(), + rc); m_router->NotifyRouterEvent(std::move(event)); // send message diff --git a/llarp/router/rc_gossiper.hpp b/llarp/router/rc_gossiper.hpp index 2f4227c44..702ef2a96 100644 --- a/llarp/router/rc_gossiper.hpp +++ b/llarp/router/rc_gossiper.hpp @@ -28,7 +28,7 @@ namespace llarp IsOurRC(const RouterContact &rc) const override; void - Init(ILinkManager *, const RouterID &, AbstractRouter*); + Init(ILinkManager *, const RouterID &, AbstractRouter *); private: RouterID m_OurRouterID; diff --git a/llarp/router/router.cpp b/llarp/router/router.cpp index 58acc9204..028ce0600 100644 --- a/llarp/router/router.cpp +++ b/llarp/router/router.cpp @@ -59,7 +59,8 @@ namespace llarp , inbound_link_msg_parser(this) , _hiddenServiceContext(this) #ifdef LOKINET_HIVE - , _randomStartDelay(std::chrono::milliseconds((llarp::randint() % 1250) + 2000)) + , _randomStartDelay( + std::chrono::milliseconds((llarp::randint() % 1250) + 2000)) #else , _randomStartDelay(std::chrono::seconds((llarp::randint() % 30) + 10)) #endif @@ -482,7 +483,8 @@ namespace llarp 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; configRouters.insert(configRouters.end(), conf->bootstrap.routers.begin(), conf->bootstrap.routers.end()); diff --git a/llarp/router/router.hpp b/llarp/router/router.hpp index 2fd7e877f..0f3bb6dd7 100644 --- a/llarp/router/router.hpp +++ b/llarp/router/router.hpp @@ -46,7 +46,7 @@ namespace tooling { struct RouterHive; -} // namespace tooling +} // namespace tooling namespace llarp { @@ -228,7 +228,6 @@ namespace llarp return _hiddenServiceContext; } - llarp_time_t _lastTick = 0s; bool diff --git a/llarp/service/address.hpp b/llarp/service/address.hpp index 881a751a0..5500ba70a 100644 --- a/llarp/service/address.hpp +++ b/llarp/service/address.hpp @@ -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)) throw std::runtime_error("invalid address"); diff --git a/llarp/service/context.cpp b/llarp/service/context.cpp index 71f89d804..bd4da3d77 100644 --- a/llarp/service/context.cpp +++ b/llarp/service/context.cpp @@ -192,9 +192,8 @@ namespace llarp return nullptr; } - void - Context::InjectEndpoint(std::string name, std::shared_ptr ep) + Context::InjectEndpoint(std::string name, std::shared_ptr< Endpoint > ep) { ep->LoadKeyFile(); if(ep->Start()) diff --git a/llarp/service/context.hpp b/llarp/service/context.hpp index 6256aa7ae..c4905ddc7 100644 --- a/llarp/service/context.hpp +++ b/llarp/service/context.hpp @@ -48,7 +48,7 @@ namespace llarp /// inject endpoint instance void - InjectEndpoint(std::string name, std::shared_ptr ep); + InjectEndpoint(std::string name, std::shared_ptr< Endpoint > ep); /// stop and remove an endpoint by name /// return false if we don't have the hidden service with that name @@ -58,7 +58,7 @@ namespace llarp Endpoint_ptr GetEndpointByName(const std::string &name); - Endpoint_ptr + Endpoint_ptr GetDefault() { return GetEndpointByName("default"); diff --git a/llarp/service/endpoint.cpp b/llarp/service/endpoint.cpp index 1f3a388f8..04f47a3be 100644 --- a/llarp/service/endpoint.cpp +++ b/llarp/service/endpoint.cpp @@ -199,17 +199,19 @@ namespace llarp // prefetch addrs for(const auto& addr : m_state->m_PrefetchAddrs) { - EnsurePathToService( - addr, [](Address, OutboundContext* ctx) { - #ifdef LOKINET_HIVE - std::vector discard; - discard.resize(128); - ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard), eProtocolControl); - #else - (void)ctx; - #endif - }, 10s); - + EnsurePathToService( + addr, + [](Address, OutboundContext* ctx) { +#ifdef LOKINET_HIVE + std::vector< byte_t > discard; + discard.resize(128); + ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard), + eProtocolControl); +#else + (void)ctx; +#endif + }, + 10s); } // deregister dead sessions @@ -477,7 +479,10 @@ namespace llarp { for(size_t i = 0; i < llarp::dht::IntroSetRequestsPerRelay; ++i) { - auto ev = std::make_unique(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)); if(PublishIntroSetVia(introset, r, path, published)) published++; diff --git a/llarp/service/endpoint.hpp b/llarp/service/endpoint.hpp index 93d980173..574fe85db 100644 --- a/llarp/service/endpoint.hpp +++ b/llarp/service/endpoint.hpp @@ -369,14 +369,13 @@ namespace llarp const std::set< RouterID >& SnodeBlacklist() const; - bool SendToServiceOrQueue(const service::Address& addr, const llarp_buffer_t& payload, ProtocolType t); bool SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& payload); - - protected: + + protected: /// parent context that owns this endpoint Context* const context; diff --git a/llarp/tooling/dht_event.cpp b/llarp/tooling/dht_event.cpp index 61d468437..34898329f 100644 --- a/llarp/tooling/dht_event.cpp +++ b/llarp/tooling/dht_event.cpp @@ -1,41 +1,49 @@ #include "dht_event.hpp" #include "service/intro_set.hpp" - 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) : - RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true), - From(from), - IntrosetLocation(location), - RelayOrder(relayOrder), - TxID(txid) - {} + PubIntroReceivedEvent::PubIntroReceivedEvent( + const llarp::RouterID& ourRouter, const llarp::dht::Key_t& from, + const llarp::dht::Key_t& location, uint64_t txid, uint64_t relayOrder) + : RouterEvent("DHT: PubIntroReceivedEvent", ourRouter, true) + , From(from) + , 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) - : RouterEvent("DHT: PubIntroSentEvent", ourRouter, false) - , introsetPubkey(introsetPubkey) - , relay(relay) - , relayIndex(relayIndex) + PubIntroSentEvent::PubIntroSentEvent(const llarp::RouterID& ourRouter, + const llarp::dht::Key_t& introsetPubkey, + const llarp::RouterID& relay, + uint64_t relayIndex) + : RouterEvent("DHT: PubIntroSentEvent", ourRouter, false) + , introsetPubkey(introsetPubkey) + , relay(relay) + , relayIndex(relayIndex) { } std::string 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( - const llarp::RouterID& ourRouter_, - const llarp::dht::Key_t& from_, - const llarp::service::EncryptedIntroSet & introset_, - uint64_t txid_) + const llarp::RouterID& ourRouter_, const llarp::dht::Key_t& from_, + const llarp::service::EncryptedIntroSet& introset_, uint64_t txid_) : RouterEvent("DHT:: GotIntroReceivedEvent", ourRouter_, true) , From(from_) , 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 diff --git a/llarp/tooling/dht_event.hpp b/llarp/tooling/dht_event.hpp index 39a6c1db1..dc5abe0eb 100644 --- a/llarp/tooling/dht_event.hpp +++ b/llarp/tooling/dht_event.hpp @@ -6,10 +6,11 @@ namespace tooling { - 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; @@ -17,34 +18,40 @@ namespace tooling uint64_t relayIndex; - std::string ToString() const override; + std::string + ToString() const override; }; 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 IntrosetLocation; uint64_t RelayOrder; uint64_t TxID; - std::string ToString() const override; + std::string + ToString() const override; }; struct GotIntroReceivedEvent : public RouterEvent { // 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? - GotIntroReceivedEvent( - const llarp::RouterID & ourRouter, - const llarp::dht::Key_t & from, - const llarp::service::EncryptedIntroSet & introset, - uint64_t txid); - + // TODO: question: what ties this to the actual logic that knows an event + // occurred? + GotIntroReceivedEvent(const llarp::RouterID& ourRouter, + const llarp::dht::Key_t& from, + const llarp::service::EncryptedIntroSet& introset, + uint64_t txid); + llarp::dht::Key_t From; llarp::service::EncryptedIntroSet Introset; uint64_t RelayOrder; uint64_t TxID; - std::string ToString() const override; + std::string + ToString() const override; }; -} +} // namespace tooling diff --git a/llarp/tooling/path_event.cpp b/llarp/tooling/path_event.cpp index 73c75b143..bb7fc7212 100644 --- a/llarp/tooling/path_event.cpp +++ b/llarp/tooling/path_event.cpp @@ -5,11 +5,12 @@ namespace tooling { - - PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr path) - : RouterEvent("PathAttemptEvent", routerID, false) - , hops(path->hops) - , pathid(path->hops[0].rxID) + PathAttemptEvent::PathAttemptEvent( + const llarp::RouterID& routerID, + std::shared_ptr< const llarp::path::Path > path) + : RouterEvent("PathAttemptEvent", routerID, false) + , hops(path->hops) + , pathid(path->hops[0].rxID) { } @@ -20,14 +21,14 @@ namespace tooling result += "---- ["; size_t i = 0; - for (const auto& hop : hops) + for(const auto& hop : hops) { i++; result += llarp::RouterID(hop.rc.pubkey).ShortString(); result += "]"; - if (i != hops.size()) + if(i != hops.size()) { result += " -> ["; } @@ -36,16 +37,17 @@ namespace tooling return result; } - - PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr hop) - : RouterEvent("PathRequestReceivedEvent", routerID, true) - , prevHop(hop->info.downstream) - , nextHop(hop->info.upstream) - , txid(hop->info.txID) - , rxid(hop->info.rxID) + PathRequestReceivedEvent::PathRequestReceivedEvent( + const llarp::RouterID& routerID, + std::shared_ptr< const llarp::path::TransitHop > hop) + : RouterEvent("PathRequestReceivedEvent", routerID, true) + , prevHop(hop->info.downstream) + , nextHop(hop->info.upstream) + , txid(hop->info.txID) + , rxid(hop->info.rxID) { isEndpoint = false; - if (routerID == nextHop) + if(routerID == nextHop) { isEndpoint = true; } @@ -61,7 +63,7 @@ namespace tooling result += routerID.ShortString(); result += "] -> ["; - if (isEndpoint) + if(isEndpoint) { result += "nowhere]"; } @@ -74,10 +76,12 @@ namespace tooling return result; } - PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status) - : RouterEvent("PathStatusReceivedEvent", routerID, true) - , rxid(rxid) - , status(status) + PathStatusReceivedEvent::PathStatusReceivedEvent( + const llarp::RouterID& routerID, const llarp::PathID_t rxid, + uint64_t status) + : RouterEvent("PathStatusReceivedEvent", routerID, true) + , rxid(rxid) + , status(status) { } @@ -91,4 +95,4 @@ namespace tooling return result; } -} // namespace tooling +} // namespace tooling diff --git a/llarp/tooling/path_event.hpp b/llarp/tooling/path_event.hpp index d4ce30272..a8b652863 100644 --- a/llarp/tooling/path_event.hpp +++ b/llarp/tooling/path_event.hpp @@ -4,23 +4,27 @@ namespace tooling { - struct PathAttemptEvent : public RouterEvent { - PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr 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 hops; + std::vector< llarp::path::PathHopConfig > hops; llarp::PathID_t pathid; }; struct PathRequestReceivedEvent : public RouterEvent { - PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr 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 nextHop; @@ -33,13 +37,15 @@ namespace tooling 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; uint64_t status; }; -} // namespace tooling +} // namespace tooling diff --git a/llarp/tooling/rc_event.cpp b/llarp/tooling/rc_event.cpp index b5894bc17..ff88d8374 100644 --- a/llarp/tooling/rc_event.cpp +++ b/llarp/tooling/rc_event.cpp @@ -2,16 +2,17 @@ namespace tooling { - RCGossipReceivedEvent::RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc) - : RouterEvent("RCGossipReceivedEvent", routerID, true) - , rc(rc) + RCGossipReceivedEvent::RCGossipReceivedEvent(const llarp::RouterID& routerID, + const llarp::RouterContact& rc) + : RouterEvent("RCGossipReceivedEvent", routerID, true), rc(rc) { } std::string 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 @@ -20,17 +21,17 @@ namespace tooling return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); } - - RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc) - : RouterEvent("RCGossipSentEvent", routerID, true) - , rc(rc) + RCGossipSentEvent::RCGossipSentEvent(const llarp::RouterID& routerID, + const llarp::RouterContact& rc) + : RouterEvent("RCGossipSentEvent", routerID, true), rc(rc) { } std::string 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 @@ -39,5 +40,4 @@ namespace tooling return RouterEvent::ToString() + " ---- RC: " + rc.ToString(); } -} // namespace tooling - +} // namespace tooling diff --git a/llarp/tooling/rc_event.hpp b/llarp/tooling/rc_event.hpp index 02f361220..46e7857cd 100644 --- a/llarp/tooling/rc_event.hpp +++ b/llarp/tooling/rc_event.hpp @@ -6,7 +6,8 @@ namespace tooling { struct RCGossipReceivedEvent : public RouterEvent { - RCGossipReceivedEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc); + RCGossipReceivedEvent(const llarp::RouterID& routerID, + const llarp::RouterContact& rc); std::string ToString() const override; @@ -19,7 +20,8 @@ namespace tooling struct RCGossipSentEvent : public RouterEvent { - RCGossipSentEvent(const llarp::RouterID& routerID, const llarp::RouterContact& rc); + RCGossipSentEvent(const llarp::RouterID& routerID, + const llarp::RouterContact& rc); std::string ToString() const override; @@ -30,5 +32,4 @@ namespace tooling llarp::RouterContact rc; }; -} // namespace tooling - +} // namespace tooling diff --git a/llarp/tooling/router_event.cpp b/llarp/tooling/router_event.cpp index ff74c68bb..1ca776df6 100644 --- a/llarp/tooling/router_event.cpp +++ b/llarp/tooling/router_event.cpp @@ -2,9 +2,9 @@ namespace tooling { - - RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered) - : eventType(eventType), routerID(routerID), triggered(triggered) + RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID, + bool triggered) + : eventType(eventType), routerID(routerID), triggered(triggered) { } @@ -19,4 +19,4 @@ namespace tooling return result; } -} // namespace tooling +} // namespace tooling diff --git a/llarp/tooling/router_event.hpp b/llarp/tooling/router_event.hpp index a72b59132..7214fc504 100644 --- a/llarp/tooling/router_event.hpp +++ b/llarp/tooling/router_event.hpp @@ -8,7 +8,6 @@ namespace llarp { - struct PathID_t; namespace path @@ -18,23 +17,23 @@ namespace llarp struct TransitHop; - } // namespace llarp::path - -} // namespace llarp + } // namespace path +} // namespace llarp namespace tooling { - struct RouterHive; struct RouterEvent { - RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered); + RouterEvent(std::string eventType, llarp::RouterID routerID, + bool triggered); virtual ~RouterEvent() = default; - virtual std::string ToString() const; + virtual std::string + ToString() const; const std::string eventType; @@ -43,6 +42,6 @@ namespace tooling bool triggered = false; }; - using RouterEventPtr = std::unique_ptr; + using RouterEventPtr = std::unique_ptr< RouterEvent >; -} // namespace tooling +} // namespace tooling diff --git a/llarp/tooling/router_hive.cpp b/llarp/tooling/router_hive.cpp index 6dca3edf2..87f7c33b6 100644 --- a/llarp/tooling/router_hive.cpp +++ b/llarp/tooling/router_hive.cpp @@ -13,7 +13,8 @@ using namespace std::chrono_literals; namespace tooling { void - RouterHive::AddRouter(const std::shared_ptr & config, std::vector *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()); if(llarp_main_setup(ctx) == 0) @@ -24,24 +25,24 @@ namespace tooling } void - RouterHive::AddRelay(const std::shared_ptr & config) + RouterHive::AddRelay(const std::shared_ptr< llarp::Config >& config) { AddRouter(config, &relays); } void - RouterHive::AddClient(const std::shared_ptr & config) + RouterHive::AddClient(const std::shared_ptr< llarp::Config >& config) { AddRouter(config, &clients); } void - RouterHive::StartRouters(std::vector *routers) + RouterHive::StartRouters(std::vector< llarp_main* >* routers) { - for (llarp_main* ctx : *routers) + for(llarp_main* ctx : *routers) { - routerMainThreads.emplace_back([ctx](){ - llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false}); + routerMainThreads.emplace_back([ctx]() { + llarp_main_run(ctx, llarp_main_runtime_opts{false, false, false}); }); std::this_thread::sleep_for(2ms); } @@ -62,26 +63,25 @@ namespace tooling void RouterHive::StopRouters() { - llarp::LogInfo("Signalling all routers to stop"); - for (llarp_main* ctx : relays) + for(llarp_main* ctx : relays) { llarp_main_signal(ctx, 2 /* SIGINT */); } - for (llarp_main* ctx : clients) + for(llarp_main* ctx : clients) { llarp_main_signal(ctx, 2 /* SIGINT */); } llarp::LogInfo("Waiting on routers to be stopped"); - for (llarp_main* ctx : relays) + for(llarp_main* ctx : relays) { while(llarp_main_is_running(ctx)) { std::this_thread::sleep_for(10ms); } } - for (llarp_main* ctx : clients) + for(llarp_main* ctx : clients) { while(llarp_main_is_running(ctx)) { @@ -90,9 +90,9 @@ namespace tooling } 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); } @@ -105,7 +105,7 @@ namespace tooling void RouterHive::NotifyEvent(RouterEventPtr event) { - std::lock_guard guard{eventQueueMutex}; + std::lock_guard< std::mutex > guard{eventQueueMutex}; eventQueue.push_back(std::move(event)); } @@ -113,9 +113,9 @@ namespace tooling RouterEventPtr RouterHive::GetNextEvent() { - std::lock_guard guard{eventQueueMutex}; + std::lock_guard< std::mutex > guard{eventQueueMutex}; - if (not eventQueue.empty()) + if(not eventQueue.empty()) { auto ptr = std::move(eventQueue.front()); eventQueue.pop_front(); @@ -124,13 +124,13 @@ namespace tooling return nullptr; } - std::deque + std::deque< RouterEventPtr > RouterHive::GetAllEvents() { - std::lock_guard guard{eventQueueMutex}; + std::lock_guard< std::mutex > guard{eventQueueMutex}; - std::deque events; - if (not eventQueue.empty()) + std::deque< RouterEventPtr > events; + if(not eventQueue.empty()) { eventQueue.swap(events); } @@ -138,16 +138,15 @@ namespace tooling } void - RouterHive::VisitRouter(llarp_main *router, std::function visit) + RouterHive::VisitRouter(llarp_main* router, + std::function< void(Context_ptr) > visit) { auto ctx = llarp::Context::Get(router); - LogicCall(ctx->logic, [visit, ctx]() { - visit(ctx); - }); + LogicCall(ctx->logic, [visit, ctx]() { visit(ctx); }); } void - RouterHive::VisitRelay(size_t index, std::function visit) + RouterHive::VisitRelay(size_t index, std::function< void(Context_ptr) > visit) { if(index >= relays.size()) { @@ -158,7 +157,8 @@ namespace tooling } void - RouterHive::VisitClient(size_t index, std::function visit) + RouterHive::VisitClient(size_t index, + std::function< void(Context_ptr) > visit) { if(index >= clients.size()) { @@ -168,35 +168,35 @@ namespace tooling VisitRouter(clients[index], visit); } - std::vector + std::vector< size_t > RouterHive::RelayConnectedRelays() { - std::vector results; + std::vector< size_t > results; results.resize(relays.size()); std::mutex results_lock; - size_t i=0; + size_t i = 0; size_t done_count = 0; - for (auto relay : relays) + for(auto relay : relays) { auto ctx = llarp::Context::Get(relay); LogicCall(ctx->logic, [&, i, ctx]() { size_t count = ctx->router->NumberOfConnectedRouters(); - std::lock_guard guard{results_lock}; + std::lock_guard< std::mutex > guard{results_lock}; results[i] = count; done_count++; }); i++; } - while (true) + while(true) { size_t read_done_count = 0; { - std::lock_guard guard{results_lock}; + std::lock_guard< std::mutex > guard{results_lock}; read_done_count = done_count; } - if (read_done_count == relays.size()) + if(read_done_count == relays.size()) break; std::this_thread::sleep_for(100ms); @@ -204,35 +204,35 @@ namespace tooling return results; } - std::vector + std::vector< llarp::RouterContact > RouterHive::GetRelayRCs() { - std::vector results; + std::vector< llarp::RouterContact > results; results.resize(relays.size()); std::mutex results_lock; - size_t i=0; + size_t i = 0; size_t done_count = 0; - for (auto relay : relays) + for(auto relay : relays) { auto ctx = llarp::Context::Get(relay); LogicCall(ctx->logic, [&, i, ctx]() { llarp::RouterContact rc = ctx->router->rc(); - std::lock_guard guard{results_lock}; + std::lock_guard< std::mutex > guard{results_lock}; results[i] = std::move(rc); done_count++; }); i++; } - while (true) + while(true) { size_t read_done_count = 0; { - std::lock_guard guard{results_lock}; + std::lock_guard< std::mutex > guard{results_lock}; read_done_count = done_count; } - if (read_done_count == relays.size()) + if(read_done_count == relays.size()) break; std::this_thread::sleep_for(100ms); @@ -240,4 +240,4 @@ namespace tooling return results; } -} // namespace tooling +} // namespace tooling diff --git a/llarp/tooling/router_hive.hpp b/llarp/tooling/router_hive.hpp index b4cc80911..cba42049c 100644 --- a/llarp/tooling/router_hive.hpp +++ b/llarp/tooling/router_hive.hpp @@ -20,39 +20,38 @@ namespace llarp namespace tooling { - struct RouterHive { - using Context_ptr = std::shared_ptr; - - private: + using Context_ptr = std::shared_ptr< llarp::Context >; + private: void - StartRouters(std::vector *routers); + StartRouters(std::vector< llarp_main * > *routers); void - AddRouter(const std::shared_ptr & config, std::vector *routers); + AddRouter(const std::shared_ptr< llarp::Config > &config, + std::vector< llarp_main * > *routers); /// safely visit router void - VisitRouter(llarp_main *router, std::function visit); + VisitRouter(llarp_main *router, std::function< void(Context_ptr) > visit); /// safely visit relay at index N void - VisitRelay(size_t index, std::function visit); + VisitRelay(size_t index, std::function< void(Context_ptr) > visit); /// safely visit client at index N void - VisitClient(size_t index, std::function visit); + VisitClient(size_t index, std::function< void(Context_ptr) > visit); - public: + public: RouterHive() = default; void - AddRelay(const std::shared_ptr & conf); + AddRelay(const std::shared_ptr< llarp::Config > &conf); void - AddClient(const std::shared_ptr & conf); + AddClient(const std::shared_ptr< llarp::Config > &conf); void StartRelays(); @@ -69,11 +68,11 @@ namespace tooling RouterEventPtr GetNextEvent(); - std::deque + std::deque< RouterEventPtr > GetAllEvents(); void - ForEachRelay(std::function visit) + ForEachRelay(std::function< void(Context_ptr) > visit) { for(size_t idx = 0; idx < relays.size(); ++idx) { @@ -82,7 +81,7 @@ namespace tooling } void - ForEachClient(std::function visit) + ForEachClient(std::function< void(Context_ptr) > visit) { for(size_t idx = 0; idx < clients.size(); ++idx) { @@ -92,25 +91,25 @@ namespace tooling /// safely visit every router context void - ForEachRouter(std::function visit) + ForEachRouter(std::function< void(Context_ptr) > visit) { ForEachRelay(visit); ForEachClient(visit); } - std::vector + std::vector< size_t > RelayConnectedRelays(); - std::vector + std::vector< llarp::RouterContact > GetRelayRCs(); - std::vector relays; - std::vector clients; + std::vector< llarp_main * > relays; + std::vector< llarp_main * > clients; - std::vector routerMainThreads; + std::vector< std::thread > routerMainThreads; std::mutex eventQueueMutex; - std::deque eventQueue; + std::deque< RouterEventPtr > eventQueue; }; -} // namespace tooling +} // namespace tooling diff --git a/llarp/util/thread/queue.hpp b/llarp/util/thread/queue.hpp index 334c1dd81..2e01051f2 100644 --- a/llarp/util/thread/queue.hpp +++ b/llarp/util/thread/queue.hpp @@ -396,13 +396,15 @@ namespace llarp { uint32_t generation = 0; uint32_t index = 0; - bool secondTry = false; - bool success = false; + bool secondTry = false; + bool success = false; 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); @@ -415,7 +417,7 @@ namespace llarp m_waitingPoppers.fetch_sub(1, std::memory_order_relaxed); } - if (success) + if(success) { QueuePopGuard< Type > popGuard(*this, generation, index); return Type(std::move(m_data[index])); diff --git a/pybind/common.hpp b/pybind/common.hpp index 3bde2fbff..a9d36fa08 100644 --- a/pybind/common.hpp +++ b/pybind/common.hpp @@ -11,26 +11,31 @@ namespace py = pybind11; namespace pybind11 { -namespace detail -{ - -template struct type_caster> - : map_caster, Key, Value> { }; - - -template -struct type_caster> -: public optional_caster> {}; - -/* -template -struct type_caster -: string_caster {}; -*/ - -} // namespace pybind11::detail -} // namespace pybind11 - + namespace detail + { + template < typename Key, typename Value, typename Hash, typename Equal, + typename Alloc > + struct type_caster< + std::unordered_multimap< Key, Value, Hash, Equal, Alloc > > + : map_caster< std::unordered_multimap< Key, Value, Hash, Equal, Alloc >, + Key, Value > + { + }; + + template < typename T > + struct type_caster< nonstd::optional< T > > + : public optional_caster< nonstd::optional< T > > + { + }; + + /* + template + struct type_caster + : string_caster {}; + */ + + } // namespace detail +} // namespace pybind11 namespace llarp { @@ -47,32 +52,32 @@ namespace llarp RouterContact_Init(py::module &mod); void - Config_Init(py::module & mod); + Config_Init(py::module &mod); void - PathTypes_Init(py::module & mod); + PathTypes_Init(py::module &mod); namespace dht { void - DHTTypes_Init(py::module& mod); + DHTTypes_Init(py::module &mod); } namespace path { void - PathHopConfig_Init(py::module & mod); + PathHopConfig_Init(py::module &mod); } namespace handlers { void - PyHandler_Init(py::module & mod); + PyHandler_Init(py::module &mod); } - namespace service + namespace service { - void + void Address_Init(py::module &mod); } @@ -81,8 +86,8 @@ namespace llarp namespace tooling { void - RouterHive_Init(py::module & mod); + RouterHive_Init(py::module &mod); void - RouterEvent_Init(py::module & mod); -} + RouterEvent_Init(py::module &mod); +} // namespace tooling diff --git a/pybind/llarp/config.cpp b/pybind/llarp/config.cpp index 29cb3f6ee..754a21c7b 100644 --- a/pybind/llarp/config.cpp +++ b/pybind/llarp/config.cpp @@ -12,108 +12,111 @@ namespace llarp } void - Config_Init(py::module & mod) + Config_Init(py::module &mod) { - using Config_ptr = std::shared_ptr; - py::class_(mod, "Config") - .def(py::init<>()) - .def_readwrite("router", &Config::router) - .def_readwrite("network", &Config::network) - .def_readwrite("connect", &Config::connect) - .def_readwrite("netdb", &Config::netdb) - .def_readwrite("dns", &Config::dns) - .def_readwrite("links", &Config::links) - .def_readwrite("services", &Config::services) - .def_readwrite("system", &Config::system) - .def_readwrite("api", &Config::api) - .def_readwrite("lokid", &Config::lokid) - .def_readwrite("bootstrap", &Config::bootstrap) - .def_readwrite("logging", &Config::logging) - .def("LoadFile", &Config::Load); - - py::class_(mod, "RouterConfig") - .def(py::init<>()) - .def_readwrite("minConnectedRouters", &RouterConfig::m_minConnectedRouters) - .def_readwrite("maxConnectedRouters", &RouterConfig::m_maxConnectedRouters) - .def_readwrite("netid", &RouterConfig::m_netId) - .def_readwrite("nickname", &RouterConfig::m_nickname) - .def_readwrite("encryptionKeyfile", &RouterConfig::m_encryptionKeyfile) - .def_readwrite("ourRcFile", &RouterConfig::m_ourRcFile) - .def_readwrite("transportKeyfile", &RouterConfig::m_transportKeyfile) - .def_readwrite("identKeyfile", &RouterConfig::m_identKeyfile) - .def_readwrite("blockBogons", &RouterConfig::m_blockBogons) - .def_readwrite("publicOverride", &RouterConfig::m_publicOverride) - .def_readwrite("ip4addr", &RouterConfig::m_ip4addr) - .def("overrideAddress", [](RouterConfig & self, std::string ip, std::string port) { - self.fromSection("public-ip", ip); - self.fromSection("public-port", port); - }) - .def_readwrite("workerThreads", &RouterConfig::m_workerThreads) - .def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads) - .def_readwrite("JobQueueSize", &RouterConfig::m_JobQueueSize) - .def_readwrite("DefaultLinkProto", &RouterConfig::m_DefaultLinkProto); - - py::class_(mod, "NetworkConfig") - .def(py::init<>()) - .def_readwrite("enableProfiling", &NetworkConfig::m_enableProfiling) - .def_readwrite("routerProfilesFile", &NetworkConfig::m_routerProfilesFile) - .def_readwrite("strictConnect", &NetworkConfig::m_strictConnect) - .def_readwrite("netConfig", &NetworkConfig::m_netConfig); - - py::class_(mod, "ConnectConfig") - .def(py::init<>()) - .def_readwrite("routers", &ConnectConfig::routers); - - py::class_(mod, "NetdbConfig") - .def(py::init<>()) - .def_readwrite("nodedbDir", &NetdbConfig::m_nodedbDir); - - py::class_(mod, "DnsConfig") - .def(py::init<>()) - .def_readwrite("netConfig", &DnsConfig::netConfig); - - py::class_(mod, "LinksConfig") - .def(py::init<>()) - .def_readwrite("OutboundLink", &LinksConfig::m_OutboundLink) - .def_readwrite("InboundLinks", &LinksConfig::m_InboundLinks); - - py::class_(mod, "ServicesConfig") - .def(py::init<>()) - .def_readwrite("services", &ServicesConfig::services); - - py::class_(mod, "SystemConfig") - .def(py::init<>()) - .def_readwrite("pidfile", &SystemConfig::pidfile); - - py::class_(mod, "ApiConfig") - .def(py::init<>()) - .def_readwrite("enableRPCServer", &ApiConfig::m_enableRPCServer) - .def_readwrite("rpcBindAddr", &ApiConfig::m_rpcBindAddr); - - py::class_(mod, "LokidConfig") - .def(py::init<>()) - .def_readwrite("usingSNSeed", &LokidConfig::usingSNSeed) - .def_readwrite("whitelistRouters", &LokidConfig::whitelistRouters) - .def_readwrite("ident_keyfile", &LokidConfig::ident_keyfile) - .def_readwrite("lokidRPCAddr", &LokidConfig::lokidRPCAddr) - .def_readwrite("lokidRPCUser", &LokidConfig::lokidRPCUser) - .def_readwrite("lokidRPCPassword", &LokidConfig::lokidRPCPassword); - - py::class_(mod, "BootstrapConfig") - .def(py::init<>()) - .def_readwrite("routers", &BootstrapConfig::routers); - - py::class_(mod, "LoggingConfig") - .def(py::init<>()) - .def_readwrite("LogJSON", &LoggingConfig::m_LogJSON) - .def_readwrite("LogFile", &LoggingConfig::m_LogFile); - - py::class_(mod, "sockaddr_in") - .def_readwrite("sin_family", &sockaddr_in::sin_family) - .def_readwrite("sin_port", &sockaddr_in::sin_port) - .def_readwrite("sin_addr", &sockaddr_in::sin_addr); - - py::class_(mod, "in_addr") - .def("set", &in_addr_set); + using Config_ptr = std::shared_ptr< Config >; + py::class_< Config, Config_ptr >(mod, "Config") + .def(py::init<>()) + .def_readwrite("router", &Config::router) + .def_readwrite("network", &Config::network) + .def_readwrite("connect", &Config::connect) + .def_readwrite("netdb", &Config::netdb) + .def_readwrite("dns", &Config::dns) + .def_readwrite("links", &Config::links) + .def_readwrite("services", &Config::services) + .def_readwrite("system", &Config::system) + .def_readwrite("api", &Config::api) + .def_readwrite("lokid", &Config::lokid) + .def_readwrite("bootstrap", &Config::bootstrap) + .def_readwrite("logging", &Config::logging) + .def("LoadFile", &Config::Load); + + py::class_< RouterConfig >(mod, "RouterConfig") + .def(py::init<>()) + .def_readwrite("minConnectedRouters", + &RouterConfig::m_minConnectedRouters) + .def_readwrite("maxConnectedRouters", + &RouterConfig::m_maxConnectedRouters) + .def_readwrite("netid", &RouterConfig::m_netId) + .def_readwrite("nickname", &RouterConfig::m_nickname) + .def_readwrite("encryptionKeyfile", &RouterConfig::m_encryptionKeyfile) + .def_readwrite("ourRcFile", &RouterConfig::m_ourRcFile) + .def_readwrite("transportKeyfile", &RouterConfig::m_transportKeyfile) + .def_readwrite("identKeyfile", &RouterConfig::m_identKeyfile) + .def_readwrite("blockBogons", &RouterConfig::m_blockBogons) + .def_readwrite("publicOverride", &RouterConfig::m_publicOverride) + .def_readwrite("ip4addr", &RouterConfig::m_ip4addr) + .def("overrideAddress", + [](RouterConfig &self, std::string ip, std::string port) { + self.fromSection("public-ip", ip); + self.fromSection("public-port", port); + }) + .def_readwrite("workerThreads", &RouterConfig::m_workerThreads) + .def_readwrite("numNetThreads", &RouterConfig::m_numNetThreads) + .def_readwrite("JobQueueSize", &RouterConfig::m_JobQueueSize) + .def_readwrite("DefaultLinkProto", &RouterConfig::m_DefaultLinkProto); + + py::class_< NetworkConfig >(mod, "NetworkConfig") + .def(py::init<>()) + .def_readwrite("enableProfiling", &NetworkConfig::m_enableProfiling) + .def_readwrite("routerProfilesFile", + &NetworkConfig::m_routerProfilesFile) + .def_readwrite("strictConnect", &NetworkConfig::m_strictConnect) + .def_readwrite("netConfig", &NetworkConfig::m_netConfig); + + py::class_< ConnectConfig >(mod, "ConnectConfig") + .def(py::init<>()) + .def_readwrite("routers", &ConnectConfig::routers); + + py::class_< NetdbConfig >(mod, "NetdbConfig") + .def(py::init<>()) + .def_readwrite("nodedbDir", &NetdbConfig::m_nodedbDir); + + py::class_< DnsConfig >(mod, "DnsConfig") + .def(py::init<>()) + .def_readwrite("netConfig", &DnsConfig::netConfig); + + py::class_< LinksConfig >(mod, "LinksConfig") + .def(py::init<>()) + .def_readwrite("OutboundLink", &LinksConfig::m_OutboundLink) + .def_readwrite("InboundLinks", &LinksConfig::m_InboundLinks); + + py::class_< ServicesConfig >(mod, "ServicesConfig") + .def(py::init<>()) + .def_readwrite("services", &ServicesConfig::services); + + py::class_< SystemConfig >(mod, "SystemConfig") + .def(py::init<>()) + .def_readwrite("pidfile", &SystemConfig::pidfile); + + py::class_< ApiConfig >(mod, "ApiConfig") + .def(py::init<>()) + .def_readwrite("enableRPCServer", &ApiConfig::m_enableRPCServer) + .def_readwrite("rpcBindAddr", &ApiConfig::m_rpcBindAddr); + + py::class_< LokidConfig >(mod, "LokidConfig") + .def(py::init<>()) + .def_readwrite("usingSNSeed", &LokidConfig::usingSNSeed) + .def_readwrite("whitelistRouters", &LokidConfig::whitelistRouters) + .def_readwrite("ident_keyfile", &LokidConfig::ident_keyfile) + .def_readwrite("lokidRPCAddr", &LokidConfig::lokidRPCAddr) + .def_readwrite("lokidRPCUser", &LokidConfig::lokidRPCUser) + .def_readwrite("lokidRPCPassword", &LokidConfig::lokidRPCPassword); + + py::class_< BootstrapConfig >(mod, "BootstrapConfig") + .def(py::init<>()) + .def_readwrite("routers", &BootstrapConfig::routers); + + py::class_< LoggingConfig >(mod, "LoggingConfig") + .def(py::init<>()) + .def_readwrite("LogJSON", &LoggingConfig::m_LogJSON) + .def_readwrite("LogFile", &LoggingConfig::m_LogFile); + + py::class_< sockaddr_in >(mod, "sockaddr_in") + .def_readwrite("sin_family", &sockaddr_in::sin_family) + .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 diff --git a/pybind/llarp/context.cpp b/pybind/llarp/context.cpp index 959e50a06..058d5e93a 100644 --- a/pybind/llarp/context.cpp +++ b/pybind/llarp/context.cpp @@ -15,25 +15,31 @@ namespace llarp [](Context_ptr self) -> int { return self->Run(llarp_main_runtime_opts{}); }) - .def("Stop", [](Context_ptr self) { - self->CloseAsync(); - }) + .def("Stop", [](Context_ptr self) { self->CloseAsync(); }) .def("IsUp", &Context::IsUp) - .def("IsRelay", [](Context_ptr self) -> bool { - return self->router->IsServiceNode(); - }) + .def("IsRelay", + [](Context_ptr self) -> bool { + return self->router->IsServiceNode(); + }) .def("LooksAlive", &Context::LooksAlive) .def("Configure", &Context::Configure) - .def("TrySendPacket", [](Context_ptr self, std::string from, service::Address to, std::string pkt) { - auto ep = self->router->hiddenServiceContext().GetEndpointByName(from); - std::vector buf; - buf.resize(pkt.size()); - std::copy_n(pkt.c_str(), pkt.size(), buf.data()); - 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("TrySendPacket", + [](Context_ptr self, std::string from, service::Address to, + std::string pkt) { + auto ep = + self->router->hiddenServiceContext().GetEndpointByName(from); + std::vector< byte_t > buf; + buf.resize(pkt.size()); + std::copy_n(pkt.c_str(), pkt.size(), buf.data()); + 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); } } // namespace llarp diff --git a/pybind/llarp/dht/dht_types.cpp b/pybind/llarp/dht/dht_types.cpp index c79636054..9f292de53 100644 --- a/pybind/llarp/dht/dht_types.cpp +++ b/pybind/llarp/dht/dht_types.cpp @@ -11,16 +11,17 @@ namespace llarp DHTTypes_Init(py::module& mod) { py::class_< Key_t >(mod, "DHTKey") - .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) { - return *lhs ^ *rhs; - }) - .def("ShortString", [](const Key_t* const key) { - return llarp::RouterID(key->as_array()).ShortString(); - }); + .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) { + return *lhs ^ *rhs; + }) + .def("ShortString", [](const Key_t* const key) { + return llarp::RouterID(key->as_array()).ShortString(); + }); } - } // namespace llarp::dht -} // namespace llarp + } // namespace dht +} // namespace llarp diff --git a/pybind/llarp/handlers/pyhandler.cpp b/pybind/llarp/handlers/pyhandler.cpp index aa8c084d0..e26c28036 100644 --- a/pybind/llarp/handlers/pyhandler.cpp +++ b/pybind/llarp/handlers/pyhandler.cpp @@ -1,18 +1,18 @@ #include "llarp/handlers/pyhandler.hpp" namespace llarp { - namespace handlers + namespace handlers { - void - PyHandler_Init(py::module & mod) + void + PyHandler_Init(py::module& mod) { - py::class_(mod, "Endpoint") - .def(py::init()) - .def("SendTo", &PythonEndpoint::SendPacket) - .def("OurAddress", &PythonEndpoint::GetOurAddress) - .def_readwrite("GotPacket", &PythonEndpoint::handlePacket); + py::class_< PythonEndpoint, PythonEndpoint_ptr >(mod, "Endpoint") + .def(py::init< std::string, Context_ptr >()) + .def("SendTo", &PythonEndpoint::SendPacket) + .def("OurAddress", &PythonEndpoint::GetOurAddress) + .def_readwrite("GotPacket", &PythonEndpoint::handlePacket); } - } // namespace handlers - -} \ No newline at end of file + } // namespace handlers + +} // namespace llarp \ No newline at end of file diff --git a/pybind/llarp/handlers/pyhandler.hpp b/pybind/llarp/handlers/pyhandler.hpp index f0b20f32b..fca49b087 100644 --- a/pybind/llarp/handlers/pyhandler.hpp +++ b/pybind/llarp/handlers/pyhandler.hpp @@ -1,41 +1,43 @@ -#pragma once +#pragma once #include "common.hpp" #include "llarp.hpp" #include "service/context.hpp" #include "service/endpoint.hpp" #include "router/abstractrouter.hpp" -namespace llarp +namespace llarp { -namespace handlers + namespace handlers { - using Context_ptr = std::shared_ptr; + using Context_ptr = std::shared_ptr< llarp::Context >; struct PythonEndpoint final : public llarp::service::Endpoint, public std::enable_shared_from_this< PythonEndpoint > { - 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) { } const std::string OurName; 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 { if(handlePacket) { - AlignedBuffer<32> addr; + AlignedBuffer< 32 > addr; bool isSnode = false; if(not GetEndpointWithConvoTag(tag, addr, isSnode)) return false; if(isSnode) return true; - std::vector pkt; + std::vector< byte_t > pkt; pkt.resize(pktbuf.sz); std::copy_n(pktbuf.base, pktbuf.sz, pkt.data()); handlePacket(service::Address(addr), std::move(pkt), proto); @@ -55,25 +57,29 @@ namespace handlers return false; } - using PacketHandler_t = std::function, service::ProtocolType)>; + using PacketHandler_t = std::function< void( + service::Address, std::vector< byte_t >, service::ProtocolType) >; PacketHandler_t handlePacket; - void - SendPacket(service::Address remote, std::vector pkt, service::ProtocolType proto) + void + SendPacket(service::Address remote, std::vector< byte_t > pkt, + service::ProtocolType proto) { - LogicCall(m_router->logic(), [remote, pkt, proto, self=shared_from_this()]() { - self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt), proto); - }); + LogicCall(m_router->logic(), + [remote, pkt, proto, self = shared_from_this()]() { + self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt), + proto); + }); } - std::string - GetOurAddress() const + std::string + GetOurAddress() const { return m_Identity.pub.Addr().ToString(); } }; - using PythonEndpoint_ptr = std::shared_ptr; - } -} \ No newline at end of file + using PythonEndpoint_ptr = std::shared_ptr< PythonEndpoint >; + } // namespace handlers +} // namespace llarp \ No newline at end of file diff --git a/pybind/llarp/path/path_hop_config.cpp b/pybind/llarp/path/path_hop_config.cpp index 7cb965282..d3c043ad3 100644 --- a/pybind/llarp/path/path_hop_config.cpp +++ b/pybind/llarp/path/path_hop_config.cpp @@ -6,24 +6,24 @@ namespace llarp namespace path { void - PathHopConfig_Init(py::module & mod) + PathHopConfig_Init(py::module &mod) { auto str_func = [](PathHopConfig *hop) { - std::string s = "Hop: ["; - s += RouterID(hop->rc.pubkey).ShortString(); - s += "] -> ["; - s += hop->upstream.ShortString(); - s += "]"; - return s; - }; + std::string s = "Hop: ["; + s += RouterID(hop->rc.pubkey).ShortString(); + s += "] -> ["; + s += hop->upstream.ShortString(); + s += "]"; + return s; + }; py::class_< PathHopConfig >(mod, "PathHopConfig") - .def_readonly("rc", &PathHopConfig::rc) - .def_readonly("upstreamRouter", &PathHopConfig::upstream) - .def_readonly("txid", &PathHopConfig::txID) - .def_readonly("rxid", &PathHopConfig::rxID) - .def("ToString", str_func) - .def("__str__", str_func) - .def("__repr__", str_func); + .def_readonly("rc", &PathHopConfig::rc) + .def_readonly("upstreamRouter", &PathHopConfig::upstream) + .def_readonly("txid", &PathHopConfig::txID) + .def_readonly("rxid", &PathHopConfig::rxID) + .def("ToString", str_func) + .def("__str__", str_func) + .def("__repr__", str_func); } - } // namespace llarp::path + } // namespace path } // namespace llarp diff --git a/pybind/llarp/path/path_types.cpp b/pybind/llarp/path/path_types.cpp index 1d5449260..a48554c86 100644 --- a/pybind/llarp/path/path_types.cpp +++ b/pybind/llarp/path/path_types.cpp @@ -6,13 +6,13 @@ namespace llarp { void - PathTypes_Init(py::module & mod) + PathTypes_Init(py::module& mod) { py::class_< PathID_t >(mod, "PathID") - .def(py::self == py::self) - .def("ShortHex", &PathID_t::ShortHex) - .def("__str__", &PathID_t::ShortHex) - .def("__repr__", &PathID_t::ShortHex); + .def(py::self == py::self) + .def("ShortHex", &PathID_t::ShortHex) + .def("__str__", &PathID_t::ShortHex) + .def("__repr__", &PathID_t::ShortHex); } } // namespace llarp diff --git a/pybind/llarp/router_contact.cpp b/pybind/llarp/router_contact.cpp index 950f26900..6c9ff954c 100644 --- a/pybind/llarp/router_contact.cpp +++ b/pybind/llarp/router_contact.cpp @@ -9,12 +9,16 @@ namespace llarp { py::class_< RouterContact >(mod, "RouterContact") .def(py::init<>()) - .def_property_readonly("routerID", [](const RouterContact* const rc) -> llarp::RouterID { - return llarp::RouterID(rc->pubkey); - }) - .def_property_readonly("AsDHTKey", [](const RouterContact* const rc) -> llarp::dht::Key_t { - return llarp::dht::Key_t{rc->pubkey.as_array()}; - }) + .def_property_readonly( + "routerID", + [](const RouterContact* const rc) -> llarp::RouterID { + return llarp::RouterID(rc->pubkey); + }) + .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("WriteFile", &RouterContact::Write) .def("ToString", &RouterContact::ToString) diff --git a/pybind/llarp/router_id.cpp b/pybind/llarp/router_id.cpp index a2d077d15..b48196a65 100644 --- a/pybind/llarp/router_id.cpp +++ b/pybind/llarp/router_id.cpp @@ -5,9 +5,9 @@ namespace llarp { void - RouterID_Init(py::module & mod) + RouterID_Init(py::module& mod) { - py::class_(mod, "RouterID") + py::class_< RouterID >(mod, "RouterID") .def("FromHex", [](RouterID* r, const std::string& hex) -> bool { return HexDecode(hex.c_str(), r->data(), r->size()); @@ -15,8 +15,9 @@ namespace llarp .def("__repr__", &RouterID::ToString) .def("__str__", &RouterID::ToString) .def("ShortString", &RouterID::ShortString) - .def("__eq__", [](const RouterID* const lhs, const RouterID* const rhs) { - return *lhs == *rhs; - }); + .def("__eq__", + [](const RouterID* const lhs, const RouterID* const rhs) { + return *lhs == *rhs; + }); } -} +} // namespace llarp diff --git a/pybind/llarp/service/address.cpp b/pybind/llarp/service/address.cpp index a5ee32b6e..af2daeba8 100644 --- a/pybind/llarp/service/address.cpp +++ b/pybind/llarp/service/address.cpp @@ -5,14 +5,14 @@ namespace llarp { namespace service { - void - Address_Init(py::module & mod) + void + Address_Init(py::module& mod) { - py::class_
(mod, "ServiceAddress") - .def(py::init()) - .def("__str__", [](const Address & addr) -> std::string { - return addr.ToString(); - }); + py::class_< Address >(mod, "ServiceAddress") + .def(py::init< std::string >()) + .def("__str__", [](const Address& addr) -> std::string { + return addr.ToString(); + }); } - } -} \ No newline at end of file + } // namespace service +} // namespace llarp \ No newline at end of file diff --git a/pybind/llarp/tooling/router_event.cpp b/pybind/llarp/tooling/router_event.cpp index 991d286fb..b3e01bbcb 100644 --- a/pybind/llarp/tooling/router_event.cpp +++ b/pybind/llarp/tooling/router_event.cpp @@ -12,55 +12,61 @@ namespace tooling { void - RouterEvent_Init(py::module & mod) + RouterEvent_Init(py::module& mod) { - py::class_(mod, "RouterEvent") - .def("__repr__", &RouterEvent::ToString) - .def("__str__", &RouterEvent::ToString) - .def_readonly("routerID", &RouterEvent::routerID) - .def_readonly("triggered", &RouterEvent::triggered); + py::class_< RouterEvent >(mod, "RouterEvent") + .def("__repr__", &RouterEvent::ToString) + .def("__str__", &RouterEvent::ToString) + .def_readonly("routerID", &RouterEvent::routerID) + .def_readonly("triggered", &RouterEvent::triggered); - py::class_(mod, "PathAttemptEvent") - .def_readonly("hops", &PathAttemptEvent::hops); + py::class_< PathAttemptEvent, RouterEvent >(mod, "PathAttemptEvent") + .def_readonly("hops", &PathAttemptEvent::hops); - py::class_(mod, "PathRequestReceivedEvent") - .def_readonly("prevHop", &PathRequestReceivedEvent::prevHop) - .def_readonly("nextHop", &PathRequestReceivedEvent::nextHop) - .def_readonly("txid", &PathRequestReceivedEvent::txid) - .def_readonly("rxid", &PathRequestReceivedEvent::rxid) - .def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint); + py::class_< PathRequestReceivedEvent, RouterEvent >( + mod, "PathRequestReceivedEvent") + .def_readonly("prevHop", &PathRequestReceivedEvent::prevHop) + .def_readonly("nextHop", &PathRequestReceivedEvent::nextHop) + .def_readonly("txid", &PathRequestReceivedEvent::txid) + .def_readonly("rxid", &PathRequestReceivedEvent::rxid) + .def_readonly("isEndpoint", &PathRequestReceivedEvent::isEndpoint); - py::class_(mod, "PathStatusReceivedEvent") - .def_readonly("rxid", &PathStatusReceivedEvent::rxid) - .def_readonly("status", &PathStatusReceivedEvent::rxid) - .def_property_readonly("Successful", [](const PathStatusReceivedEvent* const ev) { - return ev->status == llarp::LR_StatusRecord::SUCCESS; - }); + py::class_< PathStatusReceivedEvent, RouterEvent >( + mod, "PathStatusReceivedEvent") + .def_readonly("rxid", &PathStatusReceivedEvent::rxid) + .def_readonly("status", &PathStatusReceivedEvent::rxid) + .def_property_readonly( + "Successful", [](const PathStatusReceivedEvent* const ev) { + return ev->status == llarp::LR_StatusRecord::SUCCESS; + }); - py::class_(mod, "DhtPubIntroSentEvent") - .def_readonly("introsetPubkey", &PubIntroSentEvent::introsetPubkey) - .def_readonly("relay", &PubIntroSentEvent::relay) - .def_readonly("relayIndex", &PubIntroSentEvent::relayIndex); + py::class_< PubIntroSentEvent, RouterEvent >(mod, "DhtPubIntroSentEvent") + .def_readonly("introsetPubkey", &PubIntroSentEvent::introsetPubkey) + .def_readonly("relay", &PubIntroSentEvent::relay) + .def_readonly("relayIndex", &PubIntroSentEvent::relayIndex); - py::class_(mod, "DhtPubIntroReceivedEvent") - .def_readonly("from", &PubIntroReceivedEvent::From) - .def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation) - .def_readonly("relayOrder", &PubIntroReceivedEvent::RelayOrder) - .def_readonly("txid", &PubIntroReceivedEvent::TxID); + py::class_< PubIntroReceivedEvent, RouterEvent >(mod, + "DhtPubIntroReceivedEvent") + .def_readonly("from", &PubIntroReceivedEvent::From) + .def_readonly("location", &PubIntroReceivedEvent::IntrosetLocation) + .def_readonly("relayOrder", &PubIntroReceivedEvent::RelayOrder) + .def_readonly("txid", &PubIntroReceivedEvent::TxID); - py::class_(mod, "DhtGotIntroReceivedEvent") - .def_readonly("from", &GotIntroReceivedEvent::From) - .def_readonly("location", &GotIntroReceivedEvent::Introset) - .def_readonly("relayOrder", &GotIntroReceivedEvent::RelayOrder) - .def_readonly("txid", &GotIntroReceivedEvent::TxID); + py::class_< GotIntroReceivedEvent, RouterEvent >(mod, + "DhtGotIntroReceivedEvent") + .def_readonly("from", &GotIntroReceivedEvent::From) + .def_readonly("location", &GotIntroReceivedEvent::Introset) + .def_readonly("relayOrder", &GotIntroReceivedEvent::RelayOrder) + .def_readonly("txid", &GotIntroReceivedEvent::TxID); - py::class_(mod, "RCGossipReceivedEvent") - .def_readonly("rc", &RCGossipReceivedEvent::rc) - .def("LongString", &RCGossipReceivedEvent::LongString); + py::class_< RCGossipReceivedEvent, RouterEvent >(mod, + "RCGossipReceivedEvent") + .def_readonly("rc", &RCGossipReceivedEvent::rc) + .def("LongString", &RCGossipReceivedEvent::LongString); - py::class_(mod, "RCGossipSentEvent") - .def_readonly("rc", &RCGossipSentEvent::rc) - .def("LongString", &RCGossipSentEvent::LongString); + py::class_< RCGossipSentEvent, RouterEvent >(mod, "RCGossipSentEvent") + .def_readonly("rc", &RCGossipSentEvent::rc) + .def("LongString", &RCGossipSentEvent::LongString); } -} // namespace tooling +} // namespace tooling diff --git a/pybind/llarp/tooling/router_hive.cpp b/pybind/llarp/tooling/router_hive.cpp index 53b278d42..c101142c0 100644 --- a/pybind/llarp/tooling/router_hive.cpp +++ b/pybind/llarp/tooling/router_hive.cpp @@ -24,6 +24,5 @@ namespace tooling .def("GetAllEvents", &RouterHive::GetAllEvents) .def("RelayConnectedRelays", &RouterHive::RelayConnectedRelays) .def("GetRelayRCs", &RouterHive::GetRelayRCs); - } -} +} // namespace tooling diff --git a/pybind/module.cpp b/pybind/module.cpp index 82582a4ee..28d6ea8a4 100644 --- a/pybind/module.cpp +++ b/pybind/module.cpp @@ -15,8 +15,5 @@ PYBIND11_MODULE(pyllarp, m) llarp::path::PathHopConfig_Init(m); llarp::handlers::PyHandler_Init(m); llarp::service::Address_Init(m); - m.def("EnableDebug", []() { - llarp::SetLogLevel(llarp::eLogDebug); - }); - + m.def("EnableDebug", []() { llarp::SetLogLevel(llarp::eLogDebug); }); }