Merge pull request #1920 from majestrate/fixup-link-layer-state-machine-2022-05-20

state machine fix for link layer
pull/1909/head
majestrate 2 years ago committed by GitHub
commit 8529ab2c62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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