diff options
Diffstat (limited to 'src/sync/relay_connection.rs')
| -rw-r--r-- | src/sync/relay_connection.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index 09c9887..d69e112 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs | |||
| @@ -55,7 +55,8 @@ impl RelayConnection { | |||
| 55 | /// This method: | 55 | /// This method: |
| 56 | /// 1. Adds the relay to the client | 56 | /// 1. Adds the relay to the client |
| 57 | /// 2. Establishes the WebSocket connection | 57 | /// 2. Establishes the WebSocket connection |
| 58 | /// 3. Subscribes to Layer 1 filter (kinds 30617 + 30618) | 58 | /// 3. Verifies connection was established |
| 59 | /// 4. Subscribes to Layer 1 filter (kinds 30617 + 30618) | ||
| 59 | /// | 60 | /// |
| 60 | /// # Arguments | 61 | /// # Arguments |
| 61 | /// * `since` - Optional timestamp for incremental sync on reconnect | 62 | /// * `since` - Optional timestamp for incremental sync on reconnect |
| @@ -76,6 +77,21 @@ impl RelayConnection { | |||
| 76 | // Establish connection | 77 | // Establish connection |
| 77 | self.client.connect().await; | 78 | self.client.connect().await; |
| 78 | 79 | ||
| 80 | // Wait briefly for connection to establish and check status | ||
| 81 | // nostr-sdk's connect() is async and may not immediately reflect failure | ||
| 82 | tokio::time::sleep(std::time::Duration::from_millis(500)).await; | ||
| 83 | |||
| 84 | // Check if relay is actually connected | ||
| 85 | let relay = self.client.relay(&self.url).await | ||
| 86 | .map_err(|e| format!("Failed to get relay handle for {}: {}", self.url, e))?; | ||
| 87 | |||
| 88 | if !relay.is_connected() { | ||
| 89 | return Err(format!( | ||
| 90 | "Failed to connect to relay {}: connection not established after timeout", | ||
| 91 | self.url | ||
| 92 | )); | ||
| 93 | } | ||
| 94 | |||
| 79 | // Subscribe to Layer 1 (announcements) | 95 | // Subscribe to Layer 1 (announcements) |
| 80 | let filter = build_announcement_filter(since); | 96 | let filter = build_announcement_filter(since); |
| 81 | let output = self | 97 | let output = self |