Browse Source

don't send repliable datagram after less then 100 milliseconds

pull/1550/head
orignal 4 years ago
parent
commit
3ef8b3dcbb
  1. 12
      libi2pd_client/I2PTunnel.cpp
  2. 1
      libi2pd_client/I2PTunnel.h

12
libi2pd_client/I2PTunnel.cpp

@ -708,9 +708,12 @@ namespace client
if(!ecode) if(!ecode)
{ {
LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint); LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint);
LastActivity = i2p::util::GetMillisecondsSinceEpoch(); auto ts = i2p::util::GetMillisecondsSinceEpoch();
auto session = m_Destination->GetSession (Identity); auto session = m_Destination->GetSession (Identity);
if (ts > LastActivity + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL)
m_Destination->SendDatagram(session, m_Buffer, len, LocalPort, RemotePort); m_Destination->SendDatagram(session, m_Buffer, len, LocalPort, RemotePort);
else
m_Destination->SendRawDatagram(session, m_Buffer, len, LocalPort, RemotePort);
size_t numPackets = 0; size_t numPackets = 0;
while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE) while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE)
{ {
@ -724,6 +727,7 @@ namespace client
if (numPackets > 0) if (numPackets > 0)
LogPrint(eLogDebug, "UDPSession: forward more ", numPackets, "packets B from ", FromEndpoint); LogPrint(eLogDebug, "UDPSession: forward more ", numPackets, "packets B from ", FromEndpoint);
m_Destination->FlushSendQueue (session); m_Destination->FlushSendQueue (session);
LastActivity = ts;
Receive(); Receive();
} }
else else
@ -841,9 +845,13 @@ namespace client
m_LastPort = remotePort; m_LastPort = remotePort;
} }
// send off to remote i2p destination // send off to remote i2p destination
auto ts = i2p::util::GetMillisecondsSinceEpoch();
LogPrint(eLogDebug, "UDP Client: send ", transferred, " to ", m_RemoteIdent->ToBase32(), ":", RemotePort); LogPrint(eLogDebug, "UDP Client: send ", transferred, " to ", m_RemoteIdent->ToBase32(), ":", RemotePort);
auto session = m_LocalDest->GetDatagramDestination()->GetSession (*m_RemoteIdent); auto session = m_LocalDest->GetDatagramDestination()->GetSession (*m_RemoteIdent);
if (ts > m_LastSession->second + I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL)
m_LocalDest->GetDatagramDestination()->SendDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort); m_LocalDest->GetDatagramDestination()->SendDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort);
else
m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort);
size_t numPackets = 0; size_t numPackets = 0;
while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE) while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE)
{ {
@ -862,7 +870,7 @@ namespace client
// mark convo as active // mark convo as active
if (m_LastSession) if (m_LastSession)
m_LastSession->second = i2p::util::GetMillisecondsSinceEpoch(); m_LastSession->second = ts;
RecvFromLocal(); RecvFromLocal();
} }

1
libi2pd_client/I2PTunnel.h

@ -165,6 +165,7 @@ namespace client
/** 2 minute timeout for udp sessions */ /** 2 minute timeout for udp sessions */
const uint64_t I2P_UDP_SESSION_TIMEOUT = 1000 * 60 * 2; const uint64_t I2P_UDP_SESSION_TIMEOUT = 1000 * 60 * 2;
const uint64_t I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL = 100; // in milliseconds
/** max size for i2p udp */ /** max size for i2p udp */
const size_t I2P_UDP_MAX_MTU = 64*1024; const size_t I2P_UDP_MAX_MTU = 64*1024;

Loading…
Cancel
Save