Skip to content
This repository was archived by the owner on Dec 10, 2022. It is now read-only.

Commit 8df9341

Browse files
authored
Merge pull request #43 from tox-rs/tcp_limit
Add limit for TCP connections count
2 parents 953996e + 5d5dcf6 commit 8df9341

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ config = "0.9"
3030
serde = "1.0"
3131
serde_derive = "1.0"
3232
serde_yaml = "0.8.8"
33-
tox = "0.0.8"
33+
tox = { git = "https://github.com/tox-rs/tox.git" }
3434

3535
[target.'cfg(unix)'.dependencies]
3636
syslog = "4.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ keys-file: ./keys
8282
udp-address: 0.0.0.0:33445
8383
tcp-addresses:
8484
- 0.0.0.0:33445
85+
tcp-connections-limit: 512
8586
motd: "{{start_date}} {{uptime}} Tcp: incoming {{tcp_packets_in}}, outgoing {{tcp_packets_out}}, Udp: incoming {{udp_packets_in}}, outgoing {{udp_packets_out}}"
8687
bootstrap-nodes:
8788
- pk: 1D5A5F2F5D6233058BF0259B09622FB40B482E4FA0931EB8FD3AB8E7BF7DAF6F

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ fn run_tcp(config: &NodeConfig, dht_sk: SecretKey, tcp_onion: TcpOnion, stats: S
192192
let tcp_server_c = tcp_server_c.clone();
193193
let dht_sk = dht_sk.clone();
194194
let listener = TcpListener::bind(&addr).expect("Failed to bind TCP listener");
195-
tcp_server_c.run(listener, dht_sk, stats.clone())
195+
tcp_server_c.run(listener, dht_sk, stats.clone(), config.tcp_connections_limit)
196196
.map_err(Error::from)
197197
});
198198

src/node_config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ pub struct NodeConfig {
112112
#[serde(rename = "tcp-addresses")]
113113
#[serde(default)]
114114
pub tcp_addrs: Vec<SocketAddr>,
115+
/// Maximum number of active TCP connections relay can hold.
116+
#[serde(rename = "tcp-connections-limit")]
117+
pub tcp_connections_limit: usize,
115118
/// DHT SecretKey
116119
#[serde(skip_deserializing)]
117120
pub sk: Option<SecretKey>,
@@ -172,6 +175,13 @@ pub fn cli_parse() -> NodeConfig {
172175
.takes_value(true)
173176
.use_delimiter(true)
174177
.required_unless("udp-address"))
178+
.arg(Arg::with_name("tcp-connections-limit")
179+
.short("c")
180+
.long("tcp-connections-limit")
181+
.help("Maximum number of active TCP connections relay can hold")
182+
.requires("tcp-address")
183+
.takes_value(true)
184+
.default_value("512"))
175185
.arg(Arg::with_name("secret-key")
176186
.short("s")
177187
.long("secret-key")
@@ -250,6 +260,7 @@ fn parse_config(config_path: &str) -> NodeConfig {
250260
settings.set_default("motd", "This is tox-rs").expect("Can't set default value for `motd`");
251261
settings.set_default("lan-discovery", "False").expect("Can't set default value for `lan-discovery`");
252262
settings.set_default("threads", "1").expect("Can't set default value for `threads`");
263+
settings.set_default("tcp-connections-limit", "512").expect("Can't set default value for `tcp-connections-limit`");
253264

254265
let config_file = if !Path::new(config_path).exists() {
255266
panic!("Can't find config file {}", config_path);
@@ -287,6 +298,8 @@ fn run_args(matches: &ArgMatches) -> NodeConfig {
287298
Vec::new()
288299
};
289300

301+
let tcp_connections_limit = value_t!(matches.value_of("tcp-connections-limit"), usize).unwrap_or_else(|e| e.exit());
302+
290303
let sk = matches.value_of("secret-key").map(|s| {
291304
let sk_bytes: [u8; 32] = FromHex::from_hex(s).expect("Invalid DHT secret key");
292305
SecretKey::from_slice(&sk_bytes).expect("Invalid DHT secret key")
@@ -325,6 +338,7 @@ fn run_args(matches: &ArgMatches) -> NodeConfig {
325338
NodeConfig {
326339
udp_addr,
327340
tcp_addrs,
341+
tcp_connections_limit,
328342
sk,
329343
sk_passed_as_arg,
330344
keys_file,

0 commit comments

Comments
 (0)