mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Compare commits
6 Commits
d411da451a
...
93ec5ac5c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93ec5ac5c4 | ||
|
|
774c606b09 | ||
|
|
1bff42042d | ||
|
|
daeb177579 | ||
|
|
5d7a062f1b | ||
|
|
35f7bd5127 |
@@ -32,10 +32,10 @@ namespace data
|
||||
|
||||
RouterProfile::RouterProfile ():
|
||||
m_IsUpdated (false), m_LastDeclineTime (0), m_LastUnreachableTime (0),
|
||||
m_LastUpdateTime (i2p::util::GetSecondsSinceEpoch ()),
|
||||
m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0), m_NumTunnelsNonReplied (0),
|
||||
m_NumTimesTaken (0), m_NumTimesRejected (0), m_HasConnected (false),
|
||||
m_IsDuplicated (false)
|
||||
m_LastUpdateTime (i2p::util::GetSecondsSinceEpoch ()), m_LastAccessTime (0),
|
||||
m_LastPersistTime (0), m_NumTunnelsAgreed (0), m_NumTunnelsDeclined (0),
|
||||
m_NumTunnelsNonReplied (0),m_NumTimesTaken (0), m_NumTimesRejected (0),
|
||||
m_HasConnected (false), m_IsDuplicated (false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ namespace data
|
||||
|
||||
void RouterProfile::Load (const IdentHash& identHash)
|
||||
{
|
||||
m_IsUpdated = false;
|
||||
std::string ident = identHash.ToBase64 ();
|
||||
std::string path = g_ProfilesStorage.Path(ident);
|
||||
boost::property_tree::ptree pt;
|
||||
@@ -257,7 +258,10 @@ namespace data
|
||||
std::unique_lock<std::mutex> l(g_ProfilesMutex);
|
||||
auto it = g_Profiles.find (identHash);
|
||||
if (it != g_Profiles.end ())
|
||||
{
|
||||
it->second->SetLastAccessTime (i2p::util::GetSecondsSinceEpoch ());
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
auto profile = netdb.NewRouterProfile ();
|
||||
profile->Load (identHash); // if possible
|
||||
@@ -295,12 +299,14 @@ namespace data
|
||||
std::lock_guard<std::mutex> l(g_ProfilesMutex);
|
||||
for (auto it = g_Profiles.begin (); it != g_Profiles.end ();)
|
||||
{
|
||||
if (ts - it->second->GetLastUpdateTime () > PEER_PROFILE_PERSIST_INTERVAL)
|
||||
if (it->second->IsUpdated () && ts > it->second->GetLastPersistTime () + PEER_PROFILE_PERSIST_INTERVAL)
|
||||
{
|
||||
if (it->second->IsUpdated ())
|
||||
tmp.push_back (std::make_pair (it->first, it->second));
|
||||
tmp.push_back (std::make_pair (it->first, it->second));
|
||||
it->second->SetLastPersistTime (ts);
|
||||
it->second->SetUpdated (false);
|
||||
}
|
||||
if (!it->second->IsUpdated () && ts > std::max (it->second->GetLastUpdateTime (), it->second->GetLastAccessTime ()) + PEER_PROFILE_PERSIST_INTERVAL)
|
||||
it = g_Profiles.erase (it);
|
||||
}
|
||||
else
|
||||
it++;
|
||||
}
|
||||
|
||||
@@ -70,6 +70,11 @@ namespace data
|
||||
|
||||
uint64_t GetLastUpdateTime () const { return m_LastUpdateTime; };
|
||||
bool IsUpdated () const { return m_IsUpdated; };
|
||||
void SetUpdated (bool updated) { m_IsUpdated = updated; }
|
||||
uint64_t GetLastAccessTime () const { return m_LastAccessTime; };
|
||||
void SetLastAccessTime (uint64_t ts) { m_LastAccessTime = ts; };
|
||||
uint64_t GetLastPersistTime () const { return m_LastPersistTime; };
|
||||
void SetLastPersistTime (uint64_t ts) { m_LastPersistTime = ts; };
|
||||
|
||||
bool IsUseful() const;
|
||||
bool IsDuplicated () const { return m_IsDuplicated; };
|
||||
@@ -91,7 +96,8 @@ namespace data
|
||||
private:
|
||||
|
||||
bool m_IsUpdated;
|
||||
uint64_t m_LastDeclineTime, m_LastUnreachableTime, m_LastUpdateTime; // in seconds
|
||||
uint64_t m_LastDeclineTime, m_LastUnreachableTime, m_LastUpdateTime,
|
||||
m_LastAccessTime, m_LastPersistTime; // in seconds
|
||||
// participation
|
||||
uint32_t m_NumTunnelsAgreed;
|
||||
uint32_t m_NumTunnelsDeclined;
|
||||
|
||||
@@ -33,13 +33,14 @@ namespace i2p
|
||||
m_ShareRatio (100), m_Status (eRouterStatusUnknown), m_StatusV6 (eRouterStatusUnknown),
|
||||
m_Error (eRouterErrorNone), m_ErrorV6 (eRouterErrorNone),
|
||||
m_Testing (false), m_TestingV6 (false), m_NetID (I2PD_NET_ID),
|
||||
m_PublishReplyToken (0), m_IsHiddenMode (false)
|
||||
m_PublishReplyToken (0), m_IsHiddenMode (false),
|
||||
m_Rng(i2p::util::GetMonotonicMicroseconds () % 1000000LL)
|
||||
{
|
||||
}
|
||||
|
||||
void RouterContext::Init ()
|
||||
{
|
||||
srand (i2p::util::GetMillisecondsSinceEpoch () % 1000);
|
||||
srand (m_Rng () % 1000);
|
||||
m_StartupTime = i2p::util::GetMonotonicSeconds ();
|
||||
|
||||
if (!Load ())
|
||||
@@ -76,7 +77,7 @@ namespace i2p
|
||||
m_CongestionUpdateTimer->cancel ();
|
||||
m_Service->Stop ();
|
||||
CleanUp (); // GarlicDestination
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<i2p::data::RouterInfo::Buffer> RouterContext::CopyRouterInfoBuffer () const
|
||||
@@ -1359,7 +1360,7 @@ namespace i2p
|
||||
{
|
||||
m_PublishTimer->cancel ();
|
||||
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_PUBLISH_INTERVAL +
|
||||
rand () % ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE));
|
||||
m_Rng () % ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE));
|
||||
m_PublishTimer->async_wait (std::bind (&RouterContext::HandlePublishTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
@@ -1471,7 +1472,8 @@ namespace i2p
|
||||
if (m_CongestionUpdateTimer)
|
||||
{
|
||||
m_CongestionUpdateTimer->cancel ();
|
||||
m_CongestionUpdateTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_CONGESTION_UPDATE_INTERVAL));
|
||||
m_CongestionUpdateTimer->expires_from_now (boost::posix_time::seconds(
|
||||
ROUTER_INFO_CONGESTION_UPDATE_INTERVAL + m_Rng () % ROUTER_INFO_CONGESTION_UPDATE_INTERVAL_VARIANCE));
|
||||
m_CongestionUpdateTimer->async_wait (std::bind (&RouterContext::HandleCongestionUpdateTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <unordered_set>
|
||||
#include <boost/asio.hpp>
|
||||
#include "Identity.h"
|
||||
@@ -36,7 +37,8 @@ namespace garlic
|
||||
const int ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE = 105;// in seconds
|
||||
const int ROUTER_INFO_CONFIRMATION_TIMEOUT = 1600; // in milliseconds
|
||||
const int ROUTER_INFO_MAX_PUBLISH_EXCLUDED_FLOODFILLS = 15;
|
||||
const int ROUTER_INFO_CONGESTION_UPDATE_INTERVAL = 12*60; // in seconds
|
||||
const int ROUTER_INFO_CONGESTION_UPDATE_INTERVAL = 11*60; // in seconds
|
||||
const int ROUTER_INFO_CONGESTION_UPDATE_INTERVAL_VARIANCE = 130; // in seconds
|
||||
const int ROUTER_INFO_CLEANUP_INTERVAL = 102; // in seconds
|
||||
|
||||
enum RouterStatus
|
||||
@@ -263,6 +265,7 @@ namespace garlic
|
||||
uint32_t m_PublishReplyToken;
|
||||
bool m_IsHiddenMode; // not publish
|
||||
mutable std::mutex m_RouterInfoMutex;
|
||||
std::mt19937 m_Rng;
|
||||
};
|
||||
|
||||
extern RouterContext context;
|
||||
|
||||
Reference in New Issue
Block a user