Browse Source

extra bandwidth caps

pull/317/head
orignal 9 years ago
parent
commit
7149b509d7
  1. 10
      Daemon.cpp
  2. 13
      RouterContext.cpp
  3. 1
      RouterContext.h
  4. 10
      RouterInfo.cpp
  5. 14
      RouterInfo.h
  6. 5
      Transports.cpp
  7. 1
      Transports.h

10
Daemon.cpp

@ -78,16 +78,20 @@ namespace i2p
i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host)); i2p::context.UpdateAddress (boost::asio::ip::address::from_string (host));
i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0)); i2p::context.SetSupportsV6 (i2p::util::config::GetArg("-v6", 0));
i2p::context.SetFloodfill (i2p::util::config::GetArg("-floodfill", 0)); bool isFloodfill = i2p::util::config::GetArg("-floodfill", 0);
i2p::context.SetFloodfill (isFloodfill);
auto bandwidth = i2p::util::config::GetArg("-bandwidth", ""); auto bandwidth = i2p::util::config::GetArg("-bandwidth", "");
if (bandwidth.length () > 0) if (bandwidth.length () > 0)
{ {
if (bandwidth[0] > 'L') if (bandwidth[0] > 'O')
i2p::context.SetExtraBandwidth ();
else if (bandwidth[0] > 'L')
i2p::context.SetHighBandwidth (); i2p::context.SetHighBandwidth ();
else else
i2p::context.SetLowBandwidth (); i2p::context.SetLowBandwidth ();
} }
else if (isFloodfill)
i2p::context.SetExtraBandwidth ();
LogPrint(eLogDebug, "Daemon: CMD parameters:"); LogPrint(eLogDebug, "Daemon: CMD parameters:");
for (int i = 0; i < argc; ++i) for (int i = 0; i < argc; ++i)
LogPrint(eLogDebug, i, ": ", argv[i]); LogPrint(eLogDebug, i, ": ", argv[i]);

13
RouterContext.cpp

@ -149,7 +149,7 @@ namespace i2p
{ {
if (!m_RouterInfo.IsHighBandwidth ()) if (!m_RouterInfo.IsHighBandwidth ())
{ {
m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eHighBandwidth); m_RouterInfo.SetCaps ((m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eHighBandwidth) & ~i2p::data::RouterInfo::eExtraBandwidth);
UpdateRouterInfo (); UpdateRouterInfo ();
} }
} }
@ -158,7 +158,16 @@ namespace i2p
{ {
if (m_RouterInfo.IsHighBandwidth ()) if (m_RouterInfo.IsHighBandwidth ())
{ {
m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () & ~i2p::data::RouterInfo::eHighBandwidth); m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () & ~i2p::data::RouterInfo::eHighBandwidth & ~i2p::data::RouterInfo::eExtraBandwidth);
UpdateRouterInfo ();
}
}
void RouterContext::SetExtraBandwidth ()
{
if (!m_RouterInfo.IsExtraBandwidth ())
{
m_RouterInfo.SetCaps (m_RouterInfo.GetCaps () | i2p::data::RouterInfo::eExtraBandwidth | i2p::data::RouterInfo::eHighBandwidth);
UpdateRouterInfo (); UpdateRouterInfo ();
} }
} }

1
RouterContext.h

@ -62,6 +62,7 @@ namespace i2p
void SetFloodfill (bool floodfill); void SetFloodfill (bool floodfill);
void SetHighBandwidth (); void SetHighBandwidth ();
void SetLowBandwidth (); void SetLowBandwidth ();
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 (); };

10
RouterInfo.cpp

@ -265,6 +265,10 @@ namespace data
case CAPS_FLAG_HIGH_BANDWIDTH3: case CAPS_FLAG_HIGH_BANDWIDTH3:
m_Caps |= Caps::eHighBandwidth; m_Caps |= Caps::eHighBandwidth;
break; break;
case CAPS_FLAG_EXTRA_BANDWIDTH1:
case CAPS_FLAG_EXTRA_BANDWIDTH2:
m_Caps |= Caps::eExtraBandwidth;
break;
case CAPS_FLAG_HIDDEN: case CAPS_FLAG_HIDDEN:
m_Caps |= Caps::eHidden; m_Caps |= Caps::eHidden;
break; break;
@ -291,11 +295,15 @@ namespace data
std::string caps; std::string caps;
if (m_Caps & eFloodfill) if (m_Caps & eFloodfill)
{ {
caps += CAPS_FLAG_HIGH_BANDWIDTH3; // highest bandwidth if (m_Caps & eExtraBandwidth) caps += CAPS_FLAG_EXTRA_BANDWIDTH1; // 'P'
caps += CAPS_FLAG_HIGH_BANDWIDTH3; // 'O'
caps += CAPS_FLAG_FLOODFILL; // floodfill caps += CAPS_FLAG_FLOODFILL; // floodfill
} }
else else
{
if (m_Caps & eExtraBandwidth) caps += CAPS_FLAG_EXTRA_BANDWIDTH1;
caps += (m_Caps & eHighBandwidth) ? CAPS_FLAG_HIGH_BANDWIDTH3 : CAPS_FLAG_LOW_BANDWIDTH2; // bandwidth caps += (m_Caps & eHighBandwidth) ? CAPS_FLAG_HIGH_BANDWIDTH3 : CAPS_FLAG_LOW_BANDWIDTH2; // bandwidth
}
if (m_Caps & eHidden) caps += CAPS_FLAG_HIDDEN; // hidden if (m_Caps & eHidden) caps += CAPS_FLAG_HIDDEN; // hidden
if (m_Caps & eReachable) caps += CAPS_FLAG_REACHABLE; // reachable if (m_Caps & eReachable) caps += CAPS_FLAG_REACHABLE; // reachable
if (m_Caps & eUnreachable) caps += CAPS_FLAG_UNREACHABLE; // unreachable if (m_Caps & eUnreachable) caps += CAPS_FLAG_UNREACHABLE; // unreachable

14
RouterInfo.h

@ -23,6 +23,8 @@ namespace data
const char CAPS_FLAG_HIGH_BANDWIDTH1 = 'M'; const char CAPS_FLAG_HIGH_BANDWIDTH1 = 'M';
const char CAPS_FLAG_HIGH_BANDWIDTH2 = 'N'; const char CAPS_FLAG_HIGH_BANDWIDTH2 = 'N';
const char CAPS_FLAG_HIGH_BANDWIDTH3 = 'O'; const char CAPS_FLAG_HIGH_BANDWIDTH3 = 'O';
const char CAPS_FLAG_EXTRA_BANDWIDTH1 = 'P';
const char CAPS_FLAG_EXTRA_BANDWIDTH2 = 'X';
const char CAPS_FLAG_SSU_TESTING = 'B'; const char CAPS_FLAG_SSU_TESTING = 'B';
const char CAPS_FLAG_SSU_INTRODUCER = 'C'; const char CAPS_FLAG_SSU_INTRODUCER = 'C';
@ -44,11 +46,12 @@ namespace data
{ {
eFloodfill = 0x01, eFloodfill = 0x01,
eHighBandwidth = 0x02, eHighBandwidth = 0x02,
eReachable = 0x04, eExtraBandwidth = 0x04,
eSSUTesting = 0x08, eReachable = 0x08,
eSSUIntroducer = 0x10, eSSUTesting = 0x10,
eHidden = 0x20, eSSUIntroducer = 0x20,
eUnreachable = 0x40 eHidden = 0x40,
eUnreachable = 0x80
}; };
enum TransportStyle enum TransportStyle
@ -131,6 +134,7 @@ namespace data
bool IsPeerTesting () const { return m_Caps & eSSUTesting; }; bool IsPeerTesting () const { return m_Caps & eSSUTesting; };
bool IsHidden () const { return m_Caps & eHidden; }; bool IsHidden () const { return m_Caps & eHidden; };
bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; }; bool IsHighBandwidth () const { return m_Caps & RouterInfo::eHighBandwidth; };
bool IsExtraBandwidth () const { return m_Caps & RouterInfo::eExtraBandwidth; };
uint8_t GetCaps () const { return m_Caps; }; uint8_t GetCaps () const { return m_Caps; };
void SetCaps (uint8_t caps); void SetCaps (uint8_t caps);

5
Transports.cpp

@ -200,8 +200,9 @@ namespace transport
bool Transports::IsBandwidthExceeded () const bool Transports::IsBandwidthExceeded () const
{ {
if (i2p::context.GetRouterInfo ().IsHighBandwidth ()) return false; if (i2p::context.GetRouterInfo ().IsExtraBandwidth ()) return false;
return std::max (m_InBandwidth, m_OutBandwidth) > LOW_BANDWIDTH_LIMIT; auto bw = std::max (m_InBandwidth, m_OutBandwidth);
return bw > (i2p::context.GetRouterInfo ().IsHighBandwidth () ? HIGH_BANDWIDTH_LIMIT : LOW_BANDWIDTH_LIMIT);
} }
void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg) void Transports::SendMessage (const i2p::data::IdentHash& ident, std::shared_ptr<i2p::I2NPMessage> msg)

1
Transports.h

@ -67,6 +67,7 @@ namespace transport
const size_t SESSION_CREATION_TIMEOUT = 10; // in seconds const size_t SESSION_CREATION_TIMEOUT = 10; // in seconds
const uint32_t LOW_BANDWIDTH_LIMIT = 32*1024; // 32KBs const uint32_t LOW_BANDWIDTH_LIMIT = 32*1024; // 32KBs
const uint32_t HIGH_BANDWIDTH_LIMIT = 256*1024; // 256KBs
class Transports class Transports
{ {
public: public:

Loading…
Cancel
Save