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 @@ -185,7 +185,7 @@ namespace garlic
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);
buf += 4;
@ -203,7 +203,9 @@ namespace garlic @@ -203,7 +203,9 @@ namespace garlic
{
// new session
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);
uint8_t iv[32]; // IV is first 16 bytes
CryptoPP::SHA256().CalculateDigest(iv, elGamal.preIV, 32);
@ -252,7 +254,7 @@ namespace garlic @@ -252,7 +254,7 @@ namespace garlic
{
case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local");
i2p::HandleI2NPMessage (buf, len);
i2p::HandleI2NPMessage (buf, len, false);
break;
case eGarlicDeliveryTypeDestination:
{

2
Garlic.h

@ -67,7 +67,7 @@ namespace garlic @@ -67,7 +67,7 @@ namespace garlic
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 * msg, I2NPMessage * leaseSet = nullptr);

8
I2NPProtocol.cpp

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

4
I2NPProtocol.h

@ -132,8 +132,8 @@ namespace i2p @@ -132,8 +132,8 @@ namespace i2p
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg);
size_t GetI2NPMessageLength (uint8_t * msg);
void HandleI2NPMessage (uint8_t * msg, size_t len);
void HandleI2NPMessage (I2NPMessage * msg);
void HandleI2NPMessage (uint8_t * msg, size_t len, bool isFromTunnel);
void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel);
}
#endif

7
NTCPSession.cpp

@ -384,7 +384,8 @@ namespace ntcp @@ -384,7 +384,8 @@ namespace ntcp
if (m_ReceiveBufferOffset > 0)
memcpy (m_ReceiveBuffer, nextBlock, m_ReceiveBufferOffset);
}
ScheduleTermination (); // reset termination timer
Receive ();
}
}
@ -423,7 +424,7 @@ namespace ntcp @@ -423,7 +424,7 @@ namespace ntcp
if (m_NextMessageOffset >= m_NextMessage->len + 4) // +checksum
{
// we have a complete I2NP message
i2p::HandleI2NPMessage (m_NextMessage);
i2p::HandleI2NPMessage (m_NextMessage, false);
m_NextMessage = nullptr;
}
}
@ -464,7 +465,6 @@ namespace ntcp @@ -464,7 +465,6 @@ namespace ntcp
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));
ScheduleTermination (); // reset termination timer
}
void NTCPSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, i2p::I2NPMessage * msg)
@ -479,6 +479,7 @@ namespace ntcp @@ -479,6 +479,7 @@ namespace ntcp
else
{
LogPrint ("Msg sent: ", bytes_transferred);
ScheduleTermination (); // reset termination timer
}
}

2
NetDb.cpp

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

2
Transports.cpp

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

2
TunnelEndpoint.cpp

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

Loading…
Cancel
Save