From f593802a51f5480e6331e8ebd379ec880b8429ff Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 23 Jan 2016 20:52:21 -0500 Subject: [PATCH] I2CP option crypto.tagsToSend added for I2P tunnels --- ClientContext.cpp | 1 + Destination.cpp | 12 ++++++++++++ Destination.h | 4 +++- Garlic.cpp | 4 ++-- Garlic.h | 4 +++- 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index c1a1a274..ef0d58c5 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -231,6 +231,7 @@ namespace client options[I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH] = GetI2CPOption (section, I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH, DEFAULT_OUTBOUND_TUNNEL_LENGTH); options[I2CP_PARAM_INBOUND_TUNNELS_QUANTITY] = GetI2CPOption (section, I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, DEFAULT_INBOUND_TUNNELS_QUANTITY); options[I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY] = GetI2CPOption (section, I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, DEFAULT_OUTBOUND_TUNNELS_QUANTITY); + options[I2CP_PARAM_TAGS_TO_SEND] = GetI2CPOption (section, I2CP_PARAM_TAGS_TO_SEND, DEFAULT_TAGS_TO_SEND); } void ClientContext::ReadTunnels () diff --git a/Destination.cpp b/Destination.cpp index 765fbdae..233946ad 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -27,6 +27,7 @@ namespace client int outboundTunnelLen = DEFAULT_OUTBOUND_TUNNEL_LENGTH; int inboundTunnelsQuantity = DEFAULT_INBOUND_TUNNELS_QUANTITY; int outboundTunnelsQuantity = DEFAULT_OUTBOUND_TUNNELS_QUANTITY; + int numTags = DEFAULT_TAGS_TO_SEND; std::shared_ptr > explicitPeers; if (params) { @@ -70,6 +71,16 @@ namespace client LogPrint (eLogInfo, "Destination: Outbound tunnels quantity set to ", quantity); } } + it = params->find (I2CP_PARAM_TAGS_TO_SEND); + if (it != params->end ()) + { + int tagsToSend = boost::lexical_cast(it->second); + if (tagsToSend > 0) + { + numTags = tagsToSend; + LogPrint (eLogInfo, "Destination: Tags to send set to ", tagsToSend); + } + } it = params->find (I2CP_PARAM_EXPLICIT_PEERS); if (it != params->end ()) { @@ -85,6 +96,7 @@ namespace client LogPrint (eLogInfo, "Destination: Explicit peers set to ", it->second); } } + SetNumTags (numTags); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (inboundTunnelLen, outboundTunnelLen, inboundTunnelsQuantity, outboundTunnelsQuantity); if (explicitPeers) m_Pool->SetExplicitPeers (explicitPeers); diff --git a/Destination.h b/Destination.h index 3de47a81..8ff2dbc8 100644 --- a/Destination.h +++ b/Destination.h @@ -42,7 +42,9 @@ namespace client const int DEFAULT_OUTBOUND_TUNNELS_QUANTITY = 5; const char I2CP_PARAM_EXPLICIT_PEERS[] = "explicitPeers"; const int STREAM_REQUEST_TIMEOUT = 60; //in seconds - + const char I2CP_PARAM_TAGS_TO_SEND[] = "crypto.tagsToSend"; + const int DEFAULT_TAGS_TO_SEND = 40; + typedef std::function stream)> StreamRequestComplete; class ClientDestination: public i2p::garlic::GarlicDestination, diff --git a/Garlic.cpp b/Garlic.cpp index 71688305..09fd27b3 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -546,7 +546,7 @@ namespace garlic std::shared_ptr GarlicDestination::WrapMessage (std::shared_ptr destination, std::shared_ptr msg, bool attachLeaseSet) { - auto session = GetRoutingSession (destination, attachLeaseSet); // 32 tags by default + auto session = GetRoutingSession (destination, attachLeaseSet); return session->WrapSingleMessage (msg); } @@ -560,7 +560,7 @@ namespace garlic if (!session) { session = std::make_shared (this, destination, - attachLeaseSet ? 40 : 4, attachLeaseSet); // 40 tags for connections and 4 for LS requests + attachLeaseSet ? m_NumTags : 4, attachLeaseSet); // specified num tags for connections and 4 for LS requests std::unique_lock l(m_SessionsMutex); m_Sessions[destination->GetIdentHash ()] = session; } diff --git a/Garlic.h b/Garlic.h index 716bc466..585d4f27 100644 --- a/Garlic.h +++ b/Garlic.h @@ -119,9 +119,10 @@ namespace garlic { public: - GarlicDestination (): m_LastTagsCleanupTime (0) {}; + GarlicDestination (): m_NumTags (32), m_LastTagsCleanupTime (0) {}; // 32 tags by default ~GarlicDestination (); + void SetNumTags (int numTags) { m_NumTags = numTags; }; std::shared_ptr GetRoutingSession (std::shared_ptr destination, bool attachLeaseSet); void CleanupRoutingSessions (); void RemoveCreatedSession (uint32_t msgID); @@ -154,6 +155,7 @@ namespace garlic private: // outgoing sessions + int m_NumTags; std::mutex m_SessionsMutex; std::map > m_Sessions; // incoming