From d025ba279334a718d3f62be1c59fbe4d90e096e2 Mon Sep 17 00:00:00 2001 From: alexandr Date: Mon, 26 Sep 2016 01:37:00 +0500 Subject: [PATCH 01/44] Fixed visibility of variable outboundTunnel --- I2CP.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/I2CP.cpp b/I2CP.cpp index 0352cd15..41f81155 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -109,7 +109,7 @@ namespace client } else { - auto outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel (); + outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel (); auto leases = remote->GetNonExpiredLeases (); if (!leases.empty ()) remoteLease = leases[rand () % leases.size ()]; From d6aca6fa00b322e9f965327641e8d2a68edadd1d Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 29 Sep 2016 11:24:52 -0400 Subject: [PATCH 02/44] always send reply --- I2CP.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/I2CP.cpp b/I2CP.cpp index 41f81155..e0139b9f 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -66,12 +66,19 @@ namespace client memcpy (buf + 4, payload, len); msg->len += len + 4; msg->FillI2NPMessageHeader (eI2NPData); + auto s = GetSharedFromThis (); auto remote = FindLeaseSet (ident); if (remote) - GetService ().post (std::bind (&I2CPDestination::SendMsg, GetSharedFromThis (), msg, remote)); + { + GetService ().post ( + [s, msg, remote, nonce]() + { + bool sent = s->SendMsg (msg, remote); + s->m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure); + }); + } else { - auto s = GetSharedFromThis (); RequestDestination (ident, [s, msg, nonce](std::shared_ptr ls) { From e4d60929392de06f9430ca5e442746f9aab133c6 Mon Sep 17 00:00:00 2001 From: orignal Date: Sat, 1 Oct 2016 15:05:35 -0400 Subject: [PATCH 03/44] copy addresses list atomically --- RouterInfo.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RouterInfo.cpp b/RouterInfo.cpp index ff08286a..f445ca02 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -771,7 +771,11 @@ namespace data std::shared_ptr RouterInfo::GetAddress (TransportStyle s, bool v4only, bool v6only) const { +#if (BOOST_VERSION >= 105300) + auto addresses = boost::atomic_load (&m_Addresses); +#else auto addresses = m_Addresses; +#endif for (const auto& address : *addresses) { if (address->transportStyle == s) From f79ad91a9a271058e8a6dc40d80f855e8999be3d Mon Sep 17 00:00:00 2001 From: alexandr Date: Mon, 3 Oct 2016 20:01:31 +0500 Subject: [PATCH 04/44] probably fix hanging of call I2CP-SendMsgTo-FindLeaseSet --- Destination.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index 48717f5f..f06c7711 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -171,7 +171,7 @@ namespace client std::shared_ptr LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident) { - std::lock_guard lock(m_RemoteLeaseSetsMutex); + std::unique_lock lock(m_RemoteLeaseSetsMutex); auto it = m_RemoteLeaseSets.find (ident); if (it != m_RemoteLeaseSets.end ()) { @@ -186,7 +186,6 @@ namespace client { ls->PopulateLeases(); { - std::lock_guard _lock(m_RemoteLeaseSetsMutex); m_RemoteLeaseSets[ident] = ls; } } @@ -203,15 +202,12 @@ namespace client if (ls && !ls->IsExpired ()) { ls->PopulateLeases (); // since we don't store them in netdb - { - std::lock_guard lock(m_RemoteLeaseSetsMutex); - m_RemoteLeaseSets[ident] = ls; - } + m_RemoteLeaseSets[ident] = ls; return ls; } } return nullptr; - } + } std::shared_ptr LeaseSetDestination::GetLeaseSet () { From 8ff2627e8eef895bc840d335aeca5db947077d79 Mon Sep 17 00:00:00 2001 From: alexandr Date: Mon, 3 Oct 2016 20:06:10 +0500 Subject: [PATCH 05/44] minimize count of errors "I2CP: Failed to send message. No outbound tunnels" --- I2CP.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/I2CP.cpp b/I2CP.cpp index e0139b9f..04f21408 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -103,7 +103,8 @@ namespace client } auto path = remoteSession->GetSharedRoutingPath (); std::shared_ptr outboundTunnel; - std::shared_ptr remoteLease; + std::shared_ptr remoteLease; + bool unconfirmedTags=false; if (path) { if (!remoteSession->CleanupUnconfirmedTags ()) // no stuck tags @@ -112,9 +113,12 @@ namespace client remoteLease = path->remoteLease; } else + { remoteSession->SetSharedRoutingPath (nullptr); + unconfirmedTags=true; + } } - else + if (!path || unconfirmedTags) { outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel (); auto leases = remote->GetNonExpiredLeases (); From 31dde394ebff8e08f00d515722e2508d065867b1 Mon Sep 17 00:00:00 2001 From: alexandr Date: Mon, 3 Oct 2016 20:20:45 +0500 Subject: [PATCH 06/44] remove unnecessary brackets --- Destination.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index f06c7711..dbdec0c7 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -185,9 +185,7 @@ namespace client if(ls && !ls->IsExpired()) { ls->PopulateLeases(); - { - m_RemoteLeaseSets[ident] = ls; - } + m_RemoteLeaseSets[ident] = ls; } }); } From 404715e02d4b565d0f8869c80f0e20094d8f97ba Mon Sep 17 00:00:00 2001 From: brain5lug Date: Mon, 3 Oct 2016 23:24:22 +0300 Subject: [PATCH 07/44] thread sanitizer configuration option have been added --- build/CMakeLists.txt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 95f223ef..00048942 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -16,7 +16,8 @@ option(WITH_UPNP "Include support for UPnP client" OFF) option(WITH_PCH "Use precompiled header" OFF) option(WITH_GUI "Include GUI (currently MS Windows only)" ON) option(WITH_MESHNET "Build for cjdns test network" OFF) -option(WITH_ADDRSANITIZER "Build with address sanitizer (linux only)" OFF) +option(WITH_ADDRSANITIZER "Build with address sanitizer unix only" OFF) +option(WITH_THREADSANITIZER "Build with thread sanitizer unix only" OFF) # paths set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) @@ -190,10 +191,22 @@ if (WITH_ADDRSANITIZER) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" ) set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address" ) else () - error ("MSVC does not support address sanitizer option") + message( SEND_ERROR "MSVC does not support address sanitizer option") endif() endif() +if (WITH_THREADSANITIZER) + if (WITH_ADDRSANITIZER) + message( FATAL_ERROR "thread sanitizer option cannot be combined with address sanitizer") + elseif (NOT MSVC) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread" ) + set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread" ) + else () + message( SEND_ERROR "MSVC does not support address sanitizer option") + endif() +endif() + + # libraries # TODO: once CMake 3.1+ becomes mainstream, see e.g. http://stackoverflow.com/a/29871891/673826 # use imported Threads::Threads instead @@ -347,6 +360,7 @@ message(STATUS " UPnP : ${WITH_UPNP}") message(STATUS " PCH : ${WITH_PCH}") message(STATUS " MESHNET : ${WITH_MESHNET}") message(STATUS " ADDRSANITIZER : ${WITH_ADDRSANITIZER}") +message(STATUS " THEADSANITIZER : ${WITH_THREADSANITIZER}") message(STATUS "---------------------------------------") #Handle paths nicely From 5350078543d0ac04a608f2c03efd4b9e1b8f9509 Mon Sep 17 00:00:00 2001 From: brain5lug Date: Tue, 4 Oct 2016 00:24:42 +0300 Subject: [PATCH 08/44] Unused parameter warnings removal --- AddressBook.cpp | 3 ++- BOB.cpp | 42 +++++++++++++++++++++--------------------- Destination.cpp | 6 +++--- Family.cpp | 2 +- I2CP.cpp | 15 ++++++++------- I2PControl.cpp | 8 ++++---- I2PTunnel.cpp | 5 +++-- LeaseSet.cpp | 2 +- RouterContext.cpp | 2 +- SAM.cpp | 15 ++++++++------- SOCKS.cpp | 4 ++-- SSUSession.cpp | 6 +++--- Streaming.cpp | 2 +- TransitTunnel.cpp | 4 ++-- Transports.cpp | 4 ++-- Tunnel.cpp | 6 +++--- 16 files changed, 65 insertions(+), 61 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index b993f456..67eb7566 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -599,7 +599,8 @@ namespace client } } - void AddressBook::HandleLookupResponse (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) + void AddressBook::HandleLookupResponse (const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, + uint16_t /*toPort*/, const uint8_t * buf, size_t len) { if (len < 44) { diff --git a/BOB.cpp b/BOB.cpp index 8ffffba6..2d96f4b2 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -284,7 +284,7 @@ namespace client std::placeholders::_1, std::placeholders::_2)); } - void BOBCommandSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred) + void BOBCommandSession::HandleSent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) { if (ecode) { @@ -338,20 +338,20 @@ namespace client Send (len); } - void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len) + void BOBCommandSession::ZapCommandHandler (const char * /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: zap"); Terminate (); } - void BOBCommandSession::QuitCommandHandler (const char * operand, size_t len) + void BOBCommandSession::QuitCommandHandler (const char * /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: quit"); m_IsOpen = false; SendReplyOK ("Bye!"); } - void BOBCommandSession::StartCommandHandler (const char * operand, size_t len) + void BOBCommandSession::StartCommandHandler (const char * /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: start ", m_Nickname); if (m_IsActive) @@ -373,7 +373,7 @@ namespace client m_IsActive = true; } - void BOBCommandSession::StopCommandHandler (const char * operand, size_t len) + void BOBCommandSession::StopCommandHandler (const char * /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: stop ", m_Nickname); if (!m_IsActive) @@ -392,7 +392,7 @@ namespace client m_IsActive = false; } - void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) + void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: setnick ", operand); m_Nickname = operand; @@ -401,7 +401,7 @@ namespace client SendReplyOK (msg.c_str ()); } - void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len) + void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: getnick ", operand); m_CurrentDestination = m_Owner.FindDestination (operand); @@ -420,40 +420,40 @@ namespace client SendReplyError ("no nickname has been set"); } - void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len) + void BOBCommandSession::NewkeysCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: newkeys"); m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len) + void BOBCommandSession::SetkeysCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: setkeys ", operand); m_Keys.FromBase64 (operand); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::GetkeysCommandHandler (const char * operand, size_t len) + void BOBCommandSession::GetkeysCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: getkeys"); SendReplyOK (m_Keys.ToBase64 ().c_str ()); } - void BOBCommandSession::GetdestCommandHandler (const char * operand, size_t len) + void BOBCommandSession::GetdestCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: getdest"); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len) + void BOBCommandSession::OuthostCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: outhost ", operand); m_Address = operand; SendReplyOK ("outhost set"); } - void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len) + void BOBCommandSession::OutportCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: outport ", operand); m_OutPort = boost::lexical_cast(operand); @@ -463,14 +463,14 @@ namespace client SendReplyError ("port out of range"); } - void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len) + void BOBCommandSession::InhostCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: inhost ", operand); m_Address = operand; SendReplyOK ("inhost set"); } - void BOBCommandSession::InportCommandHandler (const char * operand, size_t len) + void BOBCommandSession::InportCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: inport ", operand); m_InPort = boost::lexical_cast(operand); @@ -480,7 +480,7 @@ namespace client SendReplyError ("port out of range"); } - void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len) + void BOBCommandSession::QuietCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: quiet"); if (m_Nickname.length () > 0) @@ -497,7 +497,7 @@ namespace client SendReplyError ("no nickname has been set"); } - void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len) + void BOBCommandSession::LookupCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: lookup ", operand); i2p::data::IdentHash ident; @@ -525,7 +525,7 @@ namespace client } } - void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len) + void BOBCommandSession::ClearCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: clear"); m_Owner.DeleteDestination (m_Nickname); @@ -533,7 +533,7 @@ namespace client SendReplyOK ("cleared"); } - void BOBCommandSession::ListCommandHandler (const char * operand, size_t len) + void BOBCommandSession::ListCommandHandler (const char* /*operand*/, size_t /*len*/) { LogPrint (eLogDebug, "BOB: list"); const auto& destinations = m_Owner.GetDestinations (); @@ -542,7 +542,7 @@ namespace client SendReplyOK ("Listing done"); } - void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len) + void BOBCommandSession::OptionCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: option ", operand); const char * value = strchr (operand, '='); @@ -561,7 +561,7 @@ namespace client SendReplyError ("malformed"); } - void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len) + void BOBCommandSession::StatusCommandHandler (const char* operand, size_t /*len*/) { LogPrint (eLogDebug, "BOB: status ", operand); if (m_Nickname == operand) diff --git a/Destination.cpp b/Destination.cpp index 48717f5f..0aefa6ab 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -265,7 +265,7 @@ namespace client m_Service.post (std::bind (&LeaseSetDestination::HandleDeliveryStatusMessage, shared_from_this (), msg)); } - void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) + void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t /*len*/, std::shared_ptr from) { uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET]; switch (typeID) @@ -353,7 +353,7 @@ namespace client } } - void LeaseSetDestination::HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len) + void LeaseSetDestination::HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t /*len*/) { i2p::data::IdentHash key (buf); int num = buf[32]; // num @@ -737,7 +737,7 @@ namespace client ScheduleCheckForReady(p); } - void ClientDestination::HandleDataMessage (const uint8_t * buf, size_t len) + void ClientDestination::HandleDataMessage (const uint8_t * buf, size_t /*len*/) { uint32_t length = bufbe32toh (buf); buf += 4; diff --git a/Family.cpp b/Family.cpp index c1840e51..b37af204 100644 --- a/Family.cpp +++ b/Family.cpp @@ -110,7 +110,7 @@ namespace data } bool Families::VerifyFamily (const std::string& family, const IdentHash& ident, - const char * signature, const char * key) + const char * signature, const char * /*key*/) { uint8_t buf[50], signatureBuf[64]; size_t len = family.length (), signatureLen = strlen (signature); diff --git a/I2CP.cpp b/I2CP.cpp index 41f81155..3c8ed9bb 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -186,7 +186,7 @@ namespace client std::bind (&I2CPSession::HandleReceivedHeader, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); } - void I2CPSession::HandleReceivedHeader (const boost::system::error_code& ecode, std::size_t bytes_transferred) + void I2CPSession::HandleReceivedHeader (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) { if (ecode) Terminate (); @@ -213,7 +213,7 @@ namespace client std::bind (&I2CPSession::HandleReceivedPayload, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); } - void I2CPSession::HandleReceivedPayload (const boost::system::error_code& ecode, std::size_t bytes_transferred) + void I2CPSession::HandleReceivedPayload (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) { if (ecode) Terminate (); @@ -270,7 +270,8 @@ namespace client LogPrint (eLogError, "I2CP: Can't write to the socket"); } - void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, const uint8_t * buf) + void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, + std::size_t /*bytes_transferred*/, const uint8_t* buf) { delete[] buf; if (ecode && ecode != boost::asio::error::operation_aborted) @@ -385,7 +386,7 @@ namespace client } } - void I2CPSession::DestroySessionMessageHandler (const uint8_t * buf, size_t len) + void I2CPSession::DestroySessionMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) { SendSessionStatusMessage (0); // destroy LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " destroyed"); @@ -396,7 +397,7 @@ namespace client } } - void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len) + void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) { // TODO: implement actual reconfiguration SendSessionStatusMessage (2); // updated @@ -558,7 +559,7 @@ namespace client } } - void I2CPSession::DestLookupMessageHandler (const uint8_t * buf, size_t len) + void I2CPSession::DestLookupMessageHandler (const uint8_t * buf, size_t /*len*/) { if (m_Destination) { @@ -595,7 +596,7 @@ namespace client SendI2CPMessage (I2CP_DEST_REPLY_MESSAGE, buf, 32); } - void I2CPSession::GetBandwidthLimitsMessageHandler (const uint8_t * buf, size_t len) + void I2CPSession::GetBandwidthLimitsMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) { uint8_t limits[64]; memset (limits, 0, 64); diff --git a/I2PControl.cpp b/I2PControl.cpp index 3e2e3997..7f063f35 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -295,8 +295,8 @@ namespace client std::placeholders::_1, std::placeholders::_2, socket, buf)); } - void I2PControlService::HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, - std::shared_ptr socket, std::shared_ptr buf) + void I2PControlService::HandleResponseSent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/, + std::shared_ptr /*socket*/, std::shared_ptr /*buf*/) { if (ecode) { LogPrint (eLogError, "I2PControl: write error: ", ecode.message ()); @@ -453,7 +453,7 @@ namespace client InsertParam (results, "Shutdown", ""); m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(1)); // 1 second to make sure response has been sent m_ShutdownTimer.async_wait ( - [](const boost::system::error_code& ecode) + [](const boost::system::error_code&) { Daemon.running = 0; }); @@ -467,7 +467,7 @@ namespace client InsertParam (results, "ShutdownGraceful", ""); m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(timeout + 1)); // + 1 second m_ShutdownTimer.async_wait ( - [](const boost::system::error_code& ecode) + [](const boost::system::error_code&) { Daemon.running = 0; }); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index 0c58ba9d..a9c5c313 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -439,7 +439,7 @@ namespace client } void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - std::shared_ptr resolver) + std::shared_ptr /*resolver*/) { if (!ecode) { @@ -730,7 +730,8 @@ namespace client m_Session = new UDPSession(m_LocalEndpoint, m_LocalDest, ep, *m_RemoteIdent, LocalPort, RemotePort); } - void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) + void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, + uint16_t /*toPort*/, const uint8_t * buf, size_t len) { if(m_RemoteIdent && from.GetIdentHash() == *m_RemoteIdent) { diff --git a/LeaseSet.cpp b/LeaseSet.cpp index 04dc77c5..4ddd07f3 100644 --- a/LeaseSet.cpp +++ b/LeaseSet.cpp @@ -173,7 +173,7 @@ namespace data const std::vector > LeaseSet::GetNonExpiredLeases (bool withThreshold) const { - return GetNonExpiredLeasesExcluding( [] (const Lease & l) -> bool { return false; }, withThreshold); + return GetNonExpiredLeasesExcluding( [] (const Lease &) -> bool { return false; }, withThreshold); } const std::vector > LeaseSet::GetNonExpiredLeasesExcluding (LeaseInspectFunc exclude, bool withThreshold) const diff --git a/RouterContext.cpp b/RouterContext.cpp index 6824adb8..15084bd3 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -424,7 +424,7 @@ namespace i2p return i2p::tunnel::tunnels.GetExploratoryPool (); } - void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) + void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t /*len*/, std::shared_ptr from) { i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); } diff --git a/SAM.cpp b/SAM.cpp index 2864cd6f..ce85fc8d 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -135,7 +135,7 @@ namespace client } } - void SAMSocket::HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred) + void SAMSocket::HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) { if (ecode) { @@ -166,7 +166,7 @@ namespace client } } - void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close) + void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/, bool close) { if (ecode) { @@ -262,7 +262,7 @@ namespace client } } - void SAMSocket::ProcessSessionCreate (char * buf, size_t len) + void SAMSocket::ProcessSessionCreate (char * buf, size_t /*len*/) { LogPrint (eLogDebug, "SAM: session create: ", buf); std::map params; @@ -333,7 +333,7 @@ namespace client SendMessageReply (m_Buffer, l2, false); } - void SAMSocket::ProcessStreamConnect (char * buf, size_t len) + void SAMSocket::ProcessStreamConnect (char * buf, size_t /*len*/) { LogPrint (eLogDebug, "SAM: stream connect: ", buf); std::map params; @@ -389,7 +389,7 @@ namespace client } } - void SAMSocket::ProcessStreamAccept (char * buf, size_t len) + void SAMSocket::ProcessStreamAccept (char * buf, size_t /*len*/) { LogPrint (eLogDebug, "SAM: stream accept: ", buf); std::map params; @@ -460,7 +460,7 @@ namespace client SendMessageReply (m_Buffer, len, false); } - void SAMSocket::ProcessNamingLookup (char * buf, size_t len) + void SAMSocket::ProcessNamingLookup (char * buf, size_t /*len*/) { LogPrint (eLogDebug, "SAM: naming lookup: ", buf); std::map params; @@ -652,7 +652,8 @@ namespace client LogPrint (eLogWarning, "SAM: I2P acceptor has been reset"); } - void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) + void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, + uint16_t /*toPort*/, const uint8_t* buf, size_t len) { LogPrint (eLogDebug, "SAM: datagram received ", len); auto base64 = from.ToBase64 (); diff --git a/SOCKS.cpp b/SOCKS.cpp index 9d85963b..a52fe612 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -696,7 +696,7 @@ namespace proxy } - void SOCKSHandler::HandleUpstreamData(uint8_t * dataptr, std::size_t len) + void SOCKSHandler::HandleUpstreamData(uint8_t* /*dataptr*/, std::size_t len) { if (m_state == UPSTREAM_HANDSHAKE) { m_upstream_response_len += len; @@ -739,7 +739,7 @@ namespace proxy } } - void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr) + void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator) { if (ecode) { LogPrint(eLogWarning, "SOCKS: could not connect to upstream proxy: ", ecode.message()); diff --git a/SSUSession.cpp b/SSUSession.cpp index 5cd59164..fbb5b11d 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -536,7 +536,7 @@ namespace transport Send (buf, msgLen); } - void SSUSession::ProcessRelayRequest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from) + void SSUSession::ProcessRelayRequest (const uint8_t * buf, size_t /*len*/, const boost::asio::ip::udp::endpoint& from) { uint32_t relayTag = bufbe32toh (buf); auto session = m_Server.FindRelaySession (relayTag); @@ -637,7 +637,7 @@ namespace transport LogPrint (eLogDebug, "SSU: relay intro sent"); } - void SSUSession::ProcessRelayResponse (const uint8_t * buf, size_t len) + void SSUSession::ProcessRelayResponse (const uint8_t * buf, size_t /*len*/) { LogPrint (eLogDebug, "SSU message: Relay response received"); uint8_t remoteSize = *buf; @@ -689,7 +689,7 @@ namespace transport LogPrint (eLogError, "SSU: Unsolicited RelayResponse, nonce=", nonce); } - void SSUSession::ProcessRelayIntro (const uint8_t * buf, size_t len) + void SSUSession::ProcessRelayIntro (const uint8_t * buf, size_t /*len*/) { uint8_t size = *buf; if (size == 4) diff --git a/Streaming.cpp b/Streaming.cpp index 02e738c8..e8f5a897 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -729,7 +729,7 @@ namespace stream } } - void Stream::HandleAckSendTimer (const boost::system::error_code& ecode) + void Stream::HandleAckSendTimer (const boost::system::error_code&) { if (m_IsAckSendScheduled) { diff --git a/TransitTunnel.cpp b/TransitTunnel.cpp index dfe01a05..d06f5134 100644 --- a/TransitTunnel.cpp +++ b/TransitTunnel.cpp @@ -51,12 +51,12 @@ namespace tunnel } } - void TransitTunnel::SendTunnelDataMsg (std::shared_ptr msg) + void TransitTunnel::SendTunnelDataMsg (std::shared_ptr /*msg*/) { LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ()); } - void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr tunnelMsg) + void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr /*msg*/) { LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ()); } diff --git a/Transports.cpp b/Transports.cpp index a29cac15..e0d2df7a 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -394,7 +394,7 @@ namespace transport } void Transports::HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - i2p::data::IdentHash ident, std::shared_ptr resolver) + i2p::data::IdentHash ident, std::shared_ptr /*resolver*/) { auto it1 = m_Peers.find (ident); if (it1 != m_Peers.end ()) @@ -437,7 +437,7 @@ namespace transport } void Transports::HandleSSUResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - i2p::data::IdentHash ident, std::shared_ptr resolver) + i2p::data::IdentHash ident, std::shared_ptr /*resolver*/) { auto it1 = m_Peers.find (ident); if (it1 != m_Peers.end ()) diff --git a/Tunnel.cpp b/Tunnel.cpp index 7d2e6735..3749c9ca 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -90,7 +90,7 @@ namespace tunnel i2p::transport::transports.SendMessage (GetNextIdentHash (), msg); } - bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len) + bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t /*len*/) { LogPrint (eLogDebug, "Tunnel: TunnelBuildResponse ", (int)msg[0], " records."); @@ -161,7 +161,7 @@ namespace tunnel } } - void Tunnel::SendTunnelDataMsg (std::shared_ptr msg) + void Tunnel::SendTunnelDataMsg (std::shared_ptr /*msg*/) { LogPrint (eLogWarning, "Tunnel: Can't send I2NP messages without delivery instructions"); } @@ -256,7 +256,7 @@ namespace tunnel m_Gateway.SendBuffer (); } - void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr tunnelMsg) + void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr /*msg*/) { LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ()); } From 012ade500061da29693340a48cdd6b8e67d02293 Mon Sep 17 00:00:00 2001 From: Pavel Melkozerov Date: Tue, 4 Oct 2016 18:13:45 +0300 Subject: [PATCH 09/44] Added extra-cmake-modules --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index bb81757b..be16e890 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -142,9 +142,9 @@ install: - if not defined msvc ( C:\msys64\usr\bin\bash -lc "pacman --needed --noconfirm -Sy bash pacman pacman-mirrors msys2-runtime msys2-runtime-devel cmake" && if "%x64%" == "1" ( - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-openssl mingw-w64-x86_64-boost mingw-w64-x86_64-miniupnpc" + C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-openssl mingw-w64-x86_64-boost mingw-w64-x86_64-miniupnpc mingw-w64-x86_64-extra-cmake-modules" ) else ( - C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-i686-openssl mingw-w64-i686-boost mingw-w64-i686-miniupnpc" + C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-i686-openssl mingw-w64-i686-boost mingw-w64-i686-miniupnpc mingw-w64-i686-extra-cmake-modules" ) ) cache: From e8e3db688803309c7411b29f7b6ca0c159872f98 Mon Sep 17 00:00:00 2001 From: alexandr Date: Wed, 5 Oct 2016 01:20:43 +0500 Subject: [PATCH 10/44] fix f79ad91 --- Destination.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Destination.cpp b/Destination.cpp index dbdec0c7..0b8f2859 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -185,6 +185,7 @@ namespace client if(ls && !ls->IsExpired()) { ls->PopulateLeases(); + std::unique_lock lock(m_RemoteLeaseSetsMutex); m_RemoteLeaseSets[ident] = ls; } }); From cb0f9684673432dfe391985c82ca5b1b948c0277 Mon Sep 17 00:00:00 2001 From: alexandr Date: Wed, 5 Oct 2016 06:45:41 +0500 Subject: [PATCH 11/44] Added building option "USE_ASLR" --- Makefile.mingw | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile.mingw b/Makefile.mingw index 85b6b455..5a8e8fc0 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -37,11 +37,16 @@ ifeq ($(USE_WIN32_APP), yes) DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC)) endif -ifeq ($(USE_AESNI),1) +ifeq ($(USE_AESNI),yes) CPU_FLAGS = -maes -DAESNI else CPU_FLAGS = -msse endif +ifeq ($(USE_ASLR),yes) + LDFLAGS += -Wl,--nxcompat -Wl,--high-entropy-va \ + -Wl,--dynamicbase,--export-all-symbols +endif + obj/%.o : %.rc $(WINDRES) -i $< -o $@ From ae2b5dfd3ef4f6b343e2d4f81162444164049a64 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 4 Oct 2016 17:50:18 -0400 Subject: [PATCH 12/44] fix udp tunnel route switching logic --- Datagram.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Datagram.cpp b/Datagram.cpp index b9188864..92c2509c 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -276,7 +276,7 @@ namespace datagram // our path looks dead so we need to rotate paths if (now - m_LastSuccess >= DATAGRAM_SESSION_PATH_TIMEOUT) return true; // if we have a routing session and routing path we don't need to switch paths - return m_RoutingSession != nullptr && m_RoutingSession->GetSharedRoutingPath () != nullptr; + return m_RoutingSession == nullptr || m_RoutingSession->GetSharedRoutingPath () == nullptr; } @@ -291,7 +291,7 @@ namespace datagram if(currentLease) // if we have a lease return true if it's about to expire otherwise return false return currentLease->ExpiresWithin( DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW, DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE ); // we have no current lease, we should switch - return true; + return currentLease == nullptr; } std::shared_ptr DatagramSession::GetNextRoutingPath() From 30dfe129106dd2bb5240d3d877c03f378bc10b20 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 5 Oct 2016 10:45:41 -0400 Subject: [PATCH 13/44] try fixing appveyor --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index bb81757b..ddacb73b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,7 +22,7 @@ init: if exist \OpenSSL rmdir /S /Q \OpenSSL environment: - BOOST_ROOT: C:\Libraries\boost_1_59_0 + BOOST_ROOT: C:\Libraries\boost_1_60_0 MINIUPNPC: miniupnpc-1.9.20151026 OPENSSL: OpenSSL_1_0_2e ZLIB: zlib-1.2.8 @@ -167,7 +167,7 @@ build_script: echo "bitness=%bitness%; static=%static%; dll=%dll%; type=%type%; generator=%generator%; variant=%variant%; cmake=%cmake%; cmake_extra=%cmake_extra%" - if not defined msvc ( - C:\msys64\usr\bin\bash -lc "export PATH=/mingw%bitness%/bin:/usr/bin && cd /c/projects/build && CC=/mingw%bitness%/bin/gcc.exe CXX=/mingw%bitness%/bin/g++.exe /usr/bin/cmake /c/projects/i2pd/build -G 'Unix Makefiles' -DWITH_AESNI=ON -DWITH_UPNP=ON %cmake% %cmake_extra% -DWITH_STATIC=%static% -DWITH_HARDENING=ON -DCMAKE_INSTALL_PREFIX:PATH=/c/projects/instdir -DCMAKE_FIND_ROOT_PATH=/mingw%bitness% && make install" + C:\msys64\usr\bin\bash -lc "export PATH=/mingw%bitness%/bin:/usr/bin && cd /c/projects/build && CC=/mingw%bitness%/bin/gcc.exe CXX=/mingw%bitness%/bin/g++.exe /usr/bin/cmake /c/projects/i2pd/build -G 'Unix Makefiles' -DBOOSTROOT=/mingw%bitness%/ -DWITH_AESNI=ON -DWITH_UPNP=ON %cmake% %cmake_extra% -DWITH_STATIC=%static% -DWITH_HARDENING=ON -DCMAKE_INSTALL_PREFIX:PATH=/c/projects/instdir -DCMAKE_FIND_ROOT_PATH=/mingw%bitness% && make install" && 7z a -tzip -mx9 -mmt C:\projects\i2pd\i2pd-mingw-win%bitness%-%type%.zip C:\projects\instdir\* C:\msys64\mingw%bitness%\bin\zlib1.dll C:\msys64\mingw%bitness%\bin\*eay32.dll ) - rem We are fine with multiple generated configurations in MS solution. Will use later From 4a3bf46c30878bf5d3bcacd3eda11b285b219c19 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 5 Oct 2016 11:03:51 -0400 Subject: [PATCH 14/44] Revert "try fixing appveyor" This reverts commit 30dfe129106dd2bb5240d3d877c03f378bc10b20. --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ddacb73b..bb81757b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -22,7 +22,7 @@ init: if exist \OpenSSL rmdir /S /Q \OpenSSL environment: - BOOST_ROOT: C:\Libraries\boost_1_60_0 + BOOST_ROOT: C:\Libraries\boost_1_59_0 MINIUPNPC: miniupnpc-1.9.20151026 OPENSSL: OpenSSL_1_0_2e ZLIB: zlib-1.2.8 @@ -167,7 +167,7 @@ build_script: echo "bitness=%bitness%; static=%static%; dll=%dll%; type=%type%; generator=%generator%; variant=%variant%; cmake=%cmake%; cmake_extra=%cmake_extra%" - if not defined msvc ( - C:\msys64\usr\bin\bash -lc "export PATH=/mingw%bitness%/bin:/usr/bin && cd /c/projects/build && CC=/mingw%bitness%/bin/gcc.exe CXX=/mingw%bitness%/bin/g++.exe /usr/bin/cmake /c/projects/i2pd/build -G 'Unix Makefiles' -DBOOSTROOT=/mingw%bitness%/ -DWITH_AESNI=ON -DWITH_UPNP=ON %cmake% %cmake_extra% -DWITH_STATIC=%static% -DWITH_HARDENING=ON -DCMAKE_INSTALL_PREFIX:PATH=/c/projects/instdir -DCMAKE_FIND_ROOT_PATH=/mingw%bitness% && make install" + C:\msys64\usr\bin\bash -lc "export PATH=/mingw%bitness%/bin:/usr/bin && cd /c/projects/build && CC=/mingw%bitness%/bin/gcc.exe CXX=/mingw%bitness%/bin/g++.exe /usr/bin/cmake /c/projects/i2pd/build -G 'Unix Makefiles' -DWITH_AESNI=ON -DWITH_UPNP=ON %cmake% %cmake_extra% -DWITH_STATIC=%static% -DWITH_HARDENING=ON -DCMAKE_INSTALL_PREFIX:PATH=/c/projects/instdir -DCMAKE_FIND_ROOT_PATH=/mingw%bitness% && make install" && 7z a -tzip -mx9 -mmt C:\projects\i2pd\i2pd-mingw-win%bitness%-%type%.zip C:\projects\instdir\* C:\msys64\mingw%bitness%\bin\zlib1.dll C:\msys64\mingw%bitness%\bin\*eay32.dll ) - rem We are fine with multiple generated configurations in MS solution. Will use later From 71d4221af2604850363ed890949fe5227af85cd3 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Wed, 5 Oct 2016 10:06:06 -0400 Subject: [PATCH 15/44] add keyinfo tool --- .gitignore | 10 ++++- Makefile | 8 +++- contrib/tools/Makefile | 7 ++++ contrib/tools/README.md | 6 +++ contrib/tools/keyinfo/Makefile | 8 ++++ contrib/tools/keyinfo/README.md | 5 +++ contrib/tools/keyinfo/keyinfo.cpp | 70 +++++++++++++++++++++++++++++++ 7 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 contrib/tools/Makefile create mode 100644 contrib/tools/README.md create mode 100644 contrib/tools/keyinfo/Makefile create mode 100644 contrib/tools/keyinfo/README.md create mode 100644 contrib/tools/keyinfo/keyinfo.cpp diff --git a/.gitignore b/.gitignore index b6cffd15..73297488 100644 --- a/.gitignore +++ b/.gitignore @@ -14,7 +14,7 @@ netDb autom4te.cache .deps stamp-h1 -Makefile +#Makefile config.h config.h.in~ config.log @@ -238,3 +238,11 @@ pip-log.txt # Sphinx docs/_build /androidIdea/ + + +# emacs files +*~ +*\#* + +# gdb files +.gdb_history \ No newline at end of file diff --git a/Makefile b/Makefile index 147bedd4..c68b977e 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,13 @@ $(ARLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) $(ARLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) ar -r $@ $^ -clean: +tools: $(ARLIB) + $(MAKE) -C contrib/tools/ + +clean-tools: + $(MAKE) -C contrib/tools/ clean + +clean: clean-tools rm -rf obj rm -rf docs/generated $(RM) $(I2PD) $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) diff --git a/contrib/tools/Makefile b/contrib/tools/Makefile new file mode 100644 index 00000000..6c60bb59 --- /dev/null +++ b/contrib/tools/Makefile @@ -0,0 +1,7 @@ + + +all: + $(MAKE) -C keyinfo keyinfo + +clean: + $(MAKE) -C keyinfo clean diff --git a/contrib/tools/README.md b/contrib/tools/README.md new file mode 100644 index 00000000..e598adfa --- /dev/null +++ b/contrib/tools/README.md @@ -0,0 +1,6 @@ +Collection of i2pd related tools + +# Buildling + + +run `make tools` in the root of the repo diff --git a/contrib/tools/keyinfo/Makefile b/contrib/tools/keyinfo/Makefile new file mode 100644 index 00000000..44a13ff7 --- /dev/null +++ b/contrib/tools/keyinfo/Makefile @@ -0,0 +1,8 @@ +CXXFLAGS = -I ../../../ +all: keyinfo + +keyinfo: + $(CXX) -o keyinfo keyinfo.cpp $(CXXFLAGS) -std=c++11 ../../../libi2pd.a -lssl -lcrypto -lboost_system + +clean: + $(RM) keyinfo diff --git a/contrib/tools/keyinfo/README.md b/contrib/tools/keyinfo/README.md new file mode 100644 index 00000000..b3c39a4b --- /dev/null +++ b/contrib/tools/keyinfo/README.md @@ -0,0 +1,5 @@ +# keyinfo + +print information about a private key file + + diff --git a/contrib/tools/keyinfo/keyinfo.cpp b/contrib/tools/keyinfo/keyinfo.cpp new file mode 100644 index 00000000..6b6689c6 --- /dev/null +++ b/contrib/tools/keyinfo/keyinfo.cpp @@ -0,0 +1,70 @@ +#include "Identity.h" +#include +#include +#include +#include +#include + +int main(int argc, char * argv[]) +{ + if(argc == 1) { + std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; + return -1; + } + int opt; + bool print_full = false; + bool verbose = false; + while((opt = getopt(argc, argv, "vd"))!=-1) { + switch(opt){ + case 'v': + verbose = true; + break; + case 'd': + print_full = true; + break; + default: + std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; + return -1; + } + } + std::string fname(argv[optind]); + i2p::data::PrivateKeys keys; + { + std::vector buff; + std::ifstream inf; + inf.open(fname); + if (!inf.is_open()) { + std::cout << "cannot open private key file " << fname << std::endl; + return 2; + } + inf.seekg(0, std::ios::end); + const std::size_t len = inf.tellg(); + inf.seekg(0, std::ios::beg); + buff.resize(len); + inf.read((char*)buff.data(), buff.size()); + if (!keys.FromBuffer(buff.data(), buff.size())) { + std::cout << "bad key file format" << std::endl; + return 3; + } + } + auto dest = keys.GetPublic(); + if(!dest) { + std::cout << "failed to extract public key" << std::endl; + return 3; + } + + const auto & ident = dest->GetIdentHash(); + if (verbose) { + std::cout << "Destination: " << dest->ToBase64() << std::endl; + std::cout << "Destination Hash: " << ident.ToBase64() << std::endl; + std::cout << "B32 Address: " << ident.ToBase32() << ".b32.i2p" << std::endl; + std::cout << "Signature Type: " << (int) dest->GetSigningKeyType() << std::endl; + std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl; + } else { + if(print_full) { + std::cout << dest->ToBase64() << std::endl; + } else { + std::cout << ident.ToBase32() << ".b32.i2p" << std::endl; + } + } +} From 5a796a86d70e9be041fa8d785d85b0441572b399 Mon Sep 17 00:00:00 2001 From: brain5lug Date: Mon, 3 Oct 2016 23:24:22 +0300 Subject: [PATCH 16/44] thread sanitizer configuration option have been added --- build/CMakeLists.txt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 95f223ef..00048942 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -16,7 +16,8 @@ option(WITH_UPNP "Include support for UPnP client" OFF) option(WITH_PCH "Use precompiled header" OFF) option(WITH_GUI "Include GUI (currently MS Windows only)" ON) option(WITH_MESHNET "Build for cjdns test network" OFF) -option(WITH_ADDRSANITIZER "Build with address sanitizer (linux only)" OFF) +option(WITH_ADDRSANITIZER "Build with address sanitizer unix only" OFF) +option(WITH_THREADSANITIZER "Build with thread sanitizer unix only" OFF) # paths set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) @@ -190,10 +191,22 @@ if (WITH_ADDRSANITIZER) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer" ) set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address" ) else () - error ("MSVC does not support address sanitizer option") + message( SEND_ERROR "MSVC does not support address sanitizer option") endif() endif() +if (WITH_THREADSANITIZER) + if (WITH_ADDRSANITIZER) + message( FATAL_ERROR "thread sanitizer option cannot be combined with address sanitizer") + elseif (NOT MSVC) + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread" ) + set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread" ) + else () + message( SEND_ERROR "MSVC does not support address sanitizer option") + endif() +endif() + + # libraries # TODO: once CMake 3.1+ becomes mainstream, see e.g. http://stackoverflow.com/a/29871891/673826 # use imported Threads::Threads instead @@ -347,6 +360,7 @@ message(STATUS " UPnP : ${WITH_UPNP}") message(STATUS " PCH : ${WITH_PCH}") message(STATUS " MESHNET : ${WITH_MESHNET}") message(STATUS " ADDRSANITIZER : ${WITH_ADDRSANITIZER}") +message(STATUS " THEADSANITIZER : ${WITH_THREADSANITIZER}") message(STATUS "---------------------------------------") #Handle paths nicely From 77ec4b5cad20ae6af5f89744d97337369cf6326e Mon Sep 17 00:00:00 2001 From: orignal Date: Sun, 9 Oct 2016 14:57:15 -0400 Subject: [PATCH 17/44] added warning --- Makefile.mingw | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.mingw b/Makefile.mingw index 85b6b455..2ab918b4 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -37,6 +37,7 @@ ifeq ($(USE_WIN32_APP), yes) DAEMON_OBJS += $(patsubst %.rc,obj/%.o,$(DAEMON_RC)) endif +# don't change following line to ifeq ($(USE_AESNI),yes) !!! ifeq ($(USE_AESNI),1) CPU_FLAGS = -maes -DAESNI else From 0fc4e01b1eca3c4c0719487c5c0ef4acb4fd1141 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 08:18:54 -0400 Subject: [PATCH 18/44] remove tools --- Makefile | 8 +--- contrib/tools/Makefile | 7 ---- contrib/tools/README.md | 6 --- contrib/tools/keyinfo/Makefile | 8 ---- contrib/tools/keyinfo/README.md | 5 --- contrib/tools/keyinfo/keyinfo.cpp | 70 ------------------------------- 6 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 contrib/tools/Makefile delete mode 100644 contrib/tools/README.md delete mode 100644 contrib/tools/keyinfo/Makefile delete mode 100644 contrib/tools/keyinfo/README.md delete mode 100644 contrib/tools/keyinfo/keyinfo.cpp diff --git a/Makefile b/Makefile index c68b977e..147bedd4 100644 --- a/Makefile +++ b/Makefile @@ -80,13 +80,7 @@ $(ARLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) $(ARLIB_CLIENT): $(patsubst %.cpp,obj/%.o,$(LIB_CLIENT_SRC)) ar -r $@ $^ -tools: $(ARLIB) - $(MAKE) -C contrib/tools/ - -clean-tools: - $(MAKE) -C contrib/tools/ clean - -clean: clean-tools +clean: rm -rf obj rm -rf docs/generated $(RM) $(I2PD) $(SHLIB) $(ARLIB) $(SHLIB_CLIENT) $(ARLIB_CLIENT) diff --git a/contrib/tools/Makefile b/contrib/tools/Makefile deleted file mode 100644 index 6c60bb59..00000000 --- a/contrib/tools/Makefile +++ /dev/null @@ -1,7 +0,0 @@ - - -all: - $(MAKE) -C keyinfo keyinfo - -clean: - $(MAKE) -C keyinfo clean diff --git a/contrib/tools/README.md b/contrib/tools/README.md deleted file mode 100644 index e598adfa..00000000 --- a/contrib/tools/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Collection of i2pd related tools - -# Buildling - - -run `make tools` in the root of the repo diff --git a/contrib/tools/keyinfo/Makefile b/contrib/tools/keyinfo/Makefile deleted file mode 100644 index 44a13ff7..00000000 --- a/contrib/tools/keyinfo/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -CXXFLAGS = -I ../../../ -all: keyinfo - -keyinfo: - $(CXX) -o keyinfo keyinfo.cpp $(CXXFLAGS) -std=c++11 ../../../libi2pd.a -lssl -lcrypto -lboost_system - -clean: - $(RM) keyinfo diff --git a/contrib/tools/keyinfo/README.md b/contrib/tools/keyinfo/README.md deleted file mode 100644 index b3c39a4b..00000000 --- a/contrib/tools/keyinfo/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# keyinfo - -print information about a private key file - - diff --git a/contrib/tools/keyinfo/keyinfo.cpp b/contrib/tools/keyinfo/keyinfo.cpp deleted file mode 100644 index 6b6689c6..00000000 --- a/contrib/tools/keyinfo/keyinfo.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "Identity.h" -#include -#include -#include -#include -#include - -int main(int argc, char * argv[]) -{ - if(argc == 1) { - std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; - return -1; - } - int opt; - bool print_full = false; - bool verbose = false; - while((opt = getopt(argc, argv, "vd"))!=-1) { - switch(opt){ - case 'v': - verbose = true; - break; - case 'd': - print_full = true; - break; - default: - std::cout << "usage: " << argv[0] << " [-v] [-d] privatekey.dat" << std::endl; - return -1; - } - } - std::string fname(argv[optind]); - i2p::data::PrivateKeys keys; - { - std::vector buff; - std::ifstream inf; - inf.open(fname); - if (!inf.is_open()) { - std::cout << "cannot open private key file " << fname << std::endl; - return 2; - } - inf.seekg(0, std::ios::end); - const std::size_t len = inf.tellg(); - inf.seekg(0, std::ios::beg); - buff.resize(len); - inf.read((char*)buff.data(), buff.size()); - if (!keys.FromBuffer(buff.data(), buff.size())) { - std::cout << "bad key file format" << std::endl; - return 3; - } - } - auto dest = keys.GetPublic(); - if(!dest) { - std::cout << "failed to extract public key" << std::endl; - return 3; - } - - const auto & ident = dest->GetIdentHash(); - if (verbose) { - std::cout << "Destination: " << dest->ToBase64() << std::endl; - std::cout << "Destination Hash: " << ident.ToBase64() << std::endl; - std::cout << "B32 Address: " << ident.ToBase32() << ".b32.i2p" << std::endl; - std::cout << "Signature Type: " << (int) dest->GetSigningKeyType() << std::endl; - std::cout << "Encryption Type: " << (int) dest->GetCryptoKeyType() << std::endl; - } else { - if(print_full) { - std::cout << dest->ToBase64() << std::endl; - } else { - std::cout << ident.ToBase32() << ".b32.i2p" << std::endl; - } - } -} From 8ba142eb4573d44b549bb220caae3313a9145f8d Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 6 Oct 2016 10:28:56 -0400 Subject: [PATCH 19/44] increase datagram session switching interval --- Datagram.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Datagram.h b/Datagram.h index f3aae6f9..c4ab8cd2 100644 --- a/Datagram.h +++ b/Datagram.h @@ -24,7 +24,7 @@ namespace datagram // milliseconds for how long we try sticking to a dead routing path before trying to switch const uint64_t DATAGRAM_SESSION_PATH_TIMEOUT = 5000; // milliseconds interval a routing path is used before switching - const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 60 * 1000; + const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 5 * 60 * 1000; // milliseconds before lease expire should we try switching leases const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 10 * 1000; // milliseconds fudge factor for leases handover From 43c3bdf7c55141ecc6747b9c6cde7d45ed413bc0 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 6 Oct 2016 13:41:18 -0400 Subject: [PATCH 20/44] fix --- Datagram.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Datagram.h b/Datagram.h index c4ab8cd2..f5397e56 100644 --- a/Datagram.h +++ b/Datagram.h @@ -24,7 +24,7 @@ namespace datagram // milliseconds for how long we try sticking to a dead routing path before trying to switch const uint64_t DATAGRAM_SESSION_PATH_TIMEOUT = 5000; // milliseconds interval a routing path is used before switching - const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 5 * 60 * 1000; + const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000; // milliseconds before lease expire should we try switching leases const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 10 * 1000; // milliseconds fudge factor for leases handover From 577d9ddf6571fb05aecc7b391363ba0040bb1a4c Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sun, 9 Oct 2016 10:55:55 -0400 Subject: [PATCH 21/44] fix memory leak with udp tunnel --- Datagram.cpp | 31 ++++++++++++++++++------------- Datagram.h | 3 ++- I2PTunnel.cpp | 16 +++++----------- I2PTunnel.h | 2 +- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Datagram.cpp b/Datagram.cpp index 92c2509c..0fce1166 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -12,8 +12,10 @@ namespace i2p namespace datagram { DatagramDestination::DatagramDestination (std::shared_ptr owner): - m_Owner (owner.get()), m_Receiver (nullptr) + m_Owner (owner.get()), + m_Receiver (nullptr) { + m_Identity.FromBase64 (owner->GetIdentity()->ToBase64()); } DatagramDestination::~DatagramDestination () @@ -24,16 +26,16 @@ namespace datagram void DatagramDestination::SendDatagramTo (const uint8_t * payload, size_t len, const i2p::data::IdentHash& ident, uint16_t fromPort, uint16_t toPort) { auto owner = m_Owner; - auto i = owner->GetIdentity(); - uint8_t buf[MAX_DATAGRAM_SIZE]; - auto identityLen = i->ToBuffer (buf, MAX_DATAGRAM_SIZE); + std::vector v(MAX_DATAGRAM_SIZE); + uint8_t * buf = v.data(); + auto identityLen = m_Identity.ToBuffer (buf, MAX_DATAGRAM_SIZE); uint8_t * signature = buf + identityLen; - auto signatureLen = i->GetSignatureLen (); + auto signatureLen = m_Identity.GetSignatureLen (); uint8_t * buf1 = signature + signatureLen; size_t headerLen = identityLen + signatureLen; memcpy (buf1, payload, len); - if (i->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) + if (m_Identity.GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) { uint8_t hash[32]; SHA256(buf1, len, hash); @@ -48,7 +50,7 @@ namespace datagram } - void DatagramDestination::HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) + void DatagramDestination::HandleDatagram (uint16_t fromPort, uint16_t toPort,uint8_t * const &buf, size_t len) { i2p::data::IdentityEx identity; size_t identityLen = identity.FromBuffer (buf, len); @@ -93,7 +95,7 @@ namespace datagram uint8_t uncompressed[MAX_DATAGRAM_SIZE]; size_t uncompressedLen = m_Inflator.Inflate (buf, len, uncompressed, MAX_DATAGRAM_SIZE); if (uncompressedLen) - HandleDatagram (fromPort, toPort, uncompressed, uncompressedLen); + HandleDatagram (fromPort, toPort, uncompressed, uncompressedLen); } std::shared_ptr DatagramDestination::CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort) @@ -121,7 +123,7 @@ namespace datagram if (m_Sessions.empty ()) return; auto now = i2p::util::GetMillisecondsSinceEpoch(); LogPrint(eLogDebug, "DatagramDestination: clean up sessions"); - std::lock_guard lock(m_SessionsMutex); + std::unique_lock lock(m_SessionsMutex); // for each session ... for (auto it = m_Sessions.begin (); it != m_Sessions.end (); ) { @@ -270,13 +272,16 @@ namespace datagram bool DatagramSession::ShouldUpdateRoutingPath() const { + bool dead = m_RoutingSession == nullptr || m_RoutingSession->GetSharedRoutingPath () == nullptr; auto now = i2p::util::GetMillisecondsSinceEpoch (); // we need to rotate paths becuase the routing path is too old - if (now - m_LastPathChange >= DATAGRAM_SESSION_PATH_SWITCH_INTERVAL) return true; - // our path looks dead so we need to rotate paths - if (now - m_LastSuccess >= DATAGRAM_SESSION_PATH_TIMEOUT) return true; + // if (now - m_LastPathChange >= DATAGRAM_SESSION_PATH_SWITCH_INTERVAL) return true; + // too fast switching paths + if (now - m_LastPathChange < DATAGRAM_SESSION_PATH_MIN_LIFETIME ) return false; + // our path looks dead so we need to rotate paths + if (now - m_LastSuccess >= DATAGRAM_SESSION_PATH_TIMEOUT) return !dead; // if we have a routing session and routing path we don't need to switch paths - return m_RoutingSession == nullptr || m_RoutingSession->GetSharedRoutingPath () == nullptr; + return dead; } diff --git a/Datagram.h b/Datagram.h index f5397e56..aa7f3ba1 100644 --- a/Datagram.h +++ b/Datagram.h @@ -133,13 +133,14 @@ namespace datagram std::shared_ptr CreateDataMessage (const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort); - void HandleDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len); + void HandleDatagram (uint16_t fromPort, uint16_t toPort, uint8_t *const& buf, size_t len); /** find a receiver by port, if none by port is found try default receiever, otherwise returns nullptr */ Receiver FindReceiver(uint16_t port); private: i2p::client::ClientDestination * m_Owner; + i2p::data::IdentityEx m_Identity; Receiver m_Receiver; // default std::mutex m_SessionsMutex; std::map > m_Sessions; diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index a9c5c313..a1814058 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -559,23 +559,23 @@ namespace client } /** create new udp session */ boost::asio::ip::udp::endpoint ep(m_LocalAddress, 0); - m_Sessions.push_back(new UDPSession(ep, m_LocalDest, m_RemoteEndpoint, ih, localPort, remotePort)); + m_Sessions.push_back(new UDPSession(ep, m_LocalDest, m_RemoteEndpoint, &ih, localPort, remotePort)); return m_Sessions.back(); } UDPSession::UDPSession(boost::asio::ip::udp::endpoint localEndpoint, const std::shared_ptr & localDestination, - boost::asio::ip::udp::endpoint endpoint, const i2p::data::IdentHash to, + boost::asio::ip::udp::endpoint endpoint, const i2p::data::IdentHash * to, uint16_t ourPort, uint16_t theirPort) : m_Destination(localDestination->GetDatagramDestination()), m_Service(localDestination->GetService()), IPSocket(localDestination->GetService(), localEndpoint), - Identity(to), SendEndpoint(endpoint), LastActivity(i2p::util::GetMillisecondsSinceEpoch()), LocalPort(ourPort), RemotePort(theirPort) { + memcpy(Identity, to->data(), 32); Receive(); } @@ -592,13 +592,7 @@ namespace client { LogPrint(eLogDebug, "UDPSession: forward ", len, "B from ", FromEndpoint); LastActivity = i2p::util::GetMillisecondsSinceEpoch(); - uint8_t * data = new uint8_t[len]; - memcpy(data, m_Buffer, len); - m_Service.post([&,len, data] () { - m_Destination->SendDatagramTo(data, len, Identity, 0, 0); - delete [] data; - }); - + m_Destination->SendDatagramTo(m_Buffer, len, Identity, 0, 0); Receive(); } else { LogPrint(eLogError, "UDPSession: ", ecode.message()); @@ -727,7 +721,7 @@ namespace client if(m_Session) delete m_Session; boost::asio::ip::udp::endpoint ep(boost::asio::ip::address::from_string("127.0.0.1"), 0); - m_Session = new UDPSession(m_LocalEndpoint, m_LocalDest, ep, *m_RemoteIdent, LocalPort, RemotePort); + m_Session = new UDPSession(m_LocalEndpoint, m_LocalDest, ep, m_RemoteIdent, LocalPort, RemotePort); } void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, diff --git a/I2PTunnel.h b/I2PTunnel.h index dce9f812..e6f0e84f 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -155,7 +155,7 @@ namespace client UDPSession(boost::asio::ip::udp::endpoint localEndpoint, const std::shared_ptr & localDestination, - boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash ident, + boost::asio::ip::udp::endpoint remote, const i2p::data::IdentHash * ident, uint16_t ourPort, uint16_t theirPort); void HandleReceived(const boost::system::error_code & ecode, std::size_t len); void Receive(); From 7506619f4cde2e22197af117eb0943d1f5e4314c Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Sat, 8 Oct 2016 11:58:26 -0400 Subject: [PATCH 22/44] add minimum path lifetime --- Datagram.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Datagram.h b/Datagram.h index aa7f3ba1..614a4734 100644 --- a/Datagram.h +++ b/Datagram.h @@ -22,14 +22,15 @@ namespace datagram // milliseconds for max session idle time const uint64_t DATAGRAM_SESSION_MAX_IDLE = 10 * 60 * 1000; // milliseconds for how long we try sticking to a dead routing path before trying to switch - const uint64_t DATAGRAM_SESSION_PATH_TIMEOUT = 5000; + const uint64_t DATAGRAM_SESSION_PATH_TIMEOUT = 10 * 1000; // milliseconds interval a routing path is used before switching const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000; // milliseconds before lease expire should we try switching leases const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 10 * 1000; // milliseconds fudge factor for leases handover const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE = 1000; - + // milliseconds minimum time between path switches + const uint64_t DATAGRAM_SESSION_PATH_MIN_LIFETIME = 5 * 1000; class DatagramSession { From 8a95b5b5b0012cea0b3472f9885375463ce4d7c9 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 08:30:33 -0400 Subject: [PATCH 23/44] tabify --- Datagram.cpp | 6 +++--- Datagram.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Datagram.cpp b/Datagram.cpp index 0fce1166..d0b0737a 100644 --- a/Datagram.cpp +++ b/Datagram.cpp @@ -276,9 +276,9 @@ namespace datagram auto now = i2p::util::GetMillisecondsSinceEpoch (); // we need to rotate paths becuase the routing path is too old // if (now - m_LastPathChange >= DATAGRAM_SESSION_PATH_SWITCH_INTERVAL) return true; - // too fast switching paths - if (now - m_LastPathChange < DATAGRAM_SESSION_PATH_MIN_LIFETIME ) return false; - // our path looks dead so we need to rotate paths + // too fast switching paths + if (now - m_LastPathChange < DATAGRAM_SESSION_PATH_MIN_LIFETIME ) return false; + // our path looks dead so we need to rotate paths if (now - m_LastSuccess >= DATAGRAM_SESSION_PATH_TIMEOUT) return !dead; // if we have a routing session and routing path we don't need to switch paths return dead; diff --git a/Datagram.h b/Datagram.h index 614a4734..dc63cccb 100644 --- a/Datagram.h +++ b/Datagram.h @@ -29,8 +29,8 @@ namespace datagram const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_WINDOW = 10 * 1000; // milliseconds fudge factor for leases handover const uint64_t DATAGRAM_SESSION_LEASE_HANDOVER_FUDGE = 1000; - // milliseconds minimum time between path switches - const uint64_t DATAGRAM_SESSION_PATH_MIN_LIFETIME = 5 * 1000; + // milliseconds minimum time between path switches + const uint64_t DATAGRAM_SESSION_PATH_MIN_LIFETIME = 5 * 1000; class DatagramSession { From f91f3796a889e6ae385f85ec893718d1920d4684 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 10 Oct 2016 08:59:45 -0400 Subject: [PATCH 24/44] make sure verifier gets created once --- Identity.cpp | 25 +++++++++++++++++-------- Identity.h | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index 6d37d34e..0a3eeffb 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -35,11 +35,12 @@ namespace data } IdentityEx::IdentityEx (): - m_ExtendedLen (0), m_ExtendedBuffer (nullptr) + m_IsVerifierCreated (false), m_ExtendedLen (0), m_ExtendedBuffer (nullptr) { } - IdentityEx::IdentityEx(const uint8_t * publicKey, const uint8_t * signingKey, SigningKeyType type) + IdentityEx::IdentityEx(const uint8_t * publicKey, const uint8_t * signingKey, SigningKeyType type): + m_IsVerifierCreated (false) { memcpy (m_StandardIdentity.publicKey, publicKey, sizeof (m_StandardIdentity.publicKey)); if (type != SIGNING_KEY_TYPE_DSA_SHA1) @@ -135,19 +136,19 @@ namespace data } IdentityEx::IdentityEx (const uint8_t * buf, size_t len): - m_ExtendedLen (0), m_ExtendedBuffer (nullptr) + m_IsVerifierCreated (false), m_ExtendedLen (0), m_ExtendedBuffer (nullptr) { FromBuffer (buf, len); } IdentityEx::IdentityEx (const IdentityEx& other): - m_ExtendedLen (0), m_ExtendedBuffer (nullptr) + m_IsVerifierCreated (false), m_ExtendedLen (0), m_ExtendedBuffer (nullptr) { *this = other; } IdentityEx::IdentityEx (const Identity& standard): - m_ExtendedLen (0), m_ExtendedBuffer (nullptr) + m_IsVerifierCreated (false), m_ExtendedLen (0), m_ExtendedBuffer (nullptr) { *this = standard; } @@ -173,6 +174,7 @@ namespace data m_ExtendedBuffer = nullptr; m_Verifier = nullptr; + m_IsVerifierCreated = false; return *this; } @@ -187,6 +189,7 @@ namespace data m_ExtendedLen = 0; m_Verifier = nullptr; + m_IsVerifierCreated = false; return *this; } @@ -374,7 +377,13 @@ namespace data void IdentityEx::UpdateVerifier (i2p::crypto::Verifier * verifier) const { if (!m_Verifier || !verifier) - m_Verifier.reset (verifier); + { + auto created = m_IsVerifierCreated.exchange (true); + if (!created) + m_Verifier.reset (verifier); + else + delete verifier; + } else delete verifier; } @@ -457,8 +466,8 @@ namespace data void PrivateKeys::Sign (const uint8_t * buf, int len, uint8_t * signature) const { if (!m_Signer) - CreateSigner(); - m_Signer->Sign (buf, len, signature); + CreateSigner(); + m_Signer->Sign (buf, len, signature); } void PrivateKeys::CreateSigner () const diff --git a/Identity.h b/Identity.h index 8f3e9e9d..49dada48 100644 --- a/Identity.h +++ b/Identity.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "Base.h" #include "Signature.h" @@ -104,6 +105,7 @@ namespace data Identity m_StandardIdentity; IdentHash m_IdentHash; mutable std::unique_ptr m_Verifier; + mutable std::atomic_bool m_IsVerifierCreated; // make sure we don't create twice size_t m_ExtendedLen; uint8_t * m_ExtendedBuffer; }; From 84ca992e9128f78bc147e510fd2a2895d77a1e4f Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 08:59:48 -0400 Subject: [PATCH 25/44] Revert "Unused parameter warnings removal" This reverts commit 5350078543d0ac04a608f2c03efd4b9e1b8f9509. --- AddressBook.cpp | 3 +-- BOB.cpp | 42 +++++++++++++++++++++--------------------- Destination.cpp | 6 +++--- Family.cpp | 2 +- I2CP.cpp | 15 +++++++-------- I2PControl.cpp | 8 ++++---- I2PTunnel.cpp | 5 ++--- LeaseSet.cpp | 2 +- RouterContext.cpp | 2 +- SAM.cpp | 15 +++++++-------- SOCKS.cpp | 4 ++-- SSUSession.cpp | 6 +++--- Streaming.cpp | 2 +- TransitTunnel.cpp | 4 ++-- Transports.cpp | 4 ++-- Tunnel.cpp | 6 +++--- 16 files changed, 61 insertions(+), 65 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index 67eb7566..b993f456 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -599,8 +599,7 @@ namespace client } } - void AddressBook::HandleLookupResponse (const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, - uint16_t /*toPort*/, const uint8_t * buf, size_t len) + void AddressBook::HandleLookupResponse (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) { if (len < 44) { diff --git a/BOB.cpp b/BOB.cpp index 2d96f4b2..8ffffba6 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -284,7 +284,7 @@ namespace client std::placeholders::_1, std::placeholders::_2)); } - void BOBCommandSession::HandleSent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) + void BOBCommandSession::HandleSent (const boost::system::error_code& ecode, std::size_t bytes_transferred) { if (ecode) { @@ -338,20 +338,20 @@ namespace client Send (len); } - void BOBCommandSession::ZapCommandHandler (const char * /*operand*/, size_t /*len*/) + void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: zap"); Terminate (); } - void BOBCommandSession::QuitCommandHandler (const char * /*operand*/, size_t /*len*/) + void BOBCommandSession::QuitCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: quit"); m_IsOpen = false; SendReplyOK ("Bye!"); } - void BOBCommandSession::StartCommandHandler (const char * /*operand*/, size_t /*len*/) + void BOBCommandSession::StartCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: start ", m_Nickname); if (m_IsActive) @@ -373,7 +373,7 @@ namespace client m_IsActive = true; } - void BOBCommandSession::StopCommandHandler (const char * /*operand*/, size_t /*len*/) + void BOBCommandSession::StopCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: stop ", m_Nickname); if (!m_IsActive) @@ -392,7 +392,7 @@ namespace client m_IsActive = false; } - void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t /*len*/) + void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: setnick ", operand); m_Nickname = operand; @@ -401,7 +401,7 @@ namespace client SendReplyOK (msg.c_str ()); } - void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t /*len*/) + void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: getnick ", operand); m_CurrentDestination = m_Owner.FindDestination (operand); @@ -420,40 +420,40 @@ namespace client SendReplyError ("no nickname has been set"); } - void BOBCommandSession::NewkeysCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: newkeys"); m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::SetkeysCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: setkeys ", operand); m_Keys.FromBase64 (operand); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::GetkeysCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::GetkeysCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: getkeys"); SendReplyOK (m_Keys.ToBase64 ().c_str ()); } - void BOBCommandSession::GetdestCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::GetdestCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: getdest"); SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ()); } - void BOBCommandSession::OuthostCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: outhost ", operand); m_Address = operand; SendReplyOK ("outhost set"); } - void BOBCommandSession::OutportCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: outport ", operand); m_OutPort = boost::lexical_cast(operand); @@ -463,14 +463,14 @@ namespace client SendReplyError ("port out of range"); } - void BOBCommandSession::InhostCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: inhost ", operand); m_Address = operand; SendReplyOK ("inhost set"); } - void BOBCommandSession::InportCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::InportCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: inport ", operand); m_InPort = boost::lexical_cast(operand); @@ -480,7 +480,7 @@ namespace client SendReplyError ("port out of range"); } - void BOBCommandSession::QuietCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: quiet"); if (m_Nickname.length () > 0) @@ -497,7 +497,7 @@ namespace client SendReplyError ("no nickname has been set"); } - void BOBCommandSession::LookupCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: lookup ", operand); i2p::data::IdentHash ident; @@ -525,7 +525,7 @@ namespace client } } - void BOBCommandSession::ClearCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: clear"); m_Owner.DeleteDestination (m_Nickname); @@ -533,7 +533,7 @@ namespace client SendReplyOK ("cleared"); } - void BOBCommandSession::ListCommandHandler (const char* /*operand*/, size_t /*len*/) + void BOBCommandSession::ListCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: list"); const auto& destinations = m_Owner.GetDestinations (); @@ -542,7 +542,7 @@ namespace client SendReplyOK ("Listing done"); } - void BOBCommandSession::OptionCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: option ", operand); const char * value = strchr (operand, '='); @@ -561,7 +561,7 @@ namespace client SendReplyError ("malformed"); } - void BOBCommandSession::StatusCommandHandler (const char* operand, size_t /*len*/) + void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: status ", operand); if (m_Nickname == operand) diff --git a/Destination.cpp b/Destination.cpp index d859d6b0..0b8f2859 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -260,7 +260,7 @@ namespace client m_Service.post (std::bind (&LeaseSetDestination::HandleDeliveryStatusMessage, shared_from_this (), msg)); } - void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t /*len*/, std::shared_ptr from) + void LeaseSetDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) { uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET]; switch (typeID) @@ -348,7 +348,7 @@ namespace client } } - void LeaseSetDestination::HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t /*len*/) + void LeaseSetDestination::HandleDatabaseSearchReplyMessage (const uint8_t * buf, size_t len) { i2p::data::IdentHash key (buf); int num = buf[32]; // num @@ -732,7 +732,7 @@ namespace client ScheduleCheckForReady(p); } - void ClientDestination::HandleDataMessage (const uint8_t * buf, size_t /*len*/) + void ClientDestination::HandleDataMessage (const uint8_t * buf, size_t len) { uint32_t length = bufbe32toh (buf); buf += 4; diff --git a/Family.cpp b/Family.cpp index b37af204..c1840e51 100644 --- a/Family.cpp +++ b/Family.cpp @@ -110,7 +110,7 @@ namespace data } bool Families::VerifyFamily (const std::string& family, const IdentHash& ident, - const char * signature, const char * /*key*/) + const char * signature, const char * key) { uint8_t buf[50], signatureBuf[64]; size_t len = family.length (), signatureLen = strlen (signature); diff --git a/I2CP.cpp b/I2CP.cpp index 7100250e..04f21408 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -197,7 +197,7 @@ namespace client std::bind (&I2CPSession::HandleReceivedHeader, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); } - void I2CPSession::HandleReceivedHeader (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) + void I2CPSession::HandleReceivedHeader (const boost::system::error_code& ecode, std::size_t bytes_transferred) { if (ecode) Terminate (); @@ -224,7 +224,7 @@ namespace client std::bind (&I2CPSession::HandleReceivedPayload, shared_from_this (), std::placeholders::_1, std::placeholders::_2)); } - void I2CPSession::HandleReceivedPayload (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) + void I2CPSession::HandleReceivedPayload (const boost::system::error_code& ecode, std::size_t bytes_transferred) { if (ecode) Terminate (); @@ -281,8 +281,7 @@ namespace client LogPrint (eLogError, "I2CP: Can't write to the socket"); } - void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, - std::size_t /*bytes_transferred*/, const uint8_t* buf) + void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, const uint8_t * buf) { delete[] buf; if (ecode && ecode != boost::asio::error::operation_aborted) @@ -397,7 +396,7 @@ namespace client } } - void I2CPSession::DestroySessionMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) + void I2CPSession::DestroySessionMessageHandler (const uint8_t * buf, size_t len) { SendSessionStatusMessage (0); // destroy LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " destroyed"); @@ -408,7 +407,7 @@ namespace client } } - void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) + void I2CPSession::ReconfigureSessionMessageHandler (const uint8_t * buf, size_t len) { // TODO: implement actual reconfiguration SendSessionStatusMessage (2); // updated @@ -570,7 +569,7 @@ namespace client } } - void I2CPSession::DestLookupMessageHandler (const uint8_t * buf, size_t /*len*/) + void I2CPSession::DestLookupMessageHandler (const uint8_t * buf, size_t len) { if (m_Destination) { @@ -607,7 +606,7 @@ namespace client SendI2CPMessage (I2CP_DEST_REPLY_MESSAGE, buf, 32); } - void I2CPSession::GetBandwidthLimitsMessageHandler (const uint8_t* /*buf*/, size_t /*len*/) + void I2CPSession::GetBandwidthLimitsMessageHandler (const uint8_t * buf, size_t len) { uint8_t limits[64]; memset (limits, 0, 64); diff --git a/I2PControl.cpp b/I2PControl.cpp index 7f063f35..3e2e3997 100644 --- a/I2PControl.cpp +++ b/I2PControl.cpp @@ -295,8 +295,8 @@ namespace client std::placeholders::_1, std::placeholders::_2, socket, buf)); } - void I2PControlService::HandleResponseSent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/, - std::shared_ptr /*socket*/, std::shared_ptr /*buf*/) + void I2PControlService::HandleResponseSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, + std::shared_ptr socket, std::shared_ptr buf) { if (ecode) { LogPrint (eLogError, "I2PControl: write error: ", ecode.message ()); @@ -453,7 +453,7 @@ namespace client InsertParam (results, "Shutdown", ""); m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(1)); // 1 second to make sure response has been sent m_ShutdownTimer.async_wait ( - [](const boost::system::error_code&) + [](const boost::system::error_code& ecode) { Daemon.running = 0; }); @@ -467,7 +467,7 @@ namespace client InsertParam (results, "ShutdownGraceful", ""); m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(timeout + 1)); // + 1 second m_ShutdownTimer.async_wait ( - [](const boost::system::error_code&) + [](const boost::system::error_code& ecode) { Daemon.running = 0; }); diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index a1814058..be48b83a 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -439,7 +439,7 @@ namespace client } void I2PServerTunnel::HandleResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - std::shared_ptr /*resolver*/) + std::shared_ptr resolver) { if (!ecode) { @@ -724,8 +724,7 @@ namespace client m_Session = new UDPSession(m_LocalEndpoint, m_LocalDest, ep, m_RemoteIdent, LocalPort, RemotePort); } - void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, - uint16_t /*toPort*/, const uint8_t * buf, size_t len) + void I2PUDPClientTunnel::HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) { if(m_RemoteIdent && from.GetIdentHash() == *m_RemoteIdent) { diff --git a/LeaseSet.cpp b/LeaseSet.cpp index 4ddd07f3..04dc77c5 100644 --- a/LeaseSet.cpp +++ b/LeaseSet.cpp @@ -173,7 +173,7 @@ namespace data const std::vector > LeaseSet::GetNonExpiredLeases (bool withThreshold) const { - return GetNonExpiredLeasesExcluding( [] (const Lease &) -> bool { return false; }, withThreshold); + return GetNonExpiredLeasesExcluding( [] (const Lease & l) -> bool { return false; }, withThreshold); } const std::vector > LeaseSet::GetNonExpiredLeasesExcluding (LeaseInspectFunc exclude, bool withThreshold) const diff --git a/RouterContext.cpp b/RouterContext.cpp index 15084bd3..6824adb8 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -424,7 +424,7 @@ namespace i2p return i2p::tunnel::tunnels.GetExploratoryPool (); } - void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t /*len*/, std::shared_ptr from) + void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr from) { i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); } diff --git a/SAM.cpp b/SAM.cpp index ce85fc8d..2864cd6f 100644 --- a/SAM.cpp +++ b/SAM.cpp @@ -135,7 +135,7 @@ namespace client } } - void SAMSocket::HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/) + void SAMSocket::HandleHandshakeReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred) { if (ecode) { @@ -166,7 +166,7 @@ namespace client } } - void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t /*bytes_transferred*/, bool close) + void SAMSocket::HandleMessageReplySent (const boost::system::error_code& ecode, std::size_t bytes_transferred, bool close) { if (ecode) { @@ -262,7 +262,7 @@ namespace client } } - void SAMSocket::ProcessSessionCreate (char * buf, size_t /*len*/) + void SAMSocket::ProcessSessionCreate (char * buf, size_t len) { LogPrint (eLogDebug, "SAM: session create: ", buf); std::map params; @@ -333,7 +333,7 @@ namespace client SendMessageReply (m_Buffer, l2, false); } - void SAMSocket::ProcessStreamConnect (char * buf, size_t /*len*/) + void SAMSocket::ProcessStreamConnect (char * buf, size_t len) { LogPrint (eLogDebug, "SAM: stream connect: ", buf); std::map params; @@ -389,7 +389,7 @@ namespace client } } - void SAMSocket::ProcessStreamAccept (char * buf, size_t /*len*/) + void SAMSocket::ProcessStreamAccept (char * buf, size_t len) { LogPrint (eLogDebug, "SAM: stream accept: ", buf); std::map params; @@ -460,7 +460,7 @@ namespace client SendMessageReply (m_Buffer, len, false); } - void SAMSocket::ProcessNamingLookup (char * buf, size_t /*len*/) + void SAMSocket::ProcessNamingLookup (char * buf, size_t len) { LogPrint (eLogDebug, "SAM: naming lookup: ", buf); std::map params; @@ -652,8 +652,7 @@ namespace client LogPrint (eLogWarning, "SAM: I2P acceptor has been reset"); } - void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t /*fromPort*/, - uint16_t /*toPort*/, const uint8_t* buf, size_t len) + void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len) { LogPrint (eLogDebug, "SAM: datagram received ", len); auto base64 = from.ToBase64 (); diff --git a/SOCKS.cpp b/SOCKS.cpp index a52fe612..9d85963b 100644 --- a/SOCKS.cpp +++ b/SOCKS.cpp @@ -696,7 +696,7 @@ namespace proxy } - void SOCKSHandler::HandleUpstreamData(uint8_t* /*dataptr*/, std::size_t len) + void SOCKSHandler::HandleUpstreamData(uint8_t * dataptr, std::size_t len) { if (m_state == UPSTREAM_HANDSHAKE) { m_upstream_response_len += len; @@ -739,7 +739,7 @@ namespace proxy } } - void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator) + void SOCKSHandler::HandleUpstreamConnected(const boost::system::error_code & ecode, boost::asio::ip::tcp::resolver::iterator itr) { if (ecode) { LogPrint(eLogWarning, "SOCKS: could not connect to upstream proxy: ", ecode.message()); diff --git a/SSUSession.cpp b/SSUSession.cpp index fbb5b11d..5cd59164 100644 --- a/SSUSession.cpp +++ b/SSUSession.cpp @@ -536,7 +536,7 @@ namespace transport Send (buf, msgLen); } - void SSUSession::ProcessRelayRequest (const uint8_t * buf, size_t /*len*/, const boost::asio::ip::udp::endpoint& from) + void SSUSession::ProcessRelayRequest (const uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& from) { uint32_t relayTag = bufbe32toh (buf); auto session = m_Server.FindRelaySession (relayTag); @@ -637,7 +637,7 @@ namespace transport LogPrint (eLogDebug, "SSU: relay intro sent"); } - void SSUSession::ProcessRelayResponse (const uint8_t * buf, size_t /*len*/) + void SSUSession::ProcessRelayResponse (const uint8_t * buf, size_t len) { LogPrint (eLogDebug, "SSU message: Relay response received"); uint8_t remoteSize = *buf; @@ -689,7 +689,7 @@ namespace transport LogPrint (eLogError, "SSU: Unsolicited RelayResponse, nonce=", nonce); } - void SSUSession::ProcessRelayIntro (const uint8_t * buf, size_t /*len*/) + void SSUSession::ProcessRelayIntro (const uint8_t * buf, size_t len) { uint8_t size = *buf; if (size == 4) diff --git a/Streaming.cpp b/Streaming.cpp index e8f5a897..02e738c8 100644 --- a/Streaming.cpp +++ b/Streaming.cpp @@ -729,7 +729,7 @@ namespace stream } } - void Stream::HandleAckSendTimer (const boost::system::error_code&) + void Stream::HandleAckSendTimer (const boost::system::error_code& ecode) { if (m_IsAckSendScheduled) { diff --git a/TransitTunnel.cpp b/TransitTunnel.cpp index d06f5134..dfe01a05 100644 --- a/TransitTunnel.cpp +++ b/TransitTunnel.cpp @@ -51,12 +51,12 @@ namespace tunnel } } - void TransitTunnel::SendTunnelDataMsg (std::shared_ptr /*msg*/) + void TransitTunnel::SendTunnelDataMsg (std::shared_ptr msg) { LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ()); } - void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr /*msg*/) + void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr tunnelMsg) { LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ()); } diff --git a/Transports.cpp b/Transports.cpp index e0d2df7a..a29cac15 100644 --- a/Transports.cpp +++ b/Transports.cpp @@ -394,7 +394,7 @@ namespace transport } void Transports::HandleNTCPResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - i2p::data::IdentHash ident, std::shared_ptr /*resolver*/) + i2p::data::IdentHash ident, std::shared_ptr resolver) { auto it1 = m_Peers.find (ident); if (it1 != m_Peers.end ()) @@ -437,7 +437,7 @@ namespace transport } void Transports::HandleSSUResolve (const boost::system::error_code& ecode, boost::asio::ip::tcp::resolver::iterator it, - i2p::data::IdentHash ident, std::shared_ptr /*resolver*/) + i2p::data::IdentHash ident, std::shared_ptr resolver) { auto it1 = m_Peers.find (ident); if (it1 != m_Peers.end ()) diff --git a/Tunnel.cpp b/Tunnel.cpp index 3749c9ca..7d2e6735 100644 --- a/Tunnel.cpp +++ b/Tunnel.cpp @@ -90,7 +90,7 @@ namespace tunnel i2p::transport::transports.SendMessage (GetNextIdentHash (), msg); } - bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t /*len*/) + bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len) { LogPrint (eLogDebug, "Tunnel: TunnelBuildResponse ", (int)msg[0], " records."); @@ -161,7 +161,7 @@ namespace tunnel } } - void Tunnel::SendTunnelDataMsg (std::shared_ptr /*msg*/) + void Tunnel::SendTunnelDataMsg (std::shared_ptr msg) { LogPrint (eLogWarning, "Tunnel: Can't send I2NP messages without delivery instructions"); } @@ -256,7 +256,7 @@ namespace tunnel m_Gateway.SendBuffer (); } - void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr /*msg*/) + void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr tunnelMsg) { LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ()); } From a332d687043959cc57fd7015e4cb98123e25103b Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 09:02:39 -0400 Subject: [PATCH 26/44] Revert "fix f79ad91" This reverts commit e8e3db688803309c7411b29f7b6ca0c159872f98. --- Destination.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Destination.cpp b/Destination.cpp index 0b8f2859..dbdec0c7 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -185,7 +185,6 @@ namespace client if(ls && !ls->IsExpired()) { ls->PopulateLeases(); - std::unique_lock lock(m_RemoteLeaseSetsMutex); m_RemoteLeaseSets[ident] = ls; } }); From 3095e142474b46227f991adfe7e05772eec1083e Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 09:04:24 -0400 Subject: [PATCH 27/44] undo weird mutex changes --- Destination.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index dbdec0c7..a1e1858e 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -171,7 +171,7 @@ namespace client std::shared_ptr LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident) { - std::unique_lock lock(m_RemoteLeaseSetsMutex); + std::lock_guard lock(m_RemoteLeaseSetsMutex); auto it = m_RemoteLeaseSets.find (ident); if (it != m_RemoteLeaseSets.end ()) { @@ -185,7 +185,10 @@ namespace client if(ls && !ls->IsExpired()) { ls->PopulateLeases(); - m_RemoteLeaseSets[ident] = ls; + { + std::lock_guard l(m_RemoteLeaseSetsMutex); + m_RemoteLeaseSets[ident] = ls; + } } }); } From 456d9e79e61214c16fadbcc447e3893b78d32942 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 09:06:32 -0400 Subject: [PATCH 28/44] Revert "minimize count of errors "I2CP: Failed to send message. No outbound tunnels"" This reverts commit 8ff2627e8eef895bc840d335aeca5db947077d79. --- I2CP.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/I2CP.cpp b/I2CP.cpp index 04f21408..e0139b9f 100644 --- a/I2CP.cpp +++ b/I2CP.cpp @@ -103,8 +103,7 @@ namespace client } auto path = remoteSession->GetSharedRoutingPath (); std::shared_ptr outboundTunnel; - std::shared_ptr remoteLease; - bool unconfirmedTags=false; + std::shared_ptr remoteLease; if (path) { if (!remoteSession->CleanupUnconfirmedTags ()) // no stuck tags @@ -113,12 +112,9 @@ namespace client remoteLease = path->remoteLease; } else - { remoteSession->SetSharedRoutingPath (nullptr); - unconfirmedTags=true; - } } - if (!path || unconfirmedTags) + else { outboundTunnel = GetTunnelPool ()->GetNextOutboundTunnel (); auto leases = remote->GetNonExpiredLeases (); From e8d8b290a69b47827e40ade735d1a7c1024fa26a Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Mon, 10 Oct 2016 09:07:49 -0400 Subject: [PATCH 29/44] rename --- Destination.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Destination.cpp b/Destination.cpp index a1e1858e..ccf1e6e2 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -186,7 +186,7 @@ namespace client { ls->PopulateLeases(); { - std::lock_guard l(m_RemoteLeaseSetsMutex); + std::lock_guard _lock(m_RemoteLeaseSetsMutex); m_RemoteLeaseSets[ident] = ls; } } From 3fa4e2f58dea118effe02aba21e3341f2348bf44 Mon Sep 17 00:00:00 2001 From: l-n-s Date: Mon, 10 Oct 2016 15:00:36 +0000 Subject: [PATCH 30/44] Update README.md --- README.md | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f5ce9624..7fc994bb 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,28 @@ i2pd ==== -i2pd is a full-featured C++ implementation of -[I2P](https://geti2p.net/en/about/intro) client. +i2pd (I2P Daemon) is a full-featured C++ implementation of I2P client. -I2P (Invisible Internet Project) is anonymous network which works on top of -public Internet. Privacy and anonymity are achieved by strong encryption and -bouncing your traffic through thousands of I2P nodes all around the world. +I2P (Invisible Internet Protocol) is a universal anonymous network layer. +All communications over I2P are anonymous and end-to-end encrypted, participants +don't reveal their real IP addresses. -We are building network which helps people to communicate and share information +I2P client is a software used for building and using anonymous I2P +networks. Such networks can work on top of ordinary Internet connection, LAN +and even wireless mesh-networks. + +I2P is commonly used for anonymous peer-to-peer applications (filesharing, +cryptocurrencies) and anonymous client-server applications (websites, instant +messengers, chat-servers). + +I2P allows people from all around the world to communicate and share information without restrictions. * [Website](http://i2pd.website) * [Documentation](https://i2pd.readthedocs.io/en/latest/) * [Wiki](https://github.com/PurpleI2P/i2pd/wiki) * [Tickets/Issues](https://github.com/PurpleI2P/i2pd/issues) -* [Twitter](https://twitter.com/i2porignal) +* [Twitter](https://twitter.com/hashtag/i2pd) Installing ---------- From c78ec12e99f8b10a5876ba966dc9339abc614850 Mon Sep 17 00:00:00 2001 From: l-n-s Date: Mon, 10 Oct 2016 15:07:22 +0000 Subject: [PATCH 31/44] Add specs link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7fc994bb..798209ad 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ without restrictions. * [Documentation](https://i2pd.readthedocs.io/en/latest/) * [Wiki](https://github.com/PurpleI2P/i2pd/wiki) * [Tickets/Issues](https://github.com/PurpleI2P/i2pd/issues) +* [Specifications](https://geti2p.net/spec) * [Twitter](https://twitter.com/hashtag/i2pd) Installing From 6d6352162230a9b9f1b693fe7a000c2f43337edd Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 10 Oct 2016 11:46:52 -0400 Subject: [PATCH 32/44] update miniupnpc instructions --- docs/build_notes_windows.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/docs/build_notes_windows.md b/docs/build_notes_windows.md index a217d80d..2b4b96b6 100644 --- a/docs/build_notes_windows.md +++ b/docs/build_notes_windows.md @@ -87,7 +87,19 @@ You should be able to run ./i2pd . If you need to start from the new shell, consider starting *MinGW-w64 Win32 Shell* instead of *MSYS2 Shell* as it adds`/minw32/bin` to the PATH. +### UPnP +You can install it through the MSYS2 +and build with USE_UPNP key. +```bash +pacman -S mingw-w64-i686-miniupnpc +make USE_UPNP=yes +``` +or +```bash +pacman -S mingw-w64-x86_64-miniupnpc +make USE_UPNP=yes +``` Using Visual Studio ------------------- @@ -160,20 +172,7 @@ port. You'd want to have include headers around to build i2pd with support for this. Unpack client source code in a sibling folder, e.g. C:\dev\miniupnpc . You may want to remove version number from folder name included in downloaded archive. - -You can also install it through the MSYS2 -and build with USE_UPNP key. - -```bash -pacman -S mingw-w64-i686-miniupnpc -make USE_UPNP=yes -``` -or -```bash -pacman -S mingw-x86_64-miniupnpc -make USE_UPNP=yes -``` - + ### Creating Visual Studio project Start CMake GUI, navigate to i2pd directory, choose building directory, e.g. ./out, and configure options. From f10d9e1332a747968b70fbc058a0f3820ca957e1 Mon Sep 17 00:00:00 2001 From: orignal Date: Mon, 10 Oct 2016 16:31:26 -0400 Subject: [PATCH 33/44] update reseed lists --- Config.cpp | 4 +-- .../reseed/atomike_at_mail.i2p.crt | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 contrib/certificates/reseed/atomike_at_mail.i2p.crt diff --git a/Config.cpp b/Config.cpp index 33231aa4..84633532 100644 --- a/Config.cpp +++ b/Config.cpp @@ -163,9 +163,9 @@ namespace config { "https://i2p.manas.ca:8443/," "https://i2p-0.manas.ca:8443/," "https://reseed.i2p.vzaws.com:8443/," - "https://user.mx24.eu/," "https://download.xxlspeed.com/," - "https://reseed-ru.lngserv.ru/" + "https://reseed-ru.lngserv.ru/," + "https://reseed.atomike.ninja/" ), "Reseed URLs, separated by comma") #endif ; diff --git a/contrib/certificates/reseed/atomike_at_mail.i2p.crt b/contrib/certificates/reseed/atomike_at_mail.i2p.crt new file mode 100644 index 00000000..1e724f00 --- /dev/null +++ b/contrib/certificates/reseed/atomike_at_mail.i2p.crt @@ -0,0 +1,34 @@ +-----BEGIN CERTIFICATE----- +MIIF5TCCA82gAwIBAgIRANFIiHpTaRY2Z30TQOiuqFcwDQYJKoZIhvcNAQELBQAw +cDELMAkGA1UEBhMCWFgxCzAJBgNVBAcTAlhYMQswCQYDVQQJEwJYWDEeMBwGA1UE +ChMVSTJQIEFub255bW91cyBOZXR3b3JrMQwwCgYDVQQLEwNJMlAxGTAXBgNVBAMM +EGF0b21pa2VAbWFpbC5pMnAwHhcNMTYwODAyMTQyNDEyWhcNMjYwODAyMTQyNDEy +WjBwMQswCQYDVQQGEwJYWDELMAkGA1UEBxMCWFgxCzAJBgNVBAkTAlhYMR4wHAYD +VQQKExVJMlAgQW5vbnltb3VzIE5ldHdvcmsxDDAKBgNVBAsTA0kyUDEZMBcGA1UE +AwwQYXRvbWlrZUBtYWlsLmkycDCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoC +ggIBAMLRmxclaAvm405JLHNNiniUi0aZaBoLJ+afwn2LGfTDUhTD5Y8lW6V9o90n +eTNOCaiid7bWpVBkA1M4gZ9TdUnP0POa99jXZbj4PHFRl1l8k4Ap12PUO3hgwtH7 +7j7j+UPaIuE2y+U7hJbmyQ0v7r8yjGWSTtSqs+exNhyr4Mh7DvacZySZ+oqQdXYA +vnfDpBX1dKlN1Nb4XloG0uE1OK1YfJoC+p+v8qXjKagIdZgThdmsWcQ82EGI+Q9u +VfrE4m3CNwJy0X86wMNYqHej88wBHnJMmTm+cZtFLVmZsRqnuLAQL1wrfCbGSltR +zhVQHTysLwMz9+llTXtzMf+R2kcEAYWiPc5IRVU+LvkN/610r5fuHW+OcQ9ZgRVn +PMqlv5PDG2ZxdIOAQQsOd7fH0r5q3MhqlVstVE45Rl33uA+M7wjJK2cvnOoSioxp +szn2GIZliXQXo4dJczgfN2U4PLBGRBGmrB1R2S1YsG6CrSJuMCX14VKJP69Nfm8a +EDA5GKNke+ZpXCszPLaNMB70LVFQc9FmMhsOgLIIoJBgd61uMgokMJJMLaWN0RaK +w1ZduxYGUmg2T2pi/clIkVzZmlcHKViUn0sMcKD+ibEPOvQIB/3HPEEt6iIkanc/ +da5IFzikkaykt/Tu6o8rreeEu65HkIxFaCHegSXLHSyxj00BAgMBAAGjejB4MA4G +A1UdDwEB/wQEAwIChDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwDwYD +VR0TAQH/BAUwAwEB/zAZBgNVHQ4EEgQQYXRvbWlrZUBtYWlsLmkycDAbBgNVHSME +FDASgBBhdG9taWtlQG1haWwuaTJwMA0GCSqGSIb3DQEBCwUAA4ICAQAA0MdWfN/N +1q5CdJqDyw4JQwzdYkA27Wr02qIcmwnqjcCEDPl4uDTyqN9gbEpJ48AcsdXRa6GE +lLh/qJ67I6YDe63LuhndzRULNgxGHVMGS8kBJIssQehb2rOFnbUTp0gMR+0QpXXe +omase4kL90c9uuYX1vXaO/ADssY2/QX49prwJO+UY/jGhcX4YheFI/teA85u6Qko +ero437Shqhl0kbdK+eBkOFf9a7mGxpMT73KE1jFS6433W4fFOkybQ1dcS0qStaUM +3qKC0EQCbAl1seAp3AGuG46swHZB0rZ1WCKVAr5yqCWSWMYO+fL6FosNg9z/VDVh +g6FFfoGrv19yaVFa9AvQsk1ATZ+bwtHProNx2Xet9pnAI30dT16+C5wCctoR6RVf +iOHl6CGqadjOycbMDVvOfJhypNDgWW3gBaCfXiAocJTLpR7hKNZ2bnvcP2xyXH1j +Qz/kiMJoZ3+TV1yC/x/maAHsUIQHqqd6ZRj7x5MgJq0UBdITo2ZQVfXYI0ZGIeNm +fMu+P5448+NdpASa9QoqS8kPFeUaHJMzMFHBKhrr8lTJeZ82hKBXt5jD3Tbef5Ck +n5auKu2D0IjvrzsdIpNMQAhuBPT06TW/LzN/MvardZcaLcBmcutefw6Z7RsedHvj +cGpnw4a2u9sHZIUNHzoGq32+7UWXsBI5Ow== +-----END CERTIFICATE----- From 141fb78237bd6dd0d4b9dee80093ff8c9a0840fa Mon Sep 17 00:00:00 2001 From: brain5lug Date: Tue, 11 Oct 2016 00:19:34 +0300 Subject: [PATCH 34/44] Tag class clean-up --- Tag.h | 137 +++++++++++++++++++++++++++------------------------------- 1 file changed, 64 insertions(+), 73 deletions(-) diff --git a/Tag.h b/Tag.h index 92e2f1a5..e6e7ffd4 100644 --- a/Tag.h +++ b/Tag.h @@ -1,3 +1,6 @@ +#ifndef TAG_H__ +#define TAG_H__ + /* * Copyright (c) 2013-2016, The PurpleI2P Project * @@ -6,92 +9,80 @@ * See full license text in LICENSE file at top of project tree */ -#ifndef TAG_H__ -#define TAG_H__ - -#include /* memcpy */ - +#include +#include #include "Base.h" namespace i2p { namespace data { - template - class Tag + +template +class Tag +{ + BOOST_STATIC_ASSERT_MSG(sz % 8 == 0, "Tag size must be multiple of 8 bytes"); + +public: + + Tag () = default; + Tag (const uint8_t * buf) { memcpy (m_Buf, buf, sz); } + + bool operator== (const Tag& other) const { return !memcmp (m_Buf, other.m_Buf, sz); } + bool operator< (const Tag& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; } + + uint8_t * operator()() { return m_Buf; } + const uint8_t * operator()() const { return m_Buf; } + + operator uint8_t * () { return m_Buf; } + operator const uint8_t * () const { return m_Buf; } + + const uint8_t * data() const { return m_Buf; } + const uint64_t * GetLL () const { return ll; } + + bool IsZero () const { - public: + for (size_t i = 0; i < sz/8; ++i) + if (ll[i]) return false; + return true; + } - Tag (const uint8_t * buf) { memcpy (m_Buf, buf, sz); }; - Tag (const Tag& ) = default; -#ifndef _WIN32 // FIXME!!! msvs 2013 can't compile it - Tag (Tag&& ) = default; -#endif - Tag () = default; - - Tag& operator= (const Tag& ) = default; -#ifndef _WIN32 - Tag& operator= (Tag&& ) = default; -#endif - - uint8_t * operator()() { return m_Buf; }; - const uint8_t * operator()() const { return m_Buf; }; - - operator uint8_t * () { return m_Buf; }; - operator const uint8_t * () const { return m_Buf; }; - - const uint64_t * GetLL () const { return ll; }; - - bool operator== (const Tag& other) const { return !memcmp (m_Buf, other.m_Buf, sz); }; - bool operator< (const Tag& other) const { return memcmp (m_Buf, other.m_Buf, sz) < 0; }; - - bool IsZero () const - { - for (int i = 0; i < sz/8; i++) - if (ll[i]) return false; - return true; - } - - const uint8_t * data() const { return m_Buf; } - - /** fill with a value */ - void Fill(uint8_t c) - { - memset(m_Buf, c, sz); - } + void Fill(uint8_t c) + { + memset(m_Buf, c, sz); + } - std::string ToBase64 () const - { - char str[sz*2]; - int l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2); - str[l] = 0; - return std::string (str); - } + std::string ToBase64 () const + { + char str[sz*2]; + size_t l = i2p::data::ByteStreamToBase64 (m_Buf, sz, str, sz*2); + return std::string (str, str + l); + } - std::string ToBase32 () const - { - char str[sz*2]; - int l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2); - str[l] = 0; - return std::string (str); - } + std::string ToBase32 () const + { + char str[sz*2]; + size_t l = i2p::data::ByteStreamToBase32 (m_Buf, sz, str, sz*2); + return std::string (str, str + l); + } - void FromBase32 (const std::string& s) - { - i2p::data::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz); - } + void FromBase32 (const std::string& s) + { + i2p::data::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz); + } - void FromBase64 (const std::string& s) - { - i2p::data::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz); - } + void FromBase64 (const std::string& s) + { + i2p::data::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz); + } - private: +private: - union // 8 bytes alignment - { - uint8_t m_Buf[sz]; - uint64_t ll[sz/8]; - }; + union // 8 bytes aligned + { + uint8_t m_Buf[sz]; + uint64_t ll[sz/8]; }; +}; + } // data } // i2p From 16c37a0f3d55a9f138de7d1c1df6bfabfcaa393c Mon Sep 17 00:00:00 2001 From: brain5lug Date: Tue, 11 Oct 2016 00:46:18 +0300 Subject: [PATCH 35/44] indentation fix for missed Fill function --- Tag.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tag.h b/Tag.h index e6e7ffd4..30dfa654 100644 --- a/Tag.h +++ b/Tag.h @@ -45,10 +45,10 @@ public: return true; } - void Fill(uint8_t c) - { - memset(m_Buf, c, sz); - } + void Fill(uint8_t c) + { + memset(m_Buf, c, sz); + } std::string ToBase64 () const { From e78ccc6bec772b976e1031c4bc14428f7b73d90d Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 11 Oct 2016 07:31:16 -0400 Subject: [PATCH 36/44] fixed #651. check is destination is set --- BOB.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/BOB.cpp b/BOB.cpp index 8ffffba6..fc49749f 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -568,10 +568,15 @@ namespace client { std::stringstream s; s << "DATA"; s << " NICKNAME: "; s << m_Nickname; - if (m_CurrentDestination->GetLocalDestination ()->IsReady ()) - s << " STARTING: false RUNNING: true STOPPING: false"; + if (m_CurrentDestination) + { + if (m_CurrentDestination->GetLocalDestination ()->IsReady ()) + s << " STARTING: false RUNNING: true STOPPING: false"; + else + s << " STARTING: true RUNNING: false STOPPING: false"; + } else - s << " STARTING: true RUNNING: false STOPPING: false"; + s << " STARTING: false RUNNING: false STOPPING: false"; s << " KEYS: true"; s << " QUIET: "; s << (m_IsQuiet ? "true":"false"); if (m_InPort) { From b1f8f9830b16468718c4fa247595275315ab37c2 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 11 Oct 2016 10:18:42 -0400 Subject: [PATCH 37/44] fixed another cases for #651 --- BOB.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/BOB.cpp b/BOB.cpp index fc49749f..28e7f68b 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -437,8 +437,11 @@ namespace client void BOBCommandSession::GetkeysCommandHandler (const char * operand, size_t len) { LogPrint (eLogDebug, "BOB: getkeys"); - SendReplyOK (m_Keys.ToBase64 ().c_str ()); - } + if (m_Keys.GetPublic ()) // keys are set ? + SendReplyOK (m_Keys.ToBase64 ().c_str ()); + else + SendReplyError ("keys are not set"); + } void BOBCommandSession::GetdestCommandHandler (const char * operand, size_t len) { @@ -506,6 +509,11 @@ namespace client SendReplyError ("Address Not found"); return; } + if (!m_CurrentDestination) + { + SendReplyError ("session not created"); + return; + } auto localDestination = m_CurrentDestination->GetLocalDestination (); auto leaseSet = localDestination->FindLeaseSet (ident); if (leaseSet) From f17df1f16de4baff4bb00e1b071255348d30aea8 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 11 Oct 2016 12:06:40 -0400 Subject: [PATCH 38/44] spinlock added --- Identity.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Identity.cpp b/Identity.cpp index 0a3eeffb..99da059e 100644 --- a/Identity.cpp +++ b/Identity.cpp @@ -376,13 +376,16 @@ namespace data void IdentityEx::UpdateVerifier (i2p::crypto::Verifier * verifier) const { - if (!m_Verifier || !verifier) + if (!m_Verifier) { auto created = m_IsVerifierCreated.exchange (true); if (!created) m_Verifier.reset (verifier); else + { delete verifier; + while (!m_Verifier) ; // spin lock + } } else delete verifier; @@ -391,7 +394,8 @@ namespace data void IdentityEx::DropVerifier () const { // TODO: potential race condition with Verify - m_Verifier = nullptr; + m_IsVerifierCreated = false; + m_Verifier = nullptr; } PrivateKeys& PrivateKeys::operator=(const Keys& keys) From f0d098d0efb31e7473a186942e1201343578cae3 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 11 Oct 2016 13:39:07 -0400 Subject: [PATCH 39/44] use shared local destination for lookup if destination is not set --- BOB.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/BOB.cpp b/BOB.cpp index 28e7f68b..d68c798f 100644 --- a/BOB.cpp +++ b/BOB.cpp @@ -504,17 +504,12 @@ namespace client { LogPrint (eLogDebug, "BOB: lookup ", operand); i2p::data::IdentHash ident; - if (!context.GetAddressBook ().GetIdentHash (operand, ident) || !m_CurrentDestination) + if (!context.GetAddressBook ().GetIdentHash (operand, ident)) { SendReplyError ("Address Not found"); return; } - if (!m_CurrentDestination) - { - SendReplyError ("session not created"); - return; - } - auto localDestination = m_CurrentDestination->GetLocalDestination (); + auto localDestination = m_CurrentDestination ? m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination (); auto leaseSet = localDestination->FindLeaseSet (ident); if (leaseSet) SendReplyOK (leaseSet->GetIdentity ()->ToBase64 ().c_str ()); From fe8a0c1a6b104aa159fc1bf9cd9ea6f77f3fa297 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 11 Oct 2016 15:02:23 -0400 Subject: [PATCH 40/44] #622. Force SU3 verification by reseed.verify --- Config.cpp | 1 + Reseed.cpp | 92 ++++++++++++++++++++++++------------------- docs/configuration.md | 5 ++- 3 files changed, 56 insertions(+), 42 deletions(-) diff --git a/Config.cpp b/Config.cpp index 84633532..9e981dc3 100644 --- a/Config.cpp +++ b/Config.cpp @@ -150,6 +150,7 @@ namespace config { options_description reseed("Reseed options"); reseed.add_options() + ("reseed.verify", value()->default_value(false), "Verify .su3 signature") ("reseed.file", value()->default_value(""), "Path to .su3 file") #ifdef MESHNET ("reseed.urls", value()->default_value("https://reseed.i2p.rocks:8443/"), "Reseed URLs, separated by comma") diff --git a/Reseed.cpp b/Reseed.cpp index a51dcad4..d8a265db 100644 --- a/Reseed.cpp +++ b/Reseed.cpp @@ -131,52 +131,64 @@ namespace data s.read (signerID, signerIDLength); // signerID signerID[signerIDLength] = 0; - //try to verify signature - auto it = m_SigningKeys.find (signerID); - if (it != m_SigningKeys.end ()) - { - // TODO: implement all signature types - if (signatureType == SIGNING_KEY_TYPE_RSA_SHA512_4096) + bool verify; i2p::config::GetOption("reseed.verify", verify); + if (verify) + { + //try to verify signature + auto it = m_SigningKeys.find (signerID); + if (it != m_SigningKeys.end ()) { - size_t pos = s.tellg (); - size_t tbsLen = pos + contentLength; - uint8_t * tbs = new uint8_t[tbsLen]; - s.seekg (0, std::ios::beg); - s.read ((char *)tbs, tbsLen); - uint8_t * signature = new uint8_t[signatureLength]; - s.read ((char *)signature, signatureLength); - // RSA-raw + // TODO: implement all signature types + if (signatureType == SIGNING_KEY_TYPE_RSA_SHA512_4096) { - // calculate digest - uint8_t digest[64]; - SHA512 (tbs, tbsLen, digest); - // encrypt signature - BN_CTX * bnctx = BN_CTX_new (); - BIGNUM * s = BN_new (), * n = BN_new (); - BN_bin2bn (signature, signatureLength, s); - BN_bin2bn (it->second, i2p::crypto::RSASHA5124096_KEY_LENGTH, n); - BN_mod_exp (s, s, i2p::crypto::GetRSAE (), n, bnctx); // s = s^e mod n - uint8_t * enSigBuf = new uint8_t[signatureLength]; - i2p::crypto::bn2buf (s, enSigBuf, signatureLength); - // digest is right aligned - // we can't use RSA_verify due wrong padding in SU3 - if (memcmp (enSigBuf + (signatureLength - 64), digest, 64)) - LogPrint (eLogWarning, "Reseed: SU3 signature verification failed"); - delete[] enSigBuf; - BN_free (s); BN_free (n); - BN_CTX_free (bnctx); - } + size_t pos = s.tellg (); + size_t tbsLen = pos + contentLength; + uint8_t * tbs = new uint8_t[tbsLen]; + s.seekg (0, std::ios::beg); + s.read ((char *)tbs, tbsLen); + uint8_t * signature = new uint8_t[signatureLength]; + s.read ((char *)signature, signatureLength); + // RSA-raw + { + // calculate digest + uint8_t digest[64]; + SHA512 (tbs, tbsLen, digest); + // encrypt signature + BN_CTX * bnctx = BN_CTX_new (); + BIGNUM * s = BN_new (), * n = BN_new (); + BN_bin2bn (signature, signatureLength, s); + BN_bin2bn (it->second, i2p::crypto::RSASHA5124096_KEY_LENGTH, n); + BN_mod_exp (s, s, i2p::crypto::GetRSAE (), n, bnctx); // s = s^e mod n + uint8_t * enSigBuf = new uint8_t[signatureLength]; + i2p::crypto::bn2buf (s, enSigBuf, signatureLength); + // digest is right aligned + // we can't use RSA_verify due wrong padding in SU3 + if (memcmp (enSigBuf + (signatureLength - 64), digest, 64)) + LogPrint (eLogWarning, "Reseed: SU3 signature verification failed"); + else + verify = false; // verified + delete[] enSigBuf; + BN_free (s); BN_free (n); + BN_CTX_free (bnctx); + } - delete[] signature; - delete[] tbs; - s.seekg (pos, std::ios::beg); + delete[] signature; + delete[] tbs; + s.seekg (pos, std::ios::beg); + } + else + LogPrint (eLogWarning, "Reseed: Signature type ", signatureType, " is not supported"); } else - LogPrint (eLogWarning, "Reseed: Signature type ", signatureType, " is not supported"); + LogPrint (eLogWarning, "Reseed: Certificate for ", signerID, " not loaded"); } - else - LogPrint (eLogWarning, "Reseed: Certificate for ", signerID, " not loaded"); - + + if (verify) // not verified + { + LogPrint (eLogError, "Reseed: SU3 verification failed"); + return 0; + } + // handle content int numFiles = 0; size_t contentPos = s.tellg (); diff --git a/docs/configuration.md b/docs/configuration.md index 31082dc2..dc27f78d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -72,8 +72,9 @@ All options below still possible in cmdline, but better write it in config file: * --upnp.name= - Name i2pd appears in UPnP forwardings list. I2Pd by default * --precomputation.elgamal= - Use ElGamal precomputated tables. false for x64 and true for other platforms by default -* --reseed.file - Full path to SU3 file to reseed from -* --reseed.urls - Reseed URLs, separated by comma +* --reseed.verify= - Request SU3 signature verification +* --reseed.file= - Full path to SU3 file to reseed from +* --reseed.urls= - Reseed URLs, separated by comma * --limits.transittunnels= - Override maximum number of transit tunnels. 2500 by default From 470a6f0ab2ba189e034adfd676b23b82bf8543b8 Mon Sep 17 00:00:00 2001 From: l-n-s Date: Wed, 12 Oct 2016 10:23:43 +0000 Subject: [PATCH 41/44] Add addressbook options + improved docs --- AddressBook.cpp | 23 +++++++++++++++++++---- AddressBook.h | 5 ----- Config.cpp | 11 ++++++++++- docs/configuration.md | 2 ++ docs/i2pd.conf | 14 ++++++++++++-- docs/index.rst | 2 ++ 6 files changed, 45 insertions(+), 12 deletions(-) diff --git a/AddressBook.cpp b/AddressBook.cpp index b993f456..db424308 100644 --- a/AddressBook.cpp +++ b/AddressBook.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "Base.h" #include "util.h" #include "Identity.h" @@ -15,6 +16,7 @@ #include "NetDb.h" #include "ClientContext.h" #include "AddressBook.h" +#include "Config.h" namespace i2p { @@ -404,9 +406,21 @@ namespace client m_Subscriptions.push_back (std::make_shared (*this, s)); } LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded"); + LogPrint (eLogWarning, "Addressbook: subscriptions.txt usage is deprecated, use config file instead"); } - else - LogPrint (eLogWarning, "Addressbook: subscriptions.txt not found in datadir"); + else if (!i2p::config::IsDefault("addressbook.subscriptions")) + { + // using config file items + std::string subscriptionURLs; i2p::config::GetOption("addressbook.subscriptions", subscriptionURLs); + std::vector subsList; + boost::split(subsList, subscriptionURLs, boost::is_any_of(","), boost::token_compress_on); + + for (size_t i = 0; i < subsList.size (); i++) + { + m_Subscriptions.push_back (std::make_shared (*this, subsList[i])); + } + LogPrint (eLogInfo, "Addressbook: ", m_Subscriptions.size (), " subscriptions urls loaded"); + } } else LogPrint (eLogError, "Addressbook: subscriptions already loaded"); @@ -511,10 +525,11 @@ namespace client { if (!m_IsLoaded) { - // download it from http://i2p-projekt.i2p/hosts.txt + // download it from default subscription LogPrint (eLogInfo, "Addressbook: trying to download it from default subscription."); + std::string defaultSubURL; i2p::config::GetOption("addressbook.defaulturl", defaultSubURL); if (!m_DefaultSubscription) - m_DefaultSubscription = std::make_shared(*this, DEFAULT_SUBSCRIPTION_ADDRESS); + m_DefaultSubscription = std::make_shared(*this, defaultSubURL); m_IsDownloading = true; std::thread load_hosts(std::bind (&AddressBookSubscription::CheckUpdates, m_DefaultSubscription)); load_hosts.detach(); // TODO: use join diff --git a/AddressBook.h b/AddressBook.h index 7f559cd0..a1cb3def 100644 --- a/AddressBook.h +++ b/AddressBook.h @@ -18,11 +18,6 @@ namespace i2p { namespace client { -#ifdef MESHNET - const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://i42ofzetmgicvui5sshinfckpijix2udewbam4sjo6x5fbukltia.b32.i2p/hosts.txt"; -#else - const char DEFAULT_SUBSCRIPTION_ADDRESS[] = "http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt"; -#endif const int INITIAL_SUBSCRIPTION_UPDATE_TIMEOUT = 3; // in minutes const int INITIAL_SUBSCRIPTION_RETRY_TIMEOUT = 1; // in minutes const int CONTINIOUS_SUBSCRIPTION_UPDATE_TIMEOUT = 720; // in minutes (12 hours) diff --git a/Config.cpp b/Config.cpp index 9e981dc3..f7e591be 100644 --- a/Config.cpp +++ b/Config.cpp @@ -171,12 +171,20 @@ namespace config { #endif ; + options_description addressbook("AddressBook options"); + addressbook.add_options() + ("addressbook.defaulturl", value()->default_value( + "http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt" + ), "AddressBook subscription URL for initial setup") + ("addressbook.subscriptions", value()->default_value(""), + "AddressBook subscriptions URLs, separated by comma"); + options_description trust("Trust options"); trust.add_options() ("trust.enabled", value()->default_value(false), "enable explicit trust options") ("trust.family", value()->default_value(""), "Router Familiy to trust for first hops") ("trust.hidden", value()->default_value(false), "should we hide our router from other routers?"); - + m_OptionsDesc .add(general) .add(limits) @@ -190,6 +198,7 @@ namespace config { .add(upnp) .add(precomputation) .add(reseed) + .add(addressbook) .add(trust) ; } diff --git a/docs/configuration.md b/docs/configuration.md index dc27f78d..0a774ab9 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -75,6 +75,8 @@ All options below still possible in cmdline, but better write it in config file: * --reseed.verify= - Request SU3 signature verification * --reseed.file= - Full path to SU3 file to reseed from * --reseed.urls= - Reseed URLs, separated by comma +* --addressbook.defaulturl= - AddressBook subscription URL for initial setup +* --addressbook.subscriptions= - AddressBook subscriptions URLs, separated by comma * --limits.transittunnels= - Override maximum number of transit tunnels. 2500 by default diff --git a/docs/i2pd.conf b/docs/i2pd.conf index 94287bd0..9ade3663 100644 --- a/docs/i2pd.conf +++ b/docs/i2pd.conf @@ -92,8 +92,18 @@ ipv6 = false # name = I2Pd [reseed] -## Path to reseed .su3 file (if ) -# file = +## URLs to request reseed data from, separated by comma +## Default: "mainline" I2P Network reseeds +# urls = https://reseed.i2p-projekt.de/,https://i2p.mooo.com/netDb/,https://netdb.i2p2.no/ +## Path to reseed data file (.su3) for manual reseeding +# file = /path/to/i2pseeds.su3 + +[addressbook] +## AddressBook subscription URL for initial setup +## Default: inr.i2p at "mainline" I2P Network +# defaulturl = http://joajgazyztfssty4w2on5oaqksz6tqoxbduy553y34mf4byv6gpq.b32.i2p/export/alive-hosts.txt +## Optional subscriptions URLs, separated by comma +# subscriptions = http://inr.i2p/export/alive-hosts.txt,http://stats.i2p/cgi-bin/newhosts.txt,http://rus.i2p/hosts.txt [http] ## Uncomment and set to 'false' to disable Web Console diff --git a/docs/index.rst b/docs/index.rst index 5507b075..8cfddb24 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -32,7 +32,9 @@ Contents: build_requirements build_notes_unix build_notes_windows + build_notes_cross build_notes_android + build_notes_ios configuration family usage From 9359f5b2967b463e1177aec9ccea8eafcab869cc Mon Sep 17 00:00:00 2001 From: l-n-s Date: Wed, 12 Oct 2016 12:09:58 +0000 Subject: [PATCH 42/44] Update README.md Less complicated description --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 798209ad..1fbf6c43 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,9 @@ All communications over I2P are anonymous and end-to-end encrypted, participants don't reveal their real IP addresses. I2P client is a software used for building and using anonymous I2P -networks. Such networks can work on top of ordinary Internet connection, LAN -and even wireless mesh-networks. - -I2P is commonly used for anonymous peer-to-peer applications (filesharing, -cryptocurrencies) and anonymous client-server applications (websites, instant -messengers, chat-servers). +networks. Such networks are commonly used for anonymous peer-to-peer +applications (filesharing, cryptocurrencies) and anonymous client-server +applications (websites, instant messengers, chat-servers). I2P allows people from all around the world to communicate and share information without restrictions. From 93ed032015fa9c15c875f016074c8779ce3ca353 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 12 Oct 2016 09:39:16 -0400 Subject: [PATCH 43/44] avoid potential deadlock --- Destination.cpp | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/Destination.cpp b/Destination.cpp index ccf1e6e2..d400259c 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -171,28 +171,35 @@ namespace client std::shared_ptr LeaseSetDestination::FindLeaseSet (const i2p::data::IdentHash& ident) { - std::lock_guard lock(m_RemoteLeaseSetsMutex); - auto it = m_RemoteLeaseSets.find (ident); - if (it != m_RemoteLeaseSets.end ()) + std::shared_ptr remoteLS; { - if (!it->second->IsExpired ()) + std::lock_guard lock(m_RemoteLeaseSetsMutex); + auto it = m_RemoteLeaseSets.find (ident); + if (it != m_RemoteLeaseSets.end ()) + remoteLS = it->second; + } + + if (remoteLS) + { + if (!remoteLS->IsExpired ()) { - if (it->second->ExpiresSoon()) + if (remoteLS->ExpiresSoon()) { LogPrint(eLogDebug, "Destination: Lease Set expires soon, updating before expire"); // update now before expiration for smooth handover - RequestDestination(ident, [this, ident] (std::shared_ptr ls) { + auto s = shared_from_this (); + RequestDestination(ident, [s, ident] (std::shared_ptr ls) { if(ls && !ls->IsExpired()) { ls->PopulateLeases(); { - std::lock_guard _lock(m_RemoteLeaseSetsMutex); - m_RemoteLeaseSets[ident] = ls; + std::lock_guard _lock(s->m_RemoteLeaseSetsMutex); + s->m_RemoteLeaseSets[ident] = ls; } } }); } - return it->second; + return remoteLS; } else LogPrint (eLogWarning, "Destination: remote LeaseSet expired"); @@ -203,6 +210,7 @@ namespace client if (ls && !ls->IsExpired ()) { ls->PopulateLeases (); // since we don't store them in netdb + std::lock_guard _lock(m_RemoteLeaseSetsMutex); m_RemoteLeaseSets[ident] = ls; return ls; } From 99983798a47d4b880185223783a0184eb4934932 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 12 Oct 2016 11:26:48 -0400 Subject: [PATCH 44/44] configurable netid --- Config.cpp | 1 + I2NPProtocol.cpp | 2 +- RouterContext.cpp | 6 ++++-- RouterContext.h | 5 ++++- RouterInfo.cpp | 3 ++- docs/configuration.md | 1 + 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Config.cpp b/Config.cpp index f7e591be..924f244b 100644 --- a/Config.cpp +++ b/Config.cpp @@ -49,6 +49,7 @@ namespace config { ("port", value()->default_value(0), "Port to listen for incoming connections (default: auto)") ("ipv4", value()->zero_tokens()->default_value(true), "Enable communication through ipv4") ("ipv6", value()->zero_tokens()->default_value(false), "Enable communication through ipv6") + ("netid", value()->default_value(I2PD_NET_ID), "Specify NetID. Main I2P is 2") ("daemon", value()->zero_tokens()->default_value(false), "Router will go to background after start") ("service", value()->zero_tokens()->default_value(false), "Router will use system folders like '/var/lib/i2pd'") ("notransit", value()->zero_tokens()->default_value(false), "Router will not accept transit tunnels at startup") diff --git a/I2NPProtocol.cpp b/I2NPProtocol.cpp index cbd4c3fc..cdc4fb9b 100644 --- a/I2NPProtocol.cpp +++ b/I2NPProtocol.cpp @@ -102,7 +102,7 @@ namespace i2p { RAND_bytes ((uint8_t *)&msgID, 4); htobe32buf (buf + DELIVERY_STATUS_MSGID_OFFSET, msgID); - htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, I2PD_NET_ID); + htobe64buf (buf + DELIVERY_STATUS_TIMESTAMP_OFFSET, i2p::context.GetNetID ()); } m->len += DELIVERY_STATUS_SIZE; m->FillI2NPMessageHeader (eI2NPDeliveryStatus); diff --git a/RouterContext.cpp b/RouterContext.cpp index 6824adb8..b4bbefb6 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -18,7 +18,8 @@ namespace i2p RouterContext::RouterContext (): m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false), - m_StartupTime (0), m_Status (eRouterStatusOK), m_Error (eRouterErrorNone) + m_StartupTime (0), m_Status (eRouterStatusOK), m_Error (eRouterErrorNone), + m_NetID (I2PD_NET_ID) { } @@ -76,7 +77,8 @@ namespace i2p } routerInfo.SetCaps (i2p::data::RouterInfo::eReachable | i2p::data::RouterInfo::eSSUTesting | i2p::data::RouterInfo::eSSUIntroducer); // LR, BC - routerInfo.SetProperty ("netId", std::to_string (I2PD_NET_ID)); + i2p::config::GetOption("netid", m_NetID); + routerInfo.SetProperty ("netId", std::to_string (m_NetID)); routerInfo.SetProperty ("router.version", I2P_VERSION); routerInfo.CreateBuffer (m_Keys); m_RouterInfo.SetRouterIdentity (GetIdentity ()); diff --git a/RouterContext.h b/RouterContext.h index b89b3140..7ce310ee 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -58,7 +58,9 @@ namespace i2p void SetStatus (RouterStatus status); RouterError GetError () const { return m_Error; }; void SetError (RouterError error) { m_Status = eRouterStatusError; m_Error = error; }; - + int GetNetID () const { return m_NetID; }; + void SetNetID (int netID) { m_NetID = netID; }; + void UpdatePort (int port); // called from Daemon void UpdateAddress (const boost::asio::ip::address& host); // called from SSU or Daemon bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer); @@ -117,6 +119,7 @@ namespace i2p uint32_t m_BandwidthLimit; // allowed bandwidth RouterStatus m_Status; RouterError m_Error; + int m_NetID; std::mutex m_GarlicMutex; }; diff --git a/RouterInfo.cpp b/RouterInfo.cpp index f445ca02..b570d6c2 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -13,6 +13,7 @@ #include "Timestamp.h" #include "Log.h" #include "NetDb.h" +#include "RouterContext.h" #include "RouterInfo.h" namespace i2p @@ -286,7 +287,7 @@ namespace data if (!strcmp (key, "caps")) ExtractCaps (value); // check netId - else if (!strcmp (key, ROUTER_INFO_PROPERTY_NETID) && atoi (value) != I2PD_NET_ID) + else if (!strcmp (key, ROUTER_INFO_PROPERTY_NETID) && atoi (value) != i2p::context.GetNetID ()) { LogPrint (eLogError, "RouterInfo: Unexpected ", ROUTER_INFO_PROPERTY_NETID, "=", value); m_IsUnreachable = true; diff --git a/docs/configuration.md b/docs/configuration.md index 0a774ab9..49d8c98d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -25,6 +25,7 @@ If you are upgrading your very old router (< 2.3.0) see also [this](config_opts_ * --floodfill - Router will be floodfill. false by default * --bandwidth= - Bandwidth limit: integer in KBps or letters: L (32), O (256), P (2048), X (>9000) * --family= - Name of a family, router belongs to +* --netid= - Network ID, router belongs to. Main I2P is 2. Windows-specific options: