Skip to content

Commit

Permalink
moved garlic decryption to streaming thread
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 8, 2014
1 parent 911ad52 commit 375fceb
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 15 deletions.
13 changes: 11 additions & 2 deletions Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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 ()
{
Expand Down
6 changes: 5 additions & 1 deletion Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
15 changes: 12 additions & 3 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 ())
{
Expand All @@ -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);
}

}
}
14 changes: 9 additions & 5 deletions Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
};
}
Expand Down
6 changes: 3 additions & 3 deletions I2NPProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 ());
Expand Down
2 changes: 1 addition & 1 deletion TunnelPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 375fceb

Please sign in to comment.