Merge pull request #2224 from wipedlifepotato/BandwithParameter
Some checks failed
Build Debian packages / bookworm (push) Has been cancelled
Build on Windows / clang-x86_64 (push) Has been cancelled
Build Debian packages / bullseye (push) Has been cancelled
Build Debian packages / trixie (push) Has been cancelled
Build on FreeBSD / with UPnP (push) Has been cancelled
Build on OSX / With USE_UPNP=no (push) Has been cancelled
Build on OSX / With USE_UPNP=yes (push) Has been cancelled
Build on Windows / i686 (push) Has been cancelled
Build on Windows / ucrt-x86_64 (push) Has been cancelled
Build on Windows / x86_64 (push) Has been cancelled
Build on Windows / CMake clang-x86_64 (push) Has been cancelled
Build on Windows / CMake i686 (push) Has been cancelled
Build on Windows / CMake ucrt-x86_64 (push) Has been cancelled
Build on Windows / CMake x86_64 (push) Has been cancelled
Build on Windows / XP (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=no (push) Has been cancelled
Build on Ubuntu / Make with USE_UPNP=yes (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Has been cancelled
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Has been cancelled
Build containers / Building container for linux/amd64 (push) Has been cancelled
Build containers / Building container for linux/arm64 (push) Has been cancelled
Build containers / Building container for linux/arm/v7 (push) Has been cancelled
Build containers / Building container for linux/386 (push) Has been cancelled
Build containers / Pushing merged manifest (push) Has been cancelled

feat: bandwidth with bytes/kbytes/gbytes seconds and fix for style.css
This commit is contained in:
orignal 2025-08-18 09:14:24 -04:00 committed by GitHub
commit 1c42ba85ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 62 additions and 14 deletions

View file

@ -14,7 +14,7 @@
* Minified copy of that style sheet is bundled inside i2pd sources. * Minified copy of that style sheet is bundled inside i2pd sources.
*/ */
:root { :root {
--main-bg-color: #0a0a0a; --main-bg-color: #0b0b0b;
--main-text-color: #00ff99; --main-text-color: #00ff99;
--main-link-color: #ff00ff; --main-link-color: #ff00ff;
--main-link-hover-color: #00ffff; --main-link-hover-color: #00ffff;
@ -53,6 +53,18 @@ a:hover, a.button.selected, .slide label:hover, button[type=submit]:hover {
#slide-info:checked ~ .slidecontent { #slide-info:checked ~ .slidecontent {
display: block; display: block;
} }
#slide_ntcp2 {
display: none;
}
#slide_ssu2 {
display: none;
}
#slide_ssu2:checked ~ .slidecontent {
display: block;
}
#slide_ntcp2:checked ~ .slidecontent{
display:block;
}
.header { .header {
font-size: 2.5em; font-size: 2.5em;
text-align: center; text-align: center;

View file

@ -8,6 +8,7 @@
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <regex>
#include "Daemon.h" #include "Daemon.h"
@ -186,12 +187,41 @@ namespace util
std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth); std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth);
if (bandwidth.length () > 0) if (bandwidth.length () > 0)
{ {
const auto NumBandwithRegex = std::regex(R"(^\d+$)");
const auto BandwithRegex = std::regex(R"((\d+)(b|kb|mb|gb))");
std::smatch bandWithMatch;
if (bandwidth.length () == 1 && ((bandwidth[0] >= 'K' && bandwidth[0] <= 'P') || bandwidth[0] == 'X' )) if (bandwidth.length () == 1 && ((bandwidth[0] >= 'K' && bandwidth[0] <= 'P') || bandwidth[0] == 'X' ))
{ {
i2p::context.SetBandwidth (bandwidth[0]); i2p::context.SetBandwidth (bandwidth[0]);
LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps"); LogPrint(eLogInfo, "Daemon: Bandwidth set to ", i2p::context.GetBandwidthLimit (), "KBps");
} }
else else if (std::regex_match(bandwidth, bandWithMatch, BandwithRegex)) {
const auto number = bandWithMatch[1].str();
const auto unit = bandWithMatch[2].str();
int limit = std::atoi(number.c_str());
std::cout << unit;
if (unit == "b")
{
limit /= 1000;
}
else if(unit == "mb")
{
limit *= 1000;
} else if(unit == "gb")
{
limit *= 1000000;
}
// if limit more than 32 bits then its will be negative
if (limit < 0)
{
LogPrint(eLogInfo, "Daemon: Unexpected bandwidth ", bandwidth, ". Set to 'low'");
i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2);
} else {
i2p::context.SetBandwidth(limit);
}
}
else if(std::regex_search(bandwidth, NumBandwithRegex))
{ {
auto value = std::atoi(bandwidth.c_str()); auto value = std::atoi(bandwidth.c_str());
if (value > 0) if (value > 0)

View file

@ -10,6 +10,7 @@
#include <sstream> #include <sstream>
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <regex>
#include <boost/asio.hpp> #include <boost/asio.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
@ -42,6 +43,7 @@
namespace i2p { namespace i2p {
namespace http { namespace http {
static void LoadExtCSS (std::string fileName = "style") static void LoadExtCSS (std::string fileName = "style")
{ {
std::stringstream s; std::stringstream s;
@ -166,19 +168,17 @@ namespace http {
static void ShowPageHead (std::stringstream& s) static void ShowPageHead (std::stringstream& s)
{ {
std::string webroot; i2p::config::GetOption("http.webroot", webroot); std::string webroot; i2p::config::GetOption("http.webroot", webroot);
std::string theme; i2p::config::GetOption("http.theme", theme); std::string theme; i2p::config::GetOption("http.theme", theme);
if(theme != "light" && theme != "black" )
const auto isThemeRegex = std::regex("^(white|black|light)");
if (!std::regex_search(theme, isThemeRegex))
{ {
if (theme =="white") { LoadExtCSS(theme);
theme = "light"; }
} else { else
LoadExtCSS(theme); {
} LoadExtCSS();
} }
// Page language // Page language
std::string currLang = i2p::client::context.GetLanguage ()->GetLanguage(); // get current used language std::string currLang = i2p::client::context.GetLanguage ()->GetLanguage(); // get current used language
@ -1496,7 +1496,10 @@ namespace http {
} }
else if (cmd == HTTP_COMMAND_RELOAD_CSS) else if (cmd == HTTP_COMMAND_RELOAD_CSS)
{ {
LoadExtCSS(); std::string theme; i2p::config::GetOption("http.theme", theme);
if (theme != "light" && theme != "black" && theme !="white") LoadExtCSS(theme);
else LoadExtCSS();
} }
else else
{ {

View file

@ -683,6 +683,9 @@ namespace i2p
else if (limit > (int)i2p::data::LOW_BANDWIDTH_LIMIT) { SetBandwidth('M'); } else if (limit > (int)i2p::data::LOW_BANDWIDTH_LIMIT) { SetBandwidth('M'); }
else if (limit > 12) { SetBandwidth('L'); } else if (limit > 12) { SetBandwidth('L'); }
else { SetBandwidth('K'); } else { SetBandwidth('K'); }
LogPrint(eLogInfo, "RouterContext: Set bandwidth ", limit, ". kb/s");
m_BandwidthLimit = limit; // set precise limit m_BandwidthLimit = limit; // set precise limit
} }