mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 16:34:13 +00:00
send Ack with 200 ms delay
This commit is contained in:
parent
a0a0234d29
commit
70c3bf77a9
@ -12,9 +12,10 @@ namespace stream
|
|||||||
{
|
{
|
||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local,
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local,
|
||||||
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
const i2p::data::LeaseSet& remote): m_Service (service), m_SendStreamID (0),
|
||||||
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1), m_IsOpen (false),
|
||||||
m_IsReset (false), m_LocalDestination (local), m_RemoteLeaseSet (&remote),
|
m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
|
||||||
m_RoutingSession (nullptr), m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
m_RemoteLeaseSet (&remote), m_RoutingSession (nullptr), m_ReceiveTimer (m_Service),
|
||||||
|
m_ResendTimer (m_Service), m_AckSendTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
UpdateCurrentRemoteLease ();
|
UpdateCurrentRemoteLease ();
|
||||||
@ -22,15 +23,16 @@ namespace stream
|
|||||||
|
|
||||||
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local):
|
Stream::Stream (boost::asio::io_service& service, StreamingDestination& local):
|
||||||
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
m_Service (service), m_SendStreamID (0), m_SequenceNumber (0), m_LastReceivedSequenceNumber (-1),
|
||||||
m_IsOpen (false), m_IsReset (false), m_LocalDestination (local),
|
m_IsOpen (false), m_IsReset (false), m_IsAckSendScheduled (false), m_LocalDestination (local),
|
||||||
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr),
|
m_RemoteLeaseSet (nullptr), m_RoutingSession (nullptr), m_ReceiveTimer (m_Service),
|
||||||
m_ReceiveTimer (m_Service), m_ResendTimer (m_Service)
|
m_ResendTimer (m_Service), m_AckSendTimer (m_Service)
|
||||||
{
|
{
|
||||||
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
m_RecvStreamID = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
|
||||||
}
|
}
|
||||||
|
|
||||||
Stream::~Stream ()
|
Stream::~Stream ()
|
||||||
{
|
{
|
||||||
|
m_AckSendTimer.cancel ();
|
||||||
while (!m_ReceiveQueue.empty ())
|
while (!m_ReceiveQueue.empty ())
|
||||||
{
|
{
|
||||||
auto packet = m_ReceiveQueue.front ();
|
auto packet = m_ReceiveQueue.front ();
|
||||||
@ -89,9 +91,17 @@ namespace stream
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// send ack for last message
|
// schedule ack for last message
|
||||||
if (m_IsOpen)
|
if (m_IsOpen)
|
||||||
SendQuickAck ();
|
{
|
||||||
|
if (!m_IsAckSendScheduled)
|
||||||
|
{
|
||||||
|
m_IsAckSendScheduled = true;
|
||||||
|
m_AckSendTimer.expires_from_now (boost::posix_time::milliseconds(ACK_SEND_TIMEOUT));
|
||||||
|
m_AckSendTimer.async_wait (boost::bind (&Stream::HandleAckSendTimer,
|
||||||
|
this, boost::asio::placeholders::error));
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (isSyn)
|
else if (isSyn)
|
||||||
// we have to send SYN back to incoming connection
|
// we have to send SYN back to incoming connection
|
||||||
Send (nullptr, 0); // also sets m_IsOpen
|
Send (nullptr, 0); // also sets m_IsOpen
|
||||||
@ -470,6 +480,16 @@ namespace stream
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Stream::HandleAckSendTimer (const boost::system::error_code& ecode)
|
||||||
|
{
|
||||||
|
if (ecode != boost::asio::error::operation_aborted)
|
||||||
|
{
|
||||||
|
if (m_IsOpen)
|
||||||
|
SendQuickAck ();
|
||||||
|
}
|
||||||
|
m_IsAckSendScheduled = false;
|
||||||
|
}
|
||||||
|
|
||||||
void Stream::UpdateCurrentRemoteLease ()
|
void Stream::UpdateCurrentRemoteLease ()
|
||||||
{
|
{
|
||||||
if (!m_RemoteLeaseSet)
|
if (!m_RemoteLeaseSet)
|
||||||
|
@ -36,6 +36,7 @@ namespace stream
|
|||||||
const size_t MAX_PACKET_SIZE = 4096;
|
const size_t MAX_PACKET_SIZE = 4096;
|
||||||
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
|
const size_t COMPRESSION_THRESHOLD_SIZE = 66;
|
||||||
const int RESEND_TIMEOUT = 10; // in seconds
|
const int RESEND_TIMEOUT = 10; // in seconds
|
||||||
|
const int ACK_SEND_TIMEOUT = 200; // in milliseconds
|
||||||
const int MAX_NUM_RESEND_ATTEMPTS = 5;
|
const int MAX_NUM_RESEND_ATTEMPTS = 5;
|
||||||
|
|
||||||
struct Packet
|
struct Packet
|
||||||
@ -115,13 +116,14 @@ namespace stream
|
|||||||
|
|
||||||
void ScheduleResend ();
|
void ScheduleResend ();
|
||||||
void HandleResendTimer (const boost::system::error_code& ecode);
|
void HandleResendTimer (const boost::system::error_code& ecode);
|
||||||
|
void HandleAckSendTimer (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
boost::asio::io_service& m_Service;
|
boost::asio::io_service& m_Service;
|
||||||
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
uint32_t m_SendStreamID, m_RecvStreamID, m_SequenceNumber;
|
||||||
int32_t m_LastReceivedSequenceNumber;
|
int32_t m_LastReceivedSequenceNumber;
|
||||||
bool m_IsOpen, m_IsReset;
|
bool m_IsOpen, m_IsReset, m_IsAckSendScheduled;
|
||||||
StreamingDestination& m_LocalDestination;
|
StreamingDestination& m_LocalDestination;
|
||||||
i2p::data::IdentityEx m_RemoteIdentity;
|
i2p::data::IdentityEx m_RemoteIdentity;
|
||||||
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
const i2p::data::LeaseSet * m_RemoteLeaseSet;
|
||||||
@ -130,7 +132,7 @@ namespace stream
|
|||||||
std::queue<Packet *> m_ReceiveQueue;
|
std::queue<Packet *> m_ReceiveQueue;
|
||||||
std::set<Packet *, PacketCmp> m_SavedPackets;
|
std::set<Packet *, PacketCmp> m_SavedPackets;
|
||||||
std::set<Packet *, PacketCmp> m_SentPackets;
|
std::set<Packet *, PacketCmp> m_SentPackets;
|
||||||
boost::asio::deadline_timer m_ReceiveTimer, m_ResendTimer;
|
boost::asio::deadline_timer m_ReceiveTimer, m_ResendTimer, m_AckSendTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user