Browse Source

* RouterContext : replace Set(Low|High|Extra)Bandwidth with SetBandwidth()

pull/462/head
hagen 9 years ago
parent
commit
642bcfcdea
  1. 58
      RouterContext.cpp
  2. 7
      RouterContext.h

58
RouterContext.cpp

@ -166,31 +166,47 @@ namespace i2p
} }
} }
void RouterContext::SetHighBandwidth () void RouterContext::SetBandwidth (char L) {
{ uint16_t limit = 0;
if (!m_RouterInfo.IsHighBandwidth () || m_RouterInfo.IsExtraBandwidth ()) enum { low, high, extra } type = high;
{ /* detect parameters */
m_RouterInfo.SetCaps ((m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eHighBandwidth) & ~i2p::data::RouterInfo::eExtraBandwidth); switch (L) {
UpdateRouterInfo (); case i2p::data::CAPS_FLAG_LOW_BANDWIDTH1 : limit = 12; type = low; break;
} case i2p::data::CAPS_FLAG_LOW_BANDWIDTH2 : limit = 48; type = low; break;
case i2p::data::CAPS_FLAG_HIGH_BANDWIDTH1 : limit = 64; type = high; break;
case i2p::data::CAPS_FLAG_HIGH_BANDWIDTH2 : limit = 128; type = high; break;
default:
case i2p::data::CAPS_FLAG_HIGH_BANDWIDTH3 : limit = 256; type = high; break;
case i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH1 : limit = 2048; type = extra; break;
case i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH2 : limit = 9999; type = extra; break;
}
/* floodfill requires 'extra' bandwidth */
if (m_IsFloodfill && limit < 2048) {
limit = 2048, type = extra;
LogPrint(eLogInfo, "Daemon: bandwidth set to 'extra' due to floodfill");
}
/* update caps & flags in RI */
auto caps = m_RouterInfo.GetCaps ();
caps &= ~i2p::data::RouterInfo::eHighBandwidth;
caps &= ~i2p::data::RouterInfo::eExtraBandwidth;
switch (type) {
case low : /* not set */; break;
case high : caps |= i2p::data::RouterInfo::eHighBandwidth; break;
case extra : caps |= i2p::data::RouterInfo::eExtraBandwidth; break;
} }
m_RouterInfo.SetCaps (caps);
void RouterContext::SetLowBandwidth ()
{
if (m_RouterInfo.IsHighBandwidth () || m_RouterInfo.IsExtraBandwidth ())
{
m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () & ~i2p::data::RouterInfo::eHighBandwidth & ~i2p::data::RouterInfo::eExtraBandwidth);
UpdateRouterInfo (); UpdateRouterInfo ();
} m_BandwidthLimit = limit;
} }
void RouterContext::SetExtraBandwidth () void RouterContext::SetBandwidth (int limit) {
{ if (limit > 2000) { SetBandwidth('X'); }
if (!m_RouterInfo.IsExtraBandwidth () || !m_RouterInfo.IsHighBandwidth ()) else if (limit > 256) { SetBandwidth('P'); }
{ else if (limit > 128) { SetBandwidth('O'); }
m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eExtraBandwidth | i2p::data::RouterInfo::eHighBandwidth); else if (limit > 64) { SetBandwidth('N'); }
UpdateRouterInfo (); else if (limit > 48) { SetBandwidth('M'); }
} else if (limit > 12) { SetBandwidth('L'); }
else { SetBandwidth('K'); }
} }
bool RouterContext::IsUnreachable () const bool RouterContext::IsUnreachable () const

7
RouterContext.h

@ -45,6 +45,7 @@ namespace i2p
uint32_t GetUptime () const; uint32_t GetUptime () const;
uint32_t GetStartupTime () const { return m_StartupTime; }; 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; };
RouterStatus GetStatus () const { return m_Status; }; RouterStatus GetStatus () const { return m_Status; };
void SetStatus (RouterStatus status); void SetStatus (RouterStatus status);
@ -58,9 +59,8 @@ namespace i2p
bool IsFloodfill () const { return m_IsFloodfill; }; bool IsFloodfill () const { return m_IsFloodfill; };
void SetFloodfill (bool floodfill); void SetFloodfill (bool floodfill);
void SetFamily (const std::string& family); void SetFamily (const std::string& family);
void SetHighBandwidth (); void SetBandwidth (int limit); /* in kilobytes */
void SetLowBandwidth (); void SetBandwidth (char L); /* by letter */
void SetExtraBandwidth ();
bool AcceptsTunnels () const { return m_AcceptsTunnels; }; bool AcceptsTunnels () const { return m_AcceptsTunnels; };
void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; }; void SetAcceptsTunnels (bool acceptsTunnels) { m_AcceptsTunnels = acceptsTunnels; };
bool SupportsV6 () const { return m_RouterInfo.IsV6 (); }; bool SupportsV6 () const { return m_RouterInfo.IsV6 (); };
@ -101,6 +101,7 @@ namespace i2p
uint64_t m_LastUpdateTime; uint64_t m_LastUpdateTime;
bool m_AcceptsTunnels, m_IsFloodfill; bool m_AcceptsTunnels, m_IsFloodfill;
uint64_t m_StartupTime; // in seconds since epoch uint64_t m_StartupTime; // in seconds since epoch
uint32_t m_BandwidthLimit; // allowed bandwidth
RouterStatus m_Status; RouterStatus m_Status;
std::mutex m_GarlicMutex; std::mutex m_GarlicMutex;
}; };

Loading…
Cancel
Save