From 92b96d9b15206ee5ab7aa3777947f45ec881c6a0 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Apr 2014 12:19:12 -0400 Subject: [PATCH 1/4] fixed race condition --- Tunnel.cpp | 3 +++ Tunnel.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/Tunnel.cpp b/Tunnel.cpp index 9ccf4219..4b831fbc 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -154,11 +154,14 @@ namespace tunnel else block.deliveryType = eDeliveryTypeLocal; block.data = msg; + + std::unique_lock l(m_SendMutex); m_Gateway.SendTunnelDataMsg (block); } void OutboundTunnel::SendTunnelDataMsg (std::vector msgs) { + std::unique_lock l(m_SendMutex); for (auto& it : msgs) m_Gateway.PutTunnelDataMsg (it); m_Gateway.SendBuffer (); diff --git a/Tunnel.h b/Tunnel.h index 4328ddb3..d1d77fe9 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include "Queue.h" @@ -83,6 +84,7 @@ namespace tunnel private: + std::mutex m_SendMutex; TunnelGateway m_Gateway; }; From 879306b0d45b8bed6a7d8947ef53000fd196a217 Mon Sep 17 00:00:00 2001 From: cpubug Date: Thu, 3 Apr 2014 23:54:24 +0400 Subject: [PATCH 2/4] remove 'build' from .gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0e609a70..5d0b3605 100644 --- a/.gitignore +++ b/.gitignore @@ -53,7 +53,6 @@ local.properties [Dd]ebug/ [Rr]elease/ x64/ -build/ [Bb]in/ [Oo]bj/ @@ -200,7 +199,6 @@ $RECYCLE.BIN/ *.egg *.egg-info dist/ -build/ eggs/ parts/ var/ From adbfa688ba5563ab5b62dc5eb62a4095ee40bbde Mon Sep 17 00:00:00 2001 From: cpubug Date: Thu, 3 Apr 2014 23:54:43 +0400 Subject: [PATCH 3/4] CMAKE support added --- build/CMakeLists.txt | 94 ++++++++++++++++++++++++++ build/cmake_modules/FindCryptoPP.cmake | 28 ++++++++ 2 files changed, 122 insertions(+) create mode 100644 build/CMakeLists.txt create mode 100644 build/cmake_modules/FindCryptoPP.cmake diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt new file mode 100644 index 00000000..9a6299ff --- /dev/null +++ b/build/CMakeLists.txt @@ -0,0 +1,94 @@ + +cmake_minimum_required ( VERSION 2.8 ) + +project ( i2pd ) + +set ( SRC_DIR ".." ) +set ( INC_DIR ".." ) + +add_definitions ( "-std=c++0x -Wall" ) + +set ( SOURCES + AddressBook.cpp + Garlic.cpp + HTTPServer.cpp + i2p.cpp + Identity.cpp + Log.cpp + NTCPSession.cpp + RouterContext.cpp + SSU.cpp + TransitTunnel.cpp + Tunnel.cpp + TunnelGateway.cpp + UPnP.cpp + base64.cpp + HTTPProxy.cpp + I2NPProtocol.cpp + LeaseSet.cpp + NetDb.cpp + Reseed.cpp + RouterInfo.cpp + Streaming.cpp + Transports.cpp + TunnelEndpoint.cpp + TunnelPool.cpp + util.cpp +) + +set ( HEADERS + AddressBook.h + Garlic.h + HTTPServer.h + Identity.h + Log.h + NTCPSession.h + RouterContext.h + SSU.h + TransitTunnel.h + Tunnel.h + TunnelGateway.h + UPnP.h + base64.h + HTTPProxy.h + I2NPProtocol.h + LeaseSet.h + NetDb.h + Reseed.h + RouterInfo.h + Streaming.h + Transports.h + TunnelEndpoint.h + TunnelPool.h + util.h +) + +source_group ("Header Files" FILES ${HEADERS}) +source_group ("Source Files" FILES ${SOURCES}) + +find_package ( Threads REQUIRED ) + +find_package ( Boost COMPONENTS system filesystem regex program_options REQUIRED ) + +set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) +find_package ( CryptoPP REQUIRED ) + +include_directories ( ${Boost_INCLUDE_DIRS} ${CryptoPP_INCLUDE_DIRS}) + + +unset ( TMP ) +foreach ( src ${SOURCES} ) + list ( APPEND TMP "${SRC_DIR}/${src}" ) +endforeach () +set ( SOURCES ${TMP} ) + +unset ( TMP ) +foreach ( hdr ${HEADERS} ) + list ( APPEND TMP "${INC_DIR}/${hdr}" ) +endforeach () +set ( HEADERS ${TMP} ) + + +add_executable ( ${PROJECT_NAME} WIN32 ${HEADERS} ${SOURCES} ) + +target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ${CryptoPP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/build/cmake_modules/FindCryptoPP.cmake b/build/cmake_modules/FindCryptoPP.cmake new file mode 100644 index 00000000..68177b98 --- /dev/null +++ b/build/cmake_modules/FindCryptoPP.cmake @@ -0,0 +1,28 @@ +# Find Crypto++ library +# +# Output variables : +# CryptoPP_FOUND +# CryptoPP_INCLUDE_DIRS +# CryptoPP_LIBRARIES +# + + +FIND_PATH( CryptoPP_INCLUDE_DIR cryptopp/dsa.h ) + +FIND_LIBRARY( CryptoPP_LIBRARY NAMES cryptopp ) + +# handle the QUIETLY and REQUIRED arguments and set CRYPTOPP_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(CryptoPP DEFAULT_MSG CryptoPP_LIBRARY CryptoPP_INCLUDE_DIR) + +set ( CryptoPP_FOUND FALSE ) + +if ( ${CRYPTOPP_FOUND} ) + set ( CryptoPP_FOUND TRUE ) + set ( CryptoPP_INCLUDE_DIRS ${CryptoPP_INCLUDE_DIR} ) + set ( CryptoPP_LIBRARIES ${CryptoPP_LIBRARY} ) +endif () + +MARK_AS_ADVANCED(CryptoPP_INCLUDE_DIR CryptoPP_LIBRARY) + From 24f0ff6c00ef0e39e4ba4f2a94b7dcfa452ab4cb Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 3 Apr 2014 16:27:37 -0400 Subject: [PATCH 4/4] pick tunnels from exploratory pool for exploratory --- NetDb.cpp | 5 +++-- Tunnel.h | 1 + TunnelPool.cpp | 17 ++++++++++++++++- TunnelPool.h | 3 +++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NetDb.cpp b/NetDb.cpp index 57b5029a..1855ac30 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -532,8 +532,9 @@ namespace data void NetDb::Explore () { - auto outbound = i2p::tunnel::tunnels.GetNextOutboundTunnel (); - auto inbound = i2p::tunnel::tunnels.GetNextInboundTunnel (); + auto exploratoryPool = i2p::tunnel::tunnels.GetExploratoryPool (); + auto outbound = exploratoryPool ? exploratoryPool->GetNextOutboundTunnel () : nullptr; + auto inbound = exploratoryPool ? exploratoryPool->GetNextInboundTunnel () : nullptr; if (outbound && inbound) { CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); diff --git a/Tunnel.h b/Tunnel.h index d1d77fe9..16ffa9e4 100644 --- a/Tunnel.h +++ b/Tunnel.h @@ -117,6 +117,7 @@ namespace tunnel Tunnel * GetPendingTunnel (uint32_t replyMsgID); InboundTunnel * GetNextInboundTunnel (); OutboundTunnel * GetNextOutboundTunnel (); + TunnelPool * GetExploratoryPool () const { return m_ExploratoryPool; }; TransitTunnel * GetTransitTunnel (uint32_t tunnelID); void AddTransitTunnel (TransitTunnel * tunnel); void AddOutboundTunnel (OutboundTunnel * newTunnel); diff --git a/TunnelPool.cpp b/TunnelPool.cpp index 9b552101..33f6cbda 100644 --- a/TunnelPool.cpp +++ b/TunnelPool.cpp @@ -86,7 +86,22 @@ namespace tunnel m_LastOutboundTunnel = tunnel; return tunnel; } - + + InboundTunnel * TunnelPool::GetNextInboundTunnel () + { + return GetNextTunnel (m_InboundTunnels); + } + + template + typename TTunnels::value_type TunnelPool::GetNextTunnel (TTunnels& tunnels) + { + if (tunnels.empty ()) return nullptr; + for (auto it: tunnels) + if (!it->IsFailed ()) + return it; + return nullptr; + } + void TunnelPool::CreateTunnels () { int num = m_InboundTunnels.size (); diff --git a/TunnelPool.h b/TunnelPool.h index 0e18bcd4..1ff66cf3 100644 --- a/TunnelPool.h +++ b/TunnelPool.h @@ -37,6 +37,7 @@ namespace tunnel void TunnelExpired (OutboundTunnel * expiredTunnel); std::vector GetInboundTunnels (int num) const; OutboundTunnel * GetNextOutboundTunnel (); + InboundTunnel * GetNextInboundTunnel (); const i2p::data::IdentHash& GetIdentHash () { return m_LocalDestination.GetIdentHash (); }; void TestTunnels (); @@ -46,6 +47,8 @@ namespace tunnel void CreateInboundTunnel (); void CreateOutboundTunnel (); + template + typename TTunnels::value_type GetNextTunnel (TTunnels& tunnels); private: