mirror of
				https://github.com/PurpleI2P/i2pd.git
				synced 2025-11-04 00:20:46 +00:00 
			
		
		
		
	use monotonic clock for uptime
This commit is contained in:
		
							parent
							
								
									832a9ab6b5
								
							
						
					
					
						commit
						8e919ddc8e
					
				
					 3 changed files with 9 additions and 8 deletions
				
			
		| 
						 | 
					@ -523,9 +523,10 @@ namespace data
 | 
				
			||||||
		auto total = m_RouterInfos.size ();
 | 
							auto total = m_RouterInfos.size ();
 | 
				
			||||||
		uint64_t expirationTimeout = NETDB_MAX_EXPIRATION_TIMEOUT*1000LL;
 | 
							uint64_t expirationTimeout = NETDB_MAX_EXPIRATION_TIMEOUT*1000LL;
 | 
				
			||||||
		uint64_t ts = i2p::util::GetMillisecondsSinceEpoch();
 | 
							uint64_t ts = i2p::util::GetMillisecondsSinceEpoch();
 | 
				
			||||||
 | 
							auto uptime = i2p::context.GetUptime ();	
 | 
				
			||||||
		// routers don't expire if less than 90 or uptime is less than 1 hour
 | 
							// routers don't expire if less than 90 or uptime is less than 1 hour
 | 
				
			||||||
		bool checkForExpiration = total > NETDB_MIN_ROUTERS && ts > (i2p::context.GetStartupTime () + 600)*1000LL; // 10 minutes
 | 
							bool checkForExpiration = total > NETDB_MIN_ROUTERS && uptime > 600; // 10 minutes
 | 
				
			||||||
		if (checkForExpiration && ts > (i2p::context.GetStartupTime () + 3600)*1000LL) // 1 hour
 | 
							if (checkForExpiration && uptime > 3600) // 1 hour
 | 
				
			||||||
			expirationTimeout = i2p::context.IsFloodfill () ? NETDB_FLOODFILL_EXPIRATION_TIMEOUT*1000LL :
 | 
								expirationTimeout = i2p::context.IsFloodfill () ? NETDB_FLOODFILL_EXPIRATION_TIMEOUT*1000LL :
 | 
				
			||||||
					NETDB_MIN_EXPIRATION_TIMEOUT*1000LL + (NETDB_MAX_EXPIRATION_TIMEOUT - NETDB_MIN_EXPIRATION_TIMEOUT)*1000LL*NETDB_MIN_ROUTERS/total;
 | 
										NETDB_MIN_EXPIRATION_TIMEOUT*1000LL + (NETDB_MAX_EXPIRATION_TIMEOUT - NETDB_MIN_EXPIRATION_TIMEOUT)*1000LL*NETDB_MIN_ROUTERS/total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ namespace i2p
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	RouterContext::RouterContext ():
 | 
						RouterContext::RouterContext ():
 | 
				
			||||||
		m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
 | 
							m_LastUpdateTime (0), m_AcceptsTunnels (true), m_IsFloodfill (false),
 | 
				
			||||||
		m_StartupTime (0), m_ShareRatio (100), m_Status (eRouterStatusOK),
 | 
							m_ShareRatio (100), m_Status (eRouterStatusOK),
 | 
				
			||||||
		m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID)
 | 
							m_Error (eRouterErrorNone), m_NetID (I2PD_NET_ID)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ namespace i2p
 | 
				
			||||||
	void RouterContext::Init ()
 | 
						void RouterContext::Init ()
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
 | 
							srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
 | 
				
			||||||
		m_StartupTime = i2p::util::GetSecondsSinceEpoch ();
 | 
							m_StartupTime = std::chrono::steady_clock::now();
 | 
				
			||||||
		if (!Load ())
 | 
							if (!Load ())
 | 
				
			||||||
			CreateNewRouter ();
 | 
								CreateNewRouter ();
 | 
				
			||||||
		m_Decryptor = m_Keys.CreateDecryptor (nullptr);
 | 
							m_Decryptor = m_Keys.CreateDecryptor (nullptr);
 | 
				
			||||||
| 
						 | 
					@ -716,7 +716,7 @@ namespace i2p
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	uint32_t RouterContext::GetUptime () const
 | 
						uint32_t RouterContext::GetUptime () const
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		return i2p::util::GetSecondsSinceEpoch () - m_StartupTime;
 | 
							return std::chrono::duration_cast<std::chrono::seconds> (std::chrono::steady_clock::now() - m_StartupTime).count ();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool RouterContext::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
 | 
						bool RouterContext::Decrypt (const uint8_t * encrypted, uint8_t * data, BN_CTX * ctx) const
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <mutex>
 | 
					#include <mutex>
 | 
				
			||||||
 | 
					#include <chrono>
 | 
				
			||||||
#include <boost/asio.hpp>
 | 
					#include <boost/asio.hpp>
 | 
				
			||||||
#include "Identity.h"
 | 
					#include "Identity.h"
 | 
				
			||||||
#include "RouterInfo.h"
 | 
					#include "RouterInfo.h"
 | 
				
			||||||
| 
						 | 
					@ -64,8 +65,7 @@ namespace i2p
 | 
				
			||||||
			const uint8_t * GetNTCP2IV () const { return m_NTCP2Keys ? m_NTCP2Keys->iv : nullptr; };
 | 
								const uint8_t * GetNTCP2IV () const { return m_NTCP2Keys ? m_NTCP2Keys->iv : nullptr; };
 | 
				
			||||||
			i2p::crypto::X25519Keys& GetStaticKeys (); 
 | 
								i2p::crypto::X25519Keys& GetStaticKeys (); 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			uint32_t GetUptime () const;
 | 
								uint32_t GetUptime () const; // in seconds
 | 
				
			||||||
			uint32_t GetStartupTime () const { return m_StartupTime; };
 | 
					 | 
				
			||||||
			uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
 | 
								uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
 | 
				
			||||||
			uint64_t GetBandwidthLimit () const { return m_BandwidthLimit; };
 | 
								uint64_t GetBandwidthLimit () const { return m_BandwidthLimit; };
 | 
				
			||||||
			uint64_t GetTransitBandwidthLimit () const { return (m_BandwidthLimit*m_ShareRatio)/100LL; };
 | 
								uint64_t GetTransitBandwidthLimit () const { return (m_BandwidthLimit*m_ShareRatio)/100LL; };
 | 
				
			||||||
| 
						 | 
					@ -137,7 +137,7 @@ namespace i2p
 | 
				
			||||||
			std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
 | 
								std::shared_ptr<i2p::crypto::CryptoKeyDecryptor> m_Decryptor;
 | 
				
			||||||
			uint64_t m_LastUpdateTime; // in seconds
 | 
								uint64_t m_LastUpdateTime; // in seconds
 | 
				
			||||||
			bool m_AcceptsTunnels, m_IsFloodfill;
 | 
								bool m_AcceptsTunnels, m_IsFloodfill;
 | 
				
			||||||
			uint64_t m_StartupTime; // in seconds since epoch
 | 
								std::chrono::time_point<std::chrono::steady_clock> m_StartupTime;
 | 
				
			||||||
			uint64_t m_BandwidthLimit; // allowed bandwidth
 | 
								uint64_t m_BandwidthLimit; // allowed bandwidth
 | 
				
			||||||
			int m_ShareRatio;
 | 
								int m_ShareRatio;
 | 
				
			||||||
			RouterStatus m_Status;
 | 
								RouterStatus m_Status;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue