diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 1ffe6b7a..491e239e 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -316,6 +316,11 @@ namespace transport uint8_t * buf = m_ReceiveBuffer; uint16_t size = bufbe16toh (buf); m_RemoteIdentity.FromBuffer (buf + 2, size); + if (m_Server.FindNTCPSession (m_RemoteIdentity.GetIdentHash ())) + { + LogPrint (eLogError, "NTCP session already exists"); + Terminate (); + } size_t expectedSize = size + 2/*size*/ + 4/*timestamp*/ + m_RemoteIdentity.GetSignatureLen (); size_t paddingLen = expectedSize & 0x0F; if (paddingLen) paddingLen = (16 - paddingLen); diff --git a/Transports.cpp b/Transports.cpp index b163922c..0285fe1b 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -428,7 +428,7 @@ namespace transport { auto ident = session->GetRemoteIdentity ().GetIdentHash (); auto it = m_Peers.find (ident); - if (it != m_Peers.end () && it->second.session == session) + if (it != m_Peers.end () && (!it->second.session || it->second.session == session)) { if (it->second.delayedMessages.size () > 0) ConnectToPeer (ident, it->second);