Browse Source

moved delayed queue to Peer

pull/150/head
orignal 10 years ago
parent
commit
98e930bd46
  1. 27
      NTCPSession.cpp
  2. 2
      NTCPSession.h
  3. 17
      SSUSession.cpp
  4. 2
      SSUSession.h

27
NTCPSession.cpp

@ -32,9 +32,6 @@ namespace transport
delete m_Establisher; delete m_Establisher;
if (m_NextMessage) if (m_NextMessage)
i2p::DeleteI2NPMessage (m_NextMessage); i2p::DeleteI2NPMessage (m_NextMessage);
for (auto it :m_DelayedMessages)
i2p::DeleteI2NPMessage (it);
m_DelayedMessages.clear ();
} }
void NTCPSession::CreateAESKey (uint8_t * pubKey, i2p::crypto::AESKey& key) void NTCPSession::CreateAESKey (uint8_t * pubKey, i2p::crypto::AESKey& key)
@ -78,18 +75,6 @@ namespace transport
m_IsEstablished = false; m_IsEstablished = false;
m_Socket.close (); m_Socket.close ();
transports.PeerDisconnected (shared_from_this ()); transports.PeerDisconnected (shared_from_this ());
int numDelayed = 0;
for (auto it :m_DelayedMessages)
{
// try to send them again
if (m_RemoteRouter)
transports.SendMessage (m_RemoteRouter->GetIdentHash (), it);
numDelayed++;
}
m_DelayedMessages.clear ();
if (numDelayed > 0)
LogPrint (eLogWarning, "NTCP session ", numDelayed, " not sent");
// TODO: notify tunnels
m_Server.RemoveNTCPSession (shared_from_this ()); m_Server.RemoveNTCPSession (shared_from_this ());
LogPrint ("NTCP session terminated"); LogPrint ("NTCP session terminated");
} }
@ -108,13 +93,6 @@ namespace transport
SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are SendI2NPMessage (CreateDatabaseStoreMsg ()); // we tell immediately who we are
transports.PeerConnected (shared_from_this ()); transports.PeerConnected (shared_from_this ());
if (!m_DelayedMessages.empty ())
{
for (auto it :m_DelayedMessages)
SendI2NPMessage (it);
m_DelayedMessages.clear ();
}
} }
void NTCPSession::ClientLogin () void NTCPSession::ClientLogin ()
@ -637,12 +615,7 @@ namespace transport
void NTCPSession::PostI2NPMessage (I2NPMessage * msg) void NTCPSession::PostI2NPMessage (I2NPMessage * msg)
{ {
if (msg) if (msg)
{
if (m_IsEstablished)
Send (msg); Send (msg);
else
m_DelayedMessages.push_back (msg);
}
} }
void NTCPSession::ScheduleTermination () void NTCPSession::ScheduleTermination ()

2
NTCPSession.h

@ -2,7 +2,6 @@
#define NTCP_SESSION_H__ #define NTCP_SESSION_H__
#include <inttypes.h> #include <inttypes.h>
#include <list>
#include <map> #include <map>
#include <memory> #include <memory>
#include <thread> #include <thread>
@ -129,7 +128,6 @@ namespace transport
int m_ReceiveBufferOffset; int m_ReceiveBufferOffset;
i2p::I2NPMessage * m_NextMessage; i2p::I2NPMessage * m_NextMessage;
std::list<i2p::I2NPMessage *> m_DelayedMessages;
size_t m_NextMessageOffset; size_t m_NextMessageOffset;
size_t m_NumSentBytes, m_NumReceivedBytes; size_t m_NumSentBytes, m_NumReceivedBytes;

17
SSUSession.cpp

@ -757,12 +757,6 @@ namespace transport
{ {
SendSesionDestroyed (); SendSesionDestroyed ();
transports.PeerDisconnected (shared_from_this ()); transports.PeerDisconnected (shared_from_this ());
if (!m_DelayedMessages.empty ())
{
for (auto it :m_DelayedMessages)
DeleteI2NPMessage (it);
m_DelayedMessages.clear ();
}
} }
void SSUSession::Established () void SSUSession::Established ()
@ -775,12 +769,6 @@ namespace transport
} }
SendI2NPMessage (CreateDatabaseStoreMsg ()); SendI2NPMessage (CreateDatabaseStoreMsg ());
transports.PeerConnected (shared_from_this ()); transports.PeerConnected (shared_from_this ());
if (!m_DelayedMessages.empty ())
{
for (auto it :m_DelayedMessages)
m_Data.Send (it);
m_DelayedMessages.clear ();
}
if (m_PeerTest && (m_RemoteRouter && m_RemoteRouter->IsPeerTesting ())) if (m_PeerTest && (m_RemoteRouter && m_RemoteRouter->IsPeerTesting ()))
SendPeerTest (); SendPeerTest ();
ScheduleTermination (); ScheduleTermination ();
@ -837,12 +825,7 @@ namespace transport
void SSUSession::PostI2NPMessage (I2NPMessage * msg) void SSUSession::PostI2NPMessage (I2NPMessage * msg)
{ {
if (msg) if (msg)
{
if (m_State == eSessionStateEstablished)
m_Data.Send (msg); m_Data.Send (msg);
else
m_DelayedMessages.push_back (msg);
}
} }
void SSUSession::ProcessData (uint8_t * buf, size_t len) void SSUSession::ProcessData (uint8_t * buf, size_t len)

2
SSUSession.h

@ -3,7 +3,6 @@
#include <inttypes.h> #include <inttypes.h>
#include <set> #include <set>
#include <list>
#include <memory> #include <memory>
#include "aes.h" #include "aes.h"
#include "hmac.h" #include "hmac.h"
@ -132,7 +131,6 @@ namespace transport
i2p::crypto::CBCDecryption m_SessionKeyDecryption; i2p::crypto::CBCDecryption m_SessionKeyDecryption;
i2p::crypto::AESKey m_SessionKey; i2p::crypto::AESKey m_SessionKey;
i2p::crypto::MACKey m_MacKey; i2p::crypto::MACKey m_MacKey;
std::list<i2p::I2NPMessage *> m_DelayedMessages;
SSUData m_Data; SSUData m_Data;
size_t m_NumSentBytes, m_NumReceivedBytes; size_t m_NumSentBytes, m_NumReceivedBytes;
uint32_t m_CreationTime; // seconds since epoch uint32_t m_CreationTime; // seconds since epoch

Loading…
Cancel
Save