Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont rely on operator[] side effects #1168

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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