Skip to content

Commit

Permalink
publish number of leasets and routers for floodfill
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Mar 18, 2015
1 parent 647bb50 commit 0b754ec
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion NetDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 (); };
Expand Down
13 changes: 13 additions & 0 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#include <fstream>
#include <cryptopp/dh.h>
#include <cryptopp/dsa.h>
#include <boost/lexical_cast.hpp>
#include "CryptoConst.h"
#include "RouterContext.h"
#include "Timestamp.h"
#include "I2NPProtocol.h"
#include "NetDb.h"
#include "util.h"
#include "version.h"

Expand Down Expand Up @@ -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<std::string>(i2p::data::netdb.GetNumLeaseSets ()));
m_RouterInfo.SetProperty (ROUTER_INFO_PROPERTY_ROUTERS, boost::lexical_cast<std::string>(i2p::data::netdb.GetNumRouters ()));
}
m_RouterInfo.CreateBuffer (m_Keys);
m_RouterInfo.SaveToFile (i2p::util::filesystem::GetFullPath (ROUTER_INFO));
m_LastUpdateTime = i2p::util::GetSecondsSinceEpoch ();
Expand Down Expand Up @@ -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 ();
}

Expand Down
4 changes: 4 additions & 0 deletions RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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; };

Expand Down
7 changes: 6 additions & 1 deletion RouterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion RouterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0b754ec

Please sign in to comment.