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. 12
      Garlic.h
  5. 6
      I2NPProtocol.cpp
  6. 2
      TunnelPool.cpp

13
Destination.cpp

@ -187,8 +187,7 @@ namespace stream @@ -187,8 +187,7 @@ namespace stream
if (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));
HandleNextPacket (uncompressed);
}
else
{
@ -232,6 +231,16 @@ namespace stream @@ -232,6 +231,16 @@ namespace stream
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;
void StreamingDestinations::Start ()
{

6
Destination.h

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

15
Garlic.cpp

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

12
Garlic.h

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

6
I2NPProtocol.cpp

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

2
TunnelPool.cpp

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

Loading…
Cancel
Save