2020-03-07 01:20:11 +00:00
|
|
|
#pragma once
|
2020-02-28 18:44:27 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
#include "llarp.hpp"
|
|
|
|
#include "service/context.hpp"
|
|
|
|
#include "service/endpoint.hpp"
|
|
|
|
#include "router/abstractrouter.hpp"
|
|
|
|
|
2020-03-07 01:20:11 +00:00
|
|
|
namespace llarp
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-03-07 01:20:11 +00:00
|
|
|
namespace handlers
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
using Context_ptr = std::shared_ptr<llarp::Context>;
|
2020-02-28 18:44:27 +00:00
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
struct PythonEndpoint final : public llarp::service::Endpoint,
|
|
|
|
public std::enable_shared_from_this<PythonEndpoint>
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-05-06 14:45:30 +00:00
|
|
|
PythonEndpoint(std::string name, Context_ptr routerContext)
|
2020-03-07 01:20:11 +00:00
|
|
|
: llarp::service::Endpoint(
|
2020-05-06 14:45:30 +00:00
|
|
|
routerContext->router.get(), &routerContext->router->hiddenServiceContext())
|
|
|
|
, OurName(std::move(name))
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
const std::string OurName;
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
HandleInboundPacket(
|
|
|
|
const service::ConvoTag tag,
|
|
|
|
const llarp_buffer_t& pktbuf,
|
|
|
|
service::ProtocolType proto) override
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (handlePacket)
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
AlignedBuffer<32> addr;
|
2020-02-28 18:44:27 +00:00
|
|
|
bool isSnode = false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (not GetEndpointWithConvoTag(tag, addr, isSnode))
|
2020-02-28 18:44:27 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (isSnode)
|
2020-02-28 18:44:27 +00:00
|
|
|
return true;
|
2020-04-07 18:38:56 +00:00
|
|
|
std::vector<byte_t> pkt;
|
2020-02-28 18:44:27 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using PacketHandler_t =
|
|
|
|
std::function<void(service::Address, std::vector<byte_t>, service::ProtocolType)>;
|
2020-02-28 18:44:27 +00:00
|
|
|
|
|
|
|
PacketHandler_t handlePacket;
|
|
|
|
|
2020-03-07 01:20:11 +00:00
|
|
|
void
|
2020-04-07 18:38:56 +00:00
|
|
|
SendPacket(service::Address remote, std::vector<byte_t> pkt, service::ProtocolType proto)
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
LogicCall(m_router->logic(), [remote, pkt, proto, self = shared_from_this()]() {
|
|
|
|
self->SendToServiceOrQueue(remote, llarp_buffer_t(pkt), proto);
|
|
|
|
});
|
2020-02-28 18:44:27 +00:00
|
|
|
}
|
|
|
|
|
2020-03-07 01:20:11 +00:00
|
|
|
std::string
|
|
|
|
GetOurAddress() const
|
2020-02-28 18:44:27 +00:00
|
|
|
{
|
|
|
|
return m_Identity.pub.Addr().ToString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
using PythonEndpoint_ptr = std::shared_ptr<PythonEndpoint>;
|
2020-03-07 01:20:11 +00:00
|
|
|
} // namespace handlers
|
2020-04-22 20:04:47 +00:00
|
|
|
} // namespace llarp
|