mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-28 01:44:14 +00:00
fixed race condition
This commit is contained in:
parent
8305fd5f82
commit
5730b15f01
@ -20,8 +20,9 @@ namespace transport
|
|||||||
{
|
{
|
||||||
NTCPSession::NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter):
|
NTCPSession::NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter):
|
||||||
TransportSession (in_RemoteRouter), m_Server (server), m_Socket (m_Server.GetService ()),
|
TransportSession (in_RemoteRouter), m_Server (server), m_Socket (m_Server.GetService ()),
|
||||||
m_TerminationTimer (m_Server.GetService ()), m_IsEstablished (false), m_ReceiveBufferOffset (0),
|
m_TerminationTimer (m_Server.GetService ()), m_IsEstablished (false), m_IsTerminated (false),
|
||||||
m_NextMessage (nullptr), m_IsSending (false), m_NumSentBytes (0), m_NumReceivedBytes (0)
|
m_ReceiveBufferOffset (0), m_NextMessage (nullptr), m_IsSending (false),
|
||||||
|
m_NumSentBytes (0), m_NumReceivedBytes (0)
|
||||||
{
|
{
|
||||||
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
m_DHKeysPair = transports.GetNextDHKeysPair ();
|
||||||
m_Establisher = new Establisher;
|
m_Establisher = new Establisher;
|
||||||
@ -30,10 +31,6 @@ namespace transport
|
|||||||
NTCPSession::~NTCPSession ()
|
NTCPSession::~NTCPSession ()
|
||||||
{
|
{
|
||||||
delete m_Establisher;
|
delete m_Establisher;
|
||||||
if (m_NextMessage)
|
|
||||||
i2p::DeleteI2NPMessage (m_NextMessage);
|
|
||||||
for (auto it: m_SendQueue)
|
|
||||||
DeleteI2NPMessage (it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCPSession::CreateAESKey (uint8_t * pubKey, i2p::crypto::AESKey& key)
|
void NTCPSession::CreateAESKey (uint8_t * pubKey, i2p::crypto::AESKey& key)
|
||||||
@ -72,13 +69,30 @@ namespace transport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NTCPSession::Done ()
|
||||||
|
{
|
||||||
|
m_Server.GetService ().post (std::bind (&NTCPSession::Terminate, shared_from_this ()));
|
||||||
|
}
|
||||||
|
|
||||||
void NTCPSession::Terminate ()
|
void NTCPSession::Terminate ()
|
||||||
{
|
{
|
||||||
m_IsEstablished = false;
|
if (!m_IsTerminated)
|
||||||
m_Socket.close ();
|
{
|
||||||
transports.PeerDisconnected (shared_from_this ());
|
m_IsTerminated = true;
|
||||||
m_Server.RemoveNTCPSession (shared_from_this ());
|
m_IsEstablished = false;
|
||||||
LogPrint (eLogInfo, "NTCP session terminated");
|
m_Socket.close ();
|
||||||
|
transports.PeerDisconnected (shared_from_this ());
|
||||||
|
m_Server.RemoveNTCPSession (shared_from_this ());
|
||||||
|
for (auto it: m_SendQueue)
|
||||||
|
DeleteI2NPMessage (it);
|
||||||
|
m_SendQueue.clear ();
|
||||||
|
if (m_NextMessage)
|
||||||
|
{
|
||||||
|
i2p::DeleteI2NPMessage (m_NextMessage);
|
||||||
|
m_NextMessage = nullptr;
|
||||||
|
}
|
||||||
|
LogPrint (eLogInfo, "NTCP session terminated");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTCPSession::Connected ()
|
void NTCPSession::Connected ()
|
||||||
|
@ -54,6 +54,7 @@ namespace transport
|
|||||||
NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr);
|
NTCPSession (NTCPServer& server, std::shared_ptr<const i2p::data::RouterInfo> in_RemoteRouter = nullptr);
|
||||||
~NTCPSession ();
|
~NTCPSession ();
|
||||||
void Terminate ();
|
void Terminate ();
|
||||||
|
void Done ();
|
||||||
|
|
||||||
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
boost::asio::ip::tcp::socket& GetSocket () { return m_Socket; };
|
||||||
bool IsEstablished () const { return m_IsEstablished; };
|
bool IsEstablished () const { return m_IsEstablished; };
|
||||||
@ -113,7 +114,7 @@ namespace transport
|
|||||||
NTCPServer& m_Server;
|
NTCPServer& m_Server;
|
||||||
boost::asio::ip::tcp::socket m_Socket;
|
boost::asio::ip::tcp::socket m_Socket;
|
||||||
boost::asio::deadline_timer m_TerminationTimer;
|
boost::asio::deadline_timer m_TerminationTimer;
|
||||||
bool m_IsEstablished;
|
bool m_IsEstablished, m_IsTerminated;
|
||||||
|
|
||||||
i2p::crypto::CBCDecryption m_Decryption;
|
i2p::crypto::CBCDecryption m_Decryption;
|
||||||
i2p::crypto::CBCEncryption m_Encryption;
|
i2p::crypto::CBCEncryption m_Encryption;
|
||||||
|
@ -759,9 +759,10 @@ namespace transport
|
|||||||
transports.PeerDisconnected (shared_from_this ());
|
transports.PeerDisconnected (shared_from_this ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUSession::Terminate ()
|
void SSUSession::Done ()
|
||||||
{
|
{
|
||||||
m_Server.DeleteSession (shared_from_this ());
|
boost::asio::io_service& service = IsV6 () ? m_Server.GetServiceV6 () : m_Server.GetService ();
|
||||||
|
service.post (std::bind (&SSUSession::Failed, shared_from_this ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUSession::Established ()
|
void SSUSession::Established ()
|
||||||
|
@ -63,7 +63,7 @@ namespace transport
|
|||||||
void Introduce (uint32_t iTag, const uint8_t * iKey);
|
void Introduce (uint32_t iTag, const uint8_t * iKey);
|
||||||
void WaitForIntroduction ();
|
void WaitForIntroduction ();
|
||||||
void Close ();
|
void Close ();
|
||||||
void Terminate ();
|
void Done ();
|
||||||
boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; };
|
boost::asio::ip::udp::endpoint& GetRemoteEndpoint () { return m_RemoteEndpoint; };
|
||||||
bool IsV6 () const { return m_RemoteEndpoint.address ().is_v6 (); };
|
bool IsV6 () const { return m_RemoteEndpoint.address ().is_v6 (); };
|
||||||
void SendI2NPMessage (I2NPMessage * msg);
|
void SendI2NPMessage (I2NPMessage * msg);
|
||||||
|
@ -62,7 +62,7 @@ namespace transport
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual ~TransportSession () { delete m_DHKeysPair; };
|
virtual ~TransportSession () { delete m_DHKeysPair; };
|
||||||
virtual void Terminate () = 0;
|
virtual void Done () = 0;
|
||||||
|
|
||||||
std::shared_ptr<const i2p::data::RouterInfo> GetRemoteRouter () { return m_RemoteRouter; };
|
std::shared_ptr<const i2p::data::RouterInfo> GetRemoteRouter () { return m_RemoteRouter; };
|
||||||
const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; };
|
const i2p::data::IdentityEx& GetRemoteIdentity () { return m_RemoteIdentity; };
|
||||||
|
@ -414,7 +414,7 @@ namespace transport
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Session for ", ident.ToBase64 ().substr (0, 4), " already exists");
|
LogPrint (eLogError, "Session for ", ident.ToBase64 ().substr (0, 4), " already exists");
|
||||||
session->Terminate ();
|
session->Done ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // incoming connection
|
else // incoming connection
|
||||||
|
@ -61,7 +61,7 @@ namespace transport
|
|||||||
~Peer ()
|
~Peer ()
|
||||||
{
|
{
|
||||||
for (auto it :delayedMessages)
|
for (auto it :delayedMessages)
|
||||||
i2p::DeleteI2NPMessage (it);
|
i2p::DeleteI2NPMessage (it);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user