Browse Source

skip extended options in SSU header

pull/296/head
orignal 9 years ago
parent
commit
302df75d83
  1. 17
      SSUSession.cpp
  2. 4
      SSUSession.h

17
SSUSession.cpp

@ -131,16 +131,25 @@ namespace transport @@ -131,16 +131,25 @@ namespace transport
}
}
size_t SSUSession::GetSSUHeaderSize (uint8_t * buf) const
{
size_t s = sizeof (SSUHeader);
if (((SSUHeader *)buf)->IsExtendedOptions ())
s += buf[s] + 1; // byte right after header is extended options length
return s;
}
void SSUSession::ProcessMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
{
len -= (len & 0x0F); // %16, delete extra padding
if (len <= sizeof (SSUHeader)) return; // drop empty message
//TODO: since we are accessing a uint8_t this is unlikely to crash due to alignment but should be improved
auto headerSize = GetSSUHeaderSize (buf);
SSUHeader * header = (SSUHeader *)buf;
switch (header->GetPayloadType ())
{
case PAYLOAD_TYPE_DATA:
ProcessData (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
ProcessData (buf + headerSize, len - headerSize);
break;
case PAYLOAD_TYPE_SESSION_REQUEST:
ProcessSessionRequest (buf, len, senderEndpoint);
@ -153,7 +162,7 @@ namespace transport @@ -153,7 +162,7 @@ namespace transport
break;
case PAYLOAD_TYPE_PEER_TEST:
LogPrint (eLogDebug, "SSU peer test received");
ProcessPeerTest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
ProcessPeerTest (buf + headerSize, len - headerSize, senderEndpoint);
break;
case PAYLOAD_TYPE_SESSION_DESTROYED:
{
@ -168,11 +177,11 @@ namespace transport @@ -168,11 +177,11 @@ namespace transport
break;
case PAYLOAD_TYPE_RELAY_REQUEST:
LogPrint (eLogDebug, "SSU relay request received");
ProcessRelayRequest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
ProcessRelayRequest (buf + headerSize, len - headerSize, senderEndpoint);
break;
case PAYLOAD_TYPE_RELAY_INTRO:
LogPrint (eLogDebug, "SSU relay intro received");
ProcessRelayIntro (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
ProcessRelayIntro (buf + headerSize, len - headerSize);
break;
default:
LogPrint (eLogWarning, "Unexpected SSU payload type ", (int)header->GetPayloadType ());

4
SSUSession.h

@ -13,6 +13,7 @@ namespace i2p @@ -13,6 +13,7 @@ namespace i2p
{
namespace transport
{
const uint8_t SSU_HEADER_EXTENDED_OPTIONS_INCLUDED = 0x04;
#pragma pack(1)
struct SSUHeader
{
@ -22,6 +23,7 @@ namespace transport @@ -22,6 +23,7 @@ namespace transport
uint32_t time;
uint8_t GetPayloadType () const { return flag >> 4; };
bool IsExtendedOptions () const { return flag & SSU_HEADER_EXTENDED_OPTIONS_INCLUDED; };
};
#pragma pack()
@ -93,7 +95,7 @@ namespace transport @@ -93,7 +95,7 @@ namespace transport
boost::asio::io_service& GetService ();
void CreateAESandMacKey (const uint8_t * pubKey);
size_t GetSSUHeaderSize (uint8_t * buf) const;
void PostI2NPMessages (std::vector<std::shared_ptr<I2NPMessage> > msgs);
void ProcessMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint); // call for established session
void ProcessSessionRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);

Loading…
Cancel
Save