mirror of https://github.com/oxen-io/lokinet
more introspection code
parent
931ff521d1
commit
877443d95c
@ -0,0 +1,88 @@
|
||||
#include "common.hpp"
|
||||
#include "llarp.hpp"
|
||||
#include "service/context.hpp"
|
||||
#include "service/endpoint.hpp"
|
||||
#include "router/abstractrouter.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace handlers
|
||||
{
|
||||
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())
|
||||
{
|
||||
routerContext->router->hiddenServiceContext().InjectEndpoint(name, shared_from_this());
|
||||
}
|
||||
|
||||
bool
|
||||
HandleInboundPacket(const service::ConvoTag tag, const llarp_buffer_t & pktbuf,
|
||||
service::ProtocolType proto) override
|
||||
{
|
||||
if(handlePacket)
|
||||
{
|
||||
AlignedBuffer<32> addr;
|
||||
bool isSnode = false;
|
||||
if(not GetEndpointWithConvoTag(tag, addr, isSnode))
|
||||
return false;
|
||||
if(isSnode)
|
||||
return true;
|
||||
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);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
path::PathSet_ptr
|
||||
GetSelf() override
|
||||
{
|
||||
return shared_from_this();
|
||||
}
|
||||
|
||||
bool
|
||||
SupportsV6() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
LogicCall(m_router->logic(), [remote, pkt, proto, self=shared_from_this()]() {
|
||||
self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt), proto);
|
||||
});
|
||||
}
|
||||
|
||||
std::string
|
||||
GetOurAddress() const
|
||||
{
|
||||
return m_Identity.pub.Addr().ToString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
PyHandler_Init(py::module & mod)
|
||||
{
|
||||
py::class_<PythonEndpoint, std::shared_ptr<PythonEndpoint> >(mod, "Endpoint")
|
||||
.def(py::init<std::string, Context_ptr>())
|
||||
.def("SendTo", &PythonEndpoint::SendPacket)
|
||||
.def("OurAddress", &PythonEndpoint::GetOurAddress)
|
||||
.def_readwrite("GotPacket", &PythonEndpoint::handlePacket);
|
||||
}
|
||||
|
||||
} // namespace handlers
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
#include "common.hpp"
|
||||
#include "service/address.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
void
|
||||
Address_Init(py::module & mod)
|
||||
{
|
||||
py::class_<Address>(mod, "ServiceAddress")
|
||||
.def(py::init<std::string>())
|
||||
.def("__str__", &Address::ToString);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue