11use std:: { path:: PathBuf , time:: Duration } ;
22
3+ use bon:: Builder ;
4+ use charon_p2p:: config:: P2PConfig ;
35use charon_tracing:: TracingConfig ;
46use libp2p:: relay;
57
6- use charon_p2p:: config:: P2PConfig ;
7-
88/// One hour in seconds.
99pub const ONE_HOUR_SECONDS : u64 = 60 * 60 ;
1010/// One minute in seconds.
@@ -15,125 +15,35 @@ pub const MB_32: u64 = 32 * 1024 * 1024;
1515pub const EXTERNAL_HOST_RESOLVE_INTERVAL : Duration = Duration :: from_secs ( 5 * 60 ) ;
1616
1717/// Configuration for the relay P2P layer.
18- #[ derive( Default , Debug , Clone ) ]
18+ #[ derive( Default , Debug , Clone , Builder ) ]
1919pub struct Config {
2020 /// The directory to store the relay data.
21- pub data_dir : PathBuf ,
21+ pub data_dir : Option < PathBuf > ,
2222 /// The HTTP address to listen on.
2323 pub http_addr : Option < String > ,
2424 /// The monitoring address to listen on.
25- pub monitoring_addr : String ,
25+ pub monitoring_addr : Option < String > ,
2626 /// The debug address to listen on.
27- pub debug_addr : String ,
27+ pub debug_addr : Option < String > ,
2828 /// The P2P configuration.
2929 pub p2p_config : P2PConfig ,
3030 /// The logging configuration.
31- pub log_config : TracingConfig ,
31+ pub log_config : Option < TracingConfig > ,
3232 /// Whether to automatically generate a P2P key.
33+ #[ builder( default = false ) ]
3334 pub auto_p2p_key : bool ,
3435 /// The maximum number of resources per peer.
3536 pub max_res_per_peer : usize ,
3637 /// The maximum number of connections.
3738 pub max_conns : usize ,
3839 /// Whether to filter private addresses.
40+ #[ builder( default = false ) ]
3941 pub filter_private_addrs : bool ,
4042 /// LibP2PLogLevel.
43+ #[ builder( default = "Info" . to_string( ) ) ]
4144 pub libp2p_log_level : String ,
4245}
4346
44- impl Config {
45- /// Returns a new builder for configuring a relay P2P layer.
46- pub fn builder ( ) -> ConfigBuilder {
47- ConfigBuilder :: new ( )
48- }
49- }
50-
51- /// Builder for [`Config`].
52- #[ derive( Default , Debug , Clone ) ]
53- pub struct ConfigBuilder {
54- config : Config ,
55- }
56-
57- impl ConfigBuilder {
58- /// Creates a new builder with default configuration.
59- pub fn new ( ) -> Self {
60- Self {
61- config : Config :: default ( ) ,
62- }
63- }
64-
65- /// Sets the data directory.
66- pub fn with_data_dir ( mut self , data_dir : PathBuf ) -> Self {
67- self . config . data_dir = data_dir;
68- self
69- }
70-
71- /// Sets the HTTP address.
72- pub fn with_http_addr ( mut self , http_addr : Option < String > ) -> Self {
73- self . config . http_addr = http_addr;
74- self
75- }
76-
77- /// Sets the monitoring address.
78- pub fn with_monitoring_addr ( mut self , monitoring_addr : String ) -> Self {
79- self . config . monitoring_addr = monitoring_addr;
80- self
81- }
82-
83- /// Sets the debug address.
84- pub fn with_debug_addr ( mut self , debug_addr : String ) -> Self {
85- self . config . debug_addr = debug_addr;
86- self
87- }
88-
89- /// Sets the P2P configuration.
90- pub fn with_p2p_config ( mut self , p2p_config : P2PConfig ) -> Self {
91- self . config . p2p_config = p2p_config;
92- self
93- }
94-
95- /// Sets the logging configuration.
96- pub fn with_log_config ( mut self , log_config : TracingConfig ) -> Self {
97- self . config . log_config = log_config;
98- self
99- }
100-
101- /// Sets whether to automatically generate a P2P key.
102- pub fn with_auto_p2p_key ( mut self , auto_p2p_key : bool ) -> Self {
103- self . config . auto_p2p_key = auto_p2p_key;
104- self
105- }
106-
107- /// Sets the maximum number of resources per peer.
108- pub fn with_max_res_per_peer ( mut self , max_res_per_peer : usize ) -> Self {
109- self . config . max_res_per_peer = max_res_per_peer;
110- self
111- }
112-
113- /// Sets the maximum number of connections.
114- pub fn with_max_conns ( mut self , max_conns : usize ) -> Self {
115- self . config . max_conns = max_conns;
116- self
117- }
118-
119- /// Sets whether to filter private addresses.
120- pub fn with_filter_private_addrs ( mut self , filter_private_addrs : bool ) -> Self {
121- self . config . filter_private_addrs = filter_private_addrs;
122- self
123- }
124-
125- /// Sets the LibP2P log level.
126- pub fn with_libp2p_log_level ( mut self , libp2p_log_level : String ) -> Self {
127- self . config . libp2p_log_level = libp2p_log_level;
128- self
129- }
130-
131- /// Builds the [`Config`].
132- pub fn build ( self ) -> Config {
133- self . config
134- }
135- }
136-
13747pub ( crate ) fn create_relay_config ( config : & Config ) -> relay:: Config {
13848 relay:: Config {
13949 max_reservations : config. max_conns ,
0 commit comments