1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-22 04:04:16 +00:00

drop second incoming connection with same identity

This commit is contained in:
orignal 2015-02-06 16:03:47 -05:00
parent 8e75d8c39a
commit 0518b08ca6
4 changed files with 19 additions and 4 deletions

View File

@ -759,6 +759,11 @@ namespace transport
transports.PeerDisconnected (shared_from_this ());
}
void SSUSession::Terminate ()
{
m_Server.DeleteSession (shared_from_this ());
}
void SSUSession::Established ()
{
m_State = eSessionStateEstablished;

View File

@ -63,6 +63,7 @@ namespace transport
void Introduce (uint32_t iTag, const uint8_t * iKey);
void WaitForIntroduction ();
void Close ();
void Terminate ();
boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; };
bool IsV6 () const { return m_RemoteEndpoint.address ().is_v6 (); };
void SendI2NPMessage (I2NPMessage * msg);

View File

@ -62,6 +62,7 @@ namespace transport
}
virtual ~TransportSession () { delete m_DHKeysPair; };
virtual void Terminate () = 0;
std::shared_ptr<const i2p::data::RouterInfo> GetRemoteRouter () { return m_RemoteRouter; };
const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; };

View File

@ -405,9 +405,17 @@ namespace transport
auto it = m_Peers.find (ident);
if (it != m_Peers.end ())
{
it->second.session = session;
session->SendI2NPMessages (it->second.delayedMessages);
it->second.delayedMessages.clear ();
if (!it->second.session)
{
it->second.session = session;
session->SendI2NPMessages (it->second.delayedMessages);
it->second.delayedMessages.clear ();
}
else
{
LogPrint (eLogError, "Session for ", ident.ToBase64 ().substr (0, 4), " already exists");
session->Terminate ();
}
}
else // incoming connection
m_Peers[ident] = { 0, nullptr, session };
@ -420,7 +428,7 @@ namespace transport
{
auto ident = session->GetRemoteIdentity ().GetIdentHash ();
auto it = m_Peers.find (ident);
if (it != m_Peers.end ())
if (it != m_Peers.end () && it->second.session == session)
{
if (it->second.delayedMessages.size () > 0)
ConnectToPeer (ident, it->second);