Browse Source

use Rng from pool if possible

pull/2101/head
orignal 2 months ago
parent
commit
509c039e2f
  1. 4
      libi2pd/Datagram.cpp
  2. 15
      libi2pd/Streaming.cpp
  3. 1
      libi2pd/Streaming.h

4
libi2pd/Datagram.cpp

@ -422,7 +422,7 @@ namespace datagram
{ {
auto pool = m_LocalDestination->GetTunnelPool (); auto pool = m_LocalDestination->GetTunnelPool ();
if (pool) if (pool)
idx = m_LocalDestination->GetTunnelPool ()->GetRng ()() % sz; idx = pool->GetRng ()() % sz;
} }
if (idx < 0) idx = rand () % sz; if (idx < 0) idx = rand () % sz;
path->remoteLease = ls[idx]; path->remoteLease = ls[idx];
@ -455,7 +455,7 @@ namespace datagram
{ {
auto pool = m_LocalDestination->GetTunnelPool (); auto pool = m_LocalDestination->GetTunnelPool ();
if (pool) if (pool)
idx = m_LocalDestination->GetTunnelPool ()->GetRng ()() % sz; idx = pool->GetRng ()() % sz;
} }
if (idx < 0) idx = rand () % sz; if (idx < 0) idx = rand () % sz;
path->remoteLease = ls[idx]; path->remoteLease = ls[idx];

15
libi2pd/Streaming.cpp

@ -459,7 +459,6 @@ namespace stream
void Stream::ProcessAck (Packet * packet) void Stream::ProcessAck (Packet * packet)
{ {
srand (time(NULL));
bool acknowledged = false; bool acknowledged = false;
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
uint32_t ackThrough = packet->GetAckThrough (); uint32_t ackThrough = packet->GetAckThrough ();
@ -514,7 +513,7 @@ namespace stream
acknowledged = true; acknowledged = true;
ackCount++; ackCount++;
if (m_WindowSize < MAX_WINDOW_SIZE && !m_IsFirstACK) if (m_WindowSize < MAX_WINDOW_SIZE && !m_IsFirstACK)
if (m_RTT < rand () % INITIAL_RTT) // dirty if (m_RTT < m_LocalDestination.GetRandom () % INITIAL_RTT) // dirty
m_WindowIncCounter++; m_WindowIncCounter++;
} }
else else
@ -1410,7 +1409,7 @@ namespace stream
} }
if (!updated) if (!updated)
{ {
uint32_t i = rand () % leases.size (); uint32_t i = m_LocalDestination.GetRandom () % leases.size ();
if (m_CurrentRemoteLease && leases[i]->tunnelID == m_CurrentRemoteLease->tunnelID) if (m_CurrentRemoteLease && leases[i]->tunnelID == m_CurrentRemoteLease->tunnelID)
// make sure we don't select previous // make sure we don't select previous
i = (i + 1) % leases.size (); // if so, pick next i = (i + 1) % leases.size (); // if so, pick next
@ -1811,5 +1810,15 @@ namespace stream
return msg; return msg;
} }
uint32_t StreamingDestination::GetRandom ()
{
if (m_Owner)
{
auto pool = m_Owner->GetTunnelPool ();
if (pool)
return pool->GetRng ()();
}
return rand ();
}
} }
} }

1
libi2pd/Streaming.h

@ -321,6 +321,7 @@ namespace stream
Packet * NewPacket () { return m_PacketsPool.Acquire(); } Packet * NewPacket () { return m_PacketsPool.Acquire(); }
void DeletePacket (Packet * p) { return m_PacketsPool.Release(p); } void DeletePacket (Packet * p) { return m_PacketsPool.Release(p); }
uint32_t GetRandom ();
private: private:

Loading…
Cancel
Save