mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-19 09:25:28 +00:00
635dc4fe13
llarp/config/config.cpp: respect [network]:type option llarp/handlers/exit.cpp: when [network]:type is null dont init tun interface llarp/service/context.cpp: respect [network]:type option change endpoint name back to "default" llarp/tooling/router_hive.cpp: dont use LogicCall for obtaining RCs from underlying relays, it crashes the mainloop and it's probably safe to readonly access RCs. pybind/common.hpp: remove typecasters as we use C++17 now pybind/llarp/config.cpp: remove SnappConfig wire up NetworkConfig pybind/llarp/handlers/pyhandler.hpp: remove SnappConfig from constructor pybind/llarp/handlers/pyhandler.cpp: update constructor implementation to match header test/hive/hive.py: remove broke endpoint related code wire up null endpoint option using NetworkConfig use index at 0 for relays and clients instead of 1 dont add a python endpoint to all clients
82 lines
2.2 KiB
C++
82 lines
2.2 KiB
C++
#pragma once
|
|
#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(
|
|
routerContext->router.get(), &routerContext->router->hiddenServiceContext())
|
|
, OurName(std::move(name))
|
|
{
|
|
}
|
|
const std::string OurName;
|
|
|
|
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();
|
|
}
|
|
};
|
|
|
|
using PythonEndpoint_ptr = std::shared_ptr<PythonEndpoint>;
|
|
} // namespace handlers
|
|
} // namespace llarp
|