Browse Source

drop second incoming connection with same identity

pull/157/head
orignal 10 years ago
parent
commit
0518b08ca6
  1. 5
      SSUSession.cpp
  2. 1
      SSUSession.h
  3. 1
      TransportSession.h
  4. 16
      Transports.cpp

5
SSUSession.cpp

@ -759,6 +759,11 @@ namespace transport @@ -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;

1
SSUSession.h

@ -63,6 +63,7 @@ namespace transport @@ -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);

1
TransportSession.h

@ -62,6 +62,7 @@ namespace transport @@ -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; };

16
Transports.cpp

@ -405,9 +405,17 @@ namespace transport @@ -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 @@ -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);

Loading…
Cancel
Save