mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
skip extended options in SSU header
This commit is contained in:
parent
11b7e637e9
commit
302df75d83
@ -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)
|
void SSUSession::ProcessMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
|
||||||
{
|
{
|
||||||
len -= (len & 0x0F); // %16, delete extra padding
|
len -= (len & 0x0F); // %16, delete extra padding
|
||||||
if (len <= sizeof (SSUHeader)) return; // drop empty message
|
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
|
//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;
|
SSUHeader * header = (SSUHeader *)buf;
|
||||||
switch (header->GetPayloadType ())
|
switch (header->GetPayloadType ())
|
||||||
{
|
{
|
||||||
case PAYLOAD_TYPE_DATA:
|
case PAYLOAD_TYPE_DATA:
|
||||||
ProcessData (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
|
ProcessData (buf + headerSize, len - headerSize);
|
||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_SESSION_REQUEST:
|
case PAYLOAD_TYPE_SESSION_REQUEST:
|
||||||
ProcessSessionRequest (buf, len, senderEndpoint);
|
ProcessSessionRequest (buf, len, senderEndpoint);
|
||||||
@ -153,7 +162,7 @@ namespace transport
|
|||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_PEER_TEST:
|
case PAYLOAD_TYPE_PEER_TEST:
|
||||||
LogPrint (eLogDebug, "SSU peer test received");
|
LogPrint (eLogDebug, "SSU peer test received");
|
||||||
ProcessPeerTest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
|
ProcessPeerTest (buf + headerSize, len - headerSize, senderEndpoint);
|
||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_SESSION_DESTROYED:
|
case PAYLOAD_TYPE_SESSION_DESTROYED:
|
||||||
{
|
{
|
||||||
@ -168,11 +177,11 @@ namespace transport
|
|||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_RELAY_REQUEST:
|
case PAYLOAD_TYPE_RELAY_REQUEST:
|
||||||
LogPrint (eLogDebug, "SSU relay request received");
|
LogPrint (eLogDebug, "SSU relay request received");
|
||||||
ProcessRelayRequest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
|
ProcessRelayRequest (buf + headerSize, len - headerSize, senderEndpoint);
|
||||||
break;
|
break;
|
||||||
case PAYLOAD_TYPE_RELAY_INTRO:
|
case PAYLOAD_TYPE_RELAY_INTRO:
|
||||||
LogPrint (eLogDebug, "SSU relay intro received");
|
LogPrint (eLogDebug, "SSU relay intro received");
|
||||||
ProcessRelayIntro (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
|
ProcessRelayIntro (buf + headerSize, len - headerSize);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LogPrint (eLogWarning, "Unexpected SSU payload type ", (int)header->GetPayloadType ());
|
LogPrint (eLogWarning, "Unexpected SSU payload type ", (int)header->GetPayloadType ());
|
||||||
|
@ -13,6 +13,7 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
namespace transport
|
namespace transport
|
||||||
{
|
{
|
||||||
|
const uint8_t SSU_HEADER_EXTENDED_OPTIONS_INCLUDED = 0x04;
|
||||||
#pragma pack(1)
|
#pragma pack(1)
|
||||||
struct SSUHeader
|
struct SSUHeader
|
||||||
{
|
{
|
||||||
@ -22,6 +23,7 @@ namespace transport
|
|||||||
uint32_t time;
|
uint32_t time;
|
||||||
|
|
||||||
uint8_t GetPayloadType () const { return flag >> 4; };
|
uint8_t GetPayloadType () const { return flag >> 4; };
|
||||||
|
bool IsExtendedOptions () const { return flag & SSU_HEADER_EXTENDED_OPTIONS_INCLUDED; };
|
||||||
};
|
};
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
@ -93,7 +95,7 @@ namespace transport
|
|||||||
|
|
||||||
boost::asio::io_service& GetService ();
|
boost::asio::io_service& GetService ();
|
||||||
void CreateAESandMacKey (const uint8_t * pubKey);
|
void CreateAESandMacKey (const uint8_t * pubKey);
|
||||||
|
size_t GetSSUHeaderSize (uint8_t * buf) const;
|
||||||
void PostI2NPMessages (std::vector<std::shared_ptr<I2NPMessage> > msgs);
|
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 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);
|
void ProcessSessionRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user