2021-03-09 22:24:35 +00:00
|
|
|
#include "session.hpp"
|
2019-01-16 00:24:16 +00:00
|
|
|
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/crypto/crypto.hpp>
|
|
|
|
#include <llarp/nodedb.hpp>
|
|
|
|
#include <llarp/path/path_context.hpp>
|
|
|
|
#include <llarp/path/path.hpp>
|
2021-03-26 13:16:43 +00:00
|
|
|
#include <llarp/quic/tunnel.hpp>
|
2021-03-09 22:24:35 +00:00
|
|
|
#include <llarp/router/abstractrouter.hpp>
|
|
|
|
#include <llarp/util/meta/memfn.hpp>
|
2019-07-30 23:42:13 +00:00
|
|
|
#include <utility>
|
2018-11-12 16:43:40 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace exit
|
|
|
|
{
|
2019-02-01 01:58:06 +00:00
|
|
|
BaseSession::BaseSession(
|
2019-08-02 09:27:27 +00:00
|
|
|
const llarp::RouterID& routerId,
|
2020-04-07 18:38:56 +00:00
|
|
|
std::function<bool(const llarp_buffer_t&)> writepkt,
|
|
|
|
AbstractRouter* r,
|
|
|
|
size_t numpaths,
|
|
|
|
size_t hoplen,
|
2021-03-29 16:31:55 +00:00
|
|
|
EndpointBase* parent)
|
2021-03-26 13:16:43 +00:00
|
|
|
: llarp::path::Builder{r, numpaths, hoplen}
|
|
|
|
, m_ExitRouter{routerId}
|
|
|
|
, m_WritePacket{std::move(writepkt)}
|
|
|
|
, m_Counter{0}
|
|
|
|
, m_LastUse{r->Now()}
|
|
|
|
, m_BundleRC{false}
|
2021-03-29 16:31:55 +00:00
|
|
|
, m_Parent{parent}
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2019-05-28 19:45:08 +00:00
|
|
|
CryptoManager::instance()->identity_keygen(m_ExitIdentity);
|
2018-11-14 19:34:17 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 23:42:13 +00:00
|
|
|
BaseSession::~BaseSession() = default;
|
2018-11-14 19:34:17 +00:00
|
|
|
|
2019-05-06 14:54:05 +00:00
|
|
|
void
|
|
|
|
BaseSession::HandlePathDied(path::Path_ptr p)
|
2019-03-30 13:02:10 +00:00
|
|
|
{
|
2019-05-06 14:54:05 +00:00
|
|
|
p->Rebuild();
|
2019-03-30 13:02:10 +00:00
|
|
|
}
|
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
util::StatusObject
|
|
|
|
BaseSession::ExtractStatus() const
|
2019-02-08 19:43:25 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
auto obj = path::Builder::ExtractStatus();
|
|
|
|
obj["lastExitUse"] = to_json(m_LastUse);
|
|
|
|
auto pub = m_ExitIdentity.toPublic();
|
2019-08-19 09:33:26 +00:00
|
|
|
obj["exitIdentity"] = pub.ToString();
|
2021-07-02 12:26:56 +00:00
|
|
|
obj["endpoint"] = m_ExitRouter.ToString();
|
2019-02-11 17:14:43 +00:00
|
|
|
return obj;
|
2019-02-08 19:43:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 16:14:44 +00:00
|
|
|
bool
|
|
|
|
BaseSession::LoadIdentityFromFile(const char* fname)
|
|
|
|
{
|
|
|
|
return m_ExitIdentity.LoadFromFile(fname);
|
|
|
|
}
|
|
|
|
|
2018-11-16 14:03:13 +00:00
|
|
|
bool
|
|
|
|
BaseSession::ShouldBuildMore(llarp_time_t now) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (BuildCooldownHit(now))
|
2020-03-09 21:31:43 +00:00
|
|
|
return false;
|
2020-10-27 20:27:14 +00:00
|
|
|
const size_t expect = (1 + (numDesiredPaths / 2));
|
2018-12-27 12:00:28 +00:00
|
|
|
// check 30 seconds into the future and see if we need more paths
|
2020-02-24 19:40:45 +00:00
|
|
|
const llarp_time_t future = now + 30s + buildIntervalLimit;
|
2020-03-09 21:31:43 +00:00
|
|
|
return NumPathsExistingAt(future) < expect;
|
2018-11-16 14:03:13 +00:00
|
|
|
}
|
|
|
|
|
2019-05-10 16:19:33 +00:00
|
|
|
void
|
2020-05-21 14:18:23 +00:00
|
|
|
BaseSession::BlacklistSNode(const RouterID snode)
|
2019-05-10 16:19:33 +00:00
|
|
|
{
|
|
|
|
m_SnodeBlacklist.insert(std::move(snode));
|
|
|
|
}
|
|
|
|
|
2021-02-02 14:35:40 +00:00
|
|
|
std::optional<std::vector<RouterContact>>
|
|
|
|
BaseSession::GetHopsForBuild()
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2021-04-06 19:04:07 +00:00
|
|
|
if (numHops == 1)
|
|
|
|
{
|
|
|
|
if (auto maybe = m_router->nodedb()->Get(m_ExitRouter))
|
|
|
|
return std::vector<RouterContact>{*maybe};
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return GetHopsAlignedToForBuild(m_ExitRouter);
|
2018-11-14 19:34:17 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 19:39:58 +00:00
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
BaseSession::CheckPathDead(path::Path_ptr, llarp_time_t dlt)
|
2019-04-16 19:39:58 +00:00
|
|
|
{
|
2020-05-21 14:18:23 +00:00
|
|
|
return dlt >= path::alive_timeout;
|
2019-04-16 19:39:58 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
void
|
2019-04-23 14:28:59 +00:00
|
|
|
BaseSession::HandlePathBuilt(llarp::path::Path_ptr p)
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2018-12-10 15:31:58 +00:00
|
|
|
path::Builder::HandlePathBuilt(p);
|
2019-06-02 21:19:10 +00:00
|
|
|
p->SetDropHandler(util::memFn(&BaseSession::HandleTrafficDrop, this));
|
|
|
|
p->SetDeadChecker(util::memFn(&BaseSession::CheckPathDead, this));
|
|
|
|
p->SetExitTrafficHandler(util::memFn(&BaseSession::HandleTraffic, this));
|
|
|
|
p->AddObtainExitHandler(util::memFn(&BaseSession::HandleGotExit, this));
|
2018-12-20 12:41:17 +00:00
|
|
|
|
2019-05-28 19:45:08 +00:00
|
|
|
routing::ObtainExitMessage obtain;
|
2018-11-14 19:34:17 +00:00
|
|
|
obtain.S = p->NextSeqNo();
|
2018-12-11 00:53:11 +00:00
|
|
|
obtain.T = llarp::randint();
|
2018-11-29 13:12:35 +00:00
|
|
|
PopulateRequest(obtain);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!obtain.Sign(m_ExitIdentity))
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
|
|
|
llarp::LogError("Failed to sign exit request");
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
if (p->SendExitRequest(obtain, m_router))
|
2018-11-14 19:34:17 +00:00
|
|
|
llarp::LogInfo("asking ", m_ExitRouter, " for exit");
|
|
|
|
else
|
2019-01-16 00:24:16 +00:00
|
|
|
llarp::LogError("failed to send exit request");
|
2018-11-14 19:34:17 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 19:10:42 +00:00
|
|
|
void
|
|
|
|
BaseSession::AddReadyHook(SessionReadyFunc func)
|
|
|
|
{
|
|
|
|
m_PendingCallbacks.emplace_back(func);
|
|
|
|
}
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
bool
|
2019-04-23 14:28:59 +00:00
|
|
|
BaseSession::HandleGotExit(llarp::path::Path_ptr p, llarp_time_t b)
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (b == 0s)
|
2019-04-30 21:36:27 +00:00
|
|
|
{
|
2018-11-14 19:34:17 +00:00
|
|
|
llarp::LogInfo("obtained an exit via ", p->Endpoint());
|
2021-04-07 12:03:04 +00:00
|
|
|
m_CurrentPath = p->RXID();
|
2019-03-07 15:17:29 +00:00
|
|
|
CallPendingCallbacks(true);
|
2019-04-30 21:36:27 +00:00
|
|
|
}
|
2019-03-07 15:17:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-12-13 12:27:14 +00:00
|
|
|
|
2019-03-07 15:17:29 +00:00
|
|
|
void
|
|
|
|
BaseSession::CallPendingCallbacks(bool success)
|
|
|
|
{
|
2021-11-09 19:06:20 +00:00
|
|
|
if (m_PendingCallbacks.empty())
|
|
|
|
return;
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (success)
|
2019-03-07 15:17:29 +00:00
|
|
|
{
|
2019-04-23 16:13:22 +00:00
|
|
|
auto self = shared_from_this();
|
2020-04-07 18:38:56 +00:00
|
|
|
for (auto& f : m_PendingCallbacks)
|
2019-04-23 16:13:22 +00:00
|
|
|
f(self);
|
2019-03-07 15:17:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
for (auto& f : m_PendingCallbacks)
|
2019-03-07 15:17:29 +00:00
|
|
|
f(nullptr);
|
|
|
|
}
|
2019-03-01 19:10:42 +00:00
|
|
|
m_PendingCallbacks.clear();
|
2018-11-14 19:34:17 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 18:15:22 +00:00
|
|
|
void
|
|
|
|
BaseSession::ResetInternalState()
|
|
|
|
{
|
|
|
|
auto sendExitClose = [&](const llarp::path::Path_ptr p) {
|
2020-04-07 18:38:56 +00:00
|
|
|
const static auto roles = llarp::path::ePathRoleExit | llarp::path::ePathRoleSVC;
|
|
|
|
if (p->SupportsAnyRoles(roles))
|
2019-05-07 18:15:22 +00:00
|
|
|
{
|
|
|
|
llarp::LogInfo(p->Name(), " closing exit path");
|
2019-05-28 19:45:08 +00:00
|
|
|
routing::CloseExitMessage msg;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, m_router))
|
2019-05-08 12:50:33 +00:00
|
|
|
{
|
|
|
|
p->ClearRoles(roles);
|
|
|
|
}
|
|
|
|
else
|
2019-05-07 18:15:22 +00:00
|
|
|
llarp::LogWarn(p->Name(), " failed to send exit close message");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
ForEachPath(sendExitClose);
|
|
|
|
path::Builder::ResetInternalState();
|
|
|
|
}
|
|
|
|
|
2018-12-24 16:09:05 +00:00
|
|
|
bool
|
|
|
|
BaseSession::Stop()
|
|
|
|
{
|
2019-03-07 15:17:29 +00:00
|
|
|
CallPendingCallbacks(false);
|
2019-05-28 19:45:08 +00:00
|
|
|
auto sendExitClose = [&](const path::Path_ptr p) {
|
2020-04-07 18:38:56 +00:00
|
|
|
if (p->SupportsAnyRoles(path::ePathRoleExit))
|
2018-12-24 16:09:05 +00:00
|
|
|
{
|
2019-05-28 19:45:08 +00:00
|
|
|
LogInfo(p->Name(), " closing exit path");
|
|
|
|
routing::CloseExitMessage msg;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!(msg.Sign(m_ExitIdentity) && p->SendExitClose(msg, m_router)))
|
2019-05-28 19:45:08 +00:00
|
|
|
LogWarn(p->Name(), " failed to send exit close message");
|
2018-12-24 16:09:05 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
ForEachPath(sendExitClose);
|
2019-08-02 09:27:27 +00:00
|
|
|
m_router->pathContext().RemovePathSet(shared_from_this());
|
2019-05-28 19:45:08 +00:00
|
|
|
return path::Builder::Stop();
|
2018-12-24 16:09:05 +00:00
|
|
|
}
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
bool
|
2021-03-26 13:16:43 +00:00
|
|
|
BaseSession::HandleTraffic(
|
|
|
|
llarp::path::Path_ptr path,
|
|
|
|
const llarp_buffer_t& buf,
|
|
|
|
uint64_t counter,
|
|
|
|
service::ProtocolType t)
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2021-04-07 10:29:49 +00:00
|
|
|
const service::ConvoTag tag{path->RXID().as_array()};
|
2021-03-29 16:31:55 +00:00
|
|
|
|
2021-03-26 13:16:43 +00:00
|
|
|
if (t == service::ProtocolType::QUIC)
|
|
|
|
{
|
2021-03-29 16:31:55 +00:00
|
|
|
auto quic = m_Parent->GetQUICTunnel();
|
|
|
|
if (not quic)
|
2021-03-26 13:16:43 +00:00
|
|
|
return false;
|
2021-03-29 16:31:55 +00:00
|
|
|
quic->receive_packet(tag, buf);
|
2021-03-26 13:16:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_WritePacket)
|
2018-12-13 12:27:14 +00:00
|
|
|
{
|
2019-06-11 16:44:05 +00:00
|
|
|
llarp::net::IPPacket pkt;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (!pkt.Load(buf))
|
2018-12-13 12:27:14 +00:00
|
|
|
return false;
|
2019-08-02 09:27:27 +00:00
|
|
|
m_LastUse = m_router->Now();
|
2020-01-08 16:03:52 +00:00
|
|
|
m_Downstream.emplace(counter, pkt);
|
2018-12-13 12:27:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-14 19:34:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 18:38:56 +00:00
|
|
|
BaseSession::HandleTrafficDrop(llarp::path::Path_ptr p, const PathID_t& path, uint64_t s)
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
llarp::LogError("dropped traffic on exit ", m_ExitRouter, " S=", s, " P=", path);
|
2019-08-02 09:27:27 +00:00
|
|
|
p->EnterState(path::ePathIgnore, m_router->Now());
|
2018-11-14 19:34:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2021-03-16 11:56:27 +00:00
|
|
|
BaseSession::QueueUpstreamTraffic(
|
|
|
|
llarp::net::IPPacket pkt, const size_t N, service::ProtocolType t)
|
2018-11-28 16:38:20 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
const auto pktbuf = pkt.ConstBuffer();
|
2019-10-28 19:32:16 +00:00
|
|
|
const llarp_buffer_t& buf = pktbuf;
|
2020-04-07 18:38:56 +00:00
|
|
|
auto& queue = m_Upstream[buf.sz / N];
|
2018-11-29 13:12:35 +00:00
|
|
|
// queue overflow
|
2020-04-07 18:38:56 +00:00
|
|
|
if (queue.size() >= MaxUpstreamQueueLength)
|
2018-11-29 13:12:35 +00:00
|
|
|
return false;
|
2020-04-07 18:38:56 +00:00
|
|
|
if (queue.size() == 0)
|
2018-11-29 15:45:27 +00:00
|
|
|
{
|
|
|
|
queue.emplace_back();
|
2021-03-16 11:56:27 +00:00
|
|
|
queue.back().protocol = t;
|
2018-11-29 21:19:20 +00:00
|
|
|
return queue.back().PutBuffer(buf, m_Counter++);
|
2018-11-29 15:45:27 +00:00
|
|
|
}
|
2018-12-02 18:07:07 +00:00
|
|
|
auto& back = queue.back();
|
2018-11-28 16:38:20 +00:00
|
|
|
// pack to nearest N
|
2020-04-07 18:38:56 +00:00
|
|
|
if (back.Size() + buf.sz > N)
|
2018-11-28 16:38:20 +00:00
|
|
|
{
|
2018-12-02 18:07:07 +00:00
|
|
|
queue.emplace_back();
|
2021-03-16 11:56:27 +00:00
|
|
|
queue.back().protocol = t;
|
2018-12-02 18:07:07 +00:00
|
|
|
return queue.back().PutBuffer(buf, m_Counter++);
|
2018-11-28 16:38:20 +00:00
|
|
|
}
|
2021-03-16 11:56:27 +00:00
|
|
|
back.protocol = t;
|
2019-07-06 17:03:40 +00:00
|
|
|
return back.PutBuffer(buf, m_Counter++);
|
2018-11-28 16:38:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 13:12:35 +00:00
|
|
|
bool
|
2018-12-02 18:07:07 +00:00
|
|
|
BaseSession::IsReady() const
|
2018-11-29 13:12:35 +00:00
|
|
|
{
|
2021-04-07 12:03:04 +00:00
|
|
|
if (m_CurrentPath.IsZero())
|
|
|
|
return false;
|
2020-10-27 20:27:14 +00:00
|
|
|
const size_t expect = (1 + (numDesiredPaths / 2));
|
2019-03-07 15:17:29 +00:00
|
|
|
return AvailablePaths(llarp::path::ePathRoleExit) >= expect;
|
2018-11-29 13:12:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-13 12:27:14 +00:00
|
|
|
bool
|
|
|
|
BaseSession::IsExpired(llarp_time_t now) const
|
|
|
|
{
|
2020-01-08 16:05:29 +00:00
|
|
|
return now > m_LastUse && now - m_LastUse > LifeSpan;
|
2018-12-13 12:27:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 15:08:57 +00:00
|
|
|
bool
|
|
|
|
BaseSession::UrgentBuild(llarp_time_t now) const
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (BuildCooldownHit(now))
|
2020-03-09 21:31:43 +00:00
|
|
|
return false;
|
2020-10-27 20:27:14 +00:00
|
|
|
if (IsReady() and NumInStatus(path::ePathBuilding) < numDesiredPaths)
|
|
|
|
return path::Builder::UrgentBuild(now);
|
|
|
|
return false;
|
2019-05-07 15:08:57 +00:00
|
|
|
}
|
|
|
|
|
2018-12-02 18:07:07 +00:00
|
|
|
bool
|
2019-04-30 13:56:39 +00:00
|
|
|
BaseSession::FlushUpstream()
|
2018-11-14 19:34:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
auto now = m_router->Now();
|
2021-04-06 18:32:14 +00:00
|
|
|
auto path = PickEstablishedPath(llarp::path::ePathRoleExit);
|
2020-04-07 18:38:56 +00:00
|
|
|
if (path)
|
2018-11-28 16:38:20 +00:00
|
|
|
{
|
2021-11-11 14:17:48 +00:00
|
|
|
for (auto& [i, queue] : m_Upstream)
|
2018-11-29 15:45:27 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
while (queue.size())
|
2018-12-27 12:00:28 +00:00
|
|
|
{
|
|
|
|
auto& msg = queue.front();
|
2021-04-06 18:32:14 +00:00
|
|
|
msg.S = path->NextSeqNo();
|
|
|
|
path->SendRoutingMessage(msg, m_router);
|
2018-12-27 12:00:28 +00:00
|
|
|
queue.pop_front();
|
|
|
|
}
|
2018-11-29 15:45:27 +00:00
|
|
|
}
|
2018-11-28 16:38:20 +00:00
|
|
|
}
|
2018-12-27 12:00:28 +00:00
|
|
|
else
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_Upstream.size())
|
2018-12-27 12:00:28 +00:00
|
|
|
llarp::LogWarn("no path for exit session");
|
|
|
|
// discard upstream
|
2021-11-11 14:17:48 +00:00
|
|
|
for (auto& [i, queue] : m_Upstream)
|
|
|
|
queue.clear();
|
2018-12-27 12:00:28 +00:00
|
|
|
m_Upstream.clear();
|
2020-04-07 18:38:56 +00:00
|
|
|
if (numHops == 1)
|
2019-05-03 13:15:03 +00:00
|
|
|
{
|
2019-08-02 09:27:27 +00:00
|
|
|
auto r = m_router;
|
2021-02-02 14:35:40 +00:00
|
|
|
if (const auto maybe = r->nodedb()->Get(m_ExitRouter); maybe.has_value())
|
|
|
|
r->TryConnectAsync(*maybe, 5);
|
2019-05-03 17:42:48 +00:00
|
|
|
else
|
2020-04-07 18:38:56 +00:00
|
|
|
r->LookupRouter(m_ExitRouter, [r](const std::vector<RouterContact>& results) {
|
|
|
|
if (results.size())
|
|
|
|
r->TryConnectAsync(results[0], 5);
|
|
|
|
});
|
2019-05-03 13:15:03 +00:00
|
|
|
}
|
2020-04-07 18:38:56 +00:00
|
|
|
else if (UrgentBuild(now))
|
2019-05-07 12:34:02 +00:00
|
|
|
BuildOneAlignedTo(m_ExitRouter);
|
2018-12-27 12:00:28 +00:00
|
|
|
}
|
2019-04-30 13:56:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
BaseSession::FlushDownstream()
|
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
while (m_Downstream.size())
|
2018-12-20 12:41:17 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (m_WritePacket)
|
2018-12-20 12:41:17 +00:00
|
|
|
m_WritePacket(m_Downstream.top().second.ConstBuffer());
|
|
|
|
m_Downstream.pop();
|
|
|
|
}
|
2018-11-14 19:34:17 +00:00
|
|
|
}
|
|
|
|
|
2019-02-01 01:58:06 +00:00
|
|
|
SNodeSession::SNodeSession(
|
|
|
|
const llarp::RouterID& snodeRouter,
|
2020-04-07 18:38:56 +00:00
|
|
|
std::function<bool(const llarp_buffer_t&)> writepkt,
|
|
|
|
AbstractRouter* r,
|
|
|
|
size_t numpaths,
|
|
|
|
size_t hoplen,
|
|
|
|
bool useRouterSNodeKey,
|
2021-03-29 16:31:55 +00:00
|
|
|
EndpointBase* parent)
|
|
|
|
: BaseSession{snodeRouter, writepkt, r, numpaths, hoplen, parent}
|
2018-12-13 16:14:44 +00:00
|
|
|
{
|
2020-04-07 18:38:56 +00:00
|
|
|
if (useRouterSNodeKey)
|
2018-12-13 16:14:44 +00:00
|
|
|
{
|
2019-02-11 19:45:42 +00:00
|
|
|
m_ExitIdentity = r->identity();
|
2018-12-13 16:14:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-22 14:10:30 +00:00
|
|
|
|
|
|
|
std::string
|
|
|
|
SNodeSession::Name() const
|
|
|
|
{
|
|
|
|
return "SNode::" + m_ExitRouter.ToString();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string
|
|
|
|
ExitSession::Name() const
|
|
|
|
{
|
|
|
|
return "Exit::" + m_ExitRouter.ToString();
|
|
|
|
}
|
2020-05-21 14:18:23 +00:00
|
|
|
|
|
|
|
void
|
2021-03-16 11:56:27 +00:00
|
|
|
SNodeSession::SendPacketToRemote(const llarp_buffer_t& buf, service::ProtocolType t)
|
2020-05-21 14:18:23 +00:00
|
|
|
{
|
|
|
|
net::IPPacket pkt;
|
|
|
|
if (not pkt.Load(buf))
|
|
|
|
return;
|
|
|
|
pkt.ZeroAddresses();
|
2021-03-16 11:56:27 +00:00
|
|
|
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize, t);
|
2020-05-21 14:18:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-03-16 11:56:27 +00:00
|
|
|
ExitSession::SendPacketToRemote(const llarp_buffer_t& buf, service::ProtocolType t)
|
2020-05-21 14:18:23 +00:00
|
|
|
{
|
|
|
|
net::IPPacket pkt;
|
|
|
|
if (not pkt.Load(buf))
|
|
|
|
return;
|
|
|
|
pkt.ZeroSourceAddress();
|
2021-03-16 11:56:27 +00:00
|
|
|
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize, t);
|
2020-05-21 14:18:23 +00:00
|
|
|
}
|
2018-11-14 19:34:17 +00:00
|
|
|
} // namespace exit
|
2018-12-10 15:31:58 +00:00
|
|
|
} // namespace llarp
|