mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
window size
This commit is contained in:
parent
98e713166b
commit
6990f177ba
@ -32,7 +32,7 @@ namespace transport
|
||||
TransportSession (in_RemoteRouter, SSU2_CONNECT_TIMEOUT),
|
||||
m_Server (server), m_Address (addr), m_DestConnID (0), m_SourceConnID (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);
|
||||
if (in_RemoteRouter && m_Address)
|
||||
@ -110,12 +110,12 @@ namespace transport
|
||||
|
||||
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 packet = std::make_shared<SentPacket>();
|
||||
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 ();
|
||||
size_t len = msg->GetNTCP2Length ();
|
||||
@ -180,7 +180,7 @@ namespace transport
|
||||
|
||||
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;
|
||||
for (auto it = m_SentPackets.begin (); it != m_SentPackets.end (); )
|
||||
if (ts > it->second->nextResendTime)
|
||||
@ -207,6 +207,7 @@ namespace transport
|
||||
m_SentPackets.insert (resentPackets.begin (), resentPackets.end ());
|
||||
#endif
|
||||
}
|
||||
SendQueue ();
|
||||
}
|
||||
|
||||
void SSU2Session::ProcessFirstIncomingMessage (uint64_t connID, uint8_t * buf, size_t len)
|
||||
@ -746,7 +747,10 @@ namespace transport
|
||||
m_LastActivityTimestamp = i2p::util::GetSecondsSinceEpoch ();
|
||||
m_NumReceivedBytes += len;
|
||||
if (UpdateReceivePacketNum (packetNum))
|
||||
{
|
||||
HandlePayload (payload, payloadSize);
|
||||
SendQueue (); // if we have something to send
|
||||
}
|
||||
}
|
||||
|
||||
void SSU2Session::HandlePayload (const uint8_t * buf, size_t len)
|
||||
|
@ -33,6 +33,7 @@ namespace transport
|
||||
const int SSU2_RESEND_INTERVAL = 3; // in seconds
|
||||
const int SSU2_MAX_NUM_RESENDS = 5;
|
||||
const int SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT = 30; // in seconds
|
||||
const size_t SSU2_MAX_WINDOW_SIZE = 128; // in packets
|
||||
|
||||
enum SSU2MessageType
|
||||
{
|
||||
@ -210,6 +211,7 @@ namespace transport
|
||||
std::list<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
||||
i2p::I2NPMessagesHandler m_Handler;
|
||||
bool m_IsDataReceived;
|
||||
size_t m_WindowSize;
|
||||
};
|
||||
|
||||
class SSU2Server: private i2p::util::RunnableServiceWithWork
|
||||
|
Loading…
Reference in New Issue
Block a user