@@ -18,6 +18,7 @@ use bdk_kyoto::Warning as Warn;
18
18
use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
19
19
use std:: path:: PathBuf ;
20
20
use std:: sync:: Arc ;
21
+ use std:: time:: Duration ;
21
22
22
23
use tokio:: sync:: Mutex ;
23
24
@@ -33,6 +34,8 @@ type ScanType = bdk_kyoto::ScanType;
33
34
34
35
const DEFAULT_CONNECTIONS : u8 = 2 ;
35
36
const CWD_PATH : & str = "." ;
37
+ const TCP_HANDSHAKE_TIMEOUT : Duration = Duration :: from_secs ( 2 ) ;
38
+ const MESSAGE_RESPONSE_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
36
39
37
40
/// Receive a [`CbfClient`] and [`CbfNode`].
38
41
#[ derive( Debug , uniffi:: Record ) ]
@@ -94,6 +97,8 @@ impl CbfNode {
94
97
#[ derive( Clone , uniffi:: Object ) ]
95
98
pub struct CbfBuilder {
96
99
connections : u8 ,
100
+ handshake_timeout : Duration ,
101
+ response_timeout : Duration ,
97
102
data_dir : Option < String > ,
98
103
scan_type : ScanType ,
99
104
log_level : LogLevel ,
@@ -109,6 +114,8 @@ impl CbfBuilder {
109
114
pub fn new ( ) -> Self {
110
115
CbfBuilder {
111
116
connections : DEFAULT_CONNECTIONS ,
117
+ handshake_timeout : TCP_HANDSHAKE_TIMEOUT ,
118
+ response_timeout : MESSAGE_RESPONSE_TIMEOUT ,
112
119
data_dir : None ,
113
120
scan_type : ScanType :: default ( ) ,
114
121
log_level : LogLevel :: default ( ) ,
@@ -160,6 +167,17 @@ impl CbfBuilder {
160
167
} )
161
168
}
162
169
170
+ /// Configure the time in milliseconds that a node has to:
171
+ /// 1. Respond to the initial connection
172
+ /// 2. Respond to a request
173
+ pub fn configure_timeout_millis ( & self , handshake : u64 , response : u64 ) -> Arc < Self > {
174
+ Arc :: new ( CbfBuilder {
175
+ handshake_timeout : Duration :: from_millis ( handshake) ,
176
+ response_timeout : Duration :: from_millis ( response) ,
177
+ ..self . clone ( )
178
+ } )
179
+ }
180
+
163
181
/// Configure a custom DNS resolver when querying DNS seeds. Default is `1.1.1.1` managed by
164
182
/// CloudFlare.
165
183
pub fn dns_resolver ( & self , dns_resolver : Arc < IpAddress > ) -> Arc < Self > {
@@ -193,6 +211,8 @@ impl CbfBuilder {
193
211
let mut builder = BDKCbfBuilder :: new ( wallet. network ( ) )
194
212
. required_peers ( self . connections )
195
213
. data_dir ( path_buf)
214
+ . handshake_timeout ( self . handshake_timeout )
215
+ . response_timeout ( self . response_timeout )
196
216
. log_level ( self . log_level )
197
217
. add_peers ( trusted_peers) ;
198
218
0 commit comments