mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
* add convotags to ensure path to snode
* add service::Endpoint::EnsurePathTo which gives you a std::optional<Convotag>
This commit is contained in:
parent
fe32475cad
commit
a61f846d33
3 changed files with 58 additions and 10 deletions
|
@ -325,9 +325,11 @@ namespace llarp
|
|||
{
|
||||
auto ReplyToSNodeDNSWhenReady = [self = this, reply = reply](
|
||||
RouterID snode, auto msg, bool isV6) -> bool {
|
||||
return self->EnsurePathToSNode(snode, [=](const RouterID&, exit::BaseSession_ptr s) {
|
||||
self->SendDNSReply(snode, s, msg, reply, isV6);
|
||||
});
|
||||
return self->EnsurePathToSNode(
|
||||
snode,
|
||||
[=](const RouterID&, exit::BaseSession_ptr s, [[maybe_unused]] service::ConvoTag tag) {
|
||||
self->SendDNSReply(snode, s, msg, reply, isV6);
|
||||
});
|
||||
};
|
||||
auto ReplyToLokiDNSWhenReady = [self = this, reply = reply](
|
||||
service::Address addr, auto msg, bool isV6) -> bool {
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <llarp/quic/tunnel.hpp>
|
||||
#include <llarp/ev/ev_libuv.hpp>
|
||||
#include <uvw.hpp>
|
||||
#include <variant>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -1367,10 +1368,10 @@ namespace llarp
|
|||
while (itr != range.second)
|
||||
{
|
||||
if (itr->second.first->IsReady())
|
||||
h(snode, itr->second.first);
|
||||
h(snode, itr->second.first, itr->second.second);
|
||||
else
|
||||
{
|
||||
itr->second.first->AddReadyHook(std::bind(h, snode, _1));
|
||||
itr->second.first->AddReadyHook(std::bind(h, snode, _1, itr->second.second));
|
||||
itr->second.first->BuildOne();
|
||||
}
|
||||
++itr;
|
||||
|
@ -1402,10 +1403,11 @@ namespace llarp
|
|||
auto pkt = std::make_shared<net::IPPacket>();
|
||||
if (!pkt->Load(buf))
|
||||
return false;
|
||||
EnsurePathToSNode(addr, [pkt, t](RouterID, exit::BaseSession_ptr s) {
|
||||
if (s)
|
||||
s->SendPacketToRemote(pkt->ConstBuffer(), t);
|
||||
});
|
||||
EnsurePathToSNode(
|
||||
addr, [pkt, t](RouterID, exit::BaseSession_ptr s, [[maybe_unused]] ConvoTag tag) {
|
||||
if (s)
|
||||
s->SendPacketToRemote(pkt->ConstBuffer(), t);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1472,6 +1474,44 @@ namespace llarp
|
|||
return std::nullopt;
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::EnsurePathTo(
|
||||
std::variant<Address, RouterID> addr,
|
||||
std::function<void(std::optional<ConvoTag>)> hook,
|
||||
llarp_time_t timeout)
|
||||
{
|
||||
if (auto ptr = std::get_if<Address>(&addr))
|
||||
{
|
||||
return EnsurePathToService(
|
||||
*ptr,
|
||||
[hook](auto, auto* ctx) {
|
||||
if (ctx)
|
||||
{
|
||||
hook(ctx->currentConvoTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
hook(std::nullopt);
|
||||
}
|
||||
},
|
||||
timeout);
|
||||
}
|
||||
if (auto ptr = std::get_if<RouterID>(&addr))
|
||||
{
|
||||
return EnsurePathToSNode(*ptr, [hook](auto, auto session, auto tag) {
|
||||
if (session)
|
||||
{
|
||||
hook(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
hook(std::nullopt);
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::SendToServiceOrQueue(
|
||||
const service::Address& remote, const llarp_buffer_t& data, ProtocolType t)
|
||||
|
|
|
@ -266,6 +266,12 @@ namespace llarp
|
|||
bool
|
||||
ShouldBuildMore(llarp_time_t now) const override;
|
||||
|
||||
bool
|
||||
EnsurePathTo(
|
||||
std::variant<Address, RouterID> addr,
|
||||
std::function<void(std::optional<ConvoTag>)> hook,
|
||||
llarp_time_t timeout);
|
||||
|
||||
// passed a sendto context when we have a path established otherwise
|
||||
// nullptr if the path was not made before the timeout
|
||||
using PathEnsureHook = std::function<void(Address, OutboundContext*)>;
|
||||
|
@ -275,7 +281,7 @@ namespace llarp
|
|||
bool
|
||||
EnsurePathToService(const Address remote, PathEnsureHook h, llarp_time_t timeoutMS);
|
||||
|
||||
using SNodeEnsureHook = std::function<void(const RouterID, exit::BaseSession_ptr)>;
|
||||
using SNodeEnsureHook = std::function<void(const RouterID, exit::BaseSession_ptr, ConvoTag)>;
|
||||
|
||||
/// ensure a path to a service node by public key
|
||||
bool
|
||||
|
|
Loading…
Reference in a new issue