diff --git a/NetDb.cpp b/NetDb.cpp index 147d0217..9655b6c3 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -173,7 +173,8 @@ namespace data } lastSave = ts; } - if (ts - lastPublish >= 2400) // publish every 40 minutes + if (i2p::context.GetLastUpdateTime () > lastPublish || // our router has been updated + ts - lastPublish >= 2400) // or publish every 40 minutes { Publish (); lastPublish = ts; diff --git a/NetDb.h b/NetDb.h index 7b515e2a..c912049b 100644 --- a/NetDb.h +++ b/NetDb.h @@ -90,7 +90,7 @@ namespace data void Reseed (); - // for web interface + // for web interface and stats int GetNumRouters () const { return m_RouterInfos.size (); }; int GetNumFloodfills () const { return m_Floodfills.size (); }; int GetNumLeaseSets () const { return m_LeaseSets.size (); }; diff --git a/RouterContext.cpp b/RouterContext.cpp index 1a0121ed..681ca29f 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -1,10 +1,12 @@ #include #include #include +#include #include "CryptoConst.h" #include "RouterContext.h" #include "Timestamp.h" #include "I2NPProtocol.h" +#include "NetDb.h" #include "util.h" #include "version.h" @@ -54,6 +56,12 @@ namespace i2p void RouterContext::UpdateRouterInfo () { + if (m_IsFloodfill) + { + // update routers and leasesets + m_RouterInfo.SetProperty (ROUTER_INFO_PROPERTY_LEASESETS, boost::lexical_cast(i2p::data::netdb.GetNumLeaseSets ())); + m_RouterInfo.SetProperty (ROUTER_INFO_PROPERTY_ROUTERS, boost::lexical_cast(i2p::data::netdb.GetNumRouters ())); + } m_RouterInfo.CreateBuffer (m_Keys); m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO)); m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch (); @@ -115,7 +123,12 @@ namespace i2p if (floodfill) m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eFloodfill); else + { m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () & ~i2p::data::RouterInfo::eFloodfill); + // we don't publish number of routers and leaseset for non-floodfill + m_RouterInfo.DeleteProperty (ROUTER_INFO_PROPERTY_LEASESETS); + m_RouterInfo.DeleteProperty (ROUTER_INFO_PROPERTY_ROUTERS); + } UpdateRouterInfo (); } diff --git a/RouterContext.h b/RouterContext.h index 24b761f9..1003f6cf 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -17,6 +17,9 @@ namespace i2p const char ROUTER_KEYS[] = "router.keys"; const int ROUTER_INFO_UPDATE_INTERVAL = 1800; // 30 minutes + const char ROUTER_INFO_PROPERTY_LEASESETS[] = "netdb.knownLeaseSets"; + const char ROUTER_INFO_PROPERTY_ROUTERS[] = "netdb.knownRouters"; + enum RouterStatus { eRouterStatusOK = 0, @@ -40,6 +43,7 @@ namespace i2p CryptoPP::RandomNumberGenerator& GetRandomNumberGenerator () { return m_Rnd; }; uint32_t GetUptime () const; uint32_t GetStartupTime () const { return m_StartupTime; }; + uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; }; RouterStatus GetStatus () const { return m_Status; }; void SetStatus (RouterStatus status) { m_Status = status; }; diff --git a/RouterInfo.cpp b/RouterInfo.cpp index e9105db1..fb12ff9f 100644 --- a/RouterInfo.cpp +++ b/RouterInfo.cpp @@ -548,11 +548,16 @@ namespace data ExtractCaps (caps); } - void RouterInfo::SetProperty (const char * key, const char * value) + void RouterInfo::SetProperty (const std::string& key, const std::string& value) { m_Properties[key] = value; } + void RouterInfo::DeleteProperty (const std::string& key) + { + m_Properties.erase (key); + } + bool RouterInfo::IsFloodfill () const { return m_Caps & Caps::eFloodfill; diff --git a/RouterInfo.h b/RouterInfo.h index 007c1383..fb9a6f13 100644 --- a/RouterInfo.h +++ b/RouterInfo.h @@ -105,7 +105,8 @@ namespace data void AddSSUAddress (const char * host, int port, const uint8_t * key, int mtu = 0); bool AddIntroducer (const Address * address, uint32_t tag); bool RemoveIntroducer (const boost::asio::ip::udp::endpoint& e); - void SetProperty (const char * key, const char * value); // called from RouterContext only + void SetProperty (const std::string& key, const std::string& value); // called from RouterContext only + void DeleteProperty (const std::string& key); // called from RouterContext only void ClearProperties () { m_Properties.clear (); }; bool IsFloodfill () const; bool IsNTCP (bool v4only = true) const;