Browse Source

handle SSU I2NP header

pull/36/head
orignal 11 years ago
parent
commit
656392fe1e
  1. 20
      I2NPProtocol.h
  2. 14
      SSU.cpp

20
I2NPProtocol.h

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <set> #include <set>
#include <string.h> #include <string.h>
#include "I2PEndian.h"
#include "RouterInfo.h" #include "RouterInfo.h"
namespace i2p namespace i2p
@ -19,6 +20,12 @@ namespace i2p
uint8_t chks; uint8_t chks;
}; };
struct I2NPHeaderShort
{
uint8_t typeID;
uint32_t shortExpiration;
};
struct I2NPDatabaseStoreMsg struct I2NPDatabaseStoreMsg
{ {
uint8_t key[32]; uint8_t key[32];
@ -101,6 +108,19 @@ namespace i2p
len = offset + other.GetLength (); len = offset + other.GetLength ();
return *this; return *this;
} }
// for SSU only
uint8_t * GetSSUHeader () { return buf + offset + sizeof(I2NPHeader) - sizeof(I2NPHeaderShort); };
void FromSSU (uint32_t msgID) // we have received SSU message and convert it to regular
{
I2NPHeaderShort ssu = *(I2NPHeaderShort *)GetSSUHeader ();
I2NPHeader * header = GetHeader ();
header->typeID = ssu.typeID;
header->msgID = htobe32 (msgID);
header->expiration = htobe64 (be32toh (ssu.shortExpiration)*1000LL);
header->size = htobe16 (len - offset - sizeof (I2NPHeader));
header->chks = 0;
}
}; };
I2NPMessage * NewI2NPMessage (); I2NPMessage * NewI2NPMessage ();
void DeleteI2NPMessage (I2NPMessage * msg); void DeleteI2NPMessage (I2NPMessage * msg);

14
SSU.cpp

@ -388,23 +388,31 @@ 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; msg = it->second;
memcpy (msg->buf + msg->len, buf, fragmentSize);
msg->len += fragmentSize;
}
else else
// TODO: // TODO:
LogPrint ("Unexpected follow-on fragment ", fragmentNum, " of message ", msgID); LogPrint ("Unexpected follow-on fragment ", fragmentNum, " of message ", msgID);
} }
else // first fragment else // first fragment
{
msg = NewI2NPMessage (); msg = NewI2NPMessage ();
memcpy (msg->GetSSUHeader (), buf, fragmentSize);
msg->len += fragmentSize - sizeof (I2NPHeaderShort);
}
if (msg) if (msg)
{ {
memcpy (msg->buf + msg->len, buf, fragmentSize);
msg->len += fragmentSize;
if (!fragmentNum && !isLast) if (!fragmentNum && !isLast)
m_IncomleteMessages[msgID] = msg; m_IncomleteMessages[msgID] = msg;
if (isLast) if (isLast)
{ {
if (fragmentNum > 0) if (fragmentNum > 0)
m_IncomleteMessages.erase (msgID); m_IncomleteMessages.erase (msgID);
msg->FromSSU (msgID);
i2p::HandleI2NPMessage (msg, false); i2p::HandleI2NPMessage (msg, false);
} }
} }

Loading…
Cancel
Save