Browse Source

window size

pull/1752/head
orignal 3 years ago
parent
commit
6990f177ba
  1. 12
      libi2pd/SSU2.cpp
  2. 2
      libi2pd/SSU2.h

12
libi2pd/SSU2.cpp

@ -32,7 +32,7 @@ namespace transport
TransportSession (in_RemoteRouter, SSU2_CONNECT_TIMEOUT), TransportSession (in_RemoteRouter, SSU2_CONNECT_TIMEOUT),
m_Server (server), m_Address (addr), m_DestConnID (0), m_SourceConnID (0), m_Server (server), m_Address (addr), m_DestConnID (0), m_SourceConnID (0),
m_State (eSSU2SessionStateUnknown), m_SendPacketNum (0), m_ReceivePacketNum (0), m_State (eSSU2SessionStateUnknown), m_SendPacketNum (0), m_ReceivePacketNum (0),
m_IsDataReceived (false) m_IsDataReceived (false), m_WindowSize (SSU2_MAX_WINDOW_SIZE)
{ {
m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState); m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState);
if (in_RemoteRouter && m_Address) if (in_RemoteRouter && m_Address)
@ -110,12 +110,12 @@ namespace transport
void SSU2Session::SendQueue () void SSU2Session::SendQueue ()
{ {
if (!m_SendQueue.empty ()) if (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
{ {
auto nextResend = i2p::util::GetSecondsSinceEpoch () + SSU2_RESEND_INTERVAL; auto nextResend = i2p::util::GetSecondsSinceEpoch () + SSU2_RESEND_INTERVAL;
auto packet = std::make_shared<SentPacket>(); auto packet = std::make_shared<SentPacket>();
packet->payloadSize += CreateAckBlock (packet->payload + packet->payloadSize, SSU2_MAX_PAYLOAD_SIZE - packet->payloadSize); packet->payloadSize += CreateAckBlock (packet->payload + packet->payloadSize, SSU2_MAX_PAYLOAD_SIZE - packet->payloadSize);
while (!m_SendQueue.empty ()) while (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
{ {
auto msg = m_SendQueue.front (); auto msg = m_SendQueue.front ();
size_t len = msg->GetNTCP2Length (); size_t len = msg->GetNTCP2Length ();
@ -180,7 +180,7 @@ namespace transport
void SSU2Session::Resend (uint64_t ts) void SSU2Session::Resend (uint64_t ts)
{ {
if (m_SendQueue.empty ()) return; if (m_SentPackets.empty ()) return;
std::map<uint32_t, std::shared_ptr<SentPacket> > resentPackets; std::map<uint32_t, std::shared_ptr<SentPacket> > resentPackets;
for (auto it = m_SentPackets.begin (); it != m_SentPackets.end (); ) for (auto it = m_SentPackets.begin (); it != m_SentPackets.end (); )
if (ts > it->second->nextResendTime) if (ts > it->second->nextResendTime)
@ -207,6 +207,7 @@ namespace transport
m_SentPackets.insert (resentPackets.begin (), resentPackets.end ()); m_SentPackets.insert (resentPackets.begin (), resentPackets.end ());
#endif #endif
} }
SendQueue ();
} }
void SSU2Session::ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len) void SSU2Session::ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len)
@ -746,7 +747,10 @@ namespace transport
m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch (); m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch ();
m_NumReceivedBytes += len; m_NumReceivedBytes += len;
if (UpdateReceivePacketNum (packetNum)) if (UpdateReceivePacketNum (packetNum))
{
HandlePayload (payload, payloadSize); HandlePayload (payload, payloadSize);
SendQueue (); // if we have something to send
}
} }
void SSU2Session::HandlePayload (const uint8_t * buf, size_t len) void SSU2Session::HandlePayload (const uint8_t * buf, size_t len)

2
libi2pd/SSU2.h

@ -33,6 +33,7 @@ namespace transport
const int SSU2_RESEND_INTERVAL = 3; // in seconds const int SSU2_RESEND_INTERVAL = 3; // in seconds
const int SSU2_MAX_NUM_RESENDS = 5; const int SSU2_MAX_NUM_RESENDS = 5;
const int SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT = 30; // in seconds const int SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT = 30; // in seconds
const size_t SSU2_MAX_WINDOW_SIZE = 128; // in packets
enum SSU2MessageType enum SSU2MessageType
{ {
@ -210,6 +211,7 @@ namespace transport
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue; std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
i2p::I2NPMessagesHandler m_Handler; i2p::I2NPMessagesHandler m_Handler;
bool m_IsDataReceived; bool m_IsDataReceived;
size_t m_WindowSize;
}; };
class SSU2Server: private i2p::util::RunnableServiceWithWork class SSU2Server: private i2p::util::RunnableServiceWithWork

Loading…
Cancel
Save