mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	fix code syle(spaces->tabs, tabulations)
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
		
							parent
							
								
									9633c247f0
								
							
						
					
					
						commit
						7a5146ea74
					
				
					 115 changed files with 3206 additions and 3161 deletions
				
			
		| 
						 | 
				
			
			@ -127,8 +127,8 @@ namespace i2p
 | 
			
		|||
			i2p::context.SetNetID (netID);
 | 
			
		||||
			i2p::context.Init ();
 | 
			
		||||
 | 
			
		||||
			bool ipv6;		i2p::config::GetOption("ipv6", ipv6);
 | 
			
		||||
			bool ipv4;		i2p::config::GetOption("ipv4", ipv4);
 | 
			
		||||
			bool ipv6; i2p::config::GetOption("ipv6", ipv6);
 | 
			
		||||
			bool ipv4; i2p::config::GetOption("ipv4", ipv4);
 | 
			
		||||
#ifdef MESHNET
 | 
			
		||||
			// manual override for meshnet
 | 
			
		||||
			ipv4 = false;
 | 
			
		||||
| 
						 | 
				
			
			@ -143,8 +143,8 @@ namespace i2p
 | 
			
		|||
			i2p::context.SetSupportsV6 (ipv6);
 | 
			
		||||
			i2p::context.SetSupportsV4 (ipv4);
 | 
			
		||||
 | 
			
		||||
			bool ntcp;   i2p::config::GetOption("ntcp", ntcp);
 | 
			
		||||
			i2p::context.PublishNTCPAddress (ntcp, !ipv6);  
 | 
			
		||||
			bool ntcp; i2p::config::GetOption("ntcp", ntcp);
 | 
			
		||||
			i2p::context.PublishNTCPAddress (ntcp, !ipv6);
 | 
			
		||||
			bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2);
 | 
			
		||||
			if (ntcp2)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -172,10 +172,13 @@ namespace i2p
 | 
			
		|||
			SetMaxNumTransitTunnels (transitTunnels);
 | 
			
		||||
 | 
			
		||||
			bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill);
 | 
			
		||||
			if (isFloodfill) {
 | 
			
		||||
			if (isFloodfill)
 | 
			
		||||
			{
 | 
			
		||||
				LogPrint(eLogInfo, "Daemon: router will be floodfill");
 | 
			
		||||
				i2p::context.SetFloodfill (true);
 | 
			
		||||
			}	else {
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				i2p::context.SetFloodfill (false);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -243,7 +246,8 @@ namespace i2p
 | 
			
		|||
					i2p::transport::transports.RestrictRoutesToFamilies(fams);
 | 
			
		||||
					restricted  = fams.size() > 0;
 | 
			
		||||
				}
 | 
			
		||||
				if (routers.length() > 0) {
 | 
			
		||||
				if (routers.length() > 0)
 | 
			
		||||
				{
 | 
			
		||||
					std::set<i2p::data::IdentHash> idents;
 | 
			
		||||
					size_t pos = 0, comma;
 | 
			
		||||
					do
 | 
			
		||||
| 
						 | 
				
			
			@ -279,7 +283,8 @@ namespace i2p
 | 
			
		|||
			i2p::data::netdb.Start();
 | 
			
		||||
 | 
			
		||||
			bool upnp; i2p::config::GetOption("upnp.enabled", upnp);
 | 
			
		||||
			if (upnp) {
 | 
			
		||||
			if (upnp)
 | 
			
		||||
			{
 | 
			
		||||
				d.UPnP = std::unique_ptr<i2p::transport::UPnP>(new i2p::transport::UPnP);
 | 
			
		||||
				d.UPnP->Start ();
 | 
			
		||||
			}
 | 
			
		||||
| 
						 | 
				
			
			@ -292,15 +297,15 @@ namespace i2p
 | 
			
		|||
			}
 | 
			
		||||
 | 
			
		||||
			bool ntcp; i2p::config::GetOption("ntcp", ntcp);
 | 
			
		||||
			bool ssu; i2p::config::GetOption("ssu", ssu);
 | 
			
		||||
			bool ssu;  i2p::config::GetOption("ssu", ssu);
 | 
			
		||||
			LogPrint(eLogInfo, "Daemon: starting Transports");
 | 
			
		||||
			if(!ssu) LogPrint(eLogInfo, "Daemon: ssu disabled");
 | 
			
		||||
			if(!ntcp) LogPrint(eLogInfo, "Daemon: ntcp disabled");
 | 
			
		||||
 | 
			
		||||
			i2p::transport::transports.Start(ntcp, ssu);
 | 
			
		||||
			if (i2p::transport::transports.IsBoundNTCP() || i2p::transport::transports.IsBoundSSU() || i2p::transport::transports.IsBoundNTCP2()) 
 | 
			
		||||
			if (i2p::transport::transports.IsBoundNTCP() || i2p::transport::transports.IsBoundSSU() || i2p::transport::transports.IsBoundNTCP2())
 | 
			
		||||
				LogPrint(eLogInfo, "Daemon: Transports started");
 | 
			
		||||
			else 
 | 
			
		||||
			else
 | 
			
		||||
			{
 | 
			
		||||
				LogPrint(eLogError, "Daemon: failed to start Transports");
 | 
			
		||||
				/** shut down netdb right away */
 | 
			
		||||
| 
						 | 
				
			
			@ -310,23 +315,23 @@ namespace i2p
 | 
			
		|||
			}
 | 
			
		||||
 | 
			
		||||
			bool http; i2p::config::GetOption("http.enabled", http);
 | 
			
		||||
			if (http) {
 | 
			
		||||
			if (http)
 | 
			
		||||
			{
 | 
			
		||||
				std::string httpAddr; i2p::config::GetOption("http.address", httpAddr);
 | 
			
		||||
				uint16_t    httpPort; i2p::config::GetOption("http.port", httpPort);
 | 
			
		||||
				LogPrint(eLogInfo, "Daemon: starting webconsole at ", httpAddr, ":", httpPort);
 | 
			
		||||
				try 
 | 
			
		||||
				try
 | 
			
		||||
				{
 | 
			
		||||
					d.httpServer = std::unique_ptr<i2p::http::HTTPServer>(new i2p::http::HTTPServer(httpAddr, httpPort));
 | 
			
		||||
					d.httpServer->Start();
 | 
			
		||||
				} 
 | 
			
		||||
				catch (std::exception& ex) 
 | 
			
		||||
				}
 | 
			
		||||
				catch (std::exception& ex)
 | 
			
		||||
				{
 | 
			
		||||
					LogPrint (eLogError, "Daemon: failed to start webconsole: ", ex.what ());
 | 
			
		||||
					ThrowFatal ("Unable to start webconsole at ", httpAddr, ":", httpPort, ": ", ex.what ());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			LogPrint(eLogInfo, "Daemon: starting Tunnels");
 | 
			
		||||
			i2p::tunnel::tunnels.Start();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -339,12 +344,12 @@ namespace i2p
 | 
			
		|||
				std::string i2pcpAddr; i2p::config::GetOption("i2pcontrol.address", i2pcpAddr);
 | 
			
		||||
				uint16_t    i2pcpPort; i2p::config::GetOption("i2pcontrol.port",    i2pcpPort);
 | 
			
		||||
				LogPrint(eLogInfo, "Daemon: starting I2PControl at ", i2pcpAddr, ":", i2pcpPort);
 | 
			
		||||
				try 
 | 
			
		||||
				try
 | 
			
		||||
				{
 | 
			
		||||
					d.m_I2PControlService = std::unique_ptr<i2p::client::I2PControlService>(new i2p::client::I2PControlService (i2pcpAddr, i2pcpPort));
 | 
			
		||||
					d.m_I2PControlService->Start ();
 | 
			
		||||
				} 
 | 
			
		||||
				catch (std::exception& ex) 
 | 
			
		||||
				}
 | 
			
		||||
				catch (std::exception& ex)
 | 
			
		||||
				{
 | 
			
		||||
					LogPrint (eLogError, "Daemon: failed to start I2PControl: ", ex.what ());
 | 
			
		||||
					ThrowFatal ("Unable to start I2PControl service at ", i2pcpAddr, ":", i2pcpPort, ": ", ex.what ());
 | 
			
		||||
| 
						 | 
				
			
			@ -361,7 +366,7 @@ namespace i2p
 | 
			
		|||
			LogPrint(eLogInfo, "Daemon: stopping Tunnels");
 | 
			
		||||
			i2p::tunnel::tunnels.Stop();
 | 
			
		||||
 | 
			
		||||
			if (d.UPnP) 
 | 
			
		||||
			if (d.UPnP)
 | 
			
		||||
			{
 | 
			
		||||
				d.UPnP->Stop ();
 | 
			
		||||
				d.UPnP = nullptr;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,9 +13,10 @@ namespace util
 | 
			
		|||
	class Daemon_Singleton
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
            virtual bool init(int argc, char* argv[], std::shared_ptr<std::ostream> logstream);
 | 
			
		||||
            virtual bool init(int argc, char* argv[]);
 | 
			
		||||
            virtual bool start();
 | 
			
		||||
 | 
			
		||||
			virtual bool init(int argc, char* argv[], std::shared_ptr<std::ostream> logstream);
 | 
			
		||||
			virtual bool init(int argc, char* argv[]);
 | 
			
		||||
			virtual bool start();
 | 
			
		||||
			virtual bool stop();
 | 
			
		||||
			virtual void run () {};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -23,6 +24,7 @@ namespace util
 | 
			
		|||
			bool running;
 | 
			
		||||
 | 
			
		||||
		protected:
 | 
			
		||||
 | 
			
		||||
			Daemon_Singleton();
 | 
			
		||||
			virtual ~Daemon_Singleton();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -39,6 +41,7 @@ namespace util
 | 
			
		|||
	class DaemonQT: public i2p::util::Daemon_Singleton
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			static DaemonQT& Instance()
 | 
			
		||||
			{
 | 
			
		||||
				static DaemonQT instance;
 | 
			
		||||
| 
						 | 
				
			
			@ -51,6 +54,7 @@ namespace util
 | 
			
		|||
	class DaemonWin32 : public Daemon_Singleton
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			static DaemonWin32& Instance()
 | 
			
		||||
			{
 | 
			
		||||
				static DaemonWin32 instance;
 | 
			
		||||
| 
						 | 
				
			
			@ -72,6 +76,7 @@ namespace util
 | 
			
		|||
	class DaemonAndroid: public i2p::util::Daemon_Singleton
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			static DaemonAndroid& Instance()
 | 
			
		||||
			{
 | 
			
		||||
				static DaemonAndroid instance;
 | 
			
		||||
| 
						 | 
				
			
			@ -83,6 +88,7 @@ namespace util
 | 
			
		|||
	class DaemonLinux : public Daemon_Singleton
 | 
			
		||||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			static DaemonLinux& Instance()
 | 
			
		||||
			{
 | 
			
		||||
				static DaemonLinux instance;
 | 
			
		||||
| 
						 | 
				
			
			@ -94,10 +100,12 @@ namespace util
 | 
			
		|||
			void run ();
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
 | 
			
		||||
			std::string pidfile;
 | 
			
		||||
			int pidFH;
 | 
			
		||||
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			int gracefulShutdownInterval; // in seconds
 | 
			
		||||
	};
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -892,8 +892,8 @@ namespace http {
 | 
			
		|||
	void HTTPConnection::Receive ()
 | 
			
		||||
	{
 | 
			
		||||
		m_Socket->async_read_some (boost::asio::buffer (m_Buffer, HTTP_CONNECTION_BUFFER_SIZE),
 | 
			
		||||
			 std::bind(&HTTPConnection::HandleReceive, shared_from_this (),
 | 
			
		||||
				 std::placeholders::_1, std::placeholders::_2));
 | 
			
		||||
			std::bind(&HTTPConnection::HandleReceive, shared_from_this (),
 | 
			
		||||
				std::placeholders::_1, std::placeholders::_2));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	void HTTPConnection::HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -79,17 +79,17 @@ namespace http
 | 
			
		|||
			std::string m_Hostname;
 | 
			
		||||
	};
 | 
			
		||||
 | 
			
		||||
    //all the below functions are also used by Qt GUI, see mainwindow.cpp -> getStatusPageHtml
 | 
			
		||||
    enum OutputFormatEnum { forWebConsole, forQtUi };
 | 
			
		||||
    void ShowStatus (std::stringstream& s, bool includeHiddenContent, OutputFormatEnum outputFormat);
 | 
			
		||||
    void ShowLocalDestinations (std::stringstream& s);
 | 
			
		||||
    void ShowLeasesSets(std::stringstream& s);
 | 
			
		||||
    void ShowTunnels (std::stringstream& s);
 | 
			
		||||
    void ShowTransitTunnels (std::stringstream& s);
 | 
			
		||||
    void ShowTransports (std::stringstream& s);
 | 
			
		||||
    void ShowSAMSessions (std::stringstream& s);
 | 
			
		||||
    void ShowI2PTunnels (std::stringstream& s);
 | 
			
		||||
    void ShowLocalDestination (std::stringstream& s, const std::string& b32, uint32_t token);
 | 
			
		||||
	//all the below functions are also used by Qt GUI, see mainwindow.cpp -> getStatusPageHtml
 | 
			
		||||
	enum OutputFormatEnum { forWebConsole, forQtUi };
 | 
			
		||||
	void ShowStatus (std::stringstream& s, bool includeHiddenContent, OutputFormatEnum outputFormat);
 | 
			
		||||
	void ShowLocalDestinations (std::stringstream& s);
 | 
			
		||||
	void ShowLeasesSets(std::stringstream& s);
 | 
			
		||||
	void ShowTunnels (std::stringstream& s);
 | 
			
		||||
	void ShowTransitTunnels (std::stringstream& s);
 | 
			
		||||
	void ShowTransports (std::stringstream& s);
 | 
			
		||||
	void ShowSAMSessions (std::stringstream& s);
 | 
			
		||||
	void ShowI2PTunnels (std::stringstream& s);
 | 
			
		||||
	void ShowLocalDestination (std::stringstream& s, const std::string& b32, uint32_t token);
 | 
			
		||||
} // http
 | 
			
		||||
} // i2p
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,29 +59,28 @@ namespace client
 | 
			
		|||
		m_SSLContext.use_private_key_file (i2pcp_key, boost::asio::ssl::context::pem);
 | 
			
		||||
 | 
			
		||||
		// handlers
 | 
			
		||||
		m_MethodHandlers["Authenticate"]   = &I2PControlService::AuthenticateHandler;
 | 
			
		||||
		m_MethodHandlers["Echo"]           = &I2PControlService::EchoHandler;
 | 
			
		||||
		m_MethodHandlers["I2PControl"]     = &I2PControlService::I2PControlHandler;
 | 
			
		||||
		m_MethodHandlers["RouterInfo"]     = &I2PControlService::RouterInfoHandler;
 | 
			
		||||
		m_MethodHandlers["RouterManager"]  = &I2PControlService::RouterManagerHandler;
 | 
			
		||||
		m_MethodHandlers["NetworkSetting"] = &I2PControlService::NetworkSettingHandler;
 | 
			
		||||
		m_MethodHandlers["ClientServicesInfo"]     = &I2PControlService::ClientServicesInfoHandler;
 | 
			
		||||
		m_MethodHandlers["Authenticate"]       = &I2PControlService::AuthenticateHandler;
 | 
			
		||||
		m_MethodHandlers["Echo"]               = &I2PControlService::EchoHandler;
 | 
			
		||||
		m_MethodHandlers["I2PControl"]         = &I2PControlService::I2PControlHandler;
 | 
			
		||||
		m_MethodHandlers["RouterInfo"]         = &I2PControlService::RouterInfoHandler;
 | 
			
		||||
		m_MethodHandlers["RouterManager"]      = &I2PControlService::RouterManagerHandler;
 | 
			
		||||
		m_MethodHandlers["NetworkSetting"]     = &I2PControlService::NetworkSettingHandler;
 | 
			
		||||
		m_MethodHandlers["ClientServicesInfo"] = &I2PControlService::ClientServicesInfoHandler;
 | 
			
		||||
 | 
			
		||||
		// I2PControl
 | 
			
		||||
		m_I2PControlHandlers["i2pcontrol.password"] = &I2PControlService::PasswordHandler;
 | 
			
		||||
 | 
			
		||||
		// RouterInfo
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.uptime"]  = &I2PControlService::UptimeHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.version"] = &I2PControlService::VersionHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.status"]  = &I2PControlService::StatusHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.netdb.knownpeers"]   = &I2PControlService::NetDbKnownPeersHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.netdb.activepeers"]  = &I2PControlService::NetDbActivePeersHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.bw.inbound.1s"]  = &I2PControlService::InboundBandwidth1S;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.bw.outbound.1s"] = &I2PControlService::OutboundBandwidth1S;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.status"]         = &I2PControlService::NetStatusHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.uptime"]                    = &I2PControlService::UptimeHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.version"]                   = &I2PControlService::VersionHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.status"]                    = &I2PControlService::StatusHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.netdb.knownpeers"]          = &I2PControlService::NetDbKnownPeersHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.netdb.activepeers"]         = &I2PControlService::NetDbActivePeersHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.bw.inbound.1s"]         = &I2PControlService::InboundBandwidth1S;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.bw.outbound.1s"]        = &I2PControlService::OutboundBandwidth1S;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.status"]                = &I2PControlService::NetStatusHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.tunnels.participating"] = &I2PControlService::TunnelsParticipatingHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.tunnels.successrate"] =
 | 
			
		||||
&I2PControlService::TunnelsSuccessRateHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.tunnels.successrate"]   = &I2PControlService::TunnelsSuccessRateHandler;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.total.received.bytes"]  = &I2PControlService::NetTotalReceivedBytes;
 | 
			
		||||
		m_RouterInfoHandlers["i2p.router.net.total.sent.bytes"]      = &I2PControlService::NetTotalSentBytes;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -97,10 +96,10 @@ namespace client
 | 
			
		|||
		// ClientServicesInfo
 | 
			
		||||
		m_ClientServicesInfoHandlers["I2PTunnel"] = &I2PControlService::I2PTunnelInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["HTTPProxy"] = &I2PControlService::HTTPProxyInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["SOCKS"] = &I2PControlService::SOCKSInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["SAM"] = &I2PControlService::SAMInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["BOB"] = &I2PControlService::BOBInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["I2CP"] = &I2PControlService::I2CPInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["SOCKS"]     = &I2PControlService::SOCKSInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["SAM"]       = &I2PControlService::SAMInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["BOB"]       = &I2PControlService::BOBInfoHandler;
 | 
			
		||||
		m_ClientServicesInfoHandlers["I2CP"]      = &I2PControlService::I2CPInfoHandler;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	I2PControlService::~I2PControlService ()
 | 
			
		||||
| 
						 | 
				
			
			@ -401,8 +400,8 @@ namespace client
 | 
			
		|||
			auto it1 = m_RouterInfoHandlers.find (it->first);
 | 
			
		||||
			if (it1 != m_RouterInfoHandlers.end ())
 | 
			
		||||
			{
 | 
			
		||||
				if (!first) results << ","; 
 | 
			
		||||
				else first = false;		
 | 
			
		||||
				if (!first) results << ",";
 | 
			
		||||
				else first = false;
 | 
			
		||||
				(this->*(it1->second))(results);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
| 
						 | 
				
			
			@ -500,7 +499,7 @@ namespace client
 | 
			
		|||
		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)
 | 
			
		||||
		    {
 | 
			
		||||
			{
 | 
			
		||||
				Daemon.running = 0;
 | 
			
		||||
			});
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -514,7 +513,7 @@ namespace client
 | 
			
		|||
		m_ShutdownTimer.expires_from_now (boost::posix_time::seconds(timeout + 1)); // + 1 second
 | 
			
		||||
		m_ShutdownTimer.async_wait (
 | 
			
		||||
			[](const boost::system::error_code& ecode)
 | 
			
		||||
		    {
 | 
			
		||||
			{
 | 
			
		||||
				Daemon.running = 0;
 | 
			
		||||
			});
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,6 +27,7 @@ namespace client
 | 
			
		|||
	class I2PControlService
 | 
			
		||||
	{
 | 
			
		||||
		typedef boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssl_socket;
 | 
			
		||||
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
			I2PControlService (const std::string& address, int port);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,10 +80,10 @@ namespace transport
 | 
			
		|||
	void UPnP::Discover ()
 | 
			
		||||
	{
 | 
			
		||||
		bool isError;
 | 
			
		||||
        int err;
 | 
			
		||||
		int err;
 | 
			
		||||
 | 
			
		||||
#if ((MINIUPNPC_API_VERSION >= 8) || defined (UPNPDISCOVER_SUCCESS))
 | 
			
		||||
        err = UPNPDISCOVER_SUCCESS;
 | 
			
		||||
		err = UPNPDISCOVER_SUCCESS;
 | 
			
		||||
 | 
			
		||||
#if (MINIUPNPC_API_VERSION >= 14)
 | 
			
		||||
		m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0, 0, 2, &err);
 | 
			
		||||
| 
						 | 
				
			
			@ -92,9 +92,9 @@ namespace transport
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
		isError = err != UPNPDISCOVER_SUCCESS;
 | 
			
		||||
#else  // MINIUPNPC_API_VERSION >= 8
 | 
			
		||||
        err = 0;
 | 
			
		||||
        m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0);
 | 
			
		||||
#else // MINIUPNPC_API_VERSION >= 8
 | 
			
		||||
		err = 0;
 | 
			
		||||
		m_Devlist = upnpDiscover (UPNP_RESPONSE_TIMEOUT, NULL, NULL, 0);
 | 
			
		||||
		isError = m_Devlist == NULL;
 | 
			
		||||
#endif // MINIUPNPC_API_VERSION >= 8
 | 
			
		||||
		{
 | 
			
		||||
| 
						 | 
				
			
			@ -105,15 +105,15 @@ namespace transport
 | 
			
		|||
 | 
			
		||||
		if (isError)
 | 
			
		||||
		{
 | 
			
		||||
            LogPrint (eLogError, "UPnP: unable to discover Internet Gateway Devices: error ", err);
 | 
			
		||||
			LogPrint (eLogError, "UPnP: unable to discover Internet Gateway Devices: error ", err);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		err = UPNP_GetValidIGD (m_Devlist, &m_upnpUrls, &m_upnpData, m_NetworkAddr, sizeof (m_NetworkAddr));
 | 
			
		||||
        m_upnpUrlsInitialized=err!=0;
 | 
			
		||||
		m_upnpUrlsInitialized = err != 0;
 | 
			
		||||
		if (err == UPNP_IGD_VALID_CONNECTED)
 | 
			
		||||
		{
 | 
			
		||||
            err = UPNP_GetExternalIPAddress (m_upnpUrls.controlURL, m_upnpData.first.servicetype, m_externalIPAddress);
 | 
			
		||||
			err = UPNP_GetExternalIPAddress (m_upnpUrls.controlURL, m_upnpData.first.servicetype, m_externalIPAddress);
 | 
			
		||||
			if(err != UPNPCOMMAND_SUCCESS)
 | 
			
		||||
			{
 | 
			
		||||
				LogPrint (eLogError, "UPnP: unable to get external address: error ", err);
 | 
			
		||||
| 
						 | 
				
			
			@ -124,14 +124,14 @@ namespace transport
 | 
			
		|||
				LogPrint (eLogError, "UPnP: found Internet Gateway Device ", m_upnpUrls.controlURL);
 | 
			
		||||
				if (!m_externalIPAddress[0])
 | 
			
		||||
				{
 | 
			
		||||
                    LogPrint (eLogError, "UPnP: found Internet Gateway Device doesn't know our external address");
 | 
			
		||||
					LogPrint (eLogError, "UPnP: found Internet Gateway Device doesn't know our external address");
 | 
			
		||||
					return;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
            LogPrint (eLogError, "UPnP: unable to find valid Internet Gateway Device: error ", err);
 | 
			
		||||
			LogPrint (eLogError, "UPnP: unable to find valid Internet Gateway Device: error ", err);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -182,7 +182,7 @@ namespace transport
 | 
			
		|||
		err = CheckMapping (strPort.c_str (), strType.c_str ());
 | 
			
		||||
		if (err != UPNPCOMMAND_SUCCESS) // if mapping not found
 | 
			
		||||
		{
 | 
			
		||||
            LogPrint (eLogDebug, "UPnP: possibly port ", strPort, " is not forwarded: return code ", err);
 | 
			
		||||
			LogPrint (eLogDebug, "UPnP: possibly port ", strPort, " is not forwarded: return code ", err);
 | 
			
		||||
 | 
			
		||||
#if ((MINIUPNPC_API_VERSION >= 8) || defined (UPNPDISCOVER_SUCCESS))
 | 
			
		||||
			err = UPNP_AddPortMapping (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strPort.c_str (), m_NetworkAddr, strDesc.c_str (), strType.c_str (), NULL, NULL);
 | 
			
		||||
| 
						 | 
				
			
			@ -202,7 +202,7 @@ namespace transport
 | 
			
		|||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
            LogPrint (eLogDebug, "UPnP: external forward from ", m_NetworkAddr, ":", strPort, " exists on current Internet Gateway Device");
 | 
			
		||||
			LogPrint (eLogDebug, "UPnP: external forward from ", m_NetworkAddr, ":", strPort, " exists on current Internet Gateway Device");
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -219,14 +219,14 @@ namespace transport
 | 
			
		|||
 | 
			
		||||
	void UPnP::CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address)
 | 
			
		||||
	{
 | 
			
		||||
        if(!m_upnpUrlsInitialized) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
		if(!m_upnpUrlsInitialized) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		std::string strType (GetProto (address)), strPort (std::to_string (address->port));
 | 
			
		||||
		int err = UPNPCOMMAND_SUCCESS;
 | 
			
		||||
		
 | 
			
		||||
 | 
			
		||||
		err = CheckMapping (strPort.c_str (), strType.c_str ());
 | 
			
		||||
        if (err == UPNPCOMMAND_SUCCESS)
 | 
			
		||||
		if (err == UPNPCOMMAND_SUCCESS)
 | 
			
		||||
		{
 | 
			
		||||
			err = UPNP_DeletePortMapping (m_upnpUrls.controlURL, m_upnpData.first.servicetype, strPort.c_str (), strType.c_str (), NULL);
 | 
			
		||||
			LogPrint (eLogError, "UPnP: DeletePortMapping() returned : ", err);
 | 
			
		||||
| 
						 | 
				
			
			@ -237,11 +237,11 @@ namespace transport
 | 
			
		|||
	{
 | 
			
		||||
		freeUPNPDevlist (m_Devlist);
 | 
			
		||||
		m_Devlist = 0;
 | 
			
		||||
        if(m_upnpUrlsInitialized){
 | 
			
		||||
            FreeUPNPUrls (&m_upnpUrls);
 | 
			
		||||
            m_upnpUrlsInitialized=false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
		if(m_upnpUrlsInitialized){
 | 
			
		||||
			FreeUPNPUrls (&m_upnpUrls);
 | 
			
		||||
			m_upnpUrlsInitialized=false;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	std::string UPnP::GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,41 +33,41 @@ namespace transport
 | 
			
		|||
	{
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
		UPnP ();
 | 
			
		||||
		~UPnP ();
 | 
			
		||||
		void Close ();
 | 
			
		||||
			UPnP ();
 | 
			
		||||
			~UPnP ();
 | 
			
		||||
			void Close ();
 | 
			
		||||
 | 
			
		||||
		void Start ();
 | 
			
		||||
		void Stop ();
 | 
			
		||||
			void Start ();
 | 
			
		||||
			void Stop ();
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
 | 
			
		||||
		void Discover ();
 | 
			
		||||
		int  CheckMapping (const char* port, const char* type);
 | 
			
		||||
		void PortMapping ();
 | 
			
		||||
		void TryPortMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
		void CloseMapping ();
 | 
			
		||||
		void CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
			void Discover ();
 | 
			
		||||
			int  CheckMapping (const char* port, const char* type);
 | 
			
		||||
			void PortMapping ();
 | 
			
		||||
			void TryPortMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
			void CloseMapping ();
 | 
			
		||||
			void CloseMapping (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
 | 
			
		||||
		void Run ();
 | 
			
		||||
		std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
			void Run ();
 | 
			
		||||
			std::string GetProto (std::shared_ptr<i2p::data::RouterInfo::Address> address);
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
 | 
			
		||||
		bool m_IsRunning;
 | 
			
		||||
		std::unique_ptr<std::thread> m_Thread;
 | 
			
		||||
		std::condition_variable m_Started;
 | 
			
		||||
		std::mutex m_StartedMutex;
 | 
			
		||||
		boost::asio::io_service m_Service;
 | 
			
		||||
		boost::asio::deadline_timer m_Timer;
 | 
			
		||||
        bool m_upnpUrlsInitialized=false;
 | 
			
		||||
		struct UPNPUrls m_upnpUrls;
 | 
			
		||||
		struct IGDdatas m_upnpData;
 | 
			
		||||
			bool m_IsRunning;
 | 
			
		||||
			std::unique_ptr<std::thread> m_Thread;
 | 
			
		||||
			std::condition_variable m_Started;
 | 
			
		||||
			std::mutex m_StartedMutex;
 | 
			
		||||
			boost::asio::io_service m_Service;
 | 
			
		||||
			boost::asio::deadline_timer m_Timer;
 | 
			
		||||
			bool m_upnpUrlsInitialized = false;
 | 
			
		||||
			struct UPNPUrls m_upnpUrls;
 | 
			
		||||
			struct IGDdatas m_upnpData;
 | 
			
		||||
 | 
			
		||||
		// For miniupnpc
 | 
			
		||||
		struct UPNPDev * m_Devlist = 0;
 | 
			
		||||
		char m_NetworkAddr[64];
 | 
			
		||||
		char m_externalIPAddress[40];
 | 
			
		||||
			// For miniupnpc
 | 
			
		||||
			struct UPNPDev * m_Devlist = 0;
 | 
			
		||||
			char m_NetworkAddr[64];
 | 
			
		||||
			char m_externalIPAddress[40];
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -79,10 +79,10 @@ namespace transport {
 | 
			
		|||
	class UPnP {
 | 
			
		||||
		public:
 | 
			
		||||
 | 
			
		||||
		UPnP () {};
 | 
			
		||||
		~UPnP () {};
 | 
			
		||||
		void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
 | 
			
		||||
		void Stop () {};
 | 
			
		||||
			UPnP () {};
 | 
			
		||||
			~UPnP () {};
 | 
			
		||||
			void Start () { LogPrint(eLogWarning, "UPnP: this module was disabled at compile-time"); }
 | 
			
		||||
			void Stop () {};
 | 
			
		||||
	};
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -196,5 +196,4 @@ namespace i2p
 | 
			
		|||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,7 +2,6 @@
 | 
			
		|||
#include "Daemon.h"
 | 
			
		||||
 | 
			
		||||
#if defined(QT_GUI_LIB)
 | 
			
		||||
 | 
			
		||||
namespace i2p
 | 
			
		||||
{
 | 
			
		||||
namespace qt
 | 
			
		||||
| 
						 | 
				
			
			@ -10,11 +9,11 @@ namespace qt
 | 
			
		|||
	int RunQT (int argc, char* argv[]);
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main( int argc, char* argv[] )
 | 
			
		||||
{
 | 
			
		||||
	return i2p::qt::RunQT (argc, argv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
int main( int argc, char* argv[] )
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue