mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-15 22:09:57 +00:00
store fragments inside m_OutOfSequenceFragments
This commit is contained in:
parent
08a680b53d
commit
f2b5606583
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -258,9 +258,8 @@ namespace tunnel
|
|||||||
void TunnelEndpoint::AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum,
|
void TunnelEndpoint::AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum,
|
||||||
bool isLastFragment, const uint8_t * fragment, size_t size)
|
bool isLastFragment, const uint8_t * fragment, size_t size)
|
||||||
{
|
{
|
||||||
std::unique_ptr<Fragment> f(new Fragment (isLastFragment, i2p::util::GetMillisecondsSinceEpoch (), size));
|
if (!m_OutOfSequenceFragments.try_emplace ((uint64_t)msgID << 32 | fragmentNum,
|
||||||
memcpy (f->data.data (), fragment, size);
|
isLastFragment, i2p::util::GetMillisecondsSinceEpoch (), fragment, size).second)
|
||||||
if (!m_OutOfSequenceFragments.emplace ((uint64_t)msgID << 32 | fragmentNum, std::move (f)).second)
|
|
||||||
LogPrint (eLogInfo, "TunnelMessage: Duplicate out-of-sequence fragment ", fragmentNum, " of message ", msgID);
|
LogPrint (eLogInfo, "TunnelMessage: Duplicate out-of-sequence fragment ", fragmentNum, " of message ", msgID);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +289,7 @@ namespace tunnel
|
|||||||
if (it != m_OutOfSequenceFragments.end ())
|
if (it != m_OutOfSequenceFragments.end ())
|
||||||
{
|
{
|
||||||
LogPrint (eLogDebug, "TunnelMessage: Out-of-sequence fragment ", (int)msg.nextFragmentNum, " of message ", msgID, " found");
|
LogPrint (eLogDebug, "TunnelMessage: Out-of-sequence fragment ", (int)msg.nextFragmentNum, " of message ", msgID, " found");
|
||||||
size_t size = it->second->data.size ();
|
size_t size = it->second.data.size ();
|
||||||
if (msg.data->len + size > msg.data->maxLen)
|
if (msg.data->len + size > msg.data->maxLen)
|
||||||
{
|
{
|
||||||
LogPrint (eLogWarning, "TunnelMessage: Tunnel endpoint I2NP message size ", msg.data->maxLen, " is not enough");
|
LogPrint (eLogWarning, "TunnelMessage: Tunnel endpoint I2NP message size ", msg.data->maxLen, " is not enough");
|
||||||
@ -298,9 +297,9 @@ namespace tunnel
|
|||||||
*newMsg = *(msg.data);
|
*newMsg = *(msg.data);
|
||||||
msg.data = newMsg;
|
msg.data = newMsg;
|
||||||
}
|
}
|
||||||
if (msg.data->Concat (it->second->data.data (), size) < size) // concatenate out-of-sync fragment
|
if (msg.data->Concat (it->second.data.data (), size) < size) // concatenate out-of-sync fragment
|
||||||
LogPrint (eLogError, "TunnelMessage: Tunnel endpoint I2NP buffer overflow ", msg.data->maxLen);
|
LogPrint (eLogError, "TunnelMessage: Tunnel endpoint I2NP buffer overflow ", msg.data->maxLen);
|
||||||
if (it->second->isLastFragment)
|
if (it->second.isLastFragment)
|
||||||
// message complete
|
// message complete
|
||||||
msg.nextFragmentNum = 0;
|
msg.nextFragmentNum = 0;
|
||||||
else
|
else
|
||||||
@ -349,7 +348,7 @@ namespace tunnel
|
|||||||
// out-of-sequence fragments
|
// out-of-sequence fragments
|
||||||
for (auto it = m_OutOfSequenceFragments.begin (); it != m_OutOfSequenceFragments.end ();)
|
for (auto it = m_OutOfSequenceFragments.begin (); it != m_OutOfSequenceFragments.end ();)
|
||||||
{
|
{
|
||||||
if (ts > it->second->receiveTime + i2p::I2NP_MESSAGE_EXPIRATION_TIMEOUT)
|
if (ts > it->second.receiveTime + i2p::I2NP_MESSAGE_EXPIRATION_TIMEOUT)
|
||||||
it = m_OutOfSequenceFragments.erase (it);
|
it = m_OutOfSequenceFragments.erase (it);
|
||||||
else
|
else
|
||||||
++it;
|
++it;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||||
*
|
*
|
||||||
* This file is part of Purple i2pd project and licensed under BSD3
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@ -32,7 +32,8 @@ namespace tunnel
|
|||||||
|
|
||||||
struct Fragment
|
struct Fragment
|
||||||
{
|
{
|
||||||
Fragment (bool last, uint64_t t, size_t size): isLastFragment (last), receiveTime (t), data (size) {};
|
Fragment (bool last, uint64_t t, const uint8_t * buf, size_t size):
|
||||||
|
isLastFragment (last), receiveTime (t), data (buf, buf + size) {};
|
||||||
bool isLastFragment;
|
bool isLastFragment;
|
||||||
uint64_t receiveTime; // milliseconds since epoch
|
uint64_t receiveTime; // milliseconds since epoch
|
||||||
std::vector<uint8_t> data;
|
std::vector<uint8_t> data;
|
||||||
@ -67,7 +68,7 @@ namespace tunnel
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::unordered_map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
|
std::unordered_map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
|
||||||
std::unordered_map<uint64_t, std::unique_ptr<Fragment> > m_OutOfSequenceFragments; // ((msgID << 8) + fragment#)->fragment
|
std::unordered_map<uint64_t, Fragment> m_OutOfSequenceFragments; // ((msgID << 8) + fragment#)->fragment
|
||||||
bool m_IsInbound;
|
bool m_IsInbound;
|
||||||
size_t m_NumReceivedBytes;
|
size_t m_NumReceivedBytes;
|
||||||
TunnelMessageBlockEx m_CurrentMessage;
|
TunnelMessageBlockEx m_CurrentMessage;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user