File tree Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Expand file tree Collapse file tree 2 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -280,11 +280,41 @@ impl Group {
280280 let keypair = None ;
281281
282282 let veilid = self . get_veilid_api ( ) ;
283+ let mut dht_record: Option < DHTRecordDescriptor > = None ;
284+ let mut retries = 6 ;
283285
284- let dht_record = self
285- . routing_context
286- . open_dht_record ( repo_id. clone ( ) , keypair)
287- . await ?;
286+ while retries > 0 {
287+ retries -= 1 ;
288+ let dht_record_result = self
289+ . routing_context
290+ . open_dht_record ( repo_id. clone ( ) , keypair. clone ( ) )
291+ . await ;
292+
293+ match dht_record_result {
294+ Ok ( record) => {
295+ dht_record = Some ( record) ;
296+ break ;
297+ }
298+ Err ( e) => {
299+ eprintln ! (
300+ "Failed to open DHT record: {}. Retries left: {}" ,
301+ e, retries
302+ ) ;
303+ if retries == 0 {
304+ return Err ( anyhow ! (
305+ "Unable to open DHT record, reached max retries: {}" ,
306+ e
307+ ) ) ;
308+ }
309+ }
310+ }
311+
312+ // Add a delay before retrying (wit exponential backoff)
313+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 * ( 7 - retries) as u64 ) ) . await ;
314+ }
315+
316+ // Ensure that `dht_record` is set before proceeding
317+ let dht_record = dht_record. ok_or_else ( || anyhow ! ( "DHT record retrieval failed" ) ) ?;
288318
289319 let repo = Repo {
290320 dht_record,
Original file line number Diff line number Diff line change @@ -294,8 +294,8 @@ mod tests {
294294 let ( route_id, route_id_blob) = veilid_api
295295 . new_custom_private_route (
296296 & VALID_CRYPTO_KINDS ,
297- veilid_core:: Stability :: Reliable ,
298- veilid_core:: Sequencing :: PreferOrdered ,
297+ veilid_core:: Stability :: LowLatency ,
298+ veilid_core:: Sequencing :: NoPreference ,
299299 )
300300 . await
301301 . expect ( "Failed to create route" ) ;
@@ -882,7 +882,7 @@ mod tests {
882882 sleep ( Duration :: from_secs ( 2 ) ) . await ;
883883
884884 // Download hash from peers
885- let mut retries = 5 ;
885+ let mut retries = 10 ;
886886 while retries > 0 {
887887 if group2. download_hash_from_peers ( & file_hash) . await . is_ok ( ) {
888888 println ! ( "Download success!" ) ;
You can’t perform that action at this time.
0 commit comments