clang format.......

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

@ -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<Context>
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:

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

@ -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<Context>
std::shared_ptr< Context >
Context::Get(llarp_main *m)
{
if(m == nullptr || m->ctx == nullptr)

@ -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<tooling::GotIntroReceivedEvent>(
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));

@ -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<tooling::RCGossipReceivedEvent>(router->pubkey(), rc);
tooling::RouterEventPtr event =
std::make_unique< tooling::RCGossipReceivedEvent >(
router->pubkey(), rc);
router->NotifyRouterEvent(std::move(event));
router->GossipRCIfNeeded(rc);
}

@ -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<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));
auto &dht = *ctx->impl;

@ -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;

@ -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)

@ -419,7 +419,7 @@ namespace llarp
// TODO: check if we really want to accept it
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()->NotifyRouterEvent(std::move(event));

@ -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<tooling::PathStatusReceivedEvent>(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();

@ -132,7 +132,9 @@ namespace llarp
{
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));
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(),

@ -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;

@ -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<tooling::RCGossipSentEvent>(m_router->pubkey(), rc);
tooling::RouterEventPtr event =
std::make_unique< tooling::RCGossipSentEvent >(m_router->pubkey(),
rc);
m_router->NotifyRouterEvent(std::move(event));
// send message

@ -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;

@ -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());

@ -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

@ -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");

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

@ -48,7 +48,7 @@ namespace llarp
/// inject endpoint instance
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
/// 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");

@ -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<byte_t> 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<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));
if(PublishIntroSetVia(introset, r, path, published))
published++;

@ -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;

@ -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

@ -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

@ -5,11 +5,12 @@
namespace tooling
{
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)
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<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)
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

@ -4,23 +4,27 @@
namespace tooling
{
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;
};
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 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

@ -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

@ -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

@ -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

@ -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<RouterEvent>;
using RouterEventPtr = std::unique_ptr< RouterEvent >;
} // namespace tooling
} // namespace tooling

@ -13,7 +13,8 @@ using namespace std::chrono_literals;
namespace tooling
{
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());
if(llarp_main_setup(ctx) == 0)
@ -24,24 +25,24 @@ namespace tooling
}
void
RouterHive::AddRelay(const std::shared_ptr<llarp::Config> & config)
RouterHive::AddRelay(const std::shared_ptr< llarp::Config >& config)
{
AddRouter(config, &relays);
}
void
RouterHive::AddClient(const std::shared_ptr<llarp::Config> & config)
RouterHive::AddClient(const std::shared_ptr< llarp::Config >& config)
{
AddRouter(config, &clients);
}
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](){
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<std::mutex> 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<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());
eventQueue.pop_front();
@ -124,13 +124,13 @@ namespace tooling
return nullptr;
}
std::deque<RouterEventPtr>
std::deque< RouterEventPtr >
RouterHive::GetAllEvents()
{
std::lock_guard<std::mutex> guard{eventQueueMutex};
std::lock_guard< std::mutex > guard{eventQueueMutex};
std::deque<RouterEventPtr> 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<void(Context_ptr)> 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<void(Context_ptr)> 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<void(Context_ptr)> 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<size_t>
std::vector< size_t >
RouterHive::RelayConnectedRelays()
{
std::vector<size_t> 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<std::mutex> 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<std::mutex> 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<llarp::RouterContact>
std::vector< llarp::RouterContact >
RouterHive::GetRelayRCs()
{
std::vector<llarp::RouterContact> 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<std::mutex> 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<std::mutex> 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

@ -20,39 +20,38 @@ namespace llarp
namespace tooling
{
struct RouterHive
{
using Context_ptr = std::shared_ptr<llarp::Context>;
private:
using Context_ptr = std::shared_ptr< llarp::Context >;
private:
void
StartRouters(std::vector<llarp_main *> *routers);
StartRouters(std::vector< llarp_main * > *routers);
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
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
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
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;
void
AddRelay(const std::shared_ptr<llarp::Config> & conf);
AddRelay(const std::shared_ptr< llarp::Config > &conf);
void
AddClient(const std::shared_ptr<llarp::Config> & conf);
AddClient(const std::shared_ptr< llarp::Config > &conf);
void
StartRelays();
@ -69,11 +68,11 @@ namespace tooling
RouterEventPtr
GetNextEvent();
std::deque<RouterEventPtr>
std::deque< RouterEventPtr >
GetAllEvents();
void
ForEachRelay(std::function<void(Context_ptr)> 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<void(Context_ptr)> 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<void(Context_ptr)> visit)
ForEachRouter(std::function< void(Context_ptr) > visit)
{
ForEachRelay(visit);
ForEachClient(visit);
}
std::vector<size_t>
std::vector< size_t >
RelayConnectedRelays();
std::vector<llarp::RouterContact>
std::vector< llarp::RouterContact >
GetRelayRCs();
std::vector<llarp_main *> relays;
std::vector<llarp_main *> clients;
std::vector< llarp_main * > relays;
std::vector< llarp_main * > clients;
std::vector<std::thread> routerMainThreads;
std::vector< std::thread > routerMainThreads;
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 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]));

@ -11,26 +11,31 @@ namespace py = pybind11;
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 <typename CharT, class Traits>
struct type_caster<simple_string_view>
: string_caster<simple_string_view, true> {};
*/
} // 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 <typename CharT, class Traits>
struct type_caster<simple_string_view>
: string_caster<simple_string_view, true> {};
*/
} // 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

@ -12,108 +12,111 @@ namespace llarp
}
void
Config_Init(py::module & mod)
Config_Init(py::module &mod)
{
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);
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

@ -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<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("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

@ -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

@ -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_<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);
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
}
} // namespace handlers
} // namespace llarp

@ -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<llarp::Context>;
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<byte_t> 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<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;
void
SendPacket(service::Address remote, std::vector<byte_t> 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<PythonEndpoint>;
}
}
using PythonEndpoint_ptr = std::shared_ptr< PythonEndpoint >;
} // namespace handlers
} // namespace llarp

@ -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

@ -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

@ -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)

@ -5,9 +5,9 @@
namespace llarp
{
void
RouterID_Init(py::module & mod)
RouterID_Init(py::module& mod)
{
py::class_<RouterID>(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

@ -5,14 +5,14 @@ namespace llarp
{
namespace service
{
void
Address_Init(py::module & mod)
void
Address_Init(py::module& mod)
{
py::class_<Address>(mod, "ServiceAddress")
.def(py::init<std::string>())
.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();
});
}
}
}
} // namespace service
} // namespace llarp

@ -12,55 +12,61 @@
namespace tooling
{
void
RouterEvent_Init(py::module & mod)
RouterEvent_Init(py::module& mod)
{
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_< RouterEvent >(mod, "RouterEvent")
.def("__repr__", &RouterEvent::ToString)
.def("__str__", &RouterEvent::ToString)
.def_readonly("routerID", &RouterEvent::routerID)
.def_readonly("triggered", &RouterEvent::triggered);
py::class_<PathAttemptEvent, RouterEvent>(mod, "PathAttemptEvent")
.def_readonly("hops", &PathAttemptEvent::hops);
py::class_< PathAttemptEvent, RouterEvent >(mod, "PathAttemptEvent")
.def_readonly("hops", &PathAttemptEvent::hops);
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_< 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_<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_< 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_<PubIntroSentEvent, RouterEvent>(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_<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_< 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_<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_< 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_<RCGossipReceivedEvent, RouterEvent>(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_<RCGossipSentEvent, RouterEvent>(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

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

@ -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); });
}

Loading…
Cancel
Save