Skip to content

Commit

Permalink
Merge pull request #1168 from majestrate/inter-node-commit-fixes-2020…
Browse files Browse the repository at this point in the history
…-03-07

Dont rely on operator[] side effects
  • Loading branch information
majestrate committed Mar 11, 2020
2 parents ac80357 + 7ba30ee commit ec2f691
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
10 changes: 4 additions & 6 deletions llarp/link/link_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,10 @@ namespace llarp
return;

util::Lock l(_mutex);

m_PersistingSessions[remote] =
std::max(until, m_PersistingSessions[remote]);
LogDebug("persist session to ", remote, " until ",
m_PersistingSessions[remote].count());
auto &curr = m_PersistingSessions[remote];
if(until > curr)
curr = until;
LogDebug("persist session to ", remote, " until ", curr - time_now_ms());
}

void
Expand Down Expand Up @@ -307,7 +306,6 @@ namespace llarp
auto link = GetLinkWithSessionTo(itr->first);
if(link)
{
LogDebug("keepalive to ", itr->first);
link->KeepAliveSessionTo(itr->first);
}
else
Expand Down
12 changes: 12 additions & 0 deletions llarp/link/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,11 @@ namespace llarp
{
Lock_t l(m_AuthedLinksMutex);
if(m_AuthedLinks.count(rc.pubkey) >= MaxSessionsPerKey)
{
LogDebug("Too many links to ", RouterID{rc.pubkey},
", not establishing another one");
return false;
}
}
llarp::AddressInfo to;
if(!PickAddress(rc, to))
Expand All @@ -276,7 +280,12 @@ namespace llarp
{
Lock_t l(m_PendingMutex);
if(m_Pending.count(addr) >= MaxSessionsPerKey)
{
LogDebug("Too many pending connections to ", addr,
" while establishing to ", RouterID{rc.pubkey},
", not establishing another");
return false;
}
}
std::shared_ptr< ILinkSession > s = NewOutboundSession(rc, to);
if(PutSession(s))
Expand Down Expand Up @@ -385,7 +394,10 @@ namespace llarp
while(itr != range.second)
{
if(itr->second->ShouldPing())
{
LogDebug("keepalive to ", remote);
itr->second->SendKeepAlive();
}
++itr;
}
}
Expand Down
3 changes: 0 additions & 3 deletions llarp/link/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ namespace llarp
bool
HasSessionTo(const RouterID& pk);

bool
HasSessionVia(const Addr& addr);

void
ForEachSession(std::function< void(const ILinkSession*) > visit,
bool randomize = false) const EXCLUDES(m_AuthedLinksMutex);
Expand Down
10 changes: 6 additions & 4 deletions llarp/net/net_addr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,13 @@ namespace llarp
bool
Addr::operator==(const Addr& other) const
{
if(af() == AF_INET && other.af() == AF_INET)
return port() == other.port() && addr4()->s_addr == other.addr4()->s_addr;
if(af() != other.af() || port() != other.port())
return false;

return af() == other.af() && memcmp(addr6(), other.addr6(), 16) == 0
&& port() == other.port();
if(af() == AF_INET)
return addr4()->s_addr == other.addr4()->s_addr;

return memcmp(addr6(), other.addr6(), 16) == 0;
}

Addr&
Expand Down

0 comments on commit ec2f691

Please sign in to comment.