Browse Source

moved garlic decryption to streaming thread

pull/102/head
orignal 10 years ago
parent
commit
375fceb530
  1. 13
      Destination.cpp
  2. 6
      Destination.h
  3. 15
      Garlic.cpp
  4. 14
      Garlic.h
  5. 6
      I2NPProtocol.cpp
  6. 2
      TunnelPool.cpp

13
Destination.cpp

@ -187,8 +187,7 @@ namespace stream
if (uncompressed->len <= MAX_PACKET_SIZE) if (uncompressed->len <= MAX_PACKET_SIZE)
{ {
decompressor.Get (uncompressed->buf, uncompressed->len); decompressor.Get (uncompressed->buf, uncompressed->len);
// then forward to streaming thread HandleNextPacket (uncompressed);
m_Service.post (boost::bind (&StreamingDestination::HandleNextPacket, this, uncompressed));
} }
else else
{ {
@ -232,6 +231,16 @@ namespace stream
i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool); i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool);
} }
void StreamingDestination::ProcessGarlicMessage (I2NPMessage * msg)
{
m_Service.post (boost::bind (&StreamingDestination::HandleGarlicMessage, this, msg));
}
void StreamingDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg)
{
m_Service.post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg));
}
StreamingDestinations destinations; StreamingDestinations destinations;
void StreamingDestinations::Start () void StreamingDestinations::Start ()
{ {

6
Destination.h

@ -41,11 +41,15 @@ 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 SetLeaseSetUpdated ();
// implements GarlicDestination // implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet (); const i2p::data::LeaseSet * GetLeaseSet ();
// override GarlicDestination
void ProcessGarlicMessage (I2NPMessage * msg);
void ProcessDeliveryStatusMessage (I2NPMessage * msg);
void SetLeaseSetUpdated ();
private: private:
Stream * CreateNewIncomingStream (); Stream * CreateNewIncomingStream ();

15
Garlic.cpp

@ -454,7 +454,6 @@ namespace garlic
void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID) void GarlicDestination::DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID)
{ {
std::unique_lock<std::mutex> l(m_CreatedSessionsMutex);
m_CreatedSessions[msgID] = session; m_CreatedSessions[msgID] = session;
} }
@ -463,7 +462,6 @@ namespace garlic
I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload (); I2NPDeliveryStatusMsg * deliveryStatus = (I2NPDeliveryStatusMsg *)msg->GetPayload ();
uint32_t msgID = be32toh (deliveryStatus->msgID); uint32_t msgID = be32toh (deliveryStatus->msgID);
{ {
std::unique_lock<std::mutex> l(m_CreatedSessionsMutex);
auto it = m_CreatedSessions.find (msgID); auto it = m_CreatedSessions.find (msgID);
if (it != m_CreatedSessions.end ()) if (it != m_CreatedSessions.end ())
{ {
@ -477,9 +475,20 @@ namespace garlic
void GarlicDestination::SetLeaseSetUpdated () void GarlicDestination::SetLeaseSetUpdated ()
{ {
std::unique_lock<std::mutex> l(m_CreatedSessionsMutex); std::unique_lock<std::mutex> l(m_SessionsMutex);
for (auto it: m_Sessions) for (auto it: m_Sessions)
it.second->SetLeaseSetUpdated (); it.second->SetLeaseSetUpdated ();
} }
void GarlicDestination::ProcessGarlicMessage (I2NPMessage * msg)
{
HandleGarlicMessage (msg);
}
void GarlicDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg)
{
HandleDeliveryStatusMessage (msg);
}
} }
} }

14
Garlic.h

@ -92,14 +92,19 @@ namespace garlic
I2NPMessage * msg, bool attachLeaseSet = false); I2NPMessage * msg, bool attachLeaseSet = false);
void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag
void HandleGarlicMessage (I2NPMessage * msg);
void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID); void DeliveryStatusSent (GarlicRoutingSession * session, uint32_t msgID);
void HandleDeliveryStatusMessage (I2NPMessage * msg);
virtual void ProcessGarlicMessage (I2NPMessage * msg);
virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg);
virtual void SetLeaseSetUpdated (); virtual void SetLeaseSetUpdated ();
virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
protected:
void HandleGarlicMessage (I2NPMessage * msg);
void HandleDeliveryStatusMessage (I2NPMessage * msg);
private: private:
void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption, void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,
@ -114,7 +119,6 @@ namespace garlic
// incoming // incoming
std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags; std::map<SessionTag, std::shared_ptr<i2p::crypto::CBCDecryption>> m_Tags;
// DeliveryStatus // DeliveryStatus
std::mutex m_CreatedSessionsMutex;
std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session std::map<uint32_t, GarlicRoutingSession *> m_CreatedSessions; // msgID -> session
}; };
} }

6
I2NPProtocol.cpp

@ -562,9 +562,9 @@ namespace i2p
case eI2NPGarlic: case eI2NPGarlic:
LogPrint ("Garlic"); LogPrint ("Garlic");
if (msg->from && msg->from->GetTunnelPool ()) if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->GetGarlicDestination ().HandleGarlicMessage (msg); msg->from->GetTunnelPool ()->GetGarlicDestination ().ProcessGarlicMessage (msg);
else else
i2p::context.HandleGarlicMessage (msg); i2p::context.ProcessGarlicMessage (msg);
break; break;
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
@ -577,7 +577,7 @@ namespace i2p
if (msg->from && msg->from->GetTunnelPool ()) if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg);
else else
i2p::context.HandleDeliveryStatusMessage (msg); i2p::context.ProcessDeliveryStatusMessage (msg);
break; break;
default: default:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ()); HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());

2
TunnelPool.cpp

@ -221,7 +221,7 @@ namespace tunnel
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);
} }
else else
m_LocalDestination.HandleDeliveryStatusMessage (msg); m_LocalDestination.ProcessDeliveryStatusMessage (msg);
} }
const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const const i2p::data::RouterInfo * TunnelPool::SelectNextHop (const i2p::data::RouterInfo * prevHop) const

Loading…
Cancel
Save