Browse Source

resend intervals in milliseconds

pull/1786/head
orignal 2 years ago
parent
commit
e70d57dcb4
  1. 4
      libi2pd/SSU2.cpp
  2. 3
      libi2pd/SSU2.h
  3. 16
      libi2pd/SSU2Session.cpp
  4. 6
      libi2pd/SSU2Session.h

4
libi2pd/SSU2.cpp

@ -729,7 +729,7 @@ namespace transport
void SSU2Server::ScheduleResend () void SSU2Server::ScheduleResend ()
{ {
m_ResendTimer.expires_from_now (boost::posix_time::seconds(SSU2_RESEND_INTERVAL)); m_ResendTimer.expires_from_now (boost::posix_time::milliseconds(SSU2_RESEND_CHECK_TIMEOUT));
m_ResendTimer.async_wait (std::bind (&SSU2Server::HandleResendTimer, m_ResendTimer.async_wait (std::bind (&SSU2Server::HandleResendTimer,
this, std::placeholders::_1)); this, std::placeholders::_1));
} }
@ -738,7 +738,7 @@ namespace transport
{ {
if (ecode != boost::asio::error::operation_aborted) if (ecode != boost::asio::error::operation_aborted)
{ {
auto ts = i2p::util::GetSecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
for (auto it: m_Sessions) for (auto it: m_Sessions)
it.second->Resend (ts); it.second->Resend (ts);
for (auto it: m_PendingOutgoingSessions) for (auto it: m_PendingOutgoingSessions)

3
libi2pd/SSU2.h

@ -17,7 +17,8 @@ namespace i2p
{ {
namespace transport namespace transport
{ {
const int SSU2_TERMINATION_CHECK_TIMEOUT = 30; // 30 seconds const int SSU2_TERMINATION_CHECK_TIMEOUT = 30; // in seconds
const int SSU2_RESEND_CHECK_TIMEOUT = 500; // in milliseconds
const size_t SSU2_SOCKET_RECEIVE_BUFFER_SIZE = 0x1FFFF; // 128K const size_t SSU2_SOCKET_RECEIVE_BUFFER_SIZE = 0x1FFFF; // 128K
const size_t SSU2_SOCKET_SEND_BUFFER_SIZE = 0x1FFFF; // 128K const size_t SSU2_SOCKET_SEND_BUFFER_SIZE = 0x1FFFF; // 128K
const size_t SSU2_MAX_NUM_INTRODUCERS = 3; const size_t SSU2_MAX_NUM_INTRODUCERS = 3;

16
libi2pd/SSU2Session.cpp

@ -265,7 +265,7 @@ namespace transport
{ {
if (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize) if (!m_SendQueue.empty () && m_SentPackets.size () <= m_WindowSize)
{ {
auto nextResend = i2p::util::GetSecondsSinceEpoch () + SSU2_RESEND_INTERVAL; auto nextResend = i2p::util::GetMillisecondsSinceEpoch () + SSU2_RESEND_INTERVAL;
auto packet = std::make_shared<SentPacket>(); auto packet = std::make_shared<SentPacket>();
size_t ackBlockSize = CreateAckBlock (packet->payload, m_MaxPayloadSize); size_t ackBlockSize = CreateAckBlock (packet->payload, m_MaxPayloadSize);
bool ackBlockSent = false; bool ackBlockSent = false;
@ -344,7 +344,7 @@ namespace transport
bool ackBlockSent = false; bool ackBlockSent = false;
uint32_t msgID; uint32_t msgID;
memcpy (&msgID, msg->GetHeader () + I2NP_HEADER_MSGID_OFFSET, 4); memcpy (&msgID, msg->GetHeader () + I2NP_HEADER_MSGID_OFFSET, 4);
auto nextResend = i2p::util::GetSecondsSinceEpoch () + SSU2_RESEND_INTERVAL; auto nextResend = i2p::util::GetMillisecondsSinceEpoch () + SSU2_RESEND_INTERVAL;
auto packet = std::make_shared<SentPacket>(); auto packet = std::make_shared<SentPacket>();
if (extraSize >= 8) if (extraSize >= 8)
{ {
@ -414,7 +414,6 @@ namespace transport
uint32_t packetNum = SendData (it->second->payload, it->second->payloadSize); uint32_t packetNum = SendData (it->second->payload, it->second->payloadSize);
it->second->numResends++; it->second->numResends++;
it->second->nextResendTime = ts + it->second->numResends*SSU2_RESEND_INTERVAL; it->second->nextResendTime = ts + it->second->numResends*SSU2_RESEND_INTERVAL;
m_LastActivityTimestamp = ts;
resentPackets.emplace (packetNum, it->second); resentPackets.emplace (packetNum, it->second);
it = m_SentPackets.erase (it); it = m_SentPackets.erase (it);
} }
@ -486,7 +485,7 @@ namespace transport
// we are Alice // we are Alice
m_EphemeralKeys = i2p::transport::transports.GetNextX25519KeysPair (); m_EphemeralKeys = i2p::transport::transports.GetNextX25519KeysPair ();
m_SentHandshakePacket.reset (new HandshakePacket); m_SentHandshakePacket.reset (new HandshakePacket);
auto ts = i2p::util::GetSecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL; m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL;
Header& header = m_SentHandshakePacket->header; Header& header = m_SentHandshakePacket->header;
@ -505,7 +504,7 @@ namespace transport
// payload // payload
payload[0] = eSSU2BlkDateTime; payload[0] = eSSU2BlkDateTime;
htobe16buf (payload + 1, 4); htobe16buf (payload + 1, 4);
htobe32buf (payload + 3, ts); htobe32buf (payload + 3, ts/1000);
size_t payloadSize = 7; size_t payloadSize = 7;
if (GetRouterStatus () == eRouterStatusFirewalled && m_Address->IsIntroducer ()) if (GetRouterStatus () == eRouterStatusFirewalled && m_Address->IsIntroducer ())
{ {
@ -587,7 +586,7 @@ namespace transport
// we are Bob // we are Bob
m_EphemeralKeys = i2p::transport::transports.GetNextX25519KeysPair (); m_EphemeralKeys = i2p::transport::transports.GetNextX25519KeysPair ();
m_SentHandshakePacket.reset (new HandshakePacket); m_SentHandshakePacket.reset (new HandshakePacket);
auto ts = i2p::util::GetSecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL; m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL;
uint8_t kh2[32]; uint8_t kh2[32];
@ -609,7 +608,7 @@ namespace transport
size_t maxPayloadSize = m_MaxPayloadSize - 48; size_t maxPayloadSize = m_MaxPayloadSize - 48;
payload[0] = eSSU2BlkDateTime; payload[0] = eSSU2BlkDateTime;
htobe16buf (payload + 1, 4); htobe16buf (payload + 1, 4);
htobe32buf (payload + 3, ts); htobe32buf (payload + 3, ts/1000);
size_t payloadSize = 7; size_t payloadSize = 7;
payloadSize += CreateAddressBlock (payload + payloadSize, maxPayloadSize - payloadSize, m_RemoteEndpoint); payloadSize += CreateAddressBlock (payload + payloadSize, maxPayloadSize - payloadSize, m_RemoteEndpoint);
if (m_RelayTag) if (m_RelayTag)
@ -700,8 +699,7 @@ namespace transport
{ {
// we are Alice // we are Alice
m_SentHandshakePacket.reset (new HandshakePacket); m_SentHandshakePacket.reset (new HandshakePacket);
auto ts = i2p::util::GetSecondsSinceEpoch (); m_SentHandshakePacket->nextResendTime = i2p::util::GetMillisecondsSinceEpoch () + SSU2_HANDSHAKE_RESEND_INTERVAL;
m_SentHandshakePacket->nextResendTime = ts + SSU2_HANDSHAKE_RESEND_INTERVAL;
uint8_t kh2[32]; uint8_t kh2[32];
i2p::crypto::HKDF (m_NoiseState->m_CK, nullptr, 0, "SessionConfirmed", kh2, 32); // k_header_2 = HKDF(chainKey, ZEROLEN, "SessionConfirmed", 32) i2p::crypto::HKDF (m_NoiseState->m_CK, nullptr, 0, "SessionConfirmed", kh2, 32); // k_header_2 = HKDF(chainKey, ZEROLEN, "SessionConfirmed", 32)

6
libi2pd/SSU2Session.h

@ -35,7 +35,7 @@ namespace transport
const size_t SSU2_MAX_PACKET_SIZE = 1500; const size_t SSU2_MAX_PACKET_SIZE = 1500;
const size_t SSU2_MIN_PACKET_SIZE = 1280; const size_t SSU2_MIN_PACKET_SIZE = 1280;
const int SSU2_HANDSHAKE_RESEND_INTERVAL = 1; // in seconds const int SSU2_HANDSHAKE_RESEND_INTERVAL = 1; // in seconds
const int SSU2_RESEND_INTERVAL = 3; // in seconds const int SSU2_RESEND_INTERVAL = 300; // in milliseconds
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_MIN_WINDOW_SIZE = 8; // in packets const size_t SSU2_MIN_WINDOW_SIZE = 8; // in packets
@ -189,7 +189,7 @@ namespace transport
{ {
uint8_t payload[SSU2_MAX_PACKET_SIZE]; uint8_t payload[SSU2_MAX_PACKET_SIZE];
size_t payloadSize = 0; size_t payloadSize = 0;
uint32_t nextResendTime; // in seconds uint64_t nextResendTime; // in milliseconds
int numResends = 0; int numResends = 0;
}; };
@ -199,7 +199,7 @@ namespace transport
uint8_t headerX[48]; // part1 for SessionConfirmed uint8_t headerX[48]; // part1 for SessionConfirmed
uint8_t payload[SSU2_MAX_PACKET_SIZE*2]; uint8_t payload[SSU2_MAX_PACKET_SIZE*2];
size_t payloadSize = 0; size_t payloadSize = 0;
uint32_t nextResendTime = 0; // in seconds uint64_t nextResendTime = 0; // in milliseconds
bool isSecondFragment = false; // for SessionConfirmed bool isSecondFragment = false; // for SessionConfirmed
}; };

Loading…
Cancel
Save