mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00: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;
|
delete m_Establisher;
|
||||||
m_Establisher = nullptr;
|
m_Establisher = nullptr;
|
||||||
|
|
||||||
|
delete m_DHKeysPair;
|
||||||
|
m_DHKeysPair = nullptr;
|
||||||
|
|
||||||
SendTimeSyncMessage ();
|
SendTimeSyncMessage ();
|
||||||
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
|
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
|
||||||
|
|
||||||
@ -154,6 +157,8 @@ namespace ntcp
|
|||||||
if (ecode)
|
if (ecode)
|
||||||
{
|
{
|
||||||
LogPrint ("Phase 1 read error: ", ecode.message ());
|
LogPrint ("Phase 1 read error: ", ecode.message ());
|
||||||
|
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
|
||||||
|
m_DHKeysPair = nullptr;
|
||||||
Terminate ();
|
Terminate ();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -168,6 +173,8 @@ namespace ntcp
|
|||||||
if ((m_Establisher->phase1.HXxorHI[i] ^ ident[i]) != digest[i])
|
if ((m_Establisher->phase1.HXxorHI[i] ^ ident[i]) != digest[i])
|
||||||
{
|
{
|
||||||
LogPrint ("Wrong ident");
|
LogPrint ("Wrong ident");
|
||||||
|
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
|
||||||
|
m_DHKeysPair = nullptr;
|
||||||
Terminate ();
|
Terminate ();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -224,6 +231,8 @@ namespace ntcp
|
|||||||
{
|
{
|
||||||
LogPrint ("Phase 2 read error: ", ecode.message (), ". Wrong ident assumed");
|
LogPrint ("Phase 2 read error: ", ecode.message (), ". Wrong ident assumed");
|
||||||
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
|
GetRemoteRouterInfo ().SetUnreachable (true); // this RouterInfo is not valid
|
||||||
|
i2p::transports.ReuseDHKeysPair (m_DHKeysPair);
|
||||||
|
m_DHKeysPair = nullptr;
|
||||||
Terminate ();
|
Terminate ();
|
||||||
}
|
}
|
||||||
else
|
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;
|
||||||
|
|
||||||
Transports::Transports ():
|
Transports::Transports ():
|
||||||
@ -315,4 +321,9 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
return m_DHKeysPairSupplier.Acquire ();
|
return m_DHKeysPairSupplier.Acquire ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Transports::ReuseDHKeysPair (i2p::data::DHKeysPair * pair)
|
||||||
|
{
|
||||||
|
m_DHKeysPairSupplier.Return (pair);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ namespace i2p
|
|||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
i2p::data::DHKeysPair * Acquire ();
|
i2p::data::DHKeysPair * Acquire ();
|
||||||
|
void Return (i2p::data::DHKeysPair * pair);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ namespace i2p
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int m_QueueSize;
|
const int m_QueueSize;
|
||||||
std::queue<i2p::data::DHKeysPair *> m_Queue;
|
std::queue<i2p::data::DHKeysPair *> m_Queue;
|
||||||
|
|
||||||
bool m_IsRunning;
|
bool m_IsRunning;
|
||||||
@ -55,6 +56,7 @@ namespace i2p
|
|||||||
|
|
||||||
boost::asio::io_service& GetService () { return m_Service; };
|
boost::asio::io_service& GetService () { return m_Service; };
|
||||||
i2p::data::DHKeysPair * GetNextDHKeysPair ();
|
i2p::data::DHKeysPair * GetNextDHKeysPair ();
|
||||||
|
void ReuseDHKeysPair (i2p::data::DHKeysPair * pair);
|
||||||
|
|
||||||
void AddNTCPSession (i2p::ntcp::NTCPSession * session);
|
void AddNTCPSession (i2p::ntcp::NTCPSession * session);
|
||||||
void RemoveNTCPSession (i2p::ntcp::NTCPSession * session);
|
void RemoveNTCPSession (i2p::ntcp::NTCPSession * session);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user