mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-13 04:46:38 +01:00
store sent messages until ack-ed
This commit is contained in:
parent
d5fff57edb
commit
fccb13cedd
2 changed files with 32 additions and 4 deletions
33
SSUData.cpp
33
SSUData.cpp
|
@ -19,6 +19,25 @@ namespace ssu
|
||||||
DeleteI2NPMessage (it.second->msg);
|
DeleteI2NPMessage (it.second->msg);
|
||||||
delete it.second;
|
delete it.second;
|
||||||
}
|
}
|
||||||
|
for (auto it: m_SentMessages)
|
||||||
|
{
|
||||||
|
for (auto f: it.second)
|
||||||
|
delete[] f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSUData::ProcessSentMessageAck (uint32_t msgID)
|
||||||
|
{
|
||||||
|
auto it = m_SentMessages.find (msgID);
|
||||||
|
if (it != m_SentMessages.end ())
|
||||||
|
{
|
||||||
|
// delete all ack-ed message's fragments
|
||||||
|
for (auto f: it->second)
|
||||||
|
delete[] f;
|
||||||
|
m_SentMessages.erase (it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("SSU ack received for unknown message ", msgID);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUData::ProcessMessage (uint8_t * buf, size_t len)
|
void SSUData::ProcessMessage (uint8_t * buf, size_t len)
|
||||||
|
@ -32,7 +51,8 @@ namespace ssu
|
||||||
// explicit ACKs
|
// explicit ACKs
|
||||||
uint8_t numAcks =*buf;
|
uint8_t numAcks =*buf;
|
||||||
buf++;
|
buf++;
|
||||||
// TODO: process ACKs
|
for (int i = 0; i < numAcks; i++)
|
||||||
|
ProcessSentMessageAck (be32toh (((uint32_t *)buf)[i]));
|
||||||
buf += numAcks*4;
|
buf += numAcks*4;
|
||||||
}
|
}
|
||||||
if (flag & DATA_FLAG_ACK_BITFIELDS_INCLUDED)
|
if (flag & DATA_FLAG_ACK_BITFIELDS_INCLUDED)
|
||||||
|
@ -42,8 +62,9 @@ namespace ssu
|
||||||
buf++;
|
buf++;
|
||||||
for (int i = 0; i < numBitfields; i++)
|
for (int i = 0; i < numBitfields; i++)
|
||||||
{
|
{
|
||||||
|
ProcessSentMessageAck (be32toh (*(uint32_t *)buf)); // TODO: should be replaced to fragments
|
||||||
buf += 4; // msgID
|
buf += 4; // msgID
|
||||||
// TODO: process ACH bitfields
|
// TODO: process individual Ack bitfields
|
||||||
while (*buf & 0x80) // not last
|
while (*buf & 0x80) // not last
|
||||||
buf++;
|
buf++;
|
||||||
buf++; // last byte
|
buf++; // last byte
|
||||||
|
@ -137,7 +158,9 @@ namespace ssu
|
||||||
|
|
||||||
void SSUData::Send (i2p::I2NPMessage * msg)
|
void SSUData::Send (i2p::I2NPMessage * msg)
|
||||||
{
|
{
|
||||||
uint32_t msgID = htobe32 (msg->ToSSU ());
|
uint32_t msgID = msg->ToSSU ();
|
||||||
|
auto fragments = m_SentMessages[msgID];
|
||||||
|
msgID = htobe32 (msgID);
|
||||||
size_t payloadSize = SSU_MTU - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
|
size_t payloadSize = SSU_MTU - sizeof (SSUHeader) - 9; // 9 = flag + #frg(1) + messageID(4) + frag info (3)
|
||||||
size_t len = msg->GetLength ();
|
size_t len = msg->GetLength ();
|
||||||
uint8_t * msgBuf = msg->GetSSUHeader ();
|
uint8_t * msgBuf = msg->GetSSUHeader ();
|
||||||
|
@ -145,7 +168,9 @@ namespace ssu
|
||||||
uint32_t fragmentNum = 0;
|
uint32_t fragmentNum = 0;
|
||||||
while (len > 0)
|
while (len > 0)
|
||||||
{
|
{
|
||||||
uint8_t buf[SSU_MTU + 18], * payload = buf + sizeof (SSUHeader);
|
uint8_t * buf = new uint8_t[SSU_MTU + 18];
|
||||||
|
fragments.push_back (buf);
|
||||||
|
uint8_t * payload = buf + sizeof (SSUHeader);
|
||||||
*payload = DATA_FLAG_WANT_REPLY; // for compatibility
|
*payload = DATA_FLAG_WANT_REPLY; // for compatibility
|
||||||
payload++;
|
payload++;
|
||||||
*payload = 1; // always 1 message fragment per message
|
*payload = 1; // always 1 message fragment per message
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include "I2NPProtocol.h"
|
#include "I2NPProtocol.h"
|
||||||
|
|
||||||
namespace i2p
|
namespace i2p
|
||||||
|
@ -32,6 +33,7 @@ namespace ssu
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void SendMsgAck (uint32_t msgID);
|
void SendMsgAck (uint32_t msgID);
|
||||||
|
void ProcessSentMessageAck (uint32_t msgID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -45,6 +47,7 @@ namespace ssu
|
||||||
|
|
||||||
SSUSession& m_Session;
|
SSUSession& m_Session;
|
||||||
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
|
std::map<uint32_t, IncompleteMessage *> m_IncomleteMessages;
|
||||||
|
std::map<uint32_t, std::vector<uint8_t *> > m_SentMessages; // msgID -> fragments
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue