|
|
@ -19,8 +19,27 @@ 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) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//uint8_t * start = buf;
|
|
|
|
//uint8_t * start = buf;
|
|
|
@ -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
|
|
|
|