From 05d869254df909f41889eb40d29cfa07129197c9 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 17 Jul 2014 15:22:32 -0400 Subject: [PATCH] process extended data --- SSUData.cpp | 35 ++++++++++++++++++++++++++++------- SSUData.h | 2 ++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/SSUData.cpp b/SSUData.cpp index d6b9e6e7..bf9135cc 100644 --- a/SSUData.cpp +++ b/SSUData.cpp @@ -39,12 +39,8 @@ namespace ssu } } - void SSUData::ProcessMessage (uint8_t * buf, size_t len) + void SSUData::ProcessAcks (uint8_t *& buf, uint8_t flag) { - //uint8_t * start = buf; - uint8_t flag = *buf; - buf++; - LogPrint ("Process SSU data flags=", (int)flag); if (flag & DATA_FLAG_EXPLICIT_ACKS_INCLUDED) { // explicit ACKs @@ -83,7 +79,7 @@ namespace ssu { if (fragment < numSentFragments) { - delete it->second[fragment]; + delete[] it->second[fragment]; it->second[fragment] = nullptr; } } @@ -95,7 +91,11 @@ namespace ssu } while (isNonLast); } - } + } + } + + void SSUData::ProcessFragments (uint8_t * buf) + { uint8_t numFragments = *buf; // number of fragments buf++; for (int i = 0; i < numFragments; i++) @@ -208,6 +208,27 @@ namespace ssu } } + void SSUData::ProcessMessage (uint8_t * buf, size_t len) + { + //uint8_t * start = buf; + uint8_t flag = *buf; + buf++; + LogPrint ("Process SSU data flags=", (int)flag); + // process acks if presented + if (flag & (DATA_FLAG_ACK_BITFIELDS_INCLUDED | DATA_FLAG_EXPLICIT_ACKS_INCLUDED)) + ProcessAcks (buf, flag); + // extended data if presented + if (flag & DATA_FLAG_EXTENDED_DATA_INCLUDED) + { + uint8_t extendedDataSize = *buf; + buf++; // size + LogPrint ("SSU extended data of ", extendedDataSize, " bytes presented"); + buf += extendedDataSize; + } + // process data + ProcessFragments (buf); + } + void SSUData::Send (i2p::I2NPMessage * msg) { uint32_t msgID = msg->ToSSU (); diff --git a/SSUData.h b/SSUData.h index 603f50b8..9cc548e0 100644 --- a/SSUData.h +++ b/SSUData.h @@ -65,6 +65,8 @@ namespace ssu void SendMsgAck (uint32_t msgID); void SendFragmentAck (uint32_t msgID, int fragmentNum); + void ProcessAcks (uint8_t *& buf, uint8_t flag); + void ProcessFragments (uint8_t * buf); void ProcessSentMessageAck (uint32_t msgID); private: