Added NetworkConfig.

This commit is contained in:
Jari Sundell
2025-09-11 23:09:24 +02:00
committed by GitHub
parent 65906a033a
commit ba1ba3096a
4 changed files with 26 additions and 40 deletions
+9 -7
View File
@@ -11,6 +11,7 @@
#include <torrent/data/file_manager.h> #include <torrent/data/file_manager.h>
#include <torrent/download/resource_manager.h> #include <torrent/download/resource_manager.h>
#include <torrent/net/http_stack.h> #include <torrent/net/http_stack.h>
#include <torrent/net/network_config.h>
#include <torrent/tracker/tracker.h> #include <torrent/tracker/tracker.h>
#include <torrent/utils/log.h> #include <torrent/utils/log.h>
#include <torrent/utils/option_strings.h> #include <torrent/utils/option_strings.h>
@@ -165,8 +166,9 @@ apply_xmlrpc_dialect(const std::string& arg) {
void void
initialize_command_network() { initialize_command_network() {
auto cm = torrent::connection_manager(); auto cm = torrent::connection_manager();
auto fileManager = torrent::file_manager(); auto file_manager = torrent::file_manager();
auto http_stack = torrent::net_thread::http_stack(); auto http_stack = torrent::net_thread::http_stack();
auto network_config = torrent::config::network_config();
CMD2_ANY_STRING ("encoding.add", std::bind(&apply_encoding_list, std::placeholders::_2)); CMD2_ANY_STRING ("encoding.add", std::bind(&apply_encoding_list, std::placeholders::_2));
@@ -212,16 +214,16 @@ initialize_command_network() {
CMD2_ANY_VALUE_V ("network.receive_buffer.size.set", std::bind(&torrent::ConnectionManager::set_receive_buffer_size, cm, std::placeholders::_2)); CMD2_ANY_VALUE_V ("network.receive_buffer.size.set", std::bind(&torrent::ConnectionManager::set_receive_buffer_size, cm, std::placeholders::_2));
CMD2_ANY_STRING ("network.tos.set", std::bind(&apply_tos, std::placeholders::_2)); CMD2_ANY_STRING ("network.tos.set", std::bind(&apply_tos, std::placeholders::_2));
CMD2_ANY ("network.bind_address", std::bind(&core::Manager::bind_address, control->core())); CMD2_ANY ("network.bind_address", std::bind(&torrent::net::NetworkConfig::bind_address_str, network_config));
CMD2_ANY_STRING_V("network.bind_address.set", std::bind(&core::Manager::set_bind_address, control->core(), std::placeholders::_2)); CMD2_ANY_STRING_V("network.bind_address.set", std::bind(&core::Manager::set_bind_address, control->core(), std::placeholders::_2));
CMD2_ANY ("network.local_address", std::bind(&core::Manager::local_address, control->core())); CMD2_ANY ("network.local_address", std::bind(&torrent::net::NetworkConfig::local_address_str, network_config));
CMD2_ANY_STRING_V("network.local_address.set", std::bind(&core::Manager::set_local_address, control->core(), std::placeholders::_2)); CMD2_ANY_STRING_V("network.local_address.set", std::bind(&core::Manager::set_local_address, control->core(), std::placeholders::_2));
CMD2_ANY ("network.proxy_address", std::bind(&core::Manager::proxy_address, control->core())); CMD2_ANY ("network.proxy_address", std::bind(&torrent::net::NetworkConfig::proxy_address_str, network_config));
CMD2_ANY_STRING_V("network.proxy_address.set", std::bind(&core::Manager::set_proxy_address, control->core(), std::placeholders::_2)); CMD2_ANY_STRING_V("network.proxy_address.set", std::bind(&core::Manager::set_proxy_address, control->core(), std::placeholders::_2));
CMD2_ANY ("network.open_files", std::bind(&torrent::FileManager::open_files, fileManager)); CMD2_ANY ("network.open_files", std::bind(&torrent::FileManager::open_files, file_manager));
CMD2_ANY ("network.max_open_files", std::bind(&torrent::FileManager::max_open_files, fileManager)); CMD2_ANY ("network.max_open_files", std::bind(&torrent::FileManager::max_open_files, file_manager));
CMD2_ANY_VALUE_V ("network.max_open_files.set", std::bind(&torrent::FileManager::set_max_open_files, fileManager, std::placeholders::_2)); CMD2_ANY_VALUE_V ("network.max_open_files.set", std::bind(&torrent::FileManager::set_max_open_files, file_manager, std::placeholders::_2));
CMD2_ANY ("network.total_handshakes", std::bind(&torrent::total_handshakes)); CMD2_ANY ("network.total_handshakes", std::bind(&torrent::total_handshakes));
CMD2_ANY ("network.open_sockets", std::bind(&torrent::ConnectionManager::size, cm)); CMD2_ANY ("network.open_sockets", std::bind(&torrent::ConnectionManager::size, cm));
CMD2_ANY ("network.max_open_sockets", std::bind(&torrent::ConnectionManager::max_size, cm)); CMD2_ANY ("network.max_open_sockets", std::bind(&torrent::ConnectionManager::max_size, cm));
+7 -24
View File
@@ -19,6 +19,8 @@
#include <torrent/object_stream.h> #include <torrent/object_stream.h>
#include <torrent/throttle.h> #include <torrent/throttle.h>
#include <torrent/net/http_stack.h> #include <torrent/net/http_stack.h>
#include <torrent/net/network_config.h>
#include <torrent/net/socket_address.h>
#include <torrent/utils/log.h> #include <torrent/utils/log.h>
#include "rpc/parse_commands.h" #include "rpc/parse_commands.h"
@@ -183,11 +185,6 @@ Manager::listen_open() {
throw torrent::input_error("Could not open/bind port for listening: " + std::string(rak::error_number::current().c_str())); throw torrent::input_error("Could not open/bind port for listening: " + std::string(rak::error_number::current().c_str()));
} }
std::string
Manager::bind_address() const {
return rak::socket_address::cast_from(torrent::connection_manager()->bind_address())->address_str();
}
void void
Manager::set_bind_address(const std::string& addr) { Manager::set_bind_address(const std::string& addr) {
int err; int err;
@@ -201,18 +198,14 @@ Manager::set_bind_address(const std::string& addr) {
if (torrent::connection_manager()->listen_port() != 0) { if (torrent::connection_manager()->listen_port() != 0) {
torrent::connection_manager()->listen_close(); torrent::connection_manager()->listen_close();
torrent::connection_manager()->set_bind_address(ai->address()->c_sockaddr()); torrent::config::network_config()->set_bind_address(ai->address()->c_sockaddr());
listen_open(); listen_open();
} else { } else {
torrent::connection_manager()->set_bind_address(ai->address()->c_sockaddr()); torrent::config::network_config()->set_bind_address(ai->address()->c_sockaddr());
} }
if (ai->address()->is_address_any())
torrent::net_thread::http_stack()->set_bind_address(std::string());
else
torrent::net_thread::http_stack()->set_bind_address(ai->address()->address_str());
rak::address_info::free_address_info(ai); rak::address_info::free_address_info(ai);
} catch (torrent::input_error& e) { } catch (torrent::input_error& e) {
@@ -221,11 +214,6 @@ Manager::set_bind_address(const std::string& addr) {
} }
} }
std::string
Manager::local_address() const {
return rak::socket_address::cast_from(torrent::connection_manager()->local_address())->address_str();
}
void void
Manager::set_local_address(const std::string& addr) { Manager::set_local_address(const std::string& addr) {
int err; int err;
@@ -236,8 +224,8 @@ Manager::set_local_address(const std::string& addr) {
throw torrent::input_error("Could not set local address: " + std::string(rak::address_info::strerror(err)) + "."); throw torrent::input_error("Could not set local address: " + std::string(rak::address_info::strerror(err)) + ".");
try { try {
torrent::config::network_config()->set_local_address(ai->address()->c_sockaddr());
torrent::connection_manager()->set_local_address(ai->address()->c_sockaddr());
rak::address_info::free_address_info(ai); rak::address_info::free_address_info(ai);
} catch (torrent::input_error& e) { } catch (torrent::input_error& e) {
@@ -246,11 +234,6 @@ Manager::set_local_address(const std::string& addr) {
} }
} }
std::string
Manager::proxy_address() const {
return rak::socket_address::cast_from(torrent::connection_manager()->proxy_address())->address_str();
}
void void
Manager::set_proxy_address(const std::string& addr) { Manager::set_proxy_address(const std::string& addr) {
int port; int port;
@@ -272,7 +255,7 @@ Manager::set_proxy_address(const std::string& addr) {
try { try {
ai->address()->set_port(port); ai->address()->set_port(port);
torrent::connection_manager()->set_proxy_address(ai->address()->c_sockaddr()); torrent::config::network_config()->set_proxy_address(ai->address()->c_sockaddr());
rak::address_info::free_address_info(ai); rak::address_info::free_address_info(ai);
-5
View File
@@ -61,13 +61,8 @@ public:
void listen_open(); void listen_open();
std::string bind_address() const;
void set_bind_address(const std::string& addr); void set_bind_address(const std::string& addr);
std::string local_address() const;
void set_local_address(const std::string& addr); void set_local_address(const std::string& addr);
std::string proxy_address() const;
void set_proxy_address(const std::string& addr); void set_proxy_address(const std::string& addr);
void shutdown(bool force); void shutdown(bool force);
+10 -4
View File
@@ -17,6 +17,8 @@
#include <torrent/data/file_manager.h> #include <torrent/data/file_manager.h>
#include <torrent/download/resource_manager.h> #include <torrent/download/resource_manager.h>
#include <torrent/net/http_stack.h> #include <torrent/net/http_stack.h>
#include <torrent/net/network_config.h>
#include <torrent/net/socket_address.h>
#include <torrent/peer/client_info.h> #include <torrent/peer/client_info.h>
#include "control.h" #include "control.h"
@@ -384,18 +386,22 @@ print_status_info(char* first, char* last) {
first = print_buffer(first, last, " [Port: %i]", (unsigned int)torrent::connection_manager()->listen_port()); first = print_buffer(first, last, " [Port: %i]", (unsigned int)torrent::connection_manager()->listen_port());
if (!rak::socket_address::cast_from(torrent::connection_manager()->local_address())->is_address_any()) { auto local_address = torrent::config::network_config()->local_address();
if (!torrent::sa_is_any(local_address.get())) {
first = print_buffer(first, last, " [Local "); first = print_buffer(first, last, " [Local ");
first = print_address(first, last, torrent::connection_manager()->local_address()); first = print_address(first, last, local_address.get());
first = print_buffer(first, last, "]"); first = print_buffer(first, last, "]");
} }
if (first > last) if (first > last)
throw torrent::internal_error("print_status_info(...) wrote past end of the buffer."); throw torrent::internal_error("print_status_info(...) wrote past end of the buffer.");
if (!rak::socket_address::cast_from(torrent::connection_manager()->bind_address())->is_address_any()) { auto bind_address = torrent::config::network_config()->bind_address();
if (!torrent::sa_is_any(bind_address.get())) {
first = print_buffer(first, last, " [Bind "); first = print_buffer(first, last, " [Bind ");
first = print_address(first, last, torrent::connection_manager()->bind_address()); first = print_address(first, last, bind_address.get());
first = print_buffer(first, last, "]"); first = print_buffer(first, last, "]");
} }