mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	address parameter for server tunnels
This commit is contained in:
		
							parent
							
								
									94659ba890
								
							
						
					
					
						commit
						616f0b2a21
					
				
					 3 changed files with 33 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -750,12 +750,13 @@ namespace client
 | 
			
		|||
					else // regular server tunnel by default
 | 
			
		||||
						serverTunnel = std::make_shared<I2PServerTunnel> (name, host, port, localDestination, inPort, gzip);
 | 
			
		||||
 | 
			
		||||
					if (!address.empty ())
 | 
			
		||||
						serverTunnel->SetLocalAddress (address);
 | 
			
		||||
					if(!isUniqueLocal)
 | 
			
		||||
					{
 | 
			
		||||
						LogPrint(eLogInfo, "Clients: disabling loopback address mapping");
 | 
			
		||||
						serverTunnel->SetUniqueLocal(isUniqueLocal);
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
					if (accessList.length () > 0)
 | 
			
		||||
					{
 | 
			
		||||
						std::set<i2p::data::IdentHash> idents;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -107,6 +107,18 @@ namespace client
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void I2PTunnelConnection::Connect (const boost::asio::ip::address& localAddress)
 | 
			
		||||
	{
 | 
			
		||||
		if (m_Socket)
 | 
			
		||||
		{
 | 
			
		||||
			boost::system::error_code ec;
 | 
			
		||||
			m_Socket->bind (boost::asio::ip::tcp::endpoint (localAddress, 0), ec);
 | 
			
		||||
			if (ec)
 | 
			
		||||
				LogPrint (eLogError, "I2PTunnel: can't bind to ", localAddress.to_string (), ": ", ec.message ());	
 | 
			
		||||
		}	
 | 
			
		||||
		Connect (false);
 | 
			
		||||
	}	
 | 
			
		||||
		
 | 
			
		||||
	void I2PTunnelConnection::Terminate ()
 | 
			
		||||
	{
 | 
			
		||||
		if (Kill()) return;
 | 
			
		||||
| 
						 | 
				
			
			@ -600,6 +612,16 @@ namespace client
 | 
			
		|||
		m_IsAccessList = true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void I2PServerTunnel::SetLocalAddress (const std::string& localAddress)
 | 
			
		||||
	{
 | 
			
		||||
		boost::system::error_code ec;
 | 
			
		||||
		auto addr = boost::asio::ip::address::from_string(localAddress, ec);
 | 
			
		||||
		if (!ec)
 | 
			
		||||
			m_LocalAddress.reset (new boost::asio::ip::address (addr));
 | 
			
		||||
		else
 | 
			
		||||
			LogPrint (eLogError, "I2PTunnel: can't set local address ", localAddress);
 | 
			
		||||
	}	
 | 
			
		||||
		
 | 
			
		||||
	void I2PServerTunnel::Accept ()
 | 
			
		||||
	{
 | 
			
		||||
		if (m_PortDestination)
 | 
			
		||||
| 
						 | 
				
			
			@ -631,7 +653,10 @@ namespace client
 | 
			
		|||
			// new connection
 | 
			
		||||
			auto conn = CreateI2PConnection (stream);
 | 
			
		||||
			AddHandler (conn);
 | 
			
		||||
			conn->Connect (m_IsUniqueLocal);
 | 
			
		||||
			if (m_LocalAddress)
 | 
			
		||||
				conn->Connect (*m_LocalAddress);
 | 
			
		||||
			else	
 | 
			
		||||
				conn->Connect (m_IsUniqueLocal);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,7 +48,8 @@ namespace client
 | 
			
		|||
			~I2PTunnelConnection ();
 | 
			
		||||
			void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0);
 | 
			
		||||
			void Connect (bool isUniqueLocal = true);
 | 
			
		||||
 | 
			
		||||
			void Connect (const boost::asio::ip::address& localAddress);
 | 
			
		||||
		
 | 
			
		||||
		protected:
 | 
			
		||||
 | 
			
		||||
			void Terminate ();
 | 
			
		||||
| 
						 | 
				
			
			@ -314,6 +315,8 @@ namespace client
 | 
			
		|||
			void SetUniqueLocal (bool isUniqueLocal) { m_IsUniqueLocal = isUniqueLocal; }
 | 
			
		||||
			bool IsUniqueLocal () const { return m_IsUniqueLocal; }
 | 
			
		||||
 | 
			
		||||
			void SetLocalAddress (const std::string& localAddress);
 | 
			
		||||
			
 | 
			
		||||
			const std::string& GetAddress() const { return m_Address; }
 | 
			
		||||
			int GetPort () const { return m_Port; };
 | 
			
		||||
			uint16_t GetLocalPort () const { return m_PortDestination->GetLocalPort (); };
 | 
			
		||||
| 
						 | 
				
			
			@ -339,6 +342,7 @@ namespace client
 | 
			
		|||
			std::shared_ptr<i2p::stream::StreamingDestination> m_PortDestination;
 | 
			
		||||
			std::set<i2p::data::IdentHash> m_AccessList;
 | 
			
		||||
			bool m_IsAccessList;
 | 
			
		||||
			std::unique_ptr<boost::asio::ip::address> m_LocalAddress;
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
	class I2PServerTunnelHTTP: public I2PServerTunnel
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue