@@ -18,6 +18,7 @@ use bdk_kyoto::Warning as Warn;
1818use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
1919use std:: path:: PathBuf ;
2020use std:: sync:: Arc ;
21+ use std:: time:: Duration ;
2122
2223use tokio:: sync:: Mutex ;
2324
@@ -33,6 +34,8 @@ type ScanType = bdk_kyoto::ScanType;
3334
3435const DEFAULT_CONNECTIONS : u8 = 2 ;
3536const CWD_PATH : & str = "." ;
37+ const TCP_HANDSHAKE_TIMEOUT : u64 = 2 ;
38+ const MESSAGE_RESPONSE_TIMEOUT : u64 = 5 ;
3639
3740/// Receive a [`CbfClient`] and [`CbfNode`].
3841#[ derive( Debug , uniffi:: Record ) ]
@@ -94,6 +97,8 @@ impl CbfNode {
9497#[ derive( Clone , uniffi:: Object ) ]
9598pub struct CbfBuilder {
9699 connections : u8 ,
100+ handshake_timeout : Duration ,
101+ response_timeout : Duration ,
97102 data_dir : Option < String > ,
98103 scan_type : ScanType ,
99104 log_level : LogLevel ,
@@ -109,6 +114,8 @@ impl CbfBuilder {
109114 pub fn new ( ) -> Self {
110115 CbfBuilder {
111116 connections : DEFAULT_CONNECTIONS ,
117+ handshake_timeout : Duration :: from_secs ( TCP_HANDSHAKE_TIMEOUT ) ,
118+ response_timeout : Duration :: from_secs ( MESSAGE_RESPONSE_TIMEOUT ) ,
112119 data_dir : None ,
113120 scan_type : ScanType :: default ( ) ,
114121 log_level : LogLevel :: default ( ) ,
@@ -160,6 +167,17 @@ impl CbfBuilder {
160167 } )
161168 }
162169
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+
163181 /// Configure a custom DNS resolver when querying DNS seeds. Default is `1.1.1.1` managed by
164182 /// CloudFlare.
165183 pub fn dns_resolver ( & self , dns_resolver : Arc < IpAddress > ) -> Arc < Self > {
@@ -193,6 +211,8 @@ impl CbfBuilder {
193211 let mut builder = BDKCbfBuilder :: new ( wallet. network ( ) )
194212 . required_peers ( self . connections )
195213 . data_dir ( path_buf)
214+ . handshake_timeout ( self . handshake_timeout )
215+ . response_timeout ( self . response_timeout )
196216 . log_level ( self . log_level )
197217 . add_peers ( trusted_peers) ;
198218
0 commit comments