Browse Source

reuse DH keys pairs from failed NTCP sessions

pull/98/head
orignal 10 years ago
parent
commit
7019b6d68f
  1. 9
      NTCPSession.cpp
  2. 11
      Transports.cpp
  3. 4
      Transports.h

9
NTCPSession.cpp

@ -100,6 +100,9 @@ namespace ntcp @@ -100,6 +100,9 @@ namespace ntcp
delete m_Establisher;
m_Establisher = nullptr;
delete m_DHKeysPair;
m_DHKeysPair = nullptr;
SendTimeSyncMessage ();
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
@ -154,6 +157,8 @@ namespace ntcp @@ -154,6 +157,8 @@ namespace ntcp
if (ecode)
{
LogPrint ("Phase 1 read error: ", ecode.message ());
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
}
else
@ -168,6 +173,8 @@ namespace ntcp @@ -168,6 +173,8 @@ namespace ntcp
if ((m_Establisher->phase1.HXxorHI[i] ^ ident[i]) != digest[i])
{
LogPrint ("Wrong ident");
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
return;
}
@ -224,6 +231,8 @@ namespace ntcp @@ -224,6 +231,8 @@ namespace ntcp
{
LogPrint ("Phase 2 read error: ", ecode.message (), ". Wrong ident assumed");
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
m_DHKeysPair = nullptr;
Terminate ();
}
else

11
Transports.cpp

@ -76,6 +76,12 @@ namespace i2p @@ -76,6 +76,12 @@ namespace i2p
}
}
void DHKeysPairSupplier::Return (i2p::data::DHKeysPair * pair)
{
std::unique_lock<std::mutex> l(m_AcquiredMutex);
m_Queue.push (pair);
}
Transports transports;
Transports::Transports ():
@ -315,4 +321,9 @@ namespace i2p @@ -315,4 +321,9 @@ namespace i2p
{
return m_DHKeysPairSupplier.Acquire ();
}
void Transports::ReuseDHKeysPair (i2p::data::DHKeysPair * pair)
{
m_DHKeysPairSupplier.Return (pair);
}
}

4
Transports.h

@ -26,6 +26,7 @@ namespace i2p @@ -26,6 +26,7 @@ namespace i2p
void Start ();
void Stop ();
i2p::data::DHKeysPair * Acquire ();
void Return (i2p::data::DHKeysPair * pair);
private:
@ -34,7 +35,7 @@ namespace i2p @@ -34,7 +35,7 @@ namespace i2p
private:
int m_QueueSize;
const int m_QueueSize;
std::queue<i2p::data::DHKeysPair *> m_Queue;
bool m_IsRunning;
@ -55,6 +56,7 @@ namespace i2p @@ -55,6 +56,7 @@ namespace i2p
boost::asio::io_service& GetService () { return m_Service; };
i2p::data::DHKeysPair * GetNextDHKeysPair ();
void ReuseDHKeysPair (i2p::data::DHKeysPair * pair);
void AddNTCPSession (i2p::ntcp::NTCPSession * session);
void RemoveNTCPSession (i2p::ntcp::NTCPSession * session);

Loading…
Cancel
Save