upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/client.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs
index 45bac7a..4f5c341 100644
--- a/src/lib/client.rs
+++ b/src/lib/client.rs
@@ -195,7 +195,7 @@ impl Connect for Client {
195 if !relay.is_connected() { 195 if !relay.is_connected() {
196 #[allow(clippy::large_futures)] 196 #[allow(clippy::large_futures)]
197 relay 197 relay
198 .try_connect(std::time::Duration::from_secs(LONG_TIMEOUT)) 198 .try_connect(std::time::Duration::from_secs(long_timeout()))
199 .await?; 199 .await?;
200 } 200 }
201 201
@@ -278,7 +278,7 @@ impl Connect for Client {
278 let relays_map = self.client.relays().await; 278 let relays_map = self.client.relays().await;
279 279
280 // Static timeout for get_events_per_relay (no adaptive timeout here) 280 // Static timeout for get_events_per_relay (no adaptive timeout here)
281 let static_timeout = Arc::new(AtomicU64::new(LONG_TIMEOUT)); 281 let static_timeout = Arc::new(AtomicU64::new(long_timeout()));
282 282
283 let futures: Vec<_> = relays 283 let futures: Vec<_> = relays
284 .clone() 284 .clone()
@@ -385,7 +385,7 @@ impl Connect for Client {
385 385
386 // Track current timeout value for progress bar display (starts at LONG, 386 // Track current timeout value for progress bar display (starts at LONG,
387 // switches to SHORT) 387 // switches to SHORT)
388 let current_timeout = Arc::new(AtomicU64::new(LONG_TIMEOUT)); 388 let current_timeout = Arc::new(AtomicU64::new(long_timeout()));
389 389
390 let mut processed_relays = HashSet::new(); 390 let mut processed_relays = HashSet::new();
391 391
@@ -527,7 +527,7 @@ impl Connect for Client {
527 let timeout_future = async { 527 let timeout_future = async {
528 // Poll for timeout or SUCCESS_THRESHOLD success threshold 528 // Poll for timeout or SUCCESS_THRESHOLD success threshold
529 let check_interval = Duration::from_millis(100); 529 let check_interval = Duration::from_millis(100);
530 let long_timeout_end = tokio::time::Instant::now() + Duration::from_secs(LONG_TIMEOUT); 530 let long_timeout_end = tokio::time::Instant::now() + Duration::from_secs(long_timeout());
531 531
532 loop { 532 loop {
533 // Check if SUCCESS_THRESHOLD of relays have succeeded 533 // Check if SUCCESS_THRESHOLD of relays have succeeded
@@ -567,7 +567,7 @@ impl Connect for Client {
567 } 567 }
568 timeout_type = timeout_future => { 568 timeout_type = timeout_future => {
569 Err(anyhow!("timeout after {}s timeout", 569 Err(anyhow!("timeout after {}s timeout",
570 if timeout_type == "long" { LONG_TIMEOUT } else { short_timeout() })) 570 if timeout_type == "long" { long_timeout() } else { short_timeout() }))
571 } 571 }
572 }; 572 };
573 573
@@ -731,12 +731,19 @@ impl Connect for Client {
731 } 731 }
732} 732}
733 733
734static LONG_TIMEOUT: u64 = 45;
735static SUCCESS_THRESHOLD: f64 = 0.5; // 50% of relays must succeed to switch to short timeout 734static SUCCESS_THRESHOLD: f64 = 0.5; // 50% of relays must succeed to switch to short timeout
736 735
736fn long_timeout() -> u64 {
737 if std::env::var("NGITTEST").is_ok() {
738 1
739 } else {
740 45
741 }
742}
743
737fn short_timeout() -> u64 { 744fn short_timeout() -> u64 {
738 if std::env::var("NGITTEST").is_ok() { 745 if std::env::var("NGITTEST").is_ok() {
739 3 746 1
740 } else { 747 } else {
741 7 748 7
742 } 749 }
@@ -751,7 +758,7 @@ async fn get_events_of(
751 758
752 let mut retry_delay = Duration::from_secs(2); 759 let mut retry_delay = Duration::from_secs(2);
753 let start_time = std::time::Instant::now(); 760 let start_time = std::time::Instant::now();
754 let max_timeout = Duration::from_secs(LONG_TIMEOUT); 761 let max_timeout = Duration::from_secs(long_timeout());
755 let mut last_error = None; 762 let mut last_error = None;
756 let mut attempt_num = 0; 763 let mut attempt_num = 0;
757 let dim = Style::new().color256(247); 764 let dim = Style::new().color256(247);
@@ -865,7 +872,7 @@ async fn get_events_of(
865 .fetch_events( 872 .fetch_events(
866 filter, 873 filter,
867 // Use a very long timeout; actual timeout is controlled by outer tokio::select! 874 // Use a very long timeout; actual timeout is controlled by outer tokio::select!
868 std::time::Duration::from_secs(LONG_TIMEOUT), 875 std::time::Duration::from_secs(long_timeout()),
869 ReqExitPolicy::ExitOnEOSE, 876 ReqExitPolicy::ExitOnEOSE,
870 ) 877 )
871 .await 878 .await