mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
find local destination by tunnel garlic came from
This commit is contained in:
parent
7fb93ca853
commit
400b4e7110
|
@ -157,6 +157,33 @@ namespace stream
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StreamingDestination::HandleDataMessage (const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
uint32_t length = be32toh (*(uint32_t *)buf);
|
||||||
|
buf += 4;
|
||||||
|
// we assume I2CP payload
|
||||||
|
if (buf[9] == 6) // streaming protocol
|
||||||
|
{
|
||||||
|
// unzip it
|
||||||
|
CryptoPP::Gunzip decompressor;
|
||||||
|
decompressor.Put (buf, length);
|
||||||
|
decompressor.MessageEnd();
|
||||||
|
Packet * uncompressed = new Packet;
|
||||||
|
uncompressed->offset = 0;
|
||||||
|
uncompressed->len = decompressor.MaxRetrievable ();
|
||||||
|
if (uncompressed->len > MAX_PACKET_SIZE)
|
||||||
|
{
|
||||||
|
LogPrint ("Received packet size ", uncompressed->len, " exceeds max packet size");
|
||||||
|
uncompressed->len = MAX_PACKET_SIZE;
|
||||||
|
}
|
||||||
|
decompressor.Get (uncompressed->buf, uncompressed->len);
|
||||||
|
// then forward to streaming thread
|
||||||
|
m_Service.post (boost::bind (&StreamingDestination::HandleNextPacket, this, uncompressed));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
LogPrint ("Data: unexpected protocol ", buf[9]);
|
||||||
|
}
|
||||||
|
|
||||||
void StreamingDestination::SetLeaseSetUpdated ()
|
void StreamingDestination::SetLeaseSetUpdated ()
|
||||||
{
|
{
|
||||||
UpdateLeaseSet ();
|
UpdateLeaseSet ();
|
||||||
|
@ -283,23 +310,6 @@ namespace stream
|
||||||
stream->GetLocalDestination ()->DeleteStream (stream);
|
stream->GetLocalDestination ()->DeleteStream (stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void StreamingDestinations::HandleNextPacket (i2p::data::IdentHash destination, Packet * packet)
|
|
||||||
{
|
|
||||||
m_Service.post (boost::bind (&StreamingDestinations::PostNextPacket, this, destination, packet));
|
|
||||||
}
|
|
||||||
|
|
||||||
void StreamingDestinations::PostNextPacket (i2p::data::IdentHash destination, Packet * packet)
|
|
||||||
{
|
|
||||||
auto it = m_Destinations.find (destination);
|
|
||||||
if (it != m_Destinations.end ())
|
|
||||||
it->second->HandleNextPacket (packet);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogPrint ("Local destination ", destination.ToBase64 (), " not found");
|
|
||||||
delete packet;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const
|
StreamingDestination * StreamingDestinations::FindLocalDestination (const i2p::data::IdentHash& destination) const
|
||||||
{
|
{
|
||||||
auto it = m_Destinations.find (destination);
|
auto it = m_Destinations.find (destination);
|
||||||
|
@ -363,33 +373,6 @@ namespace stream
|
||||||
return destinations;
|
return destinations;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len)
|
|
||||||
{
|
|
||||||
uint32_t length = be32toh (*(uint32_t *)buf);
|
|
||||||
buf += 4;
|
|
||||||
// we assume I2CP payload
|
|
||||||
if (buf[9] == 6) // streaming protocol
|
|
||||||
{
|
|
||||||
// unzip it
|
|
||||||
CryptoPP::Gunzip decompressor;
|
|
||||||
decompressor.Put (buf, length);
|
|
||||||
decompressor.MessageEnd();
|
|
||||||
Packet * uncompressed = new Packet;
|
|
||||||
uncompressed->offset = 0;
|
|
||||||
uncompressed->len = decompressor.MaxRetrievable ();
|
|
||||||
if (uncompressed->len > MAX_PACKET_SIZE)
|
|
||||||
{
|
|
||||||
LogPrint ("Received packet size ", uncompressed->len, " exceeds max packet size");
|
|
||||||
uncompressed->len = MAX_PACKET_SIZE;
|
|
||||||
}
|
|
||||||
decompressor.Get (uncompressed->buf, uncompressed->len);
|
|
||||||
// then forward to streaming engine thread
|
|
||||||
destinations.HandleNextPacket (destination, uncompressed);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
LogPrint ("Data: protocol ", buf[9], " is not supported");
|
|
||||||
}
|
|
||||||
|
|
||||||
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
|
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len)
|
||||||
{
|
{
|
||||||
I2NPMessage * msg = NewI2NPShortMessage ();
|
I2NPMessage * msg = NewI2NPShortMessage ();
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace stream
|
||||||
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 SetLeaseSetUpdated ();
|
void SetLeaseSetUpdated ();
|
||||||
|
void HandleDataMessage (const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -69,8 +70,6 @@ namespace stream
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
|
|
||||||
void HandleNextPacket (i2p::data::IdentHash destination, Packet * packet);
|
|
||||||
|
|
||||||
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
Stream * CreateClientStream (const i2p::data::LeaseSet& remote);
|
||||||
void DeleteStream (Stream * stream);
|
void DeleteStream (Stream * stream);
|
||||||
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
StreamingDestination * GetSharedLocalDestination () const { return m_SharedLocalDestination; };
|
||||||
|
@ -84,7 +83,6 @@ namespace stream
|
||||||
|
|
||||||
void Run ();
|
void Run ();
|
||||||
void LoadLocalDestinations ();
|
void LoadLocalDestinations ();
|
||||||
void PostNextPacket (i2p::data::IdentHash destination, Packet * packet);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -117,7 +115,6 @@ namespace stream
|
||||||
const StreamingDestinations& GetLocalDestinations ();
|
const StreamingDestinations& GetLocalDestinations ();
|
||||||
|
|
||||||
// assuming data is I2CP message
|
// assuming data is I2CP message
|
||||||
void HandleDataMessage (i2p::data::IdentHash destination, const uint8_t * buf, size_t len);
|
|
||||||
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len);
|
I2NPMessage * CreateDataMessage (Stream * s, const uint8_t * payload, size_t len);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
Garlic.cpp
13
Garlic.cpp
|
@ -434,13 +434,16 @@ namespace garlic
|
||||||
case eGarlicDeliveryTypeDestination:
|
case eGarlicDeliveryTypeDestination:
|
||||||
{
|
{
|
||||||
LogPrint ("Garlic type destination");
|
LogPrint ("Garlic type destination");
|
||||||
i2p::data::IdentHash destination (buf);
|
buf += 32; // destination. check it later or for multiple destinations
|
||||||
buf += 32;
|
|
||||||
// we assume streaming protocol for destination
|
|
||||||
// later on we should let destination decide
|
|
||||||
I2NPHeader * header = (I2NPHeader *)buf;
|
I2NPHeader * header = (I2NPHeader *)buf;
|
||||||
if (header->typeID == eI2NPData)
|
if (header->typeID == eI2NPData)
|
||||||
i2p::stream::HandleDataMessage (destination, buf + sizeof (I2NPHeader), be16toh (header->size));
|
{
|
||||||
|
auto pool = from ? from->GetTunnelPool () : nullptr;
|
||||||
|
if (pool)
|
||||||
|
pool->GetLocalDestination ().HandleDataMessage (buf + sizeof (I2NPHeader), be16toh (header->size));
|
||||||
|
else
|
||||||
|
LogPrint ("Local destination doesn't exist");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
LogPrint ("Unexpected I2NP garlic message ", (int)header->typeID);
|
LogPrint ("Unexpected I2NP garlic message ", (int)header->typeID);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -243,6 +243,7 @@ namespace data
|
||||||
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 SetLeaseSetUpdated () = 0;
|
virtual void SetLeaseSetUpdated () = 0;
|
||||||
|
virtual void HandleDataMessage (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 (); };
|
||||||
|
|
|
@ -40,6 +40,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) {};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace tunnel
|
||||||
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
|
const uint8_t * GetEncryptionPrivateKey () const { return m_LocalDestination.GetEncryptionPrivateKey (); };
|
||||||
const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); };
|
const uint8_t * GetEncryptionPublicKey () const { return m_LocalDestination.GetEncryptionPublicKey (); };
|
||||||
const i2p::data::LocalDestination& GetLocalDestination () const { return m_LocalDestination; };
|
const i2p::data::LocalDestination& GetLocalDestination () const { return m_LocalDestination; };
|
||||||
|
i2p::data::LocalDestination& GetLocalDestination () { return m_LocalDestination; };
|
||||||
bool IsExploratory () const { return GetIdentHash () == i2p::context.GetRouterIdentHash (); };
|
bool IsExploratory () const { return GetIdentHash () == i2p::context.GetRouterIdentHash (); };
|
||||||
|
|
||||||
void CreateTunnels ();
|
void CreateTunnels ();
|
||||||
|
|
Loading…
Reference in a new issue