MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / CleanUp

Method CleanUp

libi2pd/SSU2Session.cpp:3366–3434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3364 }
3365
3366 void SSU2Session::CleanUp (uint64_t ts)
3367 {
3368 for (auto it = m_IncompleteMessages.begin (); it != m_IncompleteMessages.end ();)
3369 {
3370 if (ts > it->second->lastFragmentInsertTime + SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT)
3371 {
3372 LogPrint (eLogWarning, "SSU2: message ", it->first, " was not completed in ", SSU2_INCOMPLETE_MESSAGES_CLEANUP_TIMEOUT, " seconds, deleted");
3373 it = m_IncompleteMessages.erase (it);
3374 }
3375 else
3376 ++it;
3377 }
3378 if (m_ReceivedI2NPMsgIDs.size () > SSU2_MAX_NUM_RECEIVED_I2NP_MSGIDS || ts > GetLastActivityTimestamp () + SSU2_DECAY_INTERVAL)
3379 // decay
3380 m_ReceivedI2NPMsgIDs.clear ();
3381 else
3382 {
3383 // delete old received msgIDs
3384 for (auto it = m_ReceivedI2NPMsgIDs.begin (); it != m_ReceivedI2NPMsgIDs.end ();)
3385 {
3386 if (ts > it->second + SSU2_RECEIVED_I2NP_MSGIDS_CLEANUP_TIMEOUT)
3387 it = m_ReceivedI2NPMsgIDs.erase (it);
3388 else
3389 ++it;
3390 }
3391 }
3392 if (!m_OutOfSequencePackets.empty ())
3393 {
3394 int ranges = 0;
3395 while (ranges < 8 && !m_OutOfSequencePackets.empty () &&
3396 (m_OutOfSequencePackets.size () > 2*SSU2_MAX_NUM_ACK_RANGES ||
3397 *m_OutOfSequencePackets.rbegin () > m_ReceivePacketNum + SSU2_MAX_NUM_ACK_PACKETS))
3398 {
3399 uint32_t packet = *m_OutOfSequencePackets.begin ();
3400 if (packet > m_ReceivePacketNum + 1)
3401 {
3402 // like we've just received all packets before first
3403 packet--;
3404 m_ReceivePacketNum = packet - 1;
3405 UpdateReceivePacketNum (packet);
3406 ranges++;
3407 }
3408 else
3409 {
3410 LogPrint (eLogError, "SSU2: Out of sequence packet ", packet, " is less than last received ", m_ReceivePacketNum);
3411 break;
3412 }
3413 }
3414 if (m_OutOfSequencePackets.size () > 255*4)
3415 {
3416 // seems we have a serious network issue
3417 m_ReceivePacketNum = *m_OutOfSequencePackets.rbegin ();
3418 m_OutOfSequencePackets.clear ();
3419 }
3420 }
3421
3422 for (auto it = m_RelaySessions.begin (); it != m_RelaySessions.end ();)
3423 {

Callers

nothing calls this directly

Calls 1

LogPrintFunction · 0.85

Tested by

no test coverage detected