From bc41a15ebaf97fccd3a8543656b4e198dee8ca3f Mon Sep 17 00:00:00 2001 From: 0niichan Date: Thu, 21 Jan 2016 01:33:28 +0700 Subject: [PATCH 01/17] Update Makefile.mingw new default boost' suffix; new paths --- Makefile.mingw | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.mingw b/Makefile.mingw index c2fd35a9..ad5a8ade 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,7 +1,7 @@ CXX = g++ CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN NEEDED_CXXFLAGS = -std=c++11 -BOOST_SUFFIX = -mgw48-mt-1_59 -INCFLAGS = -I/usr/include/ -I/usr/local/include/ -I/c/dev/openssl/include -I/c/dev/boost/include/boost-1_59 -LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib -L/c/dev/openssl -L/c/dev/boost/lib -LDLIBS = -lboost_system$(BOOST_SUFFIX) -lboost_date_time$(BOOST_SUFFIX) -lboost_filesystem$(BOOST_SUFFIX) -lboost_regex$(BOOST_SUFFIX) -lboost_program_options$(BOOST_SUFFIX) -lssl -lcrypto -lz -lwsock32 -lws2_32 -lgdi32 -liphlpapi -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -lpthread +BOOST_SUFFIX = -mt // Suffix of your boost libraries +INCFLAGS = -I/usr/include/ -I/usr/lib -I/usr/local/include/ -I/usr/include/boost -I/c/dev/openssl/include +LDFLAGS = -Wl,-rpath,/usr/lib -L/usr/lib -L/usr/include -L/usr/include/boost +LDLIBS = -Wl,-Bstatic -lboost_system$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_date_time$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_filesystem$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_regex$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_program_options$(BOOST_SUFFIX) -Wl,-Bstatic -lssl -Wl,-Bstatic -lcrypto -Wl,-Bstatic -lz -Wl,-Bstatic -lwsock32 -Wl,-Bstatic -lws2_32 -Wl,-Bstatic -lgdi32 -Wl,-Bstatic -liphlpapi -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -Wl,-Bstatic -lpthread From e5037fc9f9ea899b8a6b15940486f1a2edbb9bfc Mon Sep 17 00:00:00 2001 From: 0niichan Date: Thu, 21 Jan 2016 02:05:16 +0700 Subject: [PATCH 02/17] new default boost' suffix; new paths --- Makefile.mingw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.mingw b/Makefile.mingw index ad5a8ade..19a71e9b 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,7 +1,7 @@ CXX = g++ CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN NEEDED_CXXFLAGS = -std=c++11 -BOOST_SUFFIX = -mt // Suffix of your boost libraries -INCFLAGS = -I/usr/include/ -I/usr/lib -I/usr/local/include/ -I/usr/include/boost -I/c/dev/openssl/include -LDFLAGS = -Wl,-rpath,/usr/lib -L/usr/lib -L/usr/include -L/usr/include/boost +BOOST_SUFFIX = -mt # Suffix of your boost libraries +INCFLAGS = -I/usr/include -I/usr/lib -I/usr/include/boost -I/usr/include/openssl +LDFLAGS = -L/usr/include -L/usr/lib -L/usr/include/boost -L/usr/include/openssl -Wl,-rpath,/usr/lib LDLIBS = -Wl,-Bstatic -lboost_system$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_date_time$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_filesystem$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_regex$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_program_options$(BOOST_SUFFIX) -Wl,-Bstatic -lssl -Wl,-Bstatic -lcrypto -Wl,-Bstatic -lz -Wl,-Bstatic -lwsock32 -Wl,-Bstatic -lws2_32 -Wl,-Bstatic -lgdi32 -Wl,-Bstatic -liphlpapi -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -Wl,-Bstatic -lpthread From bd0eb81c1bac55361acbdbce791050b61e5d108d Mon Sep 17 00:00:00 2001 From: 0niichan Date: Thu, 21 Jan 2016 03:52:13 +0700 Subject: [PATCH 03/17] add "mkdir obj/Win32" in Windows --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 2e86fd88..b11305ce 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ else ifeq ($(UNAME),Linux) include Makefile.linux else # win32 mingw DAEMON_SRC += DaemonWin32.cpp Win32/Win32Service.cpp + WINDIR := True include Makefile.mingw endif @@ -30,6 +31,9 @@ all: mk_build_dir $(ARLIB) $(ARLIB_CLIENT) $(I2PD) mk_build_dir: mkdir -p obj + ifeq ($(WINDIR),True) + mkdir -p obj/Win32 + endif api: mk_build_dir $(SHLIB) $(ARLIB) api_client: mk_build_dir $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) From 55c279cc7e97b11033bdbd3f6b3655d98cf59906 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 20 Jan 2016 21:51:18 -0500 Subject: [PATCH 04/17] Rolled back to working Makefile.mingw --- Makefile.mingw | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.mingw b/Makefile.mingw index 19a71e9b..57fe094b 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -1,7 +1,7 @@ CXX = g++ CXXFLAGS = -O2 -D_MT -DWIN32 -D_WINDOWS -DWIN32_LEAN_AND_MEAN NEEDED_CXXFLAGS = -std=c++11 -BOOST_SUFFIX = -mt # Suffix of your boost libraries -INCFLAGS = -I/usr/include -I/usr/lib -I/usr/include/boost -I/usr/include/openssl -LDFLAGS = -L/usr/include -L/usr/lib -L/usr/include/boost -L/usr/include/openssl -Wl,-rpath,/usr/lib +BOOST_SUFFIX = -mgw48-mt-1_59 +INCFLAGS = -I/usr/include/ -I/usr/local/include/ -I/c/dev/openssl/include -I/c/dev/boost/include/boost-1_59 +LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib -L/c/dev/openssl -L/c/dev/boost/lib LDLIBS = -Wl,-Bstatic -lboost_system$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_date_time$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_filesystem$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_regex$(BOOST_SUFFIX) -Wl,-Bstatic -lboost_program_options$(BOOST_SUFFIX) -Wl,-Bstatic -lssl -Wl,-Bstatic -lcrypto -Wl,-Bstatic -lz -Wl,-Bstatic -lwsock32 -Wl,-Bstatic -lws2_32 -Wl,-Bstatic -lgdi32 -Wl,-Bstatic -liphlpapi -static-libgcc -static-libstdc++ -Wl,-Bstatic -lstdc++ -Wl,-Bstatic -lpthread From f3a7c233b386ebccb1bd7413b55a0877f712bfa9 Mon Sep 17 00:00:00 2001 From: hagen Date: Thu, 21 Jan 2016 12:40:07 +0000 Subject: [PATCH 05/17] * I2PControl.cpp : #329 --- I2PControl.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index a706cd79..0c7b63ca 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -347,8 +347,10 @@ namespace client int api = params.get (I2P_CONTROL_PARAM_API); auto password = params.get (I2P_CONTROL_PARAM_PASSWORD); LogPrint (eLogDebug, "I2PControl Authenticate API=", api, " Password=", password); - if (password != m_Password) - LogPrint (eLogError, "I2PControl Authenticate Invalid password ", password, " expected ", m_Password); + if (password != m_Password) { + LogPrint (eLogError, "I2PControl: Authenticate - Invalid password: ", password); + return; + } InsertParam (results, I2P_CONTROL_PARAM_API, api); results << ","; std::string token = boost::lexical_cast(i2p::util::GetSecondsSinceEpoch ()); From 431af2c0ddfa8c3b1385b420be24c7099a125f22 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 21 Jan 2016 15:51:08 -0500 Subject: [PATCH 06/17] fixed issue #331. reuse existing local detination for tunnels --- ClientContext.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index 4e189f26..c1a1a274 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -273,7 +273,9 @@ namespace client { i2p::data::PrivateKeys k; LoadPrivateKeys (k, keys, sigType); - localDestination = CreateNewLocalDestination (k, false, &options); + localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); + if (!localDestination) + localDestination = CreateNewLocalDestination (k, false, &options); } auto clientTunnel = new I2PClientTunnel (name, dest, address, port, localDestination, destinationPort); if (m_ClientTunnels.insert (std::make_pair (port, std::unique_ptr(clientTunnel))).second) @@ -296,9 +298,12 @@ namespace client std::map options; ReadI2CPOptions (section, options); + std::shared_ptr localDestination = nullptr; i2p::data::PrivateKeys k; LoadPrivateKeys (k, keys, sigType); - auto localDestination = CreateNewLocalDestination (k, true, &options); + localDestination = FindLocalDestination (k.GetPublic ()->GetIdentHash ()); + if (!localDestination) + localDestination = CreateNewLocalDestination (k, true, &options); I2PServerTunnel * serverTunnel = (type == I2P_TUNNELS_SECTION_TYPE_HTTP) ? new I2PServerTunnelHTTP (name, host, port, localDestination, inPort) : new I2PServerTunnel (name, host, port, localDestination, inPort); From 92830172f94f450ae1c0c6eecadf0a60dd88a753 Mon Sep 17 00:00:00 2001 From: o Date: Fri, 22 Jan 2016 16:08:54 +0500 Subject: [PATCH 07/17] asdf --- HTTPProxy.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 12d2c765..c5466d4f 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -183,6 +183,19 @@ namespace proxy bool HTTPProxyHandler::HandleData(uint8_t *http_buff, std::size_t len) { assert(len); // This should always be called with a least a byte left to parse + + + // remove "Referer" from http requst + http_buff[len] = '\0'; + char *start = strstr((char *)http_buff, "\nReferer:"); + if (start!=0) + { + char *end = strstr(start+1, "\n"); + strncpy(start, end, (char*)(http_buff + len) - end); + len = len - (end - start); + } + + while (len > 0) { //TODO: fallback to finding HOst: header if needed From 939c28b74be424cb089d6d40dc4bd1b36c492cdf Mon Sep 17 00:00:00 2001 From: xcps Date: Fri, 22 Jan 2016 16:30:24 +0500 Subject: [PATCH 08/17] removed extra lines --- HTTPProxy.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index c5466d4f..17b8e816 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -184,7 +184,6 @@ namespace proxy { assert(len); // This should always be called with a least a byte left to parse - // remove "Referer" from http requst http_buff[len] = '\0'; char *start = strstr((char *)http_buff, "\nReferer:"); @@ -194,7 +193,6 @@ namespace proxy strncpy(start, end, (char*)(http_buff + len) - end); len = len - (end - start); } - while (len > 0) { From 66637886123d27aa6e636d703a9d3755598a3520 Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 22 Jan 2016 07:08:21 -0500 Subject: [PATCH 09/17] fixed some coding style --- HTTPProxy.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index 17b8e816..fcb8674a 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -185,13 +185,16 @@ namespace proxy assert(len); // This should always be called with a least a byte left to parse // remove "Referer" from http requst - http_buff[len] = '\0'; - char *start = strstr((char *)http_buff, "\nReferer:"); - if (start!=0) + http_buff[len] = 0; + auto start = strstr((char *)http_buff, "\nReferer:"); + if (start) { - char *end = strstr(start+1, "\n"); - strncpy(start, end, (char*)(http_buff + len) - end); - len = len - (end - start); + auto end = strchr (start + 1, '\n'); + if (end) + { + strncpy(start, end, (char *)(http_buff + len) - end); + len -= (end - start); + } } while (len > 0) From 03587d703583af7626e511eb70d774b39c6efffb Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 22 Jan 2016 10:56:25 -0500 Subject: [PATCH 10/17] changed data path back to AppData/Roaming --- util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util.cpp b/util.cpp index cff2aa75..e894c44f 100644 --- a/util.cpp +++ b/util.cpp @@ -215,15 +215,15 @@ namespace filesystem boost::filesystem::path GetDefaultDataDir() { - // Windows < Vista: C:\Documents and Settings\Username\.i2pd - // Windows >= Vista: C:\Users\Username\.i2pd + // Windows < Vista: C:\Documents and Settings\Username\Application Data\i2pd + // Windows >= Vista: C:\Users\Username\AppData\Roaming\i2pd // Mac: ~/Library/Application Support/i2pd // Unix: ~/.i2pd or /var/lib/i2pd is system=1 #ifdef WIN32 // Windows char localAppData[MAX_PATH]; - SHGetFolderPath(NULL, CSIDL_PROFILE, 0, 0, localAppData); - return boost::filesystem::path(std::string(localAppData) + "\\" + "." + appName); + SHGetFolderPath(NULL, CSIDL_APPDATA, 0, NULL, localAppData); + return boost::filesystem::path(std::string(localAppData) + "\\" + appName); #else /* UNIX */ if (i2p::util::config::GetArg("-service", 0)) // use system folder return boost::filesystem::path(std::string ("/var/lib/") + appName); From 1778d82bc3d7957b3eca8afcc88e59212d731f97 Mon Sep 17 00:00:00 2001 From: Andrey Alekseenko Date: Sat, 23 Jan 2016 17:34:58 +0300 Subject: [PATCH 11/17] Better checking if boost::asio::buffer works with std::array Otherwise, had troubles with clang 3.4 and boost 1.54 --- I2PControl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/I2PControl.cpp b/I2PControl.cpp index 0c7b63ca..ad81ec93 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -209,7 +209,7 @@ namespace client { auto request = std::make_shared(); socket->async_read_some ( -#if BOOST_VERSION >= 104900 +#if defined(BOOST_ASIO_HAS_STD_ARRAY) boost::asio::buffer (*request), #else boost::asio::buffer (request->data (), request->size ()), From f593802a51f5480e6331e8ebd379ec880b8429ff Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 23 Jan 2016 20:52:21 -0500 Subject: [PATCH 12/17] 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 From f7e21dbe5cf927017453f938ae3b1bc6fc82db61 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 23 Jan 2016 22:53:19 -0500 Subject: [PATCH 13/17] show tags for local destinations --- Garlic.h | 10 ++++++++++ HTTPServer.cpp | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/Garlic.h b/Garlic.h index 585d4f27..45903f3f 100644 --- a/Garlic.h +++ b/Garlic.h @@ -113,6 +113,10 @@ namespace garlic i2p::crypto::CBCEncryption m_Encryption; std::unique_ptr m_ElGamalEncryption; + + public: + // for HTTP only + size_t GetNumOutgoingTags () const { return m_SessionTags.size (); }; }; class GarlicDestination: public i2p::data::LocalDestination @@ -163,6 +167,12 @@ namespace garlic uint32_t m_LastTagsCleanupTime; // DeliveryStatus std::map > m_CreatedSessions; // msgID -> session + + public: + + // for HTTP only + size_t GetNumIncomingTags () const { return m_Tags.size (); } + const decltype(m_Sessions)& GetSessions () const { return m_Sessions; }; }; } } diff --git a/HTTPServer.cpp b/HTTPServer.cpp index e4a75e1a..2fef6e66 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -534,6 +534,13 @@ namespace util s << "
\r\n" << std::endl; } } + s << "Tags
Incoming: " << dest->GetNumIncomingTags () << "
Outgoing:
" << std::endl; + for (auto it: dest->GetSessions ()) + { + s << i2p::client::context.GetAddressBook ().ToAddress(it.first) << " "; + s << it.second->GetNumOutgoingTags () << "
" << std::endl; + } + s << "
" << std::endl; // s << "
\r\nStreams:
\r\n"; // for (auto it: dest->GetStreamingDestination ()->GetStreams ()) // { From 0c9ce6258c1ed9a42190dd98372d30614d44eef4 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 24 Jan 2016 09:59:02 -0500 Subject: [PATCH 14/17] sockoutproxy params added --- ClientContext.cpp | 4 +++- HTTPProxy.cpp | 5 +++-- SOCKS.cpp | 3 ++- SOCKS.h | 3 ++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index ef0d58c5..00c98451 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -53,8 +53,10 @@ namespace client std::string socksProxyAddr = i2p::util::config::GetArg("-socksproxyaddress", "127.0.0.1"); uint16_t socksProxyPort = i2p::util::config::GetArg("-socksproxyport", 4447); + std::string socksOutProxyAddr = i2p::util::config::GetArg("-socksoutproxyaddress", ""); + uint16_t socksOutProxyPort = i2p::util::config::GetArg("-socksoutproxyport", 0); LogPrint(eLogInfo, "Clients: starting SOCKS Proxy at ", socksProxyAddr, ":", socksProxyPort); - m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, localDestination); + m_SocksProxy = new i2p::proxy::SOCKSProxy(socksProxyAddr, socksProxyPort, socksOutProxyAddr, socksOutProxyPort, localDestination); m_SocksProxy->Start(); // I2P tunnels diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index fcb8674a..b4010a37 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -182,7 +182,8 @@ namespace proxy bool HTTPProxyHandler::HandleData(uint8_t *http_buff, std::size_t len) { - assert(len); // This should always be called with a least a byte left to parse + // TODO: we should srtrip 'Referer' better, because it might be inside message body + /*assert(len); // This should always be called with a least a byte left to parse // remove "Referer" from http requst http_buff[len] = 0; @@ -195,7 +196,7 @@ namespace proxy strncpy(start, end, (char *)(http_buff + len) - end); len -= (end - start); } - } + }*/ while (len > 0) { diff --git a/SOCKS.cpp b/SOCKS.cpp index 3a971a60..27b23df1 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -557,7 +557,8 @@ namespace proxy } } - SOCKSServer::SOCKSServer(const std::string& address, int port, std::shared_ptr localDestination) : + SOCKSServer::SOCKSServer(const std::string& address, int port, const std::string& outAddress, int outPort, + std::shared_ptr localDestination) : TCPIPAcceptor (address, port, localDestination ? localDestination : i2p::client::context.GetSharedLocalDestination ()) { } diff --git a/SOCKS.h b/SOCKS.h index cc2cfa24..82f068fb 100644 --- a/SOCKS.h +++ b/SOCKS.h @@ -15,7 +15,8 @@ namespace proxy { public: - SOCKSServer(const std::string& address, int port, std::shared_ptr localDestination = nullptr); + SOCKSServer(const std::string& address, int port, const std::string& outAddress, int outPort, + std::shared_ptr localDestination = nullptr); ~SOCKSServer() {}; protected: From 3f0b595085d6f6d8e7c624f5eace1f0edb814de2 Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 24 Jan 2016 22:24:39 -0500 Subject: [PATCH 15/17] fixed typo --- Streaming.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Streaming.cpp b/Streaming.cpp index 6834d4bb..ea90c1f0 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -714,7 +714,7 @@ namespace stream if (m_RemoteLeaseSet) { if (!m_RoutingSession) - m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, 32); + m_RoutingSession = m_LocalDestination.GetOwner ()->GetRoutingSession (m_RemoteLeaseSet, true); auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (false); // try without threshold first if (leases.empty ()) { From 30f68759ff5cbfc4103f579aeda5221ee7eabc9e Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 25 Jan 2016 13:34:04 -0500 Subject: [PATCH 16/17] fixed race condition --- Garlic.cpp | 27 +++++++++++++++------------ Garlic.h | 11 ++++++----- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Garlic.cpp b/Garlic.cpp index 09fd27b3..1bd5cc3f 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -100,7 +100,7 @@ namespace garlic if (ts >= it->second->tagsCreationTime + OUTGOING_TAGS_EXPIRATION_TIMEOUT) { if (m_Owner) - m_Owner->RemoveCreatedSession (it->first); + m_Owner->RemoveDeliveryStatusSession (it->first); delete it->second; it = m_UnconfirmedTagsMsgs.erase (it); } @@ -553,10 +553,13 @@ namespace garlic std::shared_ptr GarlicDestination::GetRoutingSession ( std::shared_ptr destination, bool attachLeaseSet) { - auto it = m_Sessions.find (destination->GetIdentHash ()); - std::shared_ptr session; - if (it != m_Sessions.end ()) - session = it->second; + GarlicRoutingSessionPtr session; + { + std::unique_lock l(m_SessionsMutex); + auto it = m_Sessions.find (destination->GetIdentHash ()); + if (it != m_Sessions.end ()) + session = it->second; + } if (!session) { session = std::make_shared (this, destination, @@ -582,25 +585,25 @@ namespace garlic } } - void GarlicDestination::RemoveCreatedSession (uint32_t msgID) + void GarlicDestination::RemoveDeliveryStatusSession (uint32_t msgID) { - m_CreatedSessions.erase (msgID); + m_DeliveryStatusSessions.erase (msgID); } - void GarlicDestination::DeliveryStatusSent (std::shared_ptr session, uint32_t msgID) + void GarlicDestination::DeliveryStatusSent (GarlicRoutingSessionPtr session, uint32_t msgID) { - m_CreatedSessions[msgID] = session; + m_DeliveryStatusSessions[msgID] = session; } void GarlicDestination::HandleDeliveryStatusMessage (std::shared_ptr msg) { uint32_t msgID = bufbe32toh (msg->GetPayload ()); { - auto it = m_CreatedSessions.find (msgID); - if (it != m_CreatedSessions.end ()) + auto it = m_DeliveryStatusSessions.find (msgID); + if (it != m_DeliveryStatusSessions.end ()) { it->second->MessageConfirmed (msgID); - m_CreatedSessions.erase (it); + m_DeliveryStatusSessions.erase (it); LogPrint (eLogDebug, "Garlic: message ", msgID, " acknowledged"); } } diff --git a/Garlic.h b/Garlic.h index 45903f3f..1bfcab7c 100644 --- a/Garlic.h +++ b/Garlic.h @@ -118,7 +118,8 @@ namespace garlic // for HTTP only size_t GetNumOutgoingTags () const { return m_SessionTags.size (); }; }; - + using GarlicRoutingSessionPtr = std::shared_ptr; + class GarlicDestination: public i2p::data::LocalDestination { public: @@ -129,13 +130,13 @@ namespace garlic void SetNumTags (int numTags) { m_NumTags = numTags; }; std::shared_ptr GetRoutingSession (std::shared_ptr destination, bool attachLeaseSet); void CleanupRoutingSessions (); - void RemoveCreatedSession (uint32_t msgID); + void RemoveDeliveryStatusSession (uint32_t msgID); std::shared_ptr WrapMessage (std::shared_ptr destination, std::shared_ptr msg, bool attachLeaseSet = false); void AddSessionKey (const uint8_t * key, const uint8_t * tag); // one tag virtual bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag); // from different thread - void DeliveryStatusSent (std::shared_ptr session, uint32_t msgID); + void DeliveryStatusSent (GarlicRoutingSessionPtr session, uint32_t msgID); virtual void ProcessGarlicMessage (std::shared_ptr msg); virtual void ProcessDeliveryStatusMessage (std::shared_ptr msg); @@ -161,12 +162,12 @@ namespace garlic // outgoing sessions int m_NumTags; std::mutex m_SessionsMutex; - std::map > m_Sessions; + std::map m_Sessions; // incoming std::map> m_Tags; uint32_t m_LastTagsCleanupTime; // DeliveryStatus - std::map > m_CreatedSessions; // msgID -> session + std::map m_DeliveryStatusSessions; // msgID -> session public: From 8061d306ddb4a870221c31204a3b6f028bd80008 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 25 Jan 2016 14:31:51 -0500 Subject: [PATCH 17/17] check tunnel payload size --- Tunnel.cpp | 5 +++++ TunnelEndpoint.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Tunnel.cpp b/Tunnel.cpp index 267485c8..47b3246c 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -482,6 +482,11 @@ namespace tunnel uint16_t len = bufbe16toh(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET); // we make payload as new I2NP message to send msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE; + if (msg->offset + len > msg->len) + { + LogPrint (eLogError, "Tunnel: gateway payload ", (int)len, " exceeds message length ", (int)msg->len); + return; + } msg->len = msg->offset + len; auto typeID = msg->GetTypeID (); LogPrint (eLogDebug, "Tunnel: gateway of ", (int) len, " bytes for tunnel ", tunnel->GetTunnelID (), ", msg type ", (int)typeID); diff --git a/TunnelEndpoint.cpp b/TunnelEndpoint.cpp index 151a4828..0b730d35 100644 --- a/TunnelEndpoint.cpp +++ b/TunnelEndpoint.cpp @@ -90,6 +90,11 @@ namespace tunnel msg->offset = fragment - msg->buf; msg->len = msg->offset + size; + if (msg->len > msg->maxLen) + { + LogPrint (eLogError, "TunnelMessage: fragment is too long ", (int)size); + return; + } if (fragment + size < decrypted + TUNNEL_DATA_ENCRYPTED_SIZE) { // this is not last message. we have to copy it