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 @@ -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 ()
{

1
Destination.h

@ -44,6 +44,7 @@ namespace stream @@ -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 ();

14
Garlic.cpp

@ -382,19 +382,13 @@ namespace garlic @@ -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");

2
I2NPProtocol.cpp

@ -508,7 +508,7 @@ namespace i2p @@ -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);

2
I2NPProtocol.h

@ -200,7 +200,7 @@ namespace tunnel @@ -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);
}

2
Identity.h

@ -242,7 +242,7 @@ namespace data @@ -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 (); };

6
RouterContext.cpp

@ -4,6 +4,7 @@ @@ -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 @@ -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)));
}
}

2
RouterContext.h

@ -41,7 +41,7 @@ namespace i2p @@ -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; };

Loading…
Cancel
Save