Browse Source

send ack per fragment. temporary disble check for duplicated through IV

pull/93/head
orignal 11 years ago
parent
commit
2f601ce02f
  1. 4
      SSU.cpp
  2. 33
      SSUData.cpp
  3. 1
      SSUData.h

4
SSU.cpp

@ -84,10 +84,10 @@ namespace ssu @@ -84,10 +84,10 @@ namespace ssu
else
{
ScheduleTermination ();
// check for duplicate
/* // check for duplicate
const uint8_t * iv = ((SSUHeader *)buf)->iv;
if (m_ReceivedIVs.count (iv)) return; // duplicate detected
m_ReceivedIVs.insert (iv);
m_ReceivedIVs.insert (iv);*/
if (m_IsSessionKey && Validate (buf, len, m_MacKey)) // try session key first
DecryptSessionKey (buf, len);

33
SSUData.cpp

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
#include <stdlib.h>
#include "Log.h"
#include "SSU.h"
#include "SSUData.h"
@ -173,6 +174,8 @@ namespace ssu @@ -173,6 +174,8 @@ namespace ssu
DeleteI2NPMessage (msg);
}
}
else
SendFragmentAck (msgID, fragmentNum);
buf += fragmentSize;
}
}
@ -252,6 +255,36 @@ namespace ssu @@ -252,6 +255,36 @@ namespace ssu
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, 48);
m_Session.Send (buf, 48);
}
void SSUData::SendFragmentAck (uint32_t msgID, int fragmentNum)
{
if (fragmentNum > 64)
{
LogPrint ("Fragment number ", fragmentNum, " exceeds 64");
return;
}
uint8_t buf[64 + 18];
uint8_t * payload = buf + sizeof (SSUHeader);
*payload = DATA_FLAG_ACK_BITFIELDS_INCLUDED; // flag
payload++;
*payload = 1; // number of ACK bitfields
payload++;
// one ack
*(uint32_t *)(payload) = htobe32 (msgID); // msgID
payload += 4;
div_t d = div (fragmentNum, 7);
memset (payload, 0x80, d.quot); // 0x80 means non-last
payload += d.quot;
*payload = 0x40 >> d.rem; // set corresponding bit
payload++;
*payload = 0; // number of fragments
size_t len = d.quot < 4 ? 48 : 64; // 48 = 37 + 7 + 4 (3+1)
// encrypt message with session key
m_Session.FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, len);
m_Session.Send (buf, len);
}
}
}

1
SSUData.h

@ -64,6 +64,7 @@ namespace ssu @@ -64,6 +64,7 @@ namespace ssu
private:
void SendMsgAck (uint32_t msgID);
void SendFragmentAck (uint32_t msgID, int fragmentNum);
void ProcessSentMessageAck (uint32_t msgID);
private:

Loading…
Cancel
Save