From 5206e6cb885fb0b1e453972a35a551aca2c219d5 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Sun, 21 Sep 2025 23:01:18 +0200 Subject: [PATCH] Moved various socket options to NetworkConfig. --- src/command_network.cc | 35 +++++++++++++++++----------------- test/rpc/test_parse_options.cc | 12 ++++++------ 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/command_network.cc b/src/command_network.cc index 7ebbba50..19b32eef 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -30,18 +30,18 @@ torrent::Object apply_encryption(const torrent::Object::list_type& args) { - uint32_t options_mask = torrent::ConnectionManager::encryption_none; + uint32_t options_mask = torrent::net::NetworkConfig::encryption_none; for (const auto& arg : args) { uint32_t opt = torrent::option_find_string(torrent::OPTION_ENCRYPTION, arg.as_string().c_str()); - if (opt == torrent::ConnectionManager::encryption_none) - options_mask = torrent::ConnectionManager::encryption_none; + if (opt == torrent::net::NetworkConfig::encryption_none) + options_mask = torrent::net::NetworkConfig::encryption_none; else options_mask |= opt; } - torrent::connection_manager()->set_encryption_options(options_mask); + torrent::config::network_config()->set_encryption_options(options_mask); return torrent::Object(); } @@ -53,7 +53,7 @@ apply_tos(const torrent::Object::string_type& arg) { if (!rpc::parse_whole_value_nothrow(arg.c_str(), &value, 16, 1)) value = torrent::option_find_string(torrent::OPTION_IP_TOS, arg.c_str()); - torrent::connection_manager()->set_priority(value); + torrent::config::network_config()->set_priority(value); return torrent::Object(); } @@ -208,10 +208,10 @@ initialize_command_network() { CMD2_ANY ("network.http.ssl_verify_peer", [http_stack](auto, auto) { return http_stack->ssl_verify_peer(); }); CMD2_ANY_VALUE_V ("network.http.ssl_verify_peer.set", [http_stack](auto, auto& value) { return http_stack->set_ssl_verify_peer(value); }); - CMD2_ANY ("network.send_buffer.size", std::bind(&torrent::ConnectionManager::send_buffer_size, cm)); - CMD2_ANY_VALUE_V ("network.send_buffer.size.set", std::bind(&torrent::ConnectionManager::set_send_buffer_size, cm, std::placeholders::_2)); - CMD2_ANY ("network.receive_buffer.size", std::bind(&torrent::ConnectionManager::receive_buffer_size, cm)); - CMD2_ANY_VALUE_V ("network.receive_buffer.size.set", std::bind(&torrent::ConnectionManager::set_receive_buffer_size, cm, std::placeholders::_2)); + CMD2_ANY ("network.send_buffer.size", std::bind(&torrent::net::NetworkConfig::send_buffer_size, network_config)); + CMD2_ANY_VALUE_V ("network.send_buffer.size.set", std::bind(&torrent::net::NetworkConfig::set_send_buffer_size, network_config, std::placeholders::_2)); + CMD2_ANY ("network.receive_buffer.size", std::bind(&torrent::net::NetworkConfig::receive_buffer_size, network_config)); + CMD2_ANY_VALUE_V ("network.receive_buffer.size.set", std::bind(&torrent::net::NetworkConfig::set_receive_buffer_size, network_config, std::placeholders::_2)); CMD2_ANY_STRING ("network.tos.set", std::bind(&apply_tos, std::placeholders::_2)); CMD2_ANY ("network.bind_address", std::bind(&torrent::net::NetworkConfig::bind_address_str, network_config)); @@ -240,13 +240,12 @@ initialize_command_network() { CMD2_VAR_BOOL ("network.rpc.use_xmlrpc", true); CMD2_VAR_BOOL ("network.rpc.use_jsonrpc", true); - CMD2_ANY ("network.block.ipv4", std::bind(&torrent::ConnectionManager::is_block_ipv4, cm)); - CMD2_ANY_VALUE_V ("network.block.ipv4.set", std::bind(&torrent::ConnectionManager::set_block_ipv4, cm, std::placeholders::_2)); - CMD2_ANY ("network.block.ipv6", std::bind(&torrent::ConnectionManager::is_block_ipv6, cm)); - CMD2_ANY_VALUE_V ("network.block.ipv6.set", std::bind(&torrent::ConnectionManager::set_block_ipv6, cm, std::placeholders::_2)); - CMD2_ANY ("network.block.ipv4in6", std::bind(&torrent::ConnectionManager::is_block_ipv4in6, cm)); - CMD2_ANY_VALUE_V ("network.block.ipv4in6.set", std::bind(&torrent::ConnectionManager::set_block_ipv4in6, cm, std::placeholders::_2)); - - CMD2_ANY ("network.prefer.ipv6", std::bind(&torrent::ConnectionManager::is_prefer_ipv6, cm)); - CMD2_ANY_VALUE_V ("network.prefer.ipv6.set", std::bind(&torrent::ConnectionManager::set_prefer_ipv6, cm, std::placeholders::_2)); + CMD2_ANY ("network.block.ipv4", std::bind(&torrent::net::NetworkConfig::is_block_ipv4, network_config)); + CMD2_ANY_VALUE_V ("network.block.ipv4.set", std::bind(&torrent::net::NetworkConfig::set_block_ipv4, network_config, std::placeholders::_2)); + CMD2_ANY ("network.block.ipv6", std::bind(&torrent::net::NetworkConfig::is_block_ipv6, network_config)); + CMD2_ANY_VALUE_V ("network.block.ipv6.set", std::bind(&torrent::net::NetworkConfig::set_block_ipv6, network_config, std::placeholders::_2)); + CMD2_ANY ("network.block.ipv4in6", std::bind(&torrent::net::NetworkConfig::is_block_ipv4in6, network_config)); + CMD2_ANY_VALUE_V ("network.block.ipv4in6.set", std::bind(&torrent::net::NetworkConfig::set_block_ipv4in6, network_config, std::placeholders::_2)); + CMD2_ANY ("network.prefer.ipv6", std::bind(&torrent::net::NetworkConfig::is_prefer_ipv6, network_config)); + CMD2_ANY_VALUE_V ("network.prefer.ipv6.set", std::bind(&torrent::net::NetworkConfig::set_prefer_ipv6, network_config, std::placeholders::_2)); } diff --git a/test/rpc/test_parse_options.cc b/test/rpc/test_parse_options.cc index 74fc7ea3..632e32e8 100644 --- a/test/rpc/test_parse_options.cc +++ b/test/rpc/test_parse_options.cc @@ -3,8 +3,8 @@ #include "test/rpc/test_parse_options.h" #include -#include #include +#include #include #include @@ -178,11 +178,11 @@ TestParseOptions::test_flag_libtorrent() { void TestParseOptions::test_flags_libtorrent() { - FLAGS_LT_ENCRYPTION_ASSERT("", torrent::ConnectionManager::encryption_none); - FLAGS_LT_ENCRYPTION_ASSERT("none", torrent::ConnectionManager::encryption_none); - FLAGS_LT_ENCRYPTION_ASSERT("require_rc4", torrent::ConnectionManager::encryption_require_RC4); - FLAGS_LT_ENCRYPTION_ASSERT("require_RC4", torrent::ConnectionManager::encryption_require_RC4); - FLAGS_LT_ENCRYPTION_ASSERT("require_RC4 | enable_retry", torrent::ConnectionManager::encryption_require_RC4 | torrent::ConnectionManager::encryption_enable_retry); + FLAGS_LT_ENCRYPTION_ASSERT("", torrent::net::NetworkConfig::encryption_none); + FLAGS_LT_ENCRYPTION_ASSERT("none", torrent::net::NetworkConfig::encryption_none); + FLAGS_LT_ENCRYPTION_ASSERT("require_rc4", torrent::net::NetworkConfig::encryption_require_RC4); + FLAGS_LT_ENCRYPTION_ASSERT("require_RC4", torrent::net::NetworkConfig::encryption_require_RC4); + FLAGS_LT_ENCRYPTION_ASSERT("require_RC4 | enable_retry", torrent::net::NetworkConfig::encryption_require_RC4 | torrent::net::NetworkConfig::encryption_enable_retry); FLAGS_LT_ENCRYPTION_ASSERT_ERROR("require_"); }