mirror of https://github.com/oxen-io/lokinet
fix up client to snode codepath
This commit is contained in:
parent
8b2ede5fc5
commit
4889b8cddf
|
@ -127,6 +127,7 @@ namespace llarp
|
||||||
if (b == 0s)
|
if (b == 0s)
|
||||||
{
|
{
|
||||||
llarp::LogInfo("obtained an exit via ", p->Endpoint());
|
llarp::LogInfo("obtained an exit via ", p->Endpoint());
|
||||||
|
m_CurrentPath = p->RXID();
|
||||||
CallPendingCallbacks(true);
|
CallPendingCallbacks(true);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -257,6 +258,8 @@ namespace llarp
|
||||||
bool
|
bool
|
||||||
BaseSession::IsReady() const
|
BaseSession::IsReady() const
|
||||||
{
|
{
|
||||||
|
if (m_CurrentPath.IsZero())
|
||||||
|
return false;
|
||||||
const size_t expect = (1 + (numDesiredPaths / 2));
|
const size_t expect = (1 + (numDesiredPaths / 2));
|
||||||
return AvailablePaths(llarp::path::ePathRoleExit) >= expect;
|
return AvailablePaths(llarp::path::ePathRoleExit) >= expect;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,14 @@ namespace llarp
|
||||||
return m_ExitRouter;
|
return m_ExitRouter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<PathID_t>
|
||||||
|
CurrentPath() const
|
||||||
|
{
|
||||||
|
if (m_CurrentPath.IsZero())
|
||||||
|
return std::nullopt;
|
||||||
|
return m_CurrentPath;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
IsExpired(llarp_time_t now) const;
|
IsExpired(llarp_time_t now) const;
|
||||||
|
|
||||||
|
@ -151,6 +159,8 @@ namespace llarp
|
||||||
using TieredQueue_t = std::map<uint8_t, UpstreamTrafficQueue_t>;
|
using TieredQueue_t = std::map<uint8_t, UpstreamTrafficQueue_t>;
|
||||||
TieredQueue_t m_Upstream;
|
TieredQueue_t m_Upstream;
|
||||||
|
|
||||||
|
PathID_t m_CurrentPath;
|
||||||
|
|
||||||
using DownstreamPkt = std::pair<uint64_t, llarp::net::IPPacket>;
|
using DownstreamPkt = std::pair<uint64_t, llarp::net::IPPacket>;
|
||||||
|
|
||||||
struct DownstreamPktSorter
|
struct DownstreamPktSorter
|
||||||
|
|
|
@ -170,9 +170,10 @@ namespace llarp
|
||||||
|
|
||||||
for (const auto& item : m_state->m_SNodeSessions)
|
for (const auto& item : m_state->m_SNodeSessions)
|
||||||
{
|
{
|
||||||
if (item.second.second == tag)
|
if (const auto maybe = item.second->CurrentPath())
|
||||||
{
|
{
|
||||||
return item.first;
|
if (ConvoTag{maybe->as_array()} == tag)
|
||||||
|
return item.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
@ -616,7 +617,7 @@ namespace llarp
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
resetState(m_state->m_RemoteSessions, [](const auto& item) { return item.second; });
|
resetState(m_state->m_RemoteSessions, [](const auto& item) { return item.second; });
|
||||||
resetState(m_state->m_SNodeSessions, [](const auto& item) { return item.second.first; });
|
resetState(m_state->m_SNodeSessions, [](const auto& item) { return item.second; });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -1006,7 +1007,7 @@ namespace llarp
|
||||||
auto itr = range.first;
|
auto itr = range.first;
|
||||||
while (itr != range.second)
|
while (itr != range.second)
|
||||||
{
|
{
|
||||||
if (itr->second.first->IsReady())
|
if (itr->second->IsReady())
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1359,10 +1360,6 @@ namespace llarp
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
if (nodeSessions.count(snode) == 0)
|
if (nodeSessions.count(snode) == 0)
|
||||||
{
|
{
|
||||||
ConvoTag tag;
|
|
||||||
// TODO: check for collision lol no we don't but maybe we will...
|
|
||||||
// some day :DDDDD
|
|
||||||
tag.Randomize();
|
|
||||||
const auto src = xhtonl(net::TruncateV6(GetIfAddr()));
|
const auto src = xhtonl(net::TruncateV6(GetIfAddr()));
|
||||||
const auto dst = xhtonl(net::TruncateV6(ObtainIPForAddr(snode)));
|
const auto dst = xhtonl(net::TruncateV6(ObtainIPForAddr(snode)));
|
||||||
|
|
||||||
|
@ -1374,27 +1371,42 @@ namespace llarp
|
||||||
return false;
|
return false;
|
||||||
pkt.UpdateIPv4Address(src, dst);
|
pkt.UpdateIPv4Address(src, dst);
|
||||||
/// TODO: V6
|
/// TODO: V6
|
||||||
return HandleInboundPacket(tag, pkt.ConstBuffer(), ProtocolType::TrafficV4, 0);
|
auto itr = m_state->m_SNodeSessions.find(snode);
|
||||||
|
if (itr == m_state->m_SNodeSessions.end())
|
||||||
|
return false;
|
||||||
|
if (const auto maybe = itr->second->CurrentPath())
|
||||||
|
return HandleInboundPacket(
|
||||||
|
ConvoTag{maybe->as_array()}, pkt.ConstBuffer(), ProtocolType::TrafficV4, 0);
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
Router(),
|
Router(),
|
||||||
numDesiredPaths,
|
1,
|
||||||
numHops,
|
numHops,
|
||||||
false,
|
false,
|
||||||
this);
|
this);
|
||||||
|
m_state->m_SNodeSessions[snode] = session;
|
||||||
m_state->m_SNodeSessions.emplace(snode, std::make_pair(session, tag));
|
|
||||||
}
|
}
|
||||||
EnsureRouterIsKnown(snode);
|
EnsureRouterIsKnown(snode);
|
||||||
auto range = nodeSessions.equal_range(snode);
|
auto range = nodeSessions.equal_range(snode);
|
||||||
auto itr = range.first;
|
auto itr = range.first;
|
||||||
while (itr != range.second)
|
while (itr != range.second)
|
||||||
{
|
{
|
||||||
if (itr->second.first->IsReady())
|
if (itr->second->IsReady())
|
||||||
h(snode, itr->second.first, itr->second.second);
|
h(snode, itr->second, ConvoTag{itr->second->CurrentPath()->as_array()});
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itr->second.first->AddReadyHook(std::bind(h, snode, _1, itr->second.second));
|
itr->second->AddReadyHook([h, snode](auto session) {
|
||||||
itr->second.first->BuildOne();
|
if (session)
|
||||||
|
{
|
||||||
|
h(snode, session, ConvoTag{session->CurrentPath()->as_array()});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
h(snode, nullptr, ConvoTag{});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (not itr->second->BuildCooldownHit(Now()))
|
||||||
|
itr->second->BuildOne();
|
||||||
}
|
}
|
||||||
++itr;
|
++itr;
|
||||||
}
|
}
|
||||||
|
@ -1440,10 +1452,9 @@ namespace llarp
|
||||||
auto pkt = std::make_shared<net::IPPacket>();
|
auto pkt = std::make_shared<net::IPPacket>();
|
||||||
if (!pkt->Load(buf))
|
if (!pkt->Load(buf))
|
||||||
return false;
|
return false;
|
||||||
EnsurePathToSNode(addr, [=](RouterID, exit::BaseSession_ptr s, ConvoTag tag) {
|
EnsurePathToSNode(addr, [=](RouterID, exit::BaseSession_ptr s, ConvoTag) {
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
ConvoTagTX(tag);
|
|
||||||
s->SendPacketToRemote(pkt->ConstBuffer(), t);
|
s->SendPacketToRemote(pkt->ConstBuffer(), t);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1455,7 +1466,7 @@ namespace llarp
|
||||||
FlushRecvData();
|
FlushRecvData();
|
||||||
// send downstream packets to user for snode
|
// send downstream packets to user for snode
|
||||||
for (const auto& [router, session] : m_state->m_SNodeSessions)
|
for (const auto& [router, session] : m_state->m_SNodeSessions)
|
||||||
session.first->FlushDownstream();
|
session->FlushDownstream();
|
||||||
|
|
||||||
// handle inbound traffic sorted
|
// handle inbound traffic sorted
|
||||||
std::priority_queue<ProtocolMessage> queue;
|
std::priority_queue<ProtocolMessage> queue;
|
||||||
|
@ -1492,7 +1503,7 @@ namespace llarp
|
||||||
outctx->FlushUpstream();
|
outctx->FlushUpstream();
|
||||||
// TODO: locking on this container
|
// TODO: locking on this container
|
||||||
for (const auto& [router, session] : m_state->m_SNodeSessions)
|
for (const auto& [router, session] : m_state->m_SNodeSessions)
|
||||||
session.first->FlushUpstream();
|
session->FlushUpstream();
|
||||||
|
|
||||||
// send queue flush
|
// send queue flush
|
||||||
while (not m_SendQueue.empty())
|
while (not m_SendQueue.empty())
|
||||||
|
@ -1563,13 +1574,13 @@ namespace llarp
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (auto ptr = std::get_if<RouterID>(&remote))
|
if (auto* ptr = std::get_if<RouterID>(&remote))
|
||||||
{
|
{
|
||||||
for (const auto& item : m_state->m_SNodeSessions)
|
auto itr = m_state->m_SNodeSessions.find(*ptr);
|
||||||
{
|
if (itr == m_state->m_SNodeSessions.end())
|
||||||
if (item.first == *ptr)
|
return std::nullopt;
|
||||||
return item.second.second;
|
if (auto maybe = itr->second->CurrentPath())
|
||||||
}
|
return ConvoTag{maybe->as_array()};
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace llarp
|
||||||
m_SNodeSessions.begin(),
|
m_SNodeSessions.begin(),
|
||||||
m_SNodeSessions.end(),
|
m_SNodeSessions.end(),
|
||||||
std::back_inserter(obj["snodeSessions"]),
|
std::back_inserter(obj["snodeSessions"]),
|
||||||
[](const auto& item) { return item.second.first->ExtractStatus(); });
|
[](const auto& item) { return item.second->ExtractStatus(); });
|
||||||
|
|
||||||
util::StatusObject sessionObj{};
|
util::StatusObject sessionObj{};
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,7 @@ namespace llarp
|
||||||
|
|
||||||
using Sessions = std::unordered_multimap<Address, std::shared_ptr<OutboundContext>>;
|
using Sessions = std::unordered_multimap<Address, std::shared_ptr<OutboundContext>>;
|
||||||
|
|
||||||
using SNodeSessionValue = std::pair<std::shared_ptr<exit::BaseSession>, ConvoTag>;
|
using SNodeSessions = std::unordered_map<RouterID, std::shared_ptr<exit::BaseSession>>;
|
||||||
|
|
||||||
using SNodeSessions = std::unordered_multimap<RouterID, SNodeSessionValue>;
|
|
||||||
|
|
||||||
using ConvoMap = std::unordered_map<ConvoTag, Session>;
|
using ConvoMap = std::unordered_map<ConvoTag, Session>;
|
||||||
|
|
||||||
|
|
|
@ -15,19 +15,19 @@ namespace llarp
|
||||||
auto itr = sessions.begin();
|
auto itr = sessions.begin();
|
||||||
while (itr != sessions.end())
|
while (itr != sessions.end())
|
||||||
{
|
{
|
||||||
if (itr->second.first->ShouldRemove() && itr->second.first->IsStopped())
|
if (itr->second->ShouldRemove() && itr->second->IsStopped())
|
||||||
{
|
{
|
||||||
itr = sessions.erase(itr);
|
itr = sessions.erase(itr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// expunge next tick
|
// expunge next tick
|
||||||
if (itr->second.first->IsExpired(now))
|
if (itr->second->IsExpired(now))
|
||||||
{
|
{
|
||||||
itr->second.first->Stop();
|
itr->second->Stop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itr->second.first->Tick(now);
|
itr->second->Tick(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
++itr;
|
++itr;
|
||||||
|
@ -138,7 +138,7 @@ namespace llarp
|
||||||
{
|
{
|
||||||
for (auto& item : sessions)
|
for (auto& item : sessions)
|
||||||
{
|
{
|
||||||
item.second.first->Stop();
|
item.second->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue