Browse Source

HandleFollowOnFragment

pull/73/merge
orignal 11 years ago
parent
commit
49035ef55d
  1. 52
      TunnelEndpoint.cpp
  2. 11
      TunnelEndpoint.h

52
TunnelEndpoint.cpp

@ -91,7 +91,6 @@ namespace tunnel @@ -91,7 +91,6 @@ namespace tunnel
msg->offset = fragment - msg->buf;
msg->len = msg->offset + size;
bool isLastMessage = false;
if (fragment + size < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE)
{
// this is not last message. we have to copy it
@ -101,10 +100,7 @@ namespace tunnel @@ -101,10 +100,7 @@ namespace tunnel
*(m.data) = *msg;
}
else
{
m.data = msg;
isLastMessage = true;
}
if (!isFollowOnFragment && isLastFragment)
HandleNextMessage (m);
@ -119,10 +115,32 @@ namespace tunnel @@ -119,10 +115,32 @@ namespace tunnel
}
else
{
m.nextFragmentNum = fragmentNum;
HandleFollowOnFragment (msgID, isLastFragment, m);
}
}
else
LogPrint ("Message is fragmented, but msgID is not presented");
}
fragment += size;
}
}
else
{
LogPrint ("TunnelMessage: zero not found");
i2p::DeleteI2NPMessage (msg);
}
}
void TunnelEndpoint::HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, const TunnelMessageBlockEx& m)
{
auto fragment = m.data->GetBuffer ();
auto size = m.data->GetLength ();
auto it = m_IncompleteMessages.find (msgID);
if (it != m_IncompleteMessages.end())
{
if (fragmentNum == it->second.nextFragmentNum)
if (m.nextFragmentNum == it->second.nextFragmentNum)
{
I2NPMessage * incompleteMessage = it->second.data;
if (incompleteMessage->len + size < I2NP_MAX_MESSAGE_SIZE) // check if messega is not too long
@ -140,14 +158,14 @@ namespace tunnel @@ -140,14 +158,14 @@ namespace tunnel
}
else
{
LogPrint ("Fragment ", fragmentNum, " of message ", msgID, "exceeds max I2NP message size. Message dropped");
LogPrint ("Fragment ", m.nextFragmentNum, " of message ", msgID, "exceeds max I2NP message size. Message dropped");
i2p::DeleteI2NPMessage (it->second.data);
m_IncompleteMessages.erase (it);
}
}
else
{
LogPrint ("Unexpected fragment ", fragmentNum, " instead ", it->second.nextFragmentNum, " of message ", msgID, ". Discarded");
LogPrint ("Unexpected fragment ", m.nextFragmentNum, " instead ", it->second.nextFragmentNum, " of message ", msgID, ". Discarded");
i2p::DeleteI2NPMessage (it->second.data);
m_IncompleteMessages.erase (it); // TODO: store unexpected fragment for a while
}
@ -155,28 +173,8 @@ namespace tunnel @@ -155,28 +173,8 @@ namespace tunnel
else
LogPrint ("First fragment of message ", msgID, " not found. Discarded");
if (isLastMessage)
// last message is follow-on fragment
// not passed to anywhere because first fragment
i2p::DeleteI2NPMessage (msg);
else
// delete temporarty copy used for first fragment only
i2p::DeleteI2NPMessage (m.data);
}
}
else
LogPrint ("Message is fragmented, but msgID is not presented");
}
fragment += size;
}
}
else
{
LogPrint ("TunnelMessage: zero not found");
i2p::DeleteI2NPMessage (msg);
}
}
void TunnelEndpoint::HandleNextMessage (const TunnelMessageBlock& msg)
{

11
TunnelEndpoint.h

@ -13,6 +13,11 @@ namespace tunnel @@ -13,6 +13,11 @@ namespace tunnel
{
class TunnelEndpoint
{
struct TunnelMessageBlockEx: public TunnelMessageBlock
{
uint8_t nextFragmentNum;
};
public:
TunnelEndpoint (): m_NumReceivedBytes (0) {};
@ -22,15 +27,11 @@ namespace tunnel @@ -22,15 +27,11 @@ namespace tunnel
private:
void HandleFollowOnFragment (uint32_t msgID, bool isLastFragment, const TunnelMessageBlockEx& m);
void HandleNextMessage (const TunnelMessageBlock& msg);
private:
struct TunnelMessageBlockEx: public TunnelMessageBlock
{
uint8_t nextFragmentNum;
};
std::map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
size_t m_NumReceivedBytes;
};

Loading…
Cancel
Save