From df5b7c7d0d9ed26bb964ed5bb5e42c62e1ed2270 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 30 Mar 2016 21:31:17 -0400 Subject: [PATCH] specify bandwidth for floodfill --- Config.cpp | 2 +- Daemon.cpp | 39 ++++++++++++++++++++++++++++++++------- RouterContext.cpp | 17 ++++++++--------- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/Config.cpp b/Config.cpp index 73124ae4..8d42895a 100644 --- a/Config.cpp +++ b/Config.cpp @@ -123,7 +123,7 @@ namespace config { ("service", value()->zero_tokens()->default_value(false), "Router will use system folders like '/var/lib/i2pd'") ("notransit", value()->zero_tokens()->default_value(false), "Router will not accept transit tunnels at startup") ("floodfill", value()->zero_tokens()->default_value(false), "Router will be floodfill") - ("bandwidth", value()->default_value("256"), "Bandwidth limit: integer in kbps or letters: L (32), O (256), P (2048), X (>9000)") + ("bandwidth", value()->default_value(""), "Bandwidth limit: integer in kbps or letters: L (32), O (256), P (2048), X (>9000)") #ifdef _WIN32 ("svcctl", value()->default_value(""), "Windows service management ('install' or 'remove')") ("insomnia", value()->zero_tokens()->default_value(false), "Prevent system from sleeping") diff --git a/Daemon.cpp b/Daemon.cpp index 13cdc075..f15fe3e3 100644 --- a/Daemon.cpp +++ b/Daemon.cpp @@ -151,13 +151,38 @@ namespace i2p /* this section also honors 'floodfill' flag, if set above */ std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth); - if (bandwidth[0] > 'K' && bandwidth[0] < 'Z') { - i2p::context.SetBandwidth (bandwidth[0]); - LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps"); - } else if (bandwidth[0] >= '0' && bandwidth[0] <= '9') { - i2p::context.SetBandwidth (std::atoi(bandwidth.c_str())); - LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), " KBps"); - } + if (bandwidth.length () > 0) + { + if (bandwidth[0] >= 'K' && bandwidth[0] <= 'X') + { + i2p::context.SetBandwidth (bandwidth[0]); + LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps"); + } + else + { + auto value = std::atoi(bandwidth.c_str()); + if (value > 0) + { + i2p::context.SetBandwidth (value); + LogPrint(eLogInfo, "Daemon: bandwidth set to ", i2p::context.GetBandwidthLimit (), " KBps"); + } + else + { + LogPrint(eLogInfo, "Daemon: unexpected bandwidth ", bandwidth, ". Set to 'low'"); + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2); + } + } + } + else if (isFloodfill) + { + LogPrint(eLogInfo, "Daemon: floodfill bandwidth set to 'extra'"); + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH1); + } + else + { + LogPrint(eLogInfo, "Daemon: bandwidth set to 'low'"); + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2); + } std::string family; i2p::config::GetOption("family", family); i2p::context.SetFamily (family); diff --git a/RouterContext.cpp b/RouterContext.cpp index 9a1749d0..e50681d9 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -170,26 +170,24 @@ namespace i2p uint16_t limit = 0; enum { low, high, extra } type = high; /* detect parameters */ - switch (L) { + switch (L) + { 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"); + default: + limit = 48; type = low; } /* update caps & flags in RI */ auto caps = m_RouterInfo.GetCaps (); caps &= ~i2p::data::RouterInfo::eHighBandwidth; caps &= ~i2p::data::RouterInfo::eExtraBandwidth; - switch (type) { + switch (type) + { case low : /* not set */; break; case high : caps |= i2p::data::RouterInfo::eHighBandwidth; break; case extra : caps |= i2p::data::RouterInfo::eExtraBandwidth; break; @@ -199,7 +197,8 @@ namespace i2p m_BandwidthLimit = limit; } - void RouterContext::SetBandwidth (int limit) { + void RouterContext::SetBandwidth (int limit) + { if (limit > 2000) { SetBandwidth('X'); } else if (limit > 256) { SetBandwidth('P'); } else if (limit > 128) { SetBandwidth('O'); }