From 5997cb80bd17fe0f19dec911d7c3a37357bd5513 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 3 Jan 2014 22:25:22 -0500 Subject: [PATCH] differentiate garlic message received from tunnel and directly --- Garlic.cpp | 8 +++++--- Garlic.h | 2 +- I2NPProtocol.cpp | 8 ++++---- I2NPProtocol.h | 4 ++-- NTCPSession.cpp | 7 ++++--- NetDb.cpp | 2 +- Transports.cpp | 2 +- TunnelEndpoint.cpp | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index f9b88126..202949bb 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -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 { // 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 { case eGarlicDeliveryTypeLocal: LogPrint ("Garlic type local"); - i2p::HandleI2NPMessage (buf, len); + i2p::HandleI2NPMessage (buf, len, false); break; case eGarlicDeliveryTypeDestination: { diff --git a/Garlic.h b/Garlic.h index db1f008d..536ed173 100644 --- a/Garlic.h +++ b/Garlic.h @@ -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); diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index 58622fb8..76918bcd 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -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 { 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 } } - void HandleI2NPMessage (I2NPMessage * msg) + void HandleI2NPMessage (I2NPMessage * msg, bool isFromTunnel) { if (msg) { @@ -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); } } diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 2b85744c..597c00b0 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -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 diff --git a/NTCPSession.cpp b/NTCPSession.cpp index 14b74c27..be50e02b 100644 --- a/NTCPSession.cpp +++ b/NTCPSession.cpp @@ -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 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 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 else { LogPrint ("Msg sent: ", bytes_transferred); + ScheduleTermination (); // reset termination timer } } diff --git a/NetDb.cpp b/NetDb.cpp index 89364c1b..264b1631 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -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 (); } diff --git a/Transports.cpp b/Transports.cpp index 9204cea9..e9953eca 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -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)); } diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 1d856e4a..68e741a0 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -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));