@@ -112,6 +112,9 @@ pub struct NodeConfig {
112
112
#[ serde( rename = "tcp-addresses" ) ]
113
113
#[ serde( default ) ]
114
114
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 ,
115
118
/// DHT SecretKey
116
119
#[ serde( skip_deserializing) ]
117
120
pub sk : Option < SecretKey > ,
@@ -172,6 +175,13 @@ pub fn cli_parse() -> NodeConfig {
172
175
. takes_value ( true )
173
176
. use_delimiter ( true )
174
177
. 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" ) )
175
185
. arg ( Arg :: with_name ( "secret-key" )
176
186
. short ( "s" )
177
187
. long ( "secret-key" )
@@ -250,6 +260,7 @@ fn parse_config(config_path: &str) -> NodeConfig {
250
260
settings. set_default ( "motd" , "This is tox-rs" ) . expect ( "Can't set default value for `motd`" ) ;
251
261
settings. set_default ( "lan-discovery" , "False" ) . expect ( "Can't set default value for `lan-discovery`" ) ;
252
262
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`" ) ;
253
264
254
265
let config_file = if !Path :: new ( config_path) . exists ( ) {
255
266
panic ! ( "Can't find config file {}" , config_path) ;
@@ -287,6 +298,8 @@ fn run_args(matches: &ArgMatches) -> NodeConfig {
287
298
Vec :: new ( )
288
299
} ;
289
300
301
+ let tcp_connections_limit = value_t ! ( matches. value_of( "tcp-connections-limit" ) , usize ) . unwrap_or_else ( |e| e. exit ( ) ) ;
302
+
290
303
let sk = matches. value_of ( "secret-key" ) . map ( |s| {
291
304
let sk_bytes: [ u8 ; 32 ] = FromHex :: from_hex ( s) . expect ( "Invalid DHT secret key" ) ;
292
305
SecretKey :: from_slice ( & sk_bytes) . expect ( "Invalid DHT secret key" )
@@ -325,6 +338,7 @@ fn run_args(matches: &ArgMatches) -> NodeConfig {
325
338
NodeConfig {
326
339
udp_addr,
327
340
tcp_addrs,
341
+ tcp_connections_limit,
328
342
sk,
329
343
sk_passed_as_arg,
330
344
keys_file,
0 commit comments