mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 08:30:46 +00:00 
			
		
		
		
	reuse current introducers if no more available
This commit is contained in:
		
							parent
							
								
									9d79b26506
								
							
						
					
					
						commit
						7a19533380
					
				
					 3 changed files with 29 additions and 8 deletions
				
			
		| 
						 | 
				
			
			@ -670,7 +670,7 @@ namespace transport
 | 
			
		|||
		for (const auto& s : sessions)
 | 
			
		||||
		{	
 | 
			
		||||
			if (s.second->GetRelayTag () && s.second->GetState () == eSessionStateEstablished &&
 | 
			
		||||
			    ts < s.second->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
 | 
			
		||||
			    ts < s.second->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_EXPIRATION)
 | 
			
		||||
				ret.push_back (s.second);
 | 
			
		||||
		}	
 | 
			
		||||
		if ((int)ret.size () > maxNumIntroducers)
 | 
			
		||||
| 
						 | 
				
			
			@ -762,13 +762,19 @@ namespace transport
 | 
			
		|||
			for (const auto& it : introducers)
 | 
			
		||||
			{
 | 
			
		||||
				auto session = FindSession (it);
 | 
			
		||||
				if (session && ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
 | 
			
		||||
				if (session)
 | 
			
		||||
				{
 | 
			
		||||
					session->SendKeepAlive ();
 | 
			
		||||
					newList.push_back (it);
 | 
			
		||||
					numIntroducers++;
 | 
			
		||||
					if (ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_EXPIRATION)
 | 
			
		||||
						session->SendKeepAlive ();
 | 
			
		||||
					if (ts < session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION)
 | 
			
		||||
					{	
 | 
			
		||||
						newList.push_back (it);
 | 
			
		||||
						numIntroducers++;
 | 
			
		||||
					}
 | 
			
		||||
					else
 | 
			
		||||
						session = nullptr;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				if (!session)
 | 
			
		||||
					i2p::context.RemoveIntroducer (it);
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -776,6 +782,19 @@ namespace transport
 | 
			
		|||
			{
 | 
			
		||||
				// create new
 | 
			
		||||
				auto sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4); // try to find if duplicates
 | 
			
		||||
				if (sessions.empty () && !introducers.empty ())
 | 
			
		||||
				{
 | 
			
		||||
					// bump creation time for previous introducers if no new sessions found
 | 
			
		||||
					LogPrint (eLogDebug, "SSU: no new introducers found. Trying to reuse existing");
 | 
			
		||||
					for (const auto& it : introducers)
 | 
			
		||||
					{
 | 
			
		||||
						auto session = FindSession (it);
 | 
			
		||||
						if (session)
 | 
			
		||||
							session->SetCreationTime (session->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION);
 | 
			
		||||
					}	
 | 
			
		||||
					// try again
 | 
			
		||||
					sessions = FindIntroducers (SSU_MAX_NUM_INTRODUCERS, v4);
 | 
			
		||||
				}	
 | 
			
		||||
				for (const auto& it1: sessions)
 | 
			
		||||
				{
 | 
			
		||||
					const auto& ep = it1->GetRemoteEndpoint ();
 | 
			
		||||
| 
						 | 
				
			
			@ -784,7 +803,7 @@ namespace transport
 | 
			
		|||
					introducer.iPort = ep.port ();
 | 
			
		||||
					introducer.iTag = it1->GetRelayTag ();
 | 
			
		||||
					introducer.iKey = it1->GetIntroKey ();
 | 
			
		||||
					introducer.iExp = it1->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_DURATION;
 | 
			
		||||
					introducer.iExp = it1->GetCreationTime () + SSU_TO_INTRODUCER_SESSION_EXPIRATION;
 | 
			
		||||
					if (i2p::context.AddIntroducer (introducer))
 | 
			
		||||
					{
 | 
			
		||||
						newList.push_back (ep);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@ namespace transport
 | 
			
		|||
	const int SSU_KEEP_ALIVE_INTERVAL = 30; // 30 seconds
 | 
			
		||||
	const int SSU_PEER_TEST_TIMEOUT = 60; // 60 seconds
 | 
			
		||||
	const int SSU_TO_INTRODUCER_SESSION_DURATION = 3600; // 1 hour
 | 
			
		||||
	const int SSU_TO_INTRODUCER_SESSION_EXPIRATION = 4800; // 80 minutes
 | 
			
		||||
	const int SSU_TERMINATION_CHECK_TIMEOUT = 30; // 30 seconds
 | 
			
		||||
	const size_t SSU_MAX_NUM_INTRODUCERS = 3;
 | 
			
		||||
	const size_t SSU_SOCKET_RECEIVE_BUFFER_SIZE = 0x1FFFF; // 128K
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,7 +102,8 @@ namespace transport
 | 
			
		|||
			uint32_t GetRelayTag () const { return m_RelayTag; };
 | 
			
		||||
			const i2p::data::RouterInfo::IntroKey& GetIntroKey () const { return m_IntroKey; };
 | 
			
		||||
			uint32_t GetCreationTime () const { return m_CreationTime; };
 | 
			
		||||
 | 
			
		||||
			void SetCreationTime (uint32_t ts) { m_CreationTime = ts; }; // for introducers
 | 
			
		||||
			
 | 
			
		||||
			void FlushData ();
 | 
			
		||||
 | 
			
		||||
		private:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue