clang format.......

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

@ -13,7 +13,6 @@
#include <vector>
#include <unordered_set>
struct llarp_config;
namespace llarp
{

@ -336,7 +336,7 @@ namespace llarp
ptr->impl = *this;
return ptr;
}
}
} // namespace llarp
extern "C"
{
@ -560,7 +560,6 @@ llarp_main::llarp_main(llarp_config *conf)
namespace llarp
{
std::shared_ptr< Context >
Context::Get(llarp_main *m)
{

@ -28,8 +28,7 @@ namespace llarp
auto *router = dht.GetRouter();
auto ev = std::make_unique< tooling::GotIntroReceivedEvent >(
router->pubkey(),
Key_t(From.data()),
router->pubkey(), Key_t(From.data()),
(found.size() > 0 ? found[0] : llarp::service::EncryptedIntroSet{}),
txid);
router->NotifyRouterEvent(std::move(ev));

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

@ -63,7 +63,9 @@ namespace llarp
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) {
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)
}))
!= 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)

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

@ -65,7 +65,6 @@ namespace llarp
struct AbstractRouter
{
#ifdef LOKINET_HIVE
tooling::RouterHive *hive;
#endif

@ -21,7 +21,8 @@ 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;
@ -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

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

@ -228,7 +228,6 @@ namespace llarp
return _hiddenServiceContext;
}
llarp_time_t _lastTick = 0s;
bool

@ -192,7 +192,6 @@ namespace llarp
return nullptr;
}
void
Context::InjectEndpoint(std::string name, std::shared_ptr< Endpoint > ep)
{

@ -200,16 +200,18 @@ namespace llarp
for(const auto& addr : m_state->m_PrefetchAddrs)
{
EnsurePathToService(
addr, [](Address, OutboundContext* ctx) {
addr,
[](Address, OutboundContext* ctx) {
#ifdef LOKINET_HIVE
std::vector< byte_t > discard;
discard.resize(128);
ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard), eProtocolControl);
ctx->AsyncEncryptAndSendTo(llarp_buffer_t(discard),
eProtocolControl);
#else
(void)ctx;
#endif
}, 10s);
},
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,7 +369,6 @@ namespace llarp
const std::set< RouterID >&
SnodeBlacklist() const;
bool
SendToServiceOrQueue(const service::Address& addr,
const llarp_buffer_t& payload, ProtocolType t);

@ -1,18 +1,23 @@
#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)
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)
@ -23,19 +28,22 @@ namespace tooling
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,26 +18,31 @@ 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,
// 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);
@ -45,6 +51,7 @@ namespace tooling
llarp::service::EncryptedIntroSet Introset;
uint64_t RelayOrder;
uint64_t TxID;
std::string ToString() const override;
std::string
ToString() const override;
};
}
} // namespace tooling

@ -5,8 +5,9 @@
namespace tooling
{
PathAttemptEvent::PathAttemptEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::Path> path)
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)
@ -36,8 +37,9 @@ namespace tooling
return result;
}
PathRequestReceivedEvent::PathRequestReceivedEvent(const llarp::RouterID& routerID, std::shared_ptr<const llarp::path::TransitHop> hop)
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)
@ -74,7 +76,9 @@ namespace tooling
return result;
}
PathStatusReceivedEvent::PathStatusReceivedEvent(const llarp::RouterID& routerID, const llarp::PathID_t rxid, uint64_t status)
PathStatusReceivedEvent::PathStatusReceivedEvent(
const llarp::RouterID& routerID, const llarp::PathID_t rxid,
uint64_t status)
: RouterEvent("PathStatusReceivedEvent", routerID, true)
, rxid(rxid)
, status(status)

@ -4,12 +4,13 @@
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;
@ -18,9 +19,12 @@ namespace tooling
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,9 +37,11 @@ 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;

@ -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
@ -40,4 +41,3 @@ 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;
@ -31,4 +33,3 @@ namespace tooling
};
} // namespace tooling

@ -2,8 +2,8 @@
namespace tooling
{
RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID, bool triggered)
RouterEvent::RouterEvent(std::string eventType, llarp::RouterID routerID,
bool triggered)
: eventType(eventType), routerID(routerID), triggered(triggered)
{
}

@ -8,7 +8,6 @@
namespace llarp
{
struct PathID_t;
namespace path
@ -18,23 +17,23 @@ namespace llarp
struct TransitHop;
} // namespace llarp::path
} // 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;

@ -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)
@ -62,7 +63,6 @@ namespace tooling
void
RouterHive::StopRouters()
{
llarp::LogInfo("Signalling all routers to stop");
for(llarp_main* ctx : relays)
{
@ -138,12 +138,11 @@ 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
@ -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())
{

@ -20,18 +20,17 @@ namespace llarp
namespace tooling
{
struct RouterHive
{
using Context_ptr = std::shared_ptr< llarp::Context >;
private:
void
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

@ -400,9 +400,11 @@ namespace llarp
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);

@ -13,14 +13,20 @@ 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 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>> {};
: public optional_caster< nonstd::optional< T > >
{
};
/*
template <typename CharT, class Traits>
@ -28,10 +34,9 @@ struct type_caster<simple_string_view>
: string_caster<simple_string_view, true> {};
*/
} // namespace pybind11::detail
} // namespace detail
} // namespace pybind11
namespace llarp
{
void
@ -85,4 +90,4 @@ namespace tooling
void
RouterEvent_Init(py::module &mod);
}
} // namespace tooling

@ -33,8 +33,10 @@ namespace llarp
py::class_< RouterConfig >(mod, "RouterConfig")
.def(py::init<>())
.def_readwrite("minConnectedRouters", &RouterConfig::m_minConnectedRouters)
.def_readwrite("maxConnectedRouters", &RouterConfig::m_maxConnectedRouters)
.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)
@ -44,7 +46,8 @@ namespace llarp
.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) {
.def("overrideAddress",
[](RouterConfig &self, std::string ip, std::string port) {
self.fromSection("public-ip", ip);
self.fromSection("public-port", port);
})
@ -56,7 +59,8 @@ namespace llarp
py::class_< NetworkConfig >(mod, "NetworkConfig")
.def(py::init<>())
.def_readwrite("enableProfiling", &NetworkConfig::m_enableProfiling)
.def_readwrite("routerProfilesFile", &NetworkConfig::m_routerProfilesFile)
.def_readwrite("routerProfilesFile",
&NetworkConfig::m_routerProfilesFile)
.def_readwrite("strictConnect", &NetworkConfig::m_strictConnect)
.def_readwrite("netConfig", &NetworkConfig::m_netConfig);
@ -113,7 +117,6 @@ namespace llarp
.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);
}
py::class_< in_addr >(mod, "in_addr").def("set", &in_addr_set);
}
} // namespace llarp

@ -15,24 +15,30 @@ 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 {
.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);
.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);
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("AddEndpoint",
[](Context_ptr self, handlers::PythonEndpoint_ptr ep) {
self->router->hiddenServiceContext().InjectEndpoint(ep->OurName,
ep);
})
.def("CallSafe", &Context::CallSafe);
}

@ -14,7 +14,8 @@ namespace llarp
.def(py::self == py::self)
.def(py::self < py::self)
.def(py::self ^ py::self)
.def("distance", [](const Key_t* const lhs, const Key_t* const rhs) {
.def("distance",
[](const Key_t* const lhs, const Key_t* const rhs) {
return *lhs ^ *rhs;
})
.def("ShortString", [](const Key_t* const key) {
@ -22,5 +23,5 @@ namespace llarp
});
}
} // namespace llarp::dht
} // namespace dht
} // namespace llarp

@ -15,4 +15,4 @@ namespace llarp
} // namespace handlers
}
} // namespace llarp

@ -15,16 +15,18 @@ namespace handlers
: 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)
@ -55,15 +57,19 @@ 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)
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);
});
}
@ -75,5 +81,5 @@ namespace handlers
};
using PythonEndpoint_ptr = std::shared_ptr< PythonEndpoint >;
}
}
} // namespace handlers
} // namespace llarp

@ -25,5 +25,5 @@ namespace llarp
.def("__str__", str_func)
.def("__repr__", str_func);
}
} // namespace llarp::path
} // namespace path
} // namespace llarp

@ -9,10 +9,14 @@ namespace llarp
{
py::class_< RouterContact >(mod, "RouterContact")
.def(py::init<>())
.def_property_readonly("routerID", [](const RouterContact* const rc) -> llarp::RouterID {
.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 {
.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)

@ -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) {
.def("__eq__",
[](const RouterID* const lhs, const RouterID* const rhs) {
return *lhs == *rhs;
});
}
}
} // namespace llarp

@ -14,5 +14,5 @@ namespace llarp
return addr.ToString();
});
}
}
}
} // namespace service
} // namespace llarp

@ -23,17 +23,20 @@ namespace tooling
py::class_< PathAttemptEvent, RouterEvent >(mod, "PathAttemptEvent")
.def_readonly("hops", &PathAttemptEvent::hops);
py::class_<PathRequestReceivedEvent, RouterEvent>(mod, "PathRequestReceivedEvent")
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")
py::class_< PathStatusReceivedEvent, RouterEvent >(
mod, "PathStatusReceivedEvent")
.def_readonly("rxid", &PathStatusReceivedEvent::rxid)
.def_readonly("status", &PathStatusReceivedEvent::rxid)
.def_property_readonly("Successful", [](const PathStatusReceivedEvent* const ev) {
.def_property_readonly(
"Successful", [](const PathStatusReceivedEvent* const ev) {
return ev->status == llarp::LR_StatusRecord::SUCCESS;
});
@ -42,19 +45,22 @@ namespace tooling
.def_readonly("relay", &PubIntroSentEvent::relay)
.def_readonly("relayIndex", &PubIntroSentEvent::relayIndex);
py::class_<PubIntroReceivedEvent, RouterEvent>(mod, "DhtPubIntroReceivedEvent")
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")
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")
py::class_< RCGossipReceivedEvent, RouterEvent >(mod,
"RCGossipReceivedEvent")
.def_readonly("rc", &RCGossipReceivedEvent::rc)
.def("LongString", &RCGossipReceivedEvent::LongString);

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