Browse Source

handle I2NP message per destination

pull/102/head
orignal 10 years ago
parent
commit
202109ebeb
  1. 13
      Destination.cpp
  2. 1
      Destination.h
  3. 14
      Garlic.cpp
  4. 2
      I2NPProtocol.cpp
  5. 2
      I2NPProtocol.h
  6. 2
      Identity.h
  7. 6
      RouterContext.cpp
  8. 2
      RouterContext.h

13
Destination.cpp

@ -271,6 +271,19 @@ namespace stream
m_Service.post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg)); 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; StreamingDestinations destinations;
void StreamingDestinations::Start () void StreamingDestinations::Start ()
{ {

1
Destination.h

@ -44,6 +44,7 @@ namespace stream
const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; }; const i2p::data::PrivateKeys& GetPrivateKeys () const { return m_Keys; };
const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; }; const uint8_t * GetEncryptionPrivateKey () const { return m_EncryptionPrivateKey; };
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionPublicKey; };
void HandleI2NPMessage (const uint8_t * buf, size_t len);
// implements GarlicDestination // implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet (); const i2p::data::LeaseSet * GetLeaseSet ();

14
Garlic.cpp

@ -382,19 +382,13 @@ namespace garlic
{ {
case eGarlicDeliveryTypeLocal: case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local"); LogPrint ("Garlic type local");
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); HandleI2NPMessage (buf, len);
break; break;
case eGarlicDeliveryTypeDestination: case eGarlicDeliveryTypeDestination:
{
LogPrint ("Garlic type destination"); LogPrint ("Garlic type destination");
buf += 32; // destination. check it later or for multiple destinations buf += 32; // destination. check it later or for multiple destinations
I2NPHeader * header = (I2NPHeader *)buf; HandleI2NPMessage (buf, len);
if (header->typeID == eI2NPData) break;
HandleDataMessage (buf + sizeof (I2NPHeader), be16toh (header->size));
else
LogPrint ("Unexpected I2NP garlic message ", (int)header->typeID);
break;
}
case eGarlicDeliveryTypeTunnel: case eGarlicDeliveryTypeTunnel:
{ {
LogPrint ("Garlic type tunnel"); LogPrint ("Garlic type tunnel");

2
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; I2NPHeader * header = (I2NPHeader *)msg;
return be16toh (header->size) + sizeof (I2NPHeader); return be16toh (header->size) + sizeof (I2NPHeader);

2
I2NPProtocol.h

@ -200,7 +200,7 @@ namespace tunnel
const uint8_t * buf, size_t len, uint32_t replyMsgID = 0); const uint8_t * buf, size_t len, uint32_t replyMsgID = 0);
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessage * msg); 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 (uint8_t * msg, size_t len);
void HandleI2NPMessage (I2NPMessage * msg); void HandleI2NPMessage (I2NPMessage * msg);
} }

2
Identity.h

@ -242,7 +242,7 @@ namespace data
virtual const PrivateKeys& GetPrivateKeys () const = 0; virtual const PrivateKeys& GetPrivateKeys () const = 0;
virtual const uint8_t * GetEncryptionPrivateKey () const = 0; virtual const uint8_t * GetEncryptionPrivateKey () const = 0;
virtual const uint8_t * GetEncryptionPublicKey () 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 IdentityEx& GetIdentity () const { return GetPrivateKeys ().GetPublic (); };
const IdentHash& GetIdentHash () const { return GetIdentity ().GetIdentHash (); }; const IdentHash& GetIdentHash () const { return GetIdentity ().GetIdentHash (); };

6
RouterContext.cpp

@ -4,6 +4,7 @@
#include "CryptoConst.h" #include "CryptoConst.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "I2NPProtocol.h"
#include "util.h" #include "util.h"
#include "version.h" #include "version.h"
@ -158,4 +159,9 @@ namespace i2p
memcpy (keys.signingKey, ident.signingKey, sizeof (keys.signingKey)); memcpy (keys.signingKey, ident.signingKey, sizeof (keys.signingKey));
fk.write ((char *)&keys, sizeof (keys)); fk.write ((char *)&keys, sizeof (keys));
} }
void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len)
{
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf)));
}
} }

2
RouterContext.h

@ -41,7 +41,7 @@ namespace i2p
const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); }; const uint8_t * GetEncryptionPrivateKey () const { return m_Keys.GetPrivateKey (); };
const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; }; const uint8_t * GetEncryptionPublicKey () const { return GetIdentity ().GetStandardIdentity ().publicKey; };
void SetLeaseSetUpdated () {}; void SetLeaseSetUpdated () {};
void HandleDataMessage (const uint8_t * buf, size_t len) {}; void HandleI2NPMessage (const uint8_t * buf, size_t len);
// implements GarlicDestination // implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; }; const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };

Loading…
Cancel
Save