Browse Source

differentiate garlic message received from tunnel and directly

pull/8/head
orignal 11 years ago
parent
commit
5997cb80bd
  1. 8
      Garlic.cpp
  2. 2
      Garlic.h
  3. 8
      I2NPProtocol.cpp
  4. 4
      I2NPProtocol.h
  5. 7
      NTCPSession.cpp
  6. 2
      NetDb.cpp
  7. 2
      Transports.cpp
  8. 2
      TunnelEndpoint.cpp

8
Garlic.cpp

@ -185,7 +185,7 @@ namespace garlic
return ret; return ret;
} }
void GarlicRouting::HandleGarlicMessage (uint8_t * buf, size_t len) void GarlicRouting::HandleGarlicMessage (uint8_t * buf, size_t len, bool isFromTunnel)
{ {
uint32_t length = be32toh (*(uint32_t *)buf); uint32_t length = be32toh (*(uint32_t *)buf);
buf += 4; buf += 4;
@ -203,7 +203,9 @@ namespace garlic
{ {
// new session // new session
ElGamalBlock elGamal; ElGamalBlock elGamal;
i2p::crypto::ElGamalDecrypt (i2p::context.GetLeaseSetPrivateKey (), buf, (uint8_t *)&elGamal, true); i2p::crypto::ElGamalDecrypt (
isFromTunnel ? i2p::context.GetLeaseSetPrivateKey () : i2p::context.GetPrivateKey (),
buf, (uint8_t *)&elGamal, true);
memcpy (m_SessionKey, elGamal.sessionKey, 32); memcpy (m_SessionKey, elGamal.sessionKey, 32);
uint8_t iv[32]; // IV is first 16 bytes uint8_t iv[32]; // IV is first 16 bytes
CryptoPP::SHA256().CalculateDigest(iv, elGamal.preIV, 32); CryptoPP::SHA256().CalculateDigest(iv, elGamal.preIV, 32);
@ -252,7 +254,7 @@ namespace garlic
{ {
case eGarlicDeliveryTypeLocal: case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local"); LogPrint ("Garlic type local");
i2p::HandleI2NPMessage (buf, len); i2p::HandleI2NPMessage (buf, len, false);
break; break;
case eGarlicDeliveryTypeDestination: case eGarlicDeliveryTypeDestination:
{ {

2
Garlic.h

@ -67,7 +67,7 @@ namespace garlic
GarlicRouting (); GarlicRouting ();
~GarlicRouting (); ~GarlicRouting ();
void HandleGarlicMessage (uint8_t * buf, size_t len); void HandleGarlicMessage (uint8_t * buf, size_t len, bool isFromTunnel);
I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination * destination, I2NPMessage * WrapSingleMessage (const i2p::data::RoutingDestination * destination,
I2NPMessage * msg, I2NPMessage * leaseSet = nullptr); I2NPMessage * msg, I2NPMessage * leaseSet = nullptr);

8
I2NPProtocol.cpp

@ -370,7 +370,7 @@ namespace i2p
return be16toh (header->size) + sizeof (I2NPHeader); return be16toh (header->size) + sizeof (I2NPHeader);
} }
void HandleI2NPMessage (uint8_t * msg, size_t len) void HandleI2NPMessage (uint8_t * msg, size_t len, bool isFromTunnel)
{ {
I2NPHeader * header = (I2NPHeader *)msg; I2NPHeader * header = (I2NPHeader *)msg;
uint32_t msgID = be32toh (header->msgID); uint32_t msgID = be32toh (header->msgID);
@ -382,7 +382,7 @@ namespace i2p
{ {
case eI2NPGarlic: case eI2NPGarlic:
LogPrint ("Garlic"); LogPrint ("Garlic");
i2p::garlic::routing.HandleGarlicMessage (buf, size); i2p::garlic::routing.HandleGarlicMessage (buf, size, isFromTunnel);
break; break;
break; break;
case eI2NPDeliveryStatus: case eI2NPDeliveryStatus:
@ -401,7 +401,7 @@ namespace i2p
} }
} }
void HandleI2NPMessage (I2NPMessage * msg) void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel)
{ {
if (msg) if (msg)
{ {
@ -424,7 +424,7 @@ namespace i2p
i2p::data::netdb.PostI2NPMsg (msg); i2p::data::netdb.PostI2NPMsg (msg);
break; break;
default: default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength (), isFromTunnel);
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
} }
} }

4
I2NPProtocol.h

@ -132,8 +132,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); void HandleI2NPMessage (uint8_t * msg, size_t len, bool isFromTunnel);
void HandleI2NPMessage (I2NPMessage * msg); void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel);
} }
#endif #endif

7
NTCPSession.cpp

@ -384,7 +384,8 @@ namespace ntcp
if (m_ReceiveBufferOffset > 0) if (m_ReceiveBufferOffset > 0)
memcpy (m_ReceiveBuffer, nextBlock, m_ReceiveBufferOffset); memcpy (m_ReceiveBuffer, nextBlock, m_ReceiveBufferOffset);
} }
ScheduleTermination (); // reset termination timer
Receive (); Receive ();
} }
} }
@ -423,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); i2p::HandleI2NPMessage (m_NextMessage, false);
m_NextMessage = nullptr; m_NextMessage = nullptr;
} }
} }
@ -464,7 +465,6 @@ namespace ntcp
boost::asio::async_write (m_Socket, boost::asio::buffer (sendBuffer, l), boost::asio::transfer_all (), boost::asio::async_write (m_Socket, boost::asio::buffer (sendBuffer, l), boost::asio::transfer_all (),
boost::bind(&NTCPSession::HandleSent, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, msg)); boost::bind(&NTCPSession::HandleSent, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred, msg));
ScheduleTermination (); // reset termination timer
} }
void NTCPSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, i2p::I2NPMessage * msg) void NTCPSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, i2p::I2NPMessage * msg)
@ -479,6 +479,7 @@ namespace ntcp
else else
{ {
LogPrint ("Msg sent: ", bytes_transferred); LogPrint ("Msg sent: ", bytes_transferred);
ScheduleTermination (); // reset termination timer
} }
} }

2
NetDb.cpp

@ -71,7 +71,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); i2p::HandleI2NPMessage (msg, false);
} }
msg = m_Queue.Get (); msg = m_Queue.Get ();
} }

2
Transports.cpp

@ -123,7 +123,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); i2p::HandleI2NPMessage (msg, false);
else else
m_Service.post (boost::bind (&Transports::PostMessage, this, ident, msg)); m_Service.post (boost::bind (&Transports::PostMessage, this, ident, msg));
} }

2
TunnelEndpoint.cpp

@ -147,7 +147,7 @@ namespace tunnel
switch (msg.deliveryType) switch (msg.deliveryType)
{ {
case eDeliveryTypeLocal: case eDeliveryTypeLocal:
i2p::HandleI2NPMessage (msg.data); i2p::HandleI2NPMessage (msg.data, true);
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