Browse Source

don't create identity if presented in netdb already

pull/792/head
orignal 8 years ago
parent
commit
8a2c4ab3de
  1. 7
      NTCPSession.cpp
  2. 5
      SSUSession.cpp

7
NTCPSession.cpp

@ -346,12 +346,15 @@ namespace transport @@ -346,12 +346,15 @@ namespace transport
m_Decryption.Decrypt (m_ReceiveBuffer, bytes_transferred, m_ReceiveBuffer);
uint8_t * buf = m_ReceiveBuffer;
uint16_t size = bufbe16toh (buf);
SetRemoteIdentity (std::make_shared<i2p::data::IdentityEx> (buf + 2, size));
if (m_Server.FindNTCPSession (m_RemoteIdentity->GetIdentHash ()))
auto identity = std::make_shared<i2p::data::IdentityEx> (buf + 2, size);
if (m_Server.FindNTCPSession (identity->GetIdentHash ()))
{
LogPrint (eLogInfo, "NTCP: session already exists");
Terminate ();
}
auto existing = i2p::data::netdb.FindRouter (identity->GetIdentHash ()); // check if exists already
SetRemoteIdentity (existing ? existing->GetRouterIdentity () : identity);
size_t expectedSize = size + 2/*size*/ + 4/*timestamp*/ + m_RemoteIdentity->GetSignatureLen ();
size_t paddingLen = expectedSize & 0x0F;
if (paddingLen) paddingLen = (16 - paddingLen);

5
SSUSession.cpp

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
#include "Timestamp.h"
#include "RouterContext.h"
#include "Transports.h"
#include "NetDb.h"
#include "SSU.h"
#include "SSUSession.h"
@ -317,7 +318,9 @@ namespace transport @@ -317,7 +318,9 @@ namespace transport
payload++; // identity fragment info
uint16_t identitySize = bufbe16toh (payload);
payload += 2; // size of identity fragment
SetRemoteIdentity (std::make_shared<i2p::data::IdentityEx> (payload, identitySize));
auto identity = std::make_shared<i2p::data::IdentityEx> (payload, identitySize);
auto existing = i2p::data::netdb.FindRouter (identity->GetIdentHash ()); // check if exists already
SetRemoteIdentity (existing ? existing->GetRouterIdentity () : identity);
m_Data.UpdatePacketSize (m_RemoteIdentity->GetIdentHash ());
payload += identitySize; // identity
auto ts = i2p::util::GetSecondsSinceEpoch ();

Loading…
Cancel
Save