Browse Source

use share_ptr for garlic messages

pull/210/head
orignal 10 years ago
parent
commit
a0de60e179
  1. 7
      Destination.cpp
  2. 6
      Destination.h
  3. 11
      Garlic.cpp
  4. 8
      Garlic.h
  5. 21
      I2NPProtocol.cpp
  6. 4
      RouterContext.cpp
  7. 4
      RouterContext.h
  8. 11
      TunnelPool.cpp
  9. 4
      TunnelPool.h

7
Destination.cpp

@ -215,12 +215,12 @@ namespace client
return true; return true;
} }
void ClientDestination::ProcessGarlicMessage (I2NPMessage * msg) void ClientDestination::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{ {
m_Service.post (std::bind (&ClientDestination::HandleGarlicMessage, this, msg)); m_Service.post (std::bind (&ClientDestination::HandleGarlicMessage, this, msg));
} }
void ClientDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg) void ClientDestination::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{ {
m_Service.post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg)); m_Service.post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg));
} }
@ -343,7 +343,7 @@ namespace client
LogPrint ("Request for ", key.ToBase64 (), " not found"); LogPrint ("Request for ", key.ToBase64 (), " not found");
} }
void ClientDestination::HandleDeliveryStatusMessage (I2NPMessage * msg) void ClientDestination::HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{ {
uint32_t msgID = bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET); uint32_t msgID = bufbe32toh (msg->GetPayload () + DELIVERY_STATUS_MSGID_OFFSET);
if (msgID == m_PublishReplyToken) if (msgID == m_PublishReplyToken)
@ -351,7 +351,6 @@ namespace client
LogPrint (eLogDebug, "Publishing confirmed"); LogPrint (eLogDebug, "Publishing confirmed");
m_ExcludedFloodfills.clear (); m_ExcludedFloodfills.clear ();
m_PublishReplyToken = 0; m_PublishReplyToken = 0;
i2p::DeleteI2NPMessage (msg);
} }
else else
i2p::garlic::GarlicDestination::HandleDeliveryStatusMessage (msg); i2p::garlic::GarlicDestination::HandleDeliveryStatusMessage (msg);

6
Destination.h

@ -99,8 +99,8 @@ namespace client
// override GarlicDestination // override GarlicDestination
bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag);
void ProcessGarlicMessage (I2NPMessage * msg); void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatusMessage (I2NPMessage * msg); void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
void SetLeaseSetUpdated (); void SetLeaseSetUpdated ();
// I2CP // I2CP
@ -114,7 +114,7 @@ namespace client
void HandlePublishConfirmationTimer (const boost::system::error_code& ecode); void HandlePublishConfirmationTimer (const boost::system::error_code& ecode);
void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len); void HandleDatabaseStoreMessage (const uint8_t * buf, size_t len);
void HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len); void HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len);
void HandleDeliveryStatusMessage (I2NPMessage * msg); void HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete); void RequestLeaseSet (const i2p::data::IdentHash& dest, RequestComplete requestComplete);
bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, LeaseSetRequest * request); bool SendLeaseSetRequest (const i2p::data::IdentHash& dest, std::shared_ptr<const i2p::data::RouterInfo> nextFloodfill, LeaseSetRequest * request);

11
Garlic.cpp

@ -362,14 +362,13 @@ namespace garlic
return true; return true;
} }
void GarlicDestination::HandleGarlicMessage (I2NPMessage * msg) void GarlicDestination::HandleGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{ {
uint8_t * buf = msg->GetPayload (); uint8_t * buf = msg->GetPayload ();
uint32_t length = bufbe32toh (buf); uint32_t length = bufbe32toh (buf);
if (length > msg->GetLength ()) if (length > msg->GetLength ())
{ {
LogPrint (eLogError, "Garlic message length ", length, " exceeds I2NP message length ", msg->GetLength ()); LogPrint (eLogError, "Garlic message length ", length, " exceeds I2NP message length ", msg->GetLength ());
DeleteI2NPMessage (msg);
return; return;
} }
buf += 4; // length buf += 4; // length
@ -406,7 +405,6 @@ namespace garlic
else else
LogPrint (eLogError, "Failed to decrypt garlic"); LogPrint (eLogError, "Failed to decrypt garlic");
} }
DeleteI2NPMessage (msg);
// cleanup expired tags // cleanup expired tags
uint32_t ts = i2p::util::GetSecondsSinceEpoch (); uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
@ -588,7 +586,7 @@ namespace garlic
m_CreatedSessions[msgID] = session; m_CreatedSessions[msgID] = session;
} }
void GarlicDestination::HandleDeliveryStatusMessage (I2NPMessage * msg) void GarlicDestination::HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{ {
uint32_t msgID = bufbe32toh (msg->GetPayload ()); uint32_t msgID = bufbe32toh (msg->GetPayload ());
{ {
@ -600,7 +598,6 @@ namespace garlic
LogPrint (eLogInfo, "Garlic message ", msgID, " acknowledged"); LogPrint (eLogInfo, "Garlic message ", msgID, " acknowledged");
} }
} }
DeleteI2NPMessage (msg);
} }
void GarlicDestination::SetLeaseSetUpdated () void GarlicDestination::SetLeaseSetUpdated ()
@ -610,12 +607,12 @@ namespace garlic
it.second->SetLeaseSetUpdated (); it.second->SetLeaseSetUpdated ();
} }
void GarlicDestination::ProcessGarlicMessage (I2NPMessage * msg) void GarlicDestination::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{ {
HandleGarlicMessage (msg); HandleGarlicMessage (msg);
} }
void GarlicDestination::ProcessDeliveryStatusMessage (I2NPMessage * msg) void GarlicDestination::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{ {
HandleDeliveryStatusMessage (msg); HandleDeliveryStatusMessage (msg);
} }

8
Garlic.h

@ -133,8 +133,8 @@ namespace garlic
virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread
void DeliveryStatusSent (std::shared_ptr<GarlicRoutingSession> session, uint32_t msgID); void DeliveryStatusSent (std::shared_ptr<GarlicRoutingSession> session, uint32_t msgID);
virtual void ProcessGarlicMessage (I2NPMessage * msg); virtual void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
virtual void ProcessDeliveryStatusMessage (I2NPMessage * msg); virtual void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
virtual void SetLeaseSetUpdated (); virtual void SetLeaseSetUpdated ();
virtual std::shared_ptr<const i2p::data::LeaseSet> GetLeaseSet () = 0; // TODO virtual std::shared_ptr<const i2p::data::LeaseSet> GetLeaseSet () = 0; // TODO
@ -143,8 +143,8 @@ namespace garlic
protected: protected:
void HandleGarlicMessage (I2NPMessage * msg); void HandleGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void HandleDeliveryStatusMessage (I2NPMessage * msg); void HandleDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
private: private:

21
I2NPProtocol.cpp

@ -537,20 +537,20 @@ namespace i2p
i2p::tunnel::tunnels.PostTunnelData (msg); i2p::tunnel::tunnels.PostTunnelData (msg);
break; break;
case eI2NPGarlic: case eI2NPGarlic:
{
LogPrint ("Garlic"); LogPrint ("Garlic");
auto sharedMsg = ToSharedI2NPMessage (msg);
if (msg->from) if (msg->from)
{ {
if (msg->from->GetTunnelPool ()) if (msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessGarlicMessage (msg); msg->from->GetTunnelPool ()->ProcessGarlicMessage (sharedMsg);
else else
{
LogPrint (eLogInfo, "Local destination for garlic doesn't exist anymore"); LogPrint (eLogInfo, "Local destination for garlic doesn't exist anymore");
DeleteI2NPMessage (msg);
}
} }
else else
i2p::context.ProcessGarlicMessage (msg); i2p::context.ProcessGarlicMessage (sharedMsg);
break; break;
}
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
case eI2NPDatabaseSearchReply: case eI2NPDatabaseSearchReply:
case eI2NPDatabaseLookup: case eI2NPDatabaseLookup:
@ -558,12 +558,15 @@ namespace i2p
i2p::data::netdb.PostI2NPMsg (msg); i2p::data::netdb.PostI2NPMsg (msg);
break; break;
case eI2NPDeliveryStatus: case eI2NPDeliveryStatus:
{
LogPrint ("DeliveryStatus"); LogPrint ("DeliveryStatus");
auto sharedMsg = ToSharedI2NPMessage (msg);
if (msg->from && msg->from->GetTunnelPool ()) if (msg->from && msg->from->GetTunnelPool ())
msg->from->GetTunnelPool ()->ProcessDeliveryStatus (msg); msg->from->GetTunnelPool ()->ProcessDeliveryStatus (sharedMsg);
else else
i2p::context.ProcessDeliveryStatusMessage (msg); i2p::context.ProcessDeliveryStatusMessage (sharedMsg);
break; break;
}
case eI2NPVariableTunnelBuild: case eI2NPVariableTunnelBuild:
case eI2NPVariableTunnelBuildReply: case eI2NPVariableTunnelBuildReply:
case eI2NPTunnelBuild: case eI2NPTunnelBuild:

4
RouterContext.cpp

@ -299,13 +299,13 @@ namespace i2p
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from));
} }
void RouterContext::ProcessGarlicMessage (I2NPMessage * msg) void RouterContext::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{ {
std::unique_lock<std::mutex> l(m_GarlicMutex); std::unique_lock<std::mutex> l(m_GarlicMutex);
i2p::garlic::GarlicDestination::ProcessGarlicMessage (msg); i2p::garlic::GarlicDestination::ProcessGarlicMessage (msg);
} }
void RouterContext::ProcessDeliveryStatusMessage (I2NPMessage * msg) void RouterContext::ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg)
{ {
std::unique_lock<std::mutex> l(m_GarlicMutex); std::unique_lock<std::mutex> l(m_GarlicMutex);
i2p::garlic::GarlicDestination::ProcessDeliveryStatusMessage (msg); i2p::garlic::GarlicDestination::ProcessDeliveryStatusMessage (msg);

4
RouterContext.h

@ -78,8 +78,8 @@ namespace i2p
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from); void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
// override GarlicDestination // override GarlicDestination
void ProcessGarlicMessage (I2NPMessage * msg); void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatusMessage (I2NPMessage * msg); void ProcessDeliveryStatusMessage (std::shared_ptr<I2NPMessage> msg);
private: private:

11
TunnelPool.cpp

@ -260,18 +260,15 @@ namespace tunnel
} }
} }
void TunnelPool::ProcessGarlicMessage (I2NPMessage * msg) void TunnelPool::ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg)
{ {
if (m_LocalDestination) if (m_LocalDestination)
m_LocalDestination->ProcessGarlicMessage (msg); m_LocalDestination->ProcessGarlicMessage (msg);
else else
{
LogPrint (eLogWarning, "Local destination doesn't exist. Dropped"); LogPrint (eLogWarning, "Local destination doesn't exist. Dropped");
DeleteI2NPMessage (msg);
}
} }
void TunnelPool::ProcessDeliveryStatus (I2NPMessage * msg) void TunnelPool::ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg)
{ {
const uint8_t * buf = msg->GetPayload (); const uint8_t * buf = msg->GetPayload ();
uint32_t msgID = bufbe32toh (buf); uint32_t msgID = bufbe32toh (buf);
@ -288,17 +285,13 @@ namespace tunnel
it->second.second->SetState (eTunnelStateEstablished); it->second.second->SetState (eTunnelStateEstablished);
LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - timestamp, " milliseconds"); LogPrint ("Tunnel test ", it->first, " successive. ", i2p::util::GetMillisecondsSinceEpoch () - timestamp, " milliseconds");
m_Tests.erase (it); m_Tests.erase (it);
DeleteI2NPMessage (msg);
} }
else else
{ {
if (m_LocalDestination) if (m_LocalDestination)
m_LocalDestination->ProcessDeliveryStatusMessage (msg); m_LocalDestination->ProcessDeliveryStatusMessage (msg);
else else
{
LogPrint (eLogWarning, "Local destination doesn't exist. Dropped"); LogPrint (eLogWarning, "Local destination doesn't exist. Dropped");
DeleteI2NPMessage (msg);
}
} }
} }

4
TunnelPool.h

@ -47,8 +47,8 @@ namespace tunnel
std::shared_ptr<OutboundTunnel> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const; std::shared_ptr<OutboundTunnel> GetNewOutboundTunnel (std::shared_ptr<OutboundTunnel> old) const;
void TestTunnels (); void TestTunnels ();
void ProcessGarlicMessage (I2NPMessage * msg); void ProcessGarlicMessage (std::shared_ptr<I2NPMessage> msg);
void ProcessDeliveryStatus (I2NPMessage * msg); void ProcessDeliveryStatus (std::shared_ptr<I2NPMessage> msg);
bool IsActive () const { return m_IsActive; }; bool IsActive () const { return m_IsActive; };
void SetActive (bool isActive) { m_IsActive = isActive; }; void SetActive (bool isActive) { m_IsActive = isActive; };

Loading…
Cancel
Save