mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-19 01:09:58 +00:00
handle I2NP messages drops
This commit is contained in:
parent
d926a31064
commit
f008478505
@ -13,6 +13,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <functional>
|
||||||
#include "Crypto.h"
|
#include "Crypto.h"
|
||||||
#include "I2PEndian.h"
|
#include "I2PEndian.h"
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
@ -149,7 +150,8 @@ namespace tunnel
|
|||||||
uint8_t * buf;
|
uint8_t * buf;
|
||||||
size_t len, offset, maxLen;
|
size_t len, offset, maxLen;
|
||||||
std::shared_ptr<i2p::tunnel::InboundTunnel> from;
|
std::shared_ptr<i2p::tunnel::InboundTunnel> from;
|
||||||
|
std::function<void ()> onDrop;
|
||||||
|
|
||||||
I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2),
|
I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2),
|
||||||
offset(2), maxLen (0), from (nullptr) {}; // reserve 2 bytes for NTCP header
|
offset(2), maxLen (0), from (nullptr) {}; // reserve 2 bytes for NTCP header
|
||||||
|
|
||||||
@ -241,7 +243,6 @@ namespace tunnel
|
|||||||
SetSize (len - offset - I2NP_HEADER_SIZE);
|
SetSize (len - offset - I2NP_HEADER_SIZE);
|
||||||
SetChks (0);
|
SetChks (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ToNTCP2 ()
|
void ToNTCP2 ()
|
||||||
{
|
{
|
||||||
uint8_t * ntcp2 = GetNTCP2Header ();
|
uint8_t * ntcp2 = GetNTCP2Header ();
|
||||||
@ -253,6 +254,8 @@ namespace tunnel
|
|||||||
void RenewI2NPMessageHeader ();
|
void RenewI2NPMessageHeader ();
|
||||||
bool IsExpired () const;
|
bool IsExpired () const;
|
||||||
bool IsExpired (uint64_t ts) const; // in milliseconds
|
bool IsExpired (uint64_t ts) const; // in milliseconds
|
||||||
|
|
||||||
|
void Drop () { if (onDrop) { onDrop (); onDrop = nullptr; }; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<int sz>
|
template<int sz>
|
||||||
|
@ -1140,6 +1140,7 @@ namespace transport
|
|||||||
if (!msg || msg->IsExpired (ts))
|
if (!msg || msg->IsExpired (ts))
|
||||||
{
|
{
|
||||||
// drop null or expired message
|
// drop null or expired message
|
||||||
|
if (msg) msg->Drop ();
|
||||||
m_SendQueue.pop_front ();
|
m_SendQueue.pop_front ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -736,7 +736,11 @@ namespace data
|
|||||||
!i2p::transport::transports.IsConnected (floodfill->GetIdentHash ()))
|
!i2p::transport::transports.IsConnected (floodfill->GetIdentHash ()))
|
||||||
direct = false; // floodfill can't be reached directly
|
direct = false; // floodfill can't be reached directly
|
||||||
if (direct)
|
if (direct)
|
||||||
transports.SendMessage (floodfill->GetIdentHash (), dest->CreateRequestMessage (floodfill->GetIdentHash ()));
|
{
|
||||||
|
auto msg = dest->CreateRequestMessage (floodfill->GetIdentHash ());
|
||||||
|
msg->onDrop = [this, dest]() { this->m_Requests.SendNextRequest (dest); };
|
||||||
|
transports.SendMessage (floodfill->GetIdentHash (), msg);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
|
@ -188,7 +188,11 @@ namespace data
|
|||||||
!i2p::transport::transports.IsConnected (nextFloodfill->GetIdentHash ()))
|
!i2p::transport::transports.IsConnected (nextFloodfill->GetIdentHash ()))
|
||||||
direct = false; // floodfill can't be reached directly
|
direct = false; // floodfill can't be reached directly
|
||||||
if (direct)
|
if (direct)
|
||||||
i2p::transport::transports.SendMessage (nextFloodfill->GetIdentHash (), dest->CreateRequestMessage (nextFloodfill->GetIdentHash ()));
|
{
|
||||||
|
auto msg = dest->CreateRequestMessage (nextFloodfill->GetIdentHash ());
|
||||||
|
msg->onDrop = [this, dest]() { this->SendNextRequest (dest); };
|
||||||
|
i2p::transport::transports.SendMessage (nextFloodfill->GetIdentHash (), msg);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
auto pool = i2p::tunnel::tunnels.GetExploratoryPool ();
|
||||||
|
@ -382,6 +382,7 @@ namespace transport
|
|||||||
if (!msg || msg->IsExpired (ts))
|
if (!msg || msg->IsExpired (ts))
|
||||||
{
|
{
|
||||||
// drop null or expired message
|
// drop null or expired message
|
||||||
|
if (msg) msg->Drop ();
|
||||||
m_SendQueue.pop_front ();
|
m_SendQueue.pop_front ();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -86,6 +86,13 @@ namespace transport
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~Peer ()
|
||||||
|
{
|
||||||
|
// drop not sent delayed messages
|
||||||
|
for (auto& it: delayedMessages)
|
||||||
|
it->Drop ();
|
||||||
|
}
|
||||||
|
|
||||||
void Done ()
|
void Done ()
|
||||||
{
|
{
|
||||||
for (auto& it: sessions)
|
for (auto& it: sessions)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user