Rework bandwidth limiter config
This commit is contained in:
parent
4d5664a1e1
commit
6015e21fa0
4 changed files with 34 additions and 35 deletions
|
|
@ -1,14 +1,15 @@
|
|||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/node/bandwidth_limiter.hpp>
|
||||
#include <nano/node/nodeconfig.hpp>
|
||||
|
||||
/*
|
||||
* bandwidth_limiter
|
||||
*/
|
||||
|
||||
nano::bandwidth_limiter::bandwidth_limiter (nano::bandwidth_limiter::config config_a) :
|
||||
config_m{ config_a },
|
||||
limiter_generic{ config_m.standard_limit, config_m.standard_burst_ratio },
|
||||
limiter_bootstrap{ config_m.bootstrap_limit, config_m.bootstrap_burst_ratio }
|
||||
nano::bandwidth_limiter::bandwidth_limiter (nano::node_config const & node_config_a) :
|
||||
config{ node_config_a },
|
||||
limiter_generic{ config.generic_limit, config.generic_burst_ratio },
|
||||
limiter_bootstrap{ config.bootstrap_limit, config.bootstrap_burst_ratio }
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -38,4 +39,16 @@ void nano::bandwidth_limiter::reset (std::size_t limit, double burst_ratio, nano
|
|||
{
|
||||
auto & limiter = select_limiter (type);
|
||||
limiter.reset (limit, burst_ratio);
|
||||
}
|
||||
|
||||
/*
|
||||
* bandwidth_limiter_config
|
||||
*/
|
||||
|
||||
nano::bandwidth_limiter_config::bandwidth_limiter_config (nano::node_config const & node_config) :
|
||||
generic_limit{ node_config.bandwidth_limit },
|
||||
generic_burst_ratio{ node_config.bandwidth_limit_burst_ratio },
|
||||
bootstrap_limit{ node_config.bootstrap_bandwidth_limit },
|
||||
bootstrap_burst_ratio{ node_config.bootstrap_bandwidth_burst_ratio }
|
||||
{
|
||||
}
|
||||
|
|
@ -1,28 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/rate_limiting.hpp>
|
||||
#include <nano/node/fwd.hpp>
|
||||
#include <nano/node/transport/traffic_type.hpp>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class bandwidth_limiter_config final
|
||||
{
|
||||
public:
|
||||
explicit bandwidth_limiter_config (nano::node_config const &);
|
||||
|
||||
public:
|
||||
std::size_t generic_limit;
|
||||
double generic_burst_ratio;
|
||||
|
||||
std::size_t bootstrap_limit;
|
||||
double bootstrap_burst_ratio;
|
||||
};
|
||||
|
||||
/**
|
||||
* Class that tracks and manages bandwidth limits for IO operations
|
||||
*/
|
||||
class bandwidth_limiter final
|
||||
{
|
||||
public: // Config
|
||||
struct config
|
||||
{
|
||||
// standard
|
||||
std::size_t standard_limit;
|
||||
double standard_burst_ratio;
|
||||
// bootstrap
|
||||
std::size_t bootstrap_limit;
|
||||
double bootstrap_burst_ratio;
|
||||
};
|
||||
|
||||
public:
|
||||
explicit bandwidth_limiter (config);
|
||||
explicit bandwidth_limiter (nano::node_config const &);
|
||||
|
||||
/**
|
||||
* Check whether packet falls withing bandwidth limits and should be allowed
|
||||
|
|
@ -41,7 +44,7 @@ private:
|
|||
nano::rate_limiter & select_limiter (nano::transport::traffic_type type);
|
||||
|
||||
private:
|
||||
const config config_m;
|
||||
bandwidth_limiter_config const config;
|
||||
|
||||
private:
|
||||
nano::rate_limiter limiter_generic;
|
||||
|
|
|
|||
|
|
@ -54,20 +54,6 @@ extern unsigned char nano_bootstrap_weights_beta[];
|
|||
extern std::size_t nano_bootstrap_weights_beta_size;
|
||||
}
|
||||
|
||||
/*
|
||||
* configs
|
||||
*/
|
||||
|
||||
nano::bandwidth_limiter::config nano::bandwidth_limiter_config (const nano::node_config & config)
|
||||
{
|
||||
bandwidth_limiter::config cfg{};
|
||||
cfg.standard_limit = config.bandwidth_limit;
|
||||
cfg.standard_burst_ratio = config.bandwidth_limit_burst_ratio;
|
||||
cfg.bootstrap_limit = config.bootstrap_bandwidth_limit;
|
||||
cfg.bootstrap_burst_ratio = config.bootstrap_bandwidth_burst_ratio;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
/*
|
||||
* node
|
||||
*/
|
||||
|
|
@ -159,7 +145,7 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
|
|||
wallets_store (*wallets_store_impl),
|
||||
ledger_impl{ std::make_unique<nano::ledger> (store, stats, network_params.ledger, flags_a.generate_cache, config_a.representative_vote_weight_minimum.number ()) },
|
||||
ledger{ *ledger_impl },
|
||||
outbound_limiter{ bandwidth_limiter_config (config) },
|
||||
outbound_limiter{ config },
|
||||
message_processor_impl{ std::make_unique<nano::message_processor> (config.message_processor, *this) },
|
||||
message_processor{ *message_processor_impl },
|
||||
// empty `config.peering_port` means the user made no port choice at all;
|
||||
|
|
|
|||
|
|
@ -72,9 +72,6 @@ namespace rocksdb
|
|||
|
||||
namespace nano
|
||||
{
|
||||
// Configs
|
||||
bandwidth_limiter::config bandwidth_limiter_config (node_config const &);
|
||||
|
||||
class node final : public std::enable_shared_from_this<node>
|
||||
{
|
||||
public:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue