mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 02:44:15 +00:00
check for duplicate and missing fragments
This commit is contained in:
parent
e1027ffb7b
commit
a510e7c2c6
36
SSU.cpp
36
SSU.cpp
@ -27,6 +27,12 @@ namespace ssu
|
|||||||
SSUSession::~SSUSession ()
|
SSUSession::~SSUSession ()
|
||||||
{
|
{
|
||||||
delete m_DHKeysPair;
|
delete m_DHKeysPair;
|
||||||
|
for (auto it: m_IncomleteMessages)
|
||||||
|
if (it.second)
|
||||||
|
{
|
||||||
|
DeleteI2NPMessage (it.second->msg);
|
||||||
|
delete it.second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUSession::CreateAESandMacKey (uint8_t * pubKey, uint8_t * aesKey, uint8_t * macKey)
|
void SSUSession::CreateAESandMacKey (uint8_t * pubKey, uint8_t * aesKey, uint8_t * macKey)
|
||||||
@ -673,9 +679,29 @@ namespace ssu
|
|||||||
auto it = m_IncomleteMessages.find (msgID);
|
auto it = m_IncomleteMessages.find (msgID);
|
||||||
if (it != m_IncomleteMessages.end ())
|
if (it != m_IncomleteMessages.end ())
|
||||||
{
|
{
|
||||||
msg = it->second;
|
if (fragmentNum == it->second->nextFragmentNum)
|
||||||
memcpy (msg->buf + msg->len, buf, fragmentSize);
|
{
|
||||||
msg->len += fragmentSize;
|
// expected fragment
|
||||||
|
msg = it->second->msg;
|
||||||
|
memcpy (msg->buf + msg->len, buf, fragmentSize);
|
||||||
|
msg->len += fragmentSize;
|
||||||
|
it->second->nextFragmentNum++;
|
||||||
|
}
|
||||||
|
else if (fragmentNum < it->second->nextFragmentNum)
|
||||||
|
// duplicate fragment
|
||||||
|
LogPrint ("Duplicate fragment ", fragmentNum, " of message ", msgID, ". Ignored");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// missing fragment
|
||||||
|
LogPrint ("Missing fragments from ", it->second->nextFragmentNum, " to ", fragmentNum - 1, " of message ", msgID);
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLast)
|
||||||
|
{
|
||||||
|
delete it->second;
|
||||||
|
m_IncomleteMessages.erase (it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// TODO:
|
// TODO:
|
||||||
@ -691,12 +717,10 @@ namespace ssu
|
|||||||
if (msg)
|
if (msg)
|
||||||
{
|
{
|
||||||
if (!fragmentNum && !isLast)
|
if (!fragmentNum && !isLast)
|
||||||
m_IncomleteMessages[msgID] = msg;
|
m_IncomleteMessages[msgID] = new IncompleteMessage (msg);
|
||||||
if (isLast)
|
if (isLast)
|
||||||
{
|
{
|
||||||
SendMsgAck (msgID);
|
SendMsgAck (msgID);
|
||||||
if (fragmentNum > 0)
|
|
||||||
m_IncomleteMessages.erase (msgID);
|
|
||||||
msg->FromSSU (msgID);
|
msg->FromSSU (msgID);
|
||||||
if (m_State == eSessionStateEstablished)
|
if (m_State == eSessionStateEstablished)
|
||||||
i2p::HandleI2NPMessage (msg);
|
i2p::HandleI2NPMessage (msg);
|
||||||
|
10
SSU.h
10
SSU.h
@ -124,6 +124,14 @@ namespace ssu
|
|||||||
void HandleTerminationTimer (const boost::system::error_code& ecode);
|
void HandleTerminationTimer (const boost::system::error_code& ecode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
struct IncompleteMessage
|
||||||
|
{
|
||||||
|
I2NPMessage * msg;
|
||||||
|
uint8_t nextFragmentNum;
|
||||||
|
|
||||||
|
IncompleteMessage (I2NPMessage * m): msg (m), nextFragmentNum (1) {};
|
||||||
|
};
|
||||||
|
|
||||||
SSUServer& m_Server;
|
SSUServer& m_Server;
|
||||||
boost::asio::ip::udp::endpoint m_RemoteEndpoint;
|
boost::asio::ip::udp::endpoint m_RemoteEndpoint;
|
||||||
@ -137,7 +145,7 @@ namespace ssu
|
|||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
|
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
|
||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_Decryption;
|
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_Decryption;
|
||||||
uint8_t m_SessionKey[32], m_MacKey[32];
|
uint8_t m_SessionKey[32], m_MacKey[32];
|
||||||
std::map<uint32_t, I2NPMessage *> m_IncomleteMessages;
|
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
|
||||||
std::list<i2p::I2NPMessage *> m_DelayedMessages;
|
std::list<i2p::I2NPMessage *> m_DelayedMessages;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user