state machine fix for link layer

if a pending inbound session did not complete a handshake after an unclean close from a previous session the
remote udp endpoint would remain stuck mapped as authed and thus any further attempts from the remote would
be silently dropped as it entered a stuck state in the state machine. this was happening as a small part
of the state machine was hidden in the implementation details of iwp, but instead should be in the super type
as it is logic exclusively outside the details which every dialect would have regardless of its details.

this commit will unmap the udp endpoint every time it needs to in the link layer state machine, independat of
the implementation details of the diact.
pull/1919/head
Jeff 2 years ago
parent a149e6e384
commit a61e9636b2
No known key found for this signature in database
GPG Key ID: 025C02EE3A092F2D

@ -83,21 +83,6 @@ namespace llarp::iwp
}
}
bool
LinkLayer::MapAddr(const RouterID& r, ILinkSession* s)
{
if (not ILinkLayer::MapAddr(r, s))
return false;
m_AuthedAddrs.emplace(s->GetRemoteEndpoint(), r);
return true;
}
void
LinkLayer::UnmapAddr(const SockAddr& addr)
{
m_AuthedAddrs.erase(addr);
}
std::shared_ptr<ILinkSession>
LinkLayer::NewOutboundSession(const RouterContact& rc, const AddressInfo& ai)
{

@ -44,12 +44,6 @@ namespace llarp::iwp
void
RecvFrom(const SockAddr& from, ILinkSession::Packet_t pkt) override;
bool
MapAddr(const RouterID& pk, ILinkSession* s) override;
void
UnmapAddr(const SockAddr& addr);
void
WakeupPlaintext();
@ -61,7 +55,6 @@ namespace llarp::iwp
HandleWakeupPlaintext();
const std::shared_ptr<EventLoopWakeup> m_Wakeup;
std::unordered_map<SockAddr, RouterID> m_AuthedAddrs;
std::vector<ILinkSession*> m_WakingUp;
const bool m_Inbound;
};

@ -175,8 +175,7 @@ namespace llarp
if (m_State == State::Closed)
return;
auto close_msg = CreatePacket(Command::eCLOS, 0, 16, 16);
if (m_State == State::Ready)
m_Parent->UnmapAddr(m_RemoteAddr);
m_Parent->UnmapAddr(m_RemoteAddr);
m_State = State::Closed;
if (m_SentClosed.test_and_set())
return;

@ -192,6 +192,7 @@ namespace llarp
llarp::LogInfo("session to ", RouterID(itr->second->GetPubKey()), " timed out");
itr->second->Close();
closedSessions.emplace(itr->first);
UnmapAddr(itr->second->GetRemoteEndpoint());
itr = m_AuthedLinks.erase(itr);
}
}
@ -210,6 +211,7 @@ namespace llarp
else
{
LogInfo("pending session at ", itr->first, " timed out");
UnmapAddr(itr->second->GetRemoteEndpoint());
// defer call so we can acquire mutexes later
closedPending.emplace_back(std::move(itr->second));
itr = m_Pending.erase(itr);
@ -234,6 +236,12 @@ namespace llarp
}
}
void
ILinkLayer::UnmapAddr(const SockAddr& addr)
{
m_AuthedAddrs.erase(addr);
}
bool
ILinkLayer::MapAddr(const RouterID& pk, ILinkSession* s)
{
@ -249,6 +257,7 @@ namespace llarp
s->Close();
return false;
}
m_AuthedAddrs.emplace(addr, pk);
m_AuthedLinks.emplace(pk, itr->second);
itr = m_Pending.erase(itr);
m_Router->TriggerPump();
@ -435,7 +444,8 @@ namespace llarp
void
ILinkLayer::SendTo_LL(const SockAddr& to, const llarp_buffer_t& pkt)
{
m_udp->send(to, pkt);
if (not m_udp->send(to, pkt))
LogError("could not send udp packet to ", to);
}
bool

@ -101,6 +101,9 @@ namespace llarp
void
ForEachSession(std::function<void(ILinkSession*)> visit) EXCLUDES(m_AuthedLinksMutex);
void
UnmapAddr(const SockAddr& addr);
void
SendTo_LL(const SockAddr& to, const llarp_buffer_t& pkt);
@ -183,7 +186,7 @@ namespace llarp
return false;
}
virtual bool
bool
MapAddr(const RouterID& pk, ILinkSession* s);
void
@ -255,7 +258,7 @@ namespace llarp
AuthedLinks m_AuthedLinks GUARDED_BY(m_AuthedLinksMutex);
mutable DECLARE_LOCK(Mutex_t, m_PendingMutex, ACQUIRED_AFTER(m_AuthedLinksMutex));
Pending m_Pending GUARDED_BY(m_PendingMutex);
std::unordered_map<SockAddr, RouterID> m_AuthedAddrs;
std::unordered_map<SockAddr, llarp_time_t> m_RecentlyClosed;
private:

Loading…
Cancel
Save