Browse Source

inbound tunnel where an I2NP messages has been received from

pull/46/head
orignal 11 years ago
parent
commit
6732ba21f9
  1. 9
      Garlic.cpp
  2. 3
      Garlic.h
  3. 18
      I2NPProtocol.cpp
  4. 11
      I2NPProtocol.h
  5. 2
      NTCPSession.cpp
  6. 2
      NetDb.cpp
  7. 2
      SSU.cpp
  8. 2
      Transports.cpp
  9. 1
      Tunnel.cpp
  10. 2
      TunnelEndpoint.cpp

9
Garlic.cpp

@ -262,8 +262,9 @@ namespace garlic
return ret; return ret;
} }
void GarlicRouting::HandleGarlicMessage (uint8_t * buf, size_t len, bool isFromTunnel) void GarlicRouting::HandleGarlicMessage (I2NPMessage * msg)
{ {
uint8_t * buf = msg->GetPayload ();
uint32_t length = be32toh (*(uint32_t *)buf); uint32_t length = be32toh (*(uint32_t *)buf);
buf += 4; buf += 4;
std::string sessionTag((const char *)buf, 32); std::string sessionTag((const char *)buf, 32);
@ -284,7 +285,7 @@ namespace garlic
// new session // new session
ElGamalBlock elGamal; ElGamalBlock elGamal;
if (i2p::crypto::ElGamalDecrypt ( if (i2p::crypto::ElGamalDecrypt (
isFromTunnel ? i2p::context.GetLeaseSetPrivateKey () : i2p::context.GetPrivateKey (), msg->from ? i2p::context.GetLeaseSetPrivateKey () : i2p::context.GetPrivateKey (),
buf, (uint8_t *)&elGamal, true)) buf, (uint8_t *)&elGamal, true))
{ {
uint8_t iv[32]; // IV is first 16 bytes uint8_t iv[32]; // IV is first 16 bytes
@ -296,7 +297,7 @@ namespace garlic
else else
LogPrint ("Failed to decrypt garlic"); LogPrint ("Failed to decrypt garlic");
} }
DeleteI2NPMessage (msg);
} }
void GarlicRouting::HandleAESBlock (uint8_t * buf, size_t len, uint8_t * sessionKey) void GarlicRouting::HandleAESBlock (uint8_t * buf, size_t len, uint8_t * sessionKey)
@ -351,7 +352,7 @@ namespace garlic
{ {
case eGarlicDeliveryTypeLocal: case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local"); LogPrint ("Garlic type local");
i2p::HandleI2NPMessage (buf, len, false); i2p::HandleI2NPMessage (buf, len);
break; break;
case eGarlicDeliveryTypeDestination: case eGarlicDeliveryTypeDestination:
{ {

3
Garlic.h

@ -9,6 +9,7 @@
#include <cryptopp/osrng.h> #include <cryptopp/osrng.h>
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Tunnel.h"
namespace i2p namespace i2p
{ {
@ -75,7 +76,7 @@ namespace garlic
GarlicRouting (); GarlicRouting ();
~GarlicRouting (); ~GarlicRouting ();
void HandleGarlicMessage (uint8_t * buf, size_t len, bool isFromTunnel); void HandleGarlicMessage (I2NPMessage * msg);
void HandleDeliveryStatusMessage (uint8_t * buf, size_t len); void HandleDeliveryStatusMessage (uint8_t * buf, size_t len);
I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg); I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination& destination, I2NPMessage * msg);

18
I2NPProtocol.cpp

@ -22,6 +22,7 @@ namespace i2p
I2NPMessage * msg = new I2NPMessage; I2NPMessage * msg = new I2NPMessage;
msg->offset = 2; // reserve 2 bytes for NTCP header, should reserve more for SSU in future msg->offset = 2; // reserve 2 bytes for NTCP header, should reserve more for SSU in future
msg->len = sizeof (I2NPHeader) + 2; msg->len = sizeof (I2NPHeader) + 2;
msg->from = nullptr;
return msg; return msg;
} }
@ -414,7 +415,7 @@ namespace i2p
return be16toh (header->size) + sizeof (I2NPHeader); return be16toh (header->size) + sizeof (I2NPHeader);
} }
void HandleI2NPMessage (uint8_t * msg, size_t len, bool isFromTunnel) void HandleI2NPMessage (uint8_t * msg, size_t len)
{ {
I2NPHeader * header = (I2NPHeader *)msg; I2NPHeader * header = (I2NPHeader *)msg;
uint32_t msgID = be32toh (header->msgID); uint32_t msgID = be32toh (header->msgID);
@ -423,12 +424,7 @@ namespace i2p
uint8_t * buf = msg + sizeof (I2NPHeader); uint8_t * buf = msg + sizeof (I2NPHeader);
int size = be16toh (header->size); int size = be16toh (header->size);
switch (header->typeID) switch (header->typeID)
{ {
case eI2NPGarlic:
LogPrint ("Garlic");
i2p::garlic::routing.HandleGarlicMessage (buf, size, isFromTunnel);
break;
break;
case eI2NPDeliveryStatus: case eI2NPDeliveryStatus:
LogPrint ("DeliveryStatus"); LogPrint ("DeliveryStatus");
// we assume DeliveryStatusMessage is sent with garlic only // we assume DeliveryStatusMessage is sent with garlic only
@ -451,7 +447,7 @@ namespace i2p
} }
} }
void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel) void HandleI2NPMessage (I2NPMessage * msg)
{ {
if (msg) if (msg)
{ {
@ -473,8 +469,12 @@ namespace i2p
LogPrint ("DatabaseSearchReply"); LogPrint ("DatabaseSearchReply");
i2p::data::netdb.PostI2NPMsg (msg); i2p::data::netdb.PostI2NPMsg (msg);
break; break;
case eI2NPGarlic:
LogPrint ("Garlic");
i2p::garlic::routing.HandleGarlicMessage (msg);
break;
default: default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength (), isFromTunnel); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
} }
} }

11
I2NPProtocol.h

@ -91,11 +91,17 @@ namespace i2p
eI2NPVariableTunnelBuildReply = 24 eI2NPVariableTunnelBuildReply = 24
}; };
namespace tunnel
{
class InboundTunnel;
}
const int NTCP_MAX_MESSAGE_SIZE = 16384; const int NTCP_MAX_MESSAGE_SIZE = 16384;
struct I2NPMessage struct I2NPMessage
{ {
uint8_t buf[NTCP_MAX_MESSAGE_SIZE]; uint8_t buf[NTCP_MAX_MESSAGE_SIZE];
size_t len, offset; size_t len, offset;
i2p::tunnel::InboundTunnel * from;
I2NPHeader * GetHeader () { return (I2NPHeader *)(buf + offset); }; I2NPHeader * GetHeader () { return (I2NPHeader *)(buf + offset); };
uint8_t * GetPayload () { return buf + offset + sizeof(I2NPHeader); }; uint8_t * GetPayload () { return buf + offset + sizeof(I2NPHeader); };
@ -106,6 +112,7 @@ namespace i2p
{ {
memcpy (buf + offset, other.buf + other.offset, other.GetLength ()); memcpy (buf + offset, other.buf + other.offset, other.GetLength ());
len = offset + other.GetLength (); len = offset + other.GetLength ();
from = other.from;
return *this; return *this;
} }
@ -169,8 +176,8 @@ namespace i2p
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg); I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg);
size_t GetI2NPMessageLength (uint8_t * msg); size_t GetI2NPMessageLength (uint8_t * msg);
void HandleI2NPMessage (uint8_t * msg, size_t len, bool isFromTunnel); void HandleI2NPMessage (uint8_t * msg, size_t len);
void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel); void HandleI2NPMessage (I2NPMessage * msg);
} }
#endif #endif

2
NTCPSession.cpp

@ -424,7 +424,7 @@ namespace ntcp
if (m_NextMessageOffset >= m_NextMessage->len + 4) // +checksum if (m_NextMessageOffset >= m_NextMessage->len + 4) // +checksum
{ {
// we have a complete I2NP message // we have a complete I2NP message
i2p::HandleI2NPMessage (m_NextMessage, false); i2p::HandleI2NPMessage (m_NextMessage);
m_NextMessage = nullptr; m_NextMessage = nullptr;
} }
} }

2
NetDb.cpp

@ -111,7 +111,7 @@ namespace data
else // WTF? else // WTF?
{ {
LogPrint ("NetDb: unexpected message type ", msg->GetHeader ()->typeID); LogPrint ("NetDb: unexpected message type ", msg->GetHeader ()->typeID);
i2p::HandleI2NPMessage (msg, false); i2p::HandleI2NPMessage (msg);
} }
msg = m_Queue.Get (); msg = m_Queue.Get ();
} }

2
SSU.cpp

@ -614,7 +614,7 @@ namespace ssu
m_IncomleteMessages.erase (msgID); m_IncomleteMessages.erase (msgID);
msg->FromSSU (msgID); msg->FromSSU (msgID);
if (m_State == eSessionStateEstablished) if (m_State == eSessionStateEstablished)
i2p::HandleI2NPMessage (msg, false); i2p::HandleI2NPMessage (msg);
else else
{ {
// we expect DeliveryStatus // we expect DeliveryStatus

2
Transports.cpp

@ -148,7 +148,7 @@ namespace i2p
{ {
if (ident == i2p::context.GetRouterInfo ().GetIdentHash ()) if (ident == i2p::context.GetRouterInfo ().GetIdentHash ())
// we send it to ourself // we send it to ourself
i2p::HandleI2NPMessage (msg, false); i2p::HandleI2NPMessage (msg);
else else
m_Service.post (boost::bind (&Transports::PostMessage, this, ident, msg)); m_Service.post (boost::bind (&Transports::PostMessage, this, ident, msg));
} }

1
Tunnel.cpp

@ -130,6 +130,7 @@ namespace tunnel
void InboundTunnel::HandleTunnelDataMsg (I2NPMessage * msg) void InboundTunnel::HandleTunnelDataMsg (I2NPMessage * msg)
{ {
msg->from = this;
EncryptTunnelMsg (msg); EncryptTunnelMsg (msg);
m_Endpoint.HandleDecryptedTunnelDataMsg (msg); m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
} }

2
TunnelEndpoint.cpp

@ -147,7 +147,7 @@ namespace tunnel
switch (msg.deliveryType) switch (msg.deliveryType)
{ {
case eDeliveryTypeLocal: case eDeliveryTypeLocal:
i2p::HandleI2NPMessage (msg.data, true); i2p::HandleI2NPMessage (msg.data);
break; break;
case eDeliveryTypeTunnel: case eDeliveryTypeTunnel:
i2p::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data)); i2p::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data));

Loading…
Cancel
Save