-
Notifications
You must be signed in to change notification settings - Fork 790
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4813 from pwojcikdev/move-tcp-config
Cleanup `tcp_config` class
- Loading branch information
Showing
10 changed files
with
110 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <nano/node/transport/tcp_config.hpp> | ||
|
||
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 (); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#include <nano/lib/config.hpp> | ||
#include <nano/lib/constants.hpp> | ||
|
||
#include <chrono> | ||
|
||
namespace nano::transport | ||
{ | ||
class tcp_config | ||
{ | ||
public: | ||
explicit tcp_config (nano::network_constants const & network) | ||
{ | ||
if (network.is_dev_network ()) | ||
{ | ||
max_inbound_connections = 128; | ||
max_outbound_connections = 128; | ||
max_attempts = 128; | ||
max_attempts_per_ip = 128; | ||
connect_timeout = std::chrono::seconds{ 5 }; | ||
} | ||
} | ||
|
||
public: | ||
nano::error deserialize (nano::tomlconfig &); | ||
nano::error serialize (nano::tomlconfig &) const; | ||
|
||
public: | ||
size_t max_inbound_connections{ 2048 }; | ||
size_t max_outbound_connections{ 2048 }; | ||
size_t max_attempts{ 60 }; | ||
size_t max_attempts_per_ip{ 1 }; | ||
std::chrono::seconds connect_timeout{ 60 }; | ||
std::chrono::seconds handshake_timeout{ 30 }; | ||
std::chrono::seconds io_timeout{ 30 }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters