From 41977106a20b0e08b62c630fffb0902c7f298a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Mon, 30 Dec 2024 09:29:51 +0100 Subject: [PATCH] Config serialization --- nano/node/nodeconfig.cpp | 10 ++++++++++ nano/node/transport/tcp_config.cpp | 30 +++++++++++++++++++++++++++++- nano/node/transport/tcp_config.hpp | 3 ++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/nano/node/nodeconfig.cpp b/nano/node/nodeconfig.cpp index f683d1193..a6314d9d7 100644 --- a/nano/node/nodeconfig.cpp +++ b/nano/node/nodeconfig.cpp @@ -246,6 +246,10 @@ nano::error nano::node_config::serialize_toml (nano::tomlconfig & toml) const peer_history.serialize (peer_history_l); toml.put_child ("peer_history", peer_history_l); + nano::tomlconfig tcp_l; + tcp.serialize (tcp_l); + toml.put_child ("tcp", tcp_l); + nano::tomlconfig request_aggregator_l; request_aggregator.serialize (request_aggregator_l); toml.put_child ("request_aggregator", request_aggregator_l); @@ -381,6 +385,12 @@ nano::error nano::node_config::deserialize_toml (nano::tomlconfig & toml) peer_history.deserialize (config_l); } + if (toml.has_key ("tcp")) + { + auto config_l = toml.get_required_child ("tcp"); + tcp.deserialize (config_l); + } + if (toml.has_key ("request_aggregator")) { auto config_l = toml.get_required_child ("request_aggregator"); diff --git a/nano/node/transport/tcp_config.cpp b/nano/node/transport/tcp_config.cpp index 8978a9583..b85d0beb6 100644 --- a/nano/node/transport/tcp_config.cpp +++ b/nano/node/transport/tcp_config.cpp @@ -1 +1,29 @@ -#include \ No newline at end of file +#include + +nano::error nano::transport::tcp_config::serialize (nano::tomlconfig & toml) const +{ + toml.put ("max_inbound_connections", max_inbound_connections, "Maximum number of incoming TCP connections. \ntype:uint64"); + toml.put ("max_outbound_connections", max_outbound_connections, "Maximum number of outgoing TCP connections. \ntype:uint64"); + toml.put ("max_attempts", max_attempts, "Maximum connection attempts. \ntype:uint64"); + toml.put ("max_attempts_per_ip", max_attempts_per_ip, "Maximum connection attempts per IP. \ntype:uint64"); + + toml.put ("connect_timeout", connect_timeout.count (), "Timeout for establishing TCP connection in seconds. \ntype:uint64"); + toml.put ("handshake_timeout", handshake_timeout.count (), "Timeout for completing handshake in seconds. \ntype:uint64"); + toml.put ("io_timeout", io_timeout.count (), "Timeout for TCP I/O operations in seconds. \ntype:uint64"); + + return toml.get_error (); +} + +nano::error nano::transport::tcp_config::deserialize (nano::tomlconfig & toml) +{ + toml.get ("max_inbound_connections", max_inbound_connections); + toml.get ("max_outbound_connections", max_outbound_connections); + toml.get ("max_attempts", max_attempts); + toml.get ("max_attempts_per_ip", max_attempts_per_ip); + + toml.get_duration ("connect_timeout", connect_timeout); + toml.get_duration ("handshake_timeout", handshake_timeout); + toml.get_duration ("io_timeout", io_timeout); + + return toml.get_error (); +} \ No newline at end of file diff --git a/nano/node/transport/tcp_config.hpp b/nano/node/transport/tcp_config.hpp index 82fece240..1a8a99d6b 100644 --- a/nano/node/transport/tcp_config.hpp +++ b/nano/node/transport/tcp_config.hpp @@ -23,7 +23,8 @@ public: } public: - // TODO: Serialize/deserialize + nano::error deserialize (nano::tomlconfig &); + nano::error serialize (nano::tomlconfig &) const; public: size_t max_inbound_connections{ 2048 };