From f6721a2ced11468d5ce37d71fed66ebbf14758fc Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 15 Nov 2016 17:45:37 -0500 Subject: [PATCH 1/7] fixed startup crash --- Config.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Config.cpp b/Config.cpp index ed22c561..fb587e61 100644 --- a/Config.cpp +++ b/Config.cpp @@ -87,8 +87,8 @@ namespace config { ("httpproxy.outbound.length", value()->default_value("3"), "HTTP proxy outbound tunnel length") ("httpproxy.inbound.quantity", value()->default_value("5"), "HTTP proxy inbound tunnels quantity") ("httpproxy.outbound.quantity", value()->default_value("5"), "HTTP proxy outbound tunnels quantity") - ("httpproxy.latency.min", value()->default_value(0), "HTTP proxy min latency for tunnels") - ("httpproxy.latency.max", value()->default_value(0), "HTTP proxy max latency for tunnels") + ("httpproxy.latency.min", value()->default_value("0"), "HTTP proxy min latency for tunnels") + ("httpproxy.latency.max", value()->default_value("0"), "HTTP proxy max latency for tunnels") ; options_description socksproxy("SOCKS Proxy options"); @@ -101,8 +101,8 @@ namespace config { ("socksproxy.outbound.length", value()->default_value("3"), "SOCKS proxy outbound tunnel length") ("socksproxy.inbound.quantity", value()->default_value("5"), "SOCKS proxy inbound tunnels quantity") ("socksproxy.outbound.quantity", value()->default_value("5"), "SOCKS proxy outbound tunnels quantity") - ("socksproxy.latency.min", value()->default_value(0), "SOCKS proxy min latency for tunnels") - ("socksproxy.latency.max", value()->default_value(0), "SOCKS proxy max latency for tunnels") + ("socksproxy.latency.min", value()->default_value("0"), "SOCKS proxy min latency for tunnels") + ("socksproxy.latency.max", value()->default_value("0"), "SOCKS proxy max latency for tunnels") ("socksproxy.outproxy", value()->default_value("127.0.0.1"), "Upstream outproxy address for SOCKS Proxy") ("socksproxy.outproxyport", value()->default_value(9050), "Upstream outproxy port for SOCKS Proxy") ; From e0e50faa477d7443d3b3ce432e25aceb3989491b Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 16 Nov 2016 10:59:11 -0500 Subject: [PATCH 2/7] publish 0-hops leaseset --- TunnelPool.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/TunnelPool.cpp b/TunnelPool.cpp index ccd4c12c..ea7928eb 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -215,15 +215,6 @@ namespace tunnel void TunnelPool::CreateTunnels () { int num = 0; - { - std::unique_lock l(m_InboundTunnelsMutex); - for (const auto& it : m_InboundTunnels) - if (it->IsEstablished ()) num++; - } - for (int i = num; i < m_NumInboundTunnels; i++) - CreateInboundTunnel (); - - num = 0; { std::unique_lock l(m_OutboundTunnelsMutex); for (const auto& it : m_OutboundTunnels) @@ -231,6 +222,18 @@ namespace tunnel } for (int i = num; i < m_NumOutboundTunnels; i++) CreateOutboundTunnel (); + + num = 0; + { + std::unique_lock l(m_InboundTunnelsMutex); + for (const auto& it : m_InboundTunnels) + if (it->IsEstablished ()) num++; + } + for (int i = num; i < m_NumInboundTunnels; i++) + CreateInboundTunnel (); + + if (num > 0 && m_NumInboundHops <= 0 && m_LocalDestination) // zero hops IB + m_LocalDestination->SetLeaseSetUpdated (); // update LeaseSet immediately } void TunnelPool::TestTunnels () From 5d0852c1e2d940aaae5caa44df230f140fc88887 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 16 Nov 2016 12:10:13 -0500 Subject: [PATCH 3/7] fixed memory leak --- Garlic.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Garlic.cpp b/Garlic.cpp index 1cd1676e..b7d44d5e 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -277,6 +277,7 @@ namespace garlic { newTags->msgID = msgID; m_UnconfirmedTagsMsgs.emplace_back (newTags); + newTags = nullptr; // got acquired } m_Owner->DeliveryStatusSent (shared_from_this (), msgID); } @@ -300,13 +301,14 @@ namespace garlic size += CreateGarlicClove (payload + size, msg, m_Destination ? m_Destination->IsDestination () : false); (*numCloves)++; } - memset (payload + size, 0, 3); // certificate of message size += 3; htobe32buf (payload + size, msgID); // MessageID size += 4; htobe64buf (payload + size, ts + 8000); // Expiration of message, 8 sec size += 8; + + if (newTags) delete newTags; // not acquired, delete return size; } From a91460826407bdca1005a3042e90fb602842ca34 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 16 Nov 2016 14:43:29 -0500 Subject: [PATCH 4/7] clean up non received DeliveryStatus messages --- Garlic.cpp | 38 +++++++++++++++++++++++++++++--------- Garlic.h | 3 +++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index b7d44d5e..35c8bc15 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -20,6 +20,7 @@ namespace garlic std::shared_ptr destination, int numTags, bool attachLeaseSet): m_Owner (owner), m_Destination (destination), m_NumTags (numTags), m_LeaseSetUpdateStatus (attachLeaseSet ? eLeaseSetUpdated : eLeaseSetDoNotSend), + m_LeaseSetUpdateMsgID (0), m_ElGamalEncryption (new i2p::crypto::ElGamalEncryption (destination->GetEncryptionPublicKey ())) { // create new session tags and session key @@ -28,7 +29,7 @@ namespace garlic } GarlicRoutingSession::GarlicRoutingSession (const uint8_t * sessionKey, const SessionTag& sessionTag): - m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetDoNotSend) + m_Owner (nullptr), m_Destination (nullptr), m_NumTags (1), m_LeaseSetUpdateStatus (eLeaseSetDoNotSend), m_LeaseSetUpdateMsgID (0) { memcpy (m_SessionKey, sessionKey, 32); m_Encryption.SetKey (m_SessionKey); @@ -83,6 +84,7 @@ namespace garlic if (msgID == m_LeaseSetUpdateMsgID) { m_LeaseSetUpdateStatus = eLeaseSetUpToDate; + m_LeaseSetUpdateMsgID = 0; LogPrint (eLogInfo, "Garlic: LeaseSet update confirmed"); } else @@ -117,7 +119,7 @@ namespace garlic bool GarlicRoutingSession::CleanupExpiredTags () { - uint32_t ts = i2p::util::GetSecondsSinceEpoch (); + auto ts = i2p::util::GetSecondsSinceEpoch (); for (auto it = m_SessionTags.begin (); it != m_SessionTags.end ();) { if (ts >= it->creationTime + OUTGOING_TAGS_EXPIRATION_TIMEOUT) @@ -126,6 +128,12 @@ namespace garlic ++it; } CleanupUnconfirmedTags (); + if (m_LeaseSetUpdateMsgID && ts*1000LL > m_LeaseSetSubmissionTime + LEASET_CONFIRMATION_TIMEOUT) + { + if (m_Owner) + m_Owner->RemoveDeliveryStatusSession (m_LeaseSetUpdateMsgID); + m_LeaseSetUpdateMsgID = 0; + } return !m_SessionTags.empty () || !m_UnconfirmedTagsMsgs.empty (); } @@ -287,6 +295,7 @@ namespace garlic // attach LeaseSet if (m_LeaseSetUpdateStatus == eLeaseSetUpdated) { + if (m_LeaseSetUpdateMsgID) m_Owner->RemoveDeliveryStatusSession (m_LeaseSetUpdateMsgID); // remove previous m_LeaseSetUpdateStatus = eLeaseSetSubmitted; m_LeaseSetUpdateMsgID = msgID; m_LeaseSetSubmissionTime = ts; @@ -625,18 +634,29 @@ namespace garlic LogPrint (eLogDebug, "Garlic: ", numExpiredTags, " tags expired for ", GetIdentHash().ToBase64 ()); // outgoing - std::unique_lock l(m_SessionsMutex); - for (auto it = m_Sessions.begin (); it != m_Sessions.end ();) { - it->second->GetSharedRoutingPath (); // delete shared path if necessary - if (!it->second->CleanupExpiredTags ()) + std::unique_lock l(m_SessionsMutex); + for (auto it = m_Sessions.begin (); it != m_Sessions.end ();) { - LogPrint (eLogInfo, "Routing session to ", it->first.ToBase32 (), " deleted"); - it = m_Sessions.erase (it); + it->second->GetSharedRoutingPath (); // delete shared path if necessary + if (!it->second->CleanupExpiredTags ()) + { + LogPrint (eLogInfo, "Routing session to ", it->first.ToBase32 (), " deleted"); + it->second->SetOwner (nullptr); + it = m_Sessions.erase (it); + } + else + ++it; } + } + // delivery status sessions + for (auto it = m_DeliveryStatusSessions.begin (); it != m_DeliveryStatusSessions.end (); ) + { + if (it->second->GetOwner () != this) + it = m_DeliveryStatusSessions.erase (it); else ++it; - } + } } void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID) diff --git a/Garlic.h b/Garlic.h index a3ab7d92..e0e65111 100644 --- a/Garlic.h +++ b/Garlic.h @@ -111,6 +111,9 @@ namespace garlic std::shared_ptr GetSharedRoutingPath (); void SetSharedRoutingPath (std::shared_ptr path); + const GarlicDestination * GetOwner () const { return m_Owner; } + void SetOwner (GarlicDestination * owner) { m_Owner = owner; } + private: size_t CreateAESBlock (uint8_t * buf, std::shared_ptr msg); From 1aa939ae73aee341c07de1af12d1c0c5930e38f8 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 16 Nov 2016 19:32:45 -0500 Subject: [PATCH 5/7] correct tigger for 0-hops LeaseSet update --- TunnelPool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TunnelPool.cpp b/TunnelPool.cpp index ea7928eb..07057918 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -232,7 +232,7 @@ namespace tunnel for (int i = num; i < m_NumInboundTunnels; i++) CreateInboundTunnel (); - if (num > 0 && m_NumInboundHops <= 0 && m_LocalDestination) // zero hops IB + if (num < m_NumInboundTunnels && m_NumInboundHops <= 0 && m_LocalDestination) // zero hops IB m_LocalDestination->SetLeaseSetUpdated (); // update LeaseSet immediately } From 913438e3ff767990336cff0718704e123adc6975 Mon Sep 17 00:00:00 2001 From: atnaguzin Date: Thu, 17 Nov 2016 06:04:29 +0300 Subject: [PATCH 6/7] addresshelper message changed to "Proxy info" --- HTTPProxy.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 60b6bc33..c40989d1 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -29,7 +29,7 @@ namespace proxy { static const char *pageHead = "\r\n" - " I2P HTTP proxy: error\r\n" + " I2Pd HTTP proxy\r\n" "