From 202109ebeb890628dc30932f33468d1a6f92cf51 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 11 Oct 2014 21:27:55 -0400 Subject: [PATCH] handle I2NP message per destination --- Destination.cpp | 13 +++++++++++++ Destination.h | 1 + Garlic.cpp | 14 ++++---------- I2NPProtocol.cpp | 2 +- I2NPProtocol.h | 2 +- Identity.h | 2 +- RouterContext.cpp | 6 ++++++ RouterContext.h | 2 +- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index e7d70630..fc6fa1a0 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -271,6 +271,19 @@ namespace stream m_Service.post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg)); } + void StreamingDestination::HandleI2NPMessage (const uint8_t * buf, size_t len) + { + I2NPHeader * header = (I2NPHeader *)buf; + switch (header->typeID) + { + case eI2NPData: + HandleDataMessage (buf + sizeof (I2NPHeader), be16toh (header->size)); + break; + default: + i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); + } + } + StreamingDestinations destinations; void StreamingDestinations::Start () { diff --git a/Destination.h b/Destination.h index 6e6a7597..e028d372 100644 --- a/Destination.h +++ b/Destination.h @@ -44,6 +44,7 @@ namespace stream const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; + void HandleI2NPMessage (const uint8_t * buf, size_t len); // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet (); diff --git a/Garlic.cpp b/Garlic.cpp index b238b74f..df3587d0 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -382,19 +382,13 @@ namespace garlic { case eGarlicDeliveryTypeLocal: LogPrint ("Garlic type local"); - i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); + HandleI2NPMessage (buf, len); break; - case eGarlicDeliveryTypeDestination: - { + case eGarlicDeliveryTypeDestination: LogPrint ("Garlic type destination"); buf += 32; // destination. check it later or for multiple destinations - I2NPHeader * header = (I2NPHeader *)buf; - if (header->typeID == eI2NPData) - HandleDataMessage (buf + sizeof (I2NPHeader), be16toh (header->size)); - else - LogPrint ("Unexpected I2NP garlic message ", (int)header->typeID); - break; - } + HandleI2NPMessage (buf, len); + break; case eGarlicDeliveryTypeTunnel: { LogPrint ("Garlic type tunnel"); diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index a48d4f2d..12ee678f 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -508,7 +508,7 @@ namespace i2p } } - size_t GetI2NPMessageLength (uint8_t * msg) + size_t GetI2NPMessageLength (const uint8_t * msg) { I2NPHeader * header = (I2NPHeader *)msg; return be16toh (header->size) + sizeof (I2NPHeader); diff --git a/I2NPProtocol.h b/I2NPProtocol.h index 1493c26f..b96ca02e 100644 --- a/I2NPProtocol.h +++ b/I2NPProtocol.h @@ -200,7 +200,7 @@ namespace tunnel const uint8_t * buf, size_t len, uint32_t replyMsgID = 0); I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg); - size_t GetI2NPMessageLength (uint8_t * msg); + size_t GetI2NPMessageLength (const uint8_t * msg); void HandleI2NPMessage (uint8_t * msg, size_t len); void HandleI2NPMessage (I2NPMessage * msg); } diff --git a/Identity.h b/Identity.h index 95cc6d63..ea036921 100644 --- a/Identity.h +++ b/Identity.h @@ -242,7 +242,7 @@ namespace data virtual const PrivateKeys& GetPrivateKeys () const = 0; virtual const uint8_t * GetEncryptionPrivateKey () const = 0; virtual const uint8_t * GetEncryptionPublicKey () const = 0; - virtual void HandleDataMessage (const uint8_t * buf, size_t len) = 0; + virtual void HandleI2NPMessage (const uint8_t * buf, size_t len) = 0; const IdentityEx& GetIdentity () const { return GetPrivateKeys ().GetPublic (); }; const IdentHash& GetIdentHash () const { return GetIdentity ().GetIdentHash (); }; diff --git a/RouterContext.cpp b/RouterContext.cpp index b5402a75..be1aaaa4 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -4,6 +4,7 @@ #include "CryptoConst.h" #include "RouterContext.h" #include "Timestamp.h" +#include "I2NPProtocol.h" #include "util.h" #include "version.h" @@ -158,4 +159,9 @@ namespace i2p memcpy (keys.signingKey, ident.signingKey, sizeof (keys.signingKey)); fk.write ((char *)&keys, sizeof (keys)); } + + void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len) + { + i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); + } } diff --git a/RouterContext.h b/RouterContext.h index 3dee227e..0c39c0dd 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -41,7 +41,7 @@ namespace i2p const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); }; const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; }; void SetLeaseSetUpdated () {}; - void HandleDataMessage (const uint8_t * buf, size_t len) {}; + void HandleI2NPMessage (const uint8_t * buf, size_t len); // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };