mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
reuse DH keys pairs from failed NTCP sessions
This commit is contained in:
parent
06f9e68169
commit
7019b6d68f
|
@ -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
|
|||
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
|
|||
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
|
|||
{
|
||||
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
|
||||
|
|
|
@ -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
|
|||
{
|
||||
return m_DHKeysPairSupplier.Acquire ();
|
||||
}
|
||||
|
||||
void Transports::ReuseDHKeysPair (i2p::data::DHKeysPair * pair)
|
||||
{
|
||||
m_DHKeysPairSupplier.Return (pair);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|||
|
||||
private:
|
||||
|
||||
int m_QueueSize;
|
||||
const int m_QueueSize;
|
||||
std::queue<i2p::data::DHKeysPair *> m_Queue;
|
||||
|
||||
bool m_IsRunning;
|
||||
|
@ -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…
Reference in a new issue