mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	some cleanup
This commit is contained in:
		
							parent
							
								
									faae2709d9
								
							
						
					
					
						commit
						c2f13a1496
					
				
					 5 changed files with 11 additions and 56 deletions
				
			
		| 
						 | 
				
			
			@ -142,8 +142,7 @@ namespace i2p
 | 
			
		|||
			i2p::context.SetSupportsV6 (ipv6);
 | 
			
		||||
			i2p::context.SetSupportsV4 (ipv4);
 | 
			
		||||
 | 
			
		||||
			bool ntcp;   i2p::config::GetOption("ntcp", ntcp);
 | 
			
		||||
			i2p::context.PublishNTCPAddress (ntcp, !ipv6);  
 | 
			
		||||
			i2p::context.RemoveNTCPAddress (!ipv6); // TODO: remove later 
 | 
			
		||||
			bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
 | 
			
		||||
			if (ntcp2)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -151,7 +150,7 @@ namespace i2p
 | 
			
		|||
				if (published)
 | 
			
		||||
				{
 | 
			
		||||
					uint16_t ntcp2port; i2p::config::GetOption("ntcp2.port", ntcp2port);
 | 
			
		||||
					if (!ntcp && !ntcp2port) ntcp2port = port; // use standard port
 | 
			
		||||
					if (!ntcp2port) ntcp2port = port; // use standard port
 | 
			
		||||
					i2p::context.PublishNTCP2Address (ntcp2port, true); // publish
 | 
			
		||||
					if (ipv6)
 | 
			
		||||
					{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -373,37 +373,9 @@ namespace i2p
 | 
			
		|||
		return m_RouterInfo.GetCaps () & i2p::data::RouterInfo::eUnreachable;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RouterContext::PublishNTCPAddress (bool publish, bool v4only)
 | 
			
		||||
	void RouterContext::RemoveNTCPAddress (bool v4only)
 | 
			
		||||
	{
 | 
			
		||||
		auto& addresses = m_RouterInfo.GetAddresses ();
 | 
			
		||||
		if (publish)
 | 
			
		||||
		{
 | 
			
		||||
			for (const auto& addr : addresses) // v4
 | 
			
		||||
			{
 | 
			
		||||
				if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
 | 
			
		||||
					addr->host.is_v4 ())
 | 
			
		||||
				{
 | 
			
		||||
					// insert NTCP address with host/port from SSU
 | 
			
		||||
					m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			if (!v4only)
 | 
			
		||||
			{
 | 
			
		||||
				for (const auto& addr : addresses) // v6
 | 
			
		||||
				{
 | 
			
		||||
					if (addr->transportStyle == i2p::data::RouterInfo::eTransportSSU &&
 | 
			
		||||
						addr->host.is_v6 ())
 | 
			
		||||
					{
 | 
			
		||||
						// insert NTCP address with host/port from SSU
 | 
			
		||||
						m_RouterInfo.AddNTCPAddress (addr->host.to_string ().c_str (), addr->port);
 | 
			
		||||
						break;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
		for (auto it = addresses.begin (); it != addresses.end ();)
 | 
			
		||||
		{
 | 
			
		||||
			if ((*it)->transportStyle == i2p::data::RouterInfo::eTransportNTCP && !(*it)->IsNTCP2 () &&
 | 
			
		||||
| 
						 | 
				
			
			@ -416,7 +388,6 @@ namespace i2p
 | 
			
		|||
				++it;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RouterContext::SetUnreachable ()
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -89,7 +89,7 @@ namespace i2p
 | 
			
		|||
			void UpdateAddress (const boost::asio::ip::address& host);	// called from SSU or Daemon
 | 
			
		||||
			void PublishNTCP2Address (int port, bool publish = true, bool v4only = false);
 | 
			
		||||
			void UpdateNTCP2Address (bool enable);
 | 
			
		||||
			void PublishNTCPAddress (bool publish, bool v4only = true);
 | 
			
		||||
			void RemoveNTCPAddress (bool v4only = true); // delete NTCP address for older routers. TODO: remove later
 | 
			
		||||
			bool AddIntroducer (const i2p::data::RouterInfo::Introducer& introducer);
 | 
			
		||||
			void RemoveIntroducer (const boost::asio::ip::udp::endpoint& e);
 | 
			
		||||
			bool IsUnreachable () const;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -709,20 +709,6 @@ namespace data
 | 
			
		|||
		s.write (str.c_str (), len);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RouterInfo::AddNTCPAddress (const char * host, int port)
 | 
			
		||||
	{
 | 
			
		||||
		auto addr = std::make_shared<Address>();
 | 
			
		||||
		addr->host = boost::asio::ip::address::from_string (host);
 | 
			
		||||
		addr->port = port;
 | 
			
		||||
		addr->transportStyle = eTransportNTCP;
 | 
			
		||||
		addr->cost = 6;
 | 
			
		||||
		addr->date = 0;
 | 
			
		||||
		for (const auto& it: *m_Addresses) // don't insert same address twice
 | 
			
		||||
			if (*it == *addr) return;
 | 
			
		||||
		m_SupportedTransports |= addr->host.is_v6 () ? eNTCPV6 : eNTCPV4;
 | 
			
		||||
		m_Addresses->push_front(std::move(addr)); // always make NTCP first
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void RouterInfo::AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu)
 | 
			
		||||
	{
 | 
			
		||||
		auto addr = std::make_shared<Address>();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -157,7 +157,6 @@ namespace data
 | 
			
		|||
			std::shared_ptr<const Address> GetSSUAddress (bool v4only = true) const;
 | 
			
		||||
			std::shared_ptr<const Address> GetSSUV6Address () const;
 | 
			
		||||
 | 
			
		||||
			void AddNTCPAddress (const char * host, int port);
 | 
			
		||||
			void AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu = 0);
 | 
			
		||||
			void AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv, const boost::asio::ip::address& host = boost::asio::ip::address(), int port = 0);
 | 
			
		||||
			bool AddIntroducer (const Introducer& introducer);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue