@@ -22,7 +22,8 @@ use serde::{Deserialize, Serialize};
2222/// Configuration for LDK Server.
2323#[ derive( Debug ) ]
2424pub struct Config {
25- pub listening_addr : SocketAddress ,
25+ pub listening_addrs : Option < Vec < SocketAddress > > ,
26+ pub announcement_addrs : Option < Vec < SocketAddress > > ,
2627 pub alias : Option < NodeAlias > ,
2728 pub network : Network ,
2829 pub api_key : String ,
@@ -55,13 +56,40 @@ impl TryFrom<TomlConfig> for Config {
5556 type Error = io:: Error ;
5657
5758 fn try_from ( toml_config : TomlConfig ) -> io:: Result < Self > {
58- let listening_addr =
59- SocketAddress :: from_str ( & toml_config. node . listening_address ) . map_err ( |e| {
60- io:: Error :: new (
61- io:: ErrorKind :: InvalidInput ,
62- format ! ( "Invalid listening address configured: {}" , e) ,
63- )
64- } ) ?;
59+ let listening_addrs = toml_config
60+ . node
61+ . listening_addresses
62+ . map ( |addresses| {
63+ addresses
64+ . into_iter ( )
65+ . map ( |addr| {
66+ SocketAddress :: from_str ( & addr) . map_err ( |e| {
67+ io:: Error :: new (
68+ io:: ErrorKind :: InvalidInput ,
69+ format ! ( "Invalid listening address configured: {}" , e) ,
70+ )
71+ } )
72+ } )
73+ . collect ( )
74+ } )
75+ . transpose ( ) ?;
76+ let announcement_addrs = toml_config
77+ . node
78+ . announcement_addresses
79+ . map ( |addresses| {
80+ addresses
81+ . into_iter ( )
82+ . map ( |addr| {
83+ SocketAddress :: from_str ( & addr) . map_err ( |e| {
84+ io:: Error :: new (
85+ io:: ErrorKind :: InvalidInput ,
86+ format ! ( "Invalid announcement address configured: {}" , e) ,
87+ )
88+ } )
89+ } )
90+ . collect ( )
91+ } )
92+ . transpose ( ) ?;
6593 let rest_service_addr = SocketAddr :: from_str ( & toml_config. node . rest_service_address )
6694 . map_err ( |e| {
6795 io:: Error :: new (
@@ -161,7 +189,8 @@ impl TryFrom<TomlConfig> for Config {
161189 } ) ;
162190
163191 Ok ( Config {
164- listening_addr,
192+ listening_addrs,
193+ announcement_addrs,
165194 network : toml_config. node . network ,
166195 alias,
167196 rest_service_addr,
@@ -195,7 +224,8 @@ pub struct TomlConfig {
195224#[ derive( Deserialize , Serialize ) ]
196225struct NodeConfig {
197226 network : Network ,
198- listening_address : String ,
227+ listening_addresses : Option < Vec < String > > ,
228+ announcement_addresses : Option < Vec < String > > ,
199229 rest_service_address : String ,
200230 alias : Option < String > ,
201231 api_key : String ,
@@ -331,7 +361,8 @@ mod tests {
331361 let toml_config = r#"
332362 [node]
333363 network = "regtest"
334- listening_address = "localhost:3001"
364+ listening_addresses = ["localhost:3001"]
365+ announcement_addresses = ["54.3.7.81:3001"]
335366 rest_service_address = "127.0.0.1:3002"
336367 alias = "LDK Server"
337368 api_key = "test_api_key"
@@ -375,7 +406,8 @@ mod tests {
375406
376407 let config = load_config ( storage_path. join ( config_file_name) ) . unwrap ( ) ;
377408 let expected = Config {
378- listening_addr : SocketAddress :: from_str ( "localhost:3001" ) . unwrap ( ) ,
409+ listening_addrs : Some ( vec ! [ SocketAddress :: from_str( "localhost:3001" ) . unwrap( ) ] ) ,
410+ announcement_addrs : Some ( vec ! [ SocketAddress :: from_str( "54.3.7.81:3001" ) . unwrap( ) ] ) ,
379411 alias : Some ( NodeAlias ( bytes) ) ,
380412 network : Network :: Regtest ,
381413 rest_service_addr : SocketAddr :: from_str ( "127.0.0.1:3002" ) . unwrap ( ) ,
@@ -407,7 +439,9 @@ mod tests {
407439 log_file_path : Some ( "/var/log/ldk-server.log" . to_string ( ) ) ,
408440 } ;
409441
410- assert_eq ! ( config. listening_addr, expected. listening_addr) ;
442+ assert_eq ! ( config. listening_addrs, expected. listening_addrs) ;
443+ assert_eq ! ( config. announcement_addrs, expected. announcement_addrs) ;
444+ assert_eq ! ( config. alias, expected. alias) ;
411445 assert_eq ! ( config. network, expected. network) ;
412446 assert_eq ! ( config. rest_service_addr, expected. rest_service_addr) ;
413447 assert_eq ! ( config. api_key, expected. api_key) ;
@@ -424,13 +458,14 @@ mod tests {
424458 assert_eq ! ( config. rabbitmq_exchange_name, expected. rabbitmq_exchange_name) ;
425459 #[ cfg( feature = "experimental-lsps2-support" ) ]
426460 assert_eq ! ( config. lsps2_service_config. is_some( ) , expected. lsps2_service_config. is_some( ) ) ;
461+ assert_eq ! ( config. log_level, expected. log_level) ;
462+ assert_eq ! ( config. log_file_path, expected. log_file_path) ;
427463
428464 // Test case where only electrum is set
429465
430466 let toml_config = r#"
431467 [node]
432468 network = "regtest"
433- listening_address = "localhost:3001"
434469 rest_service_address = "127.0.0.1:3002"
435470 alias = "LDK Server"
436471 api_key = "test_api_key"
@@ -475,7 +510,6 @@ mod tests {
475510 let toml_config = r#"
476511 [node]
477512 network = "regtest"
478- listening_address = "localhost:3001"
479513 rest_service_address = "127.0.0.1:3002"
480514 alias = "LDK Server"
481515 api_key = "test_api_key"
@@ -524,7 +558,6 @@ mod tests {
524558 let toml_config = r#"
525559 [node]
526560 network = "regtest"
527- listening_address = "localhost:3001"
528561 rest_service_address = "127.0.0.1:3002"
529562 alias = "LDK Server"
530563 api_key = "test_api_key"
0 commit comments