From f46d96c4c650c7104ba42ed66ddddb1acb2fd8d2 Mon Sep 17 00:00:00 2001 From: orignal Date: Thu, 12 Jan 2017 16:17:11 -0500 Subject: [PATCH] renamed maptolooback to enableuniquelocal --- ClientContext.cpp | 15 +++++++++------ ClientContext.h | 2 +- I2PTunnel.cpp | 23 ++++++++++++----------- I2PTunnel.h | 11 ++++++----- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/ClientContext.cpp b/ClientContext.cpp index af108dd7..0354e708 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -527,7 +527,7 @@ namespace client i2p::data::SigningKeyType sigType = section.second.get (I2P_SERVER_TUNNEL_SIGNATURE_TYPE, i2p::data::SIGNING_KEY_TYPE_ECDSA_SHA256_P256); uint32_t maxConns = section.second.get(i2p::stream::I2CP_PARAM_STREAMING_MAX_CONNS_PER_MIN, i2p::stream::DEFAULT_MAX_CONNS_PER_MIN); std::string address = section.second.get (I2P_SERVER_TUNNEL_ADDRESS, "127.0.0.1"); - bool mapToLoopback = section.second.get(I2P_SERVER_TUNNEL_MAPTOLOOPBACK, true); + bool isUniqueLocal = section.second.get(I2P_SERVER_TUNNEL_ENABLE_UNIQUE_LOCAL, true); // I2CP std::map options; @@ -547,10 +547,11 @@ namespace client auto localAddress = boost::asio::ip::address::from_string(address); boost::asio::ip::udp::endpoint endpoint(boost::asio::ip::address::from_string(host), port); I2PUDPServerTunnel * serverTunnel = new I2PUDPServerTunnel(name, localDestination, localAddress, endpoint, port); - if(!mapToLoopback) { + if(!isUniqueLocal) + { LogPrint(eLogInfo, "Clients: disabling loopback address mapping"); + serverTunnel->SetUniqueLocal(isUniqueLocal); } - serverTunnel->SetMapToLoopback(mapToLoopback); std::lock_guard lock(m_ForwardsMutex); if(m_ServerForwards.insert( std::make_pair( @@ -577,10 +578,12 @@ namespace client LogPrint(eLogInfo, "Clients: Set Max Conns To ", maxConns); serverTunnel->SetMaxConnsPerMinute(maxConns); - if(!mapToLoopback) + if(!isUniqueLocal) + { LogPrint(eLogInfo, "Clients: disabling loopback address mapping"); - serverTunnel->SetMapToLoopback(mapToLoopback); - + serverTunnel->SetUniqueLocal(isUniqueLocal); + } + if (accessList.length () > 0) { std::set idents; diff --git a/ClientContext.h b/ClientContext.h index fad042ed..1aa1e7f0 100644 --- a/ClientContext.h +++ b/ClientContext.h @@ -45,7 +45,7 @@ namespace client const char I2P_SERVER_TUNNEL_GZIP[] = "gzip"; const char I2P_SERVER_TUNNEL_WEBIRC_PASSWORD[] = "webircpassword"; const char I2P_SERVER_TUNNEL_ADDRESS[] = "address"; - const char I2P_SERVER_TUNNEL_MAPTOLOOPBACK[] = "maploopback"; + const char I2P_SERVER_TUNNEL_ENABLE_UNIQUE_LOCAL[] = "enableuniquelocal"; class ClientContext { diff --git a/I2PTunnel.cpp b/I2PTunnel.cpp index d5238e14..6f45bcbe 100644 --- a/I2PTunnel.cpp +++ b/I2PTunnel.cpp @@ -79,14 +79,14 @@ namespace client } - void I2PTunnelConnection::Connect (bool mapToLoopback) + void I2PTunnelConnection::Connect (bool isUniqueLocal) { I2PTunnelSetSocketOptions(m_Socket); - if (m_Socket) { - + if (m_Socket) + { #ifdef __linux__ - if (m_RemoteEndpoint.address ().is_v4 () && - m_RemoteEndpoint.address ().to_v4 ().to_bytes ()[0] == 127 && mapToLoopback) + if (isUniqueLocal && m_RemoteEndpoint.address ().is_v4 () && + m_RemoteEndpoint.address ().to_v4 ().to_bytes ()[0] == 127) { m_Socket->open (boost::asio::ip::tcp::v4 ()); auto ident = m_Stream->GetRemoteIdentity()->GetIdentHash(); @@ -432,7 +432,7 @@ namespace client I2PServerTunnel::I2PServerTunnel (const std::string& name, const std::string& address, int port, std::shared_ptr localDestination, int inport, bool gzip): - I2PService (localDestination), m_MapToLoopback(true), m_Name (name), m_Address (address), m_Port (port), m_IsAccessList (false) + I2PService (localDestination), m_IsUniqueLocal(true), m_Name (name), m_Address (address), m_Port (port), m_IsAccessList (false) { m_PortDestination = localDestination->CreateStreamingDestination (inport > 0 ? inport : port, gzip); } @@ -517,7 +517,7 @@ namespace client { auto conn = std::make_shared (this, stream, std::make_shared (GetService ()), GetEndpoint ()); AddHandler (conn); - conn->Connect (m_MapToLoopback); + conn->Connect (m_IsUniqueLocal); } I2PServerTunnelHTTP::I2PServerTunnelHTTP (const std::string& name, const std::string& address, @@ -598,12 +598,13 @@ namespace client } boost::asio::ip::address addr; /** create new udp session */ - if(m_LocalAddress.is_loopback() && m_MapToLoopback) { + if(m_IsUniqueLocal && m_LocalAddress.is_loopback()) + { auto ident = from.GetIdentHash(); addr = GetLoopbackAddressFor(ident); - } else { + } + else addr = m_LocalAddress; - } boost::asio::ip::udp::endpoint ep(addr, 0); m_Sessions.push_back(std::make_shared(ep, m_LocalDest, m_RemoteEndpoint, &ih, localPort, remotePort)); auto & back = m_Sessions.back(); @@ -649,7 +650,7 @@ namespace client I2PUDPServerTunnel::I2PUDPServerTunnel(const std::string & name, std::shared_ptr localDestination, boost::asio::ip::address localAddress, boost::asio::ip::udp::endpoint forwardTo, uint16_t port) : - m_MapToLoopback(true), + m_IsUniqueLocal(true), m_Name(name), m_LocalAddress(localAddress), m_RemoteEndpoint(forwardTo) diff --git a/I2PTunnel.h b/I2PTunnel.h index 2b895508..fab33803 100644 --- a/I2PTunnel.h +++ b/I2PTunnel.h @@ -38,7 +38,7 @@ namespace client const boost::asio::ip::tcp::endpoint& target, bool quiet = true); // from I2P ~I2PTunnelConnection (); void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0); - void Connect (bool mapToLoopback = true); + void Connect (bool isUniqueLocal = true); protected: @@ -201,7 +201,7 @@ namespace client std::vector > GetSessions(); std::shared_ptr GetLocalDestination () const { return m_LocalDest; } - void SetMapToLoopback(bool mapToLoopback = true) { m_MapToLoopback = mapToLoopback; } + void SetUniqueLocal(bool isUniqueLocal = true) { m_IsUniqueLocal = isUniqueLocal; } private: @@ -209,7 +209,7 @@ namespace client UDPSessionPtr ObtainUDPSession(const i2p::data::IdentityEx& from, uint16_t localPort, uint16_t remotePort); private: - bool m_MapToLoopback; + bool m_IsUniqueLocal; const std::string m_Name; boost::asio::ip::address m_LocalAddress; boost::asio::ip::udp::endpoint m_RemoteEndpoint; @@ -267,7 +267,7 @@ namespace client void SetAccessList (const std::set& accessList); - void SetMapToLoopback(bool mapToLoopback) { m_MapToLoopback = mapToLoopback; } + void SetUniqueLocal (bool isUniqueLocal) { m_IsUniqueLocal = isUniqueLocal; } const std::string& GetAddress() const { return m_Address; } int GetPort () const { return m_Port; }; @@ -288,7 +288,8 @@ namespace client virtual void CreateI2PConnection (std::shared_ptr stream); private: - bool m_MapToLoopback; + + bool m_IsUniqueLocal; std::string m_Name, m_Address; int m_Port; boost::asio::ip::tcp::endpoint m_Endpoint;