various cleanups

pull/1576/head
Jeff Becker 3 years ago
parent b36f87a4d2
commit 2e8f47a7fa
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -274,24 +274,18 @@ namespace llarp
BaseSession::FlushUpstream()
{
auto now = m_router->Now();
auto path = PickRandomEstablishedPath(llarp::path::ePathRoleExit);
auto path = PickEstablishedPath(llarp::path::ePathRoleExit);
if (path)
{
for (auto& item : m_Upstream)
{
auto& queue = item.second; // XXX: uninitialised memory here!
auto& queue = item.second;
while (queue.size())
{
auto& msg = queue.front();
if (path)
{
msg.S = path->NextSeqNo();
path->SendRoutingMessage(msg, m_router);
}
msg.S = path->NextSeqNo();
path->SendRoutingMessage(msg, m_router);
queue.pop_front();
// spread across all paths
path = PickRandomEstablishedPath(llarp::path::ePathRoleExit);
}
}
}

@ -365,7 +365,7 @@ namespace llarp
pk = itr->second;
}
// check if this key is a service node
if (m_SNodeKeys.find(pk) != m_SNodeKeys.end())
if (m_SNodeKeys.count(pk))
{
// check if it's a service node session we made and queue it via our
// snode session that we made otherwise use an inbound session that
@ -417,11 +417,7 @@ namespace llarp
auto itr = m_SNodeSessions.begin();
while (itr != m_SNodeSessions.end())
{
// TODO: move flush upstream to router event loop
if (!itr->second->FlushUpstream())
{
LogWarn("failed to flush snode traffic to ", itr->first, " via outbound session");
}
itr->second->FlushUpstream();
itr->second->FlushDownstream();
++itr;
}
@ -504,11 +500,11 @@ namespace llarp
huint128_t
ExitEndpoint::GetIPForIdent(const PubKey pk)
{
huint128_t found = {0};
huint128_t found{};
if (!HasLocalMappedAddrFor(pk))
{
// allocate and map
found.h = AllocateNewAddress().h;
found = AllocateNewAddress();
if (!m_KeyToIP.emplace(pk, found).second)
{
LogError(Name(), "failed to map ", pk, " to ", found);
@ -525,7 +521,7 @@ namespace llarp
LogError(Name(), "failed to map ", pk, " to ", found);
}
else
found.h = m_KeyToIP[pk].h;
found = m_KeyToIP[pk];
MarkIPActive(found);
m_KeyToIP.rehash(0);
@ -748,8 +744,8 @@ namespace llarp
huint128_t
ExitEndpoint::ObtainServiceNodeIP(const RouterID& other)
{
const PubKey pubKey(other);
const PubKey us(m_Router->pubkey());
const PubKey pubKey{other};
const PubKey us{m_Router->pubkey()};
// just in case
if (pubKey == us)
return m_IfAddr;
@ -766,7 +762,7 @@ namespace llarp
true,
this);
// this is a new service node make an outbound session to them
m_SNodeSessions.emplace(other, session);
m_SNodeSessions[other] = session;
}
return ip;
}

@ -516,8 +516,6 @@ namespace llarp
{
std::stringstream ss;
ss << "TX=" << TXID() << " RX=" << RXID();
if (m_PathSet)
ss << " on " << m_PathSet->Name();
return ss.str();
}
@ -691,7 +689,6 @@ namespace llarp
if (m_BuiltHook)
m_BuiltHook(shared_from_this());
m_BuiltHook = nullptr;
LogDebug("path latency is now ", intro.latency, " for ", Name());
return true;
}

@ -413,6 +413,31 @@ namespace llarp
return nullptr;
}
Path_ptr
PathSet::PickEstablishedPath(PathRole roles) const
{
std::vector<Path_ptr> established;
Lock_t l(m_PathsMutex);
auto itr = m_Paths.begin();
while (itr != m_Paths.end())
{
if (itr->second->IsReady() && itr->second->SupportsAnyRoles(roles))
established.push_back(itr->second);
++itr;
}
Path_ptr chosen = nullptr;
llarp_time_t minLatency = 30s;
for (const auto& path : established)
{
if (path->intro.latency < minLatency)
{
minLatency = path->intro.latency;
chosen = path;
}
}
return chosen;
}
void
PathSet::UpstreamFlush(AbstractRouter* r)
{

@ -237,6 +237,9 @@ namespace llarp
Path_ptr
GetEstablishedPathClosestTo(RouterID router, PathRole roles = ePathRoleAny) const;
Path_ptr
PickEstablishedPath(PathRole roles = ePathRoleAny) const;
Path_ptr
PickRandomEstablishedPath(PathRole roles = ePathRoleAny) const;

Loading…
Cancel
Save