upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sync/mod.rs6
-rw-r--r--src/sync/relay_connection.rs28
2 files changed, 10 insertions, 24 deletions
diff --git a/src/sync/mod.rs b/src/sync/mod.rs
index 85ab680..3f8e503 100644
--- a/src/sync/mod.rs
+++ b/src/sync/mod.rs
@@ -1205,8 +1205,8 @@ impl SyncManager {
1205 1205
1206 let timeout = self.health_tracker.base_backoff_secs(); 1206 let timeout = self.health_tracker.base_backoff_secs();
1207 1207
1208 match connection.connect_and_subscribe(None, timeout).await { 1208 match connection.connect(timeout).await {
1209 Ok(_) => { 1209 Ok(()) => {
1210 // Success - record and send notification 1210 // Success - record and send notification
1211 self.health_tracker.record_success(relay_url); 1211 self.health_tracker.record_success(relay_url);
1212 1212
@@ -1346,7 +1346,7 @@ impl SyncManager {
1346 1346
1347 // 3. Keep RelayConnection in HashMap for reuse on reconnect 1347 // 3. Keep RelayConnection in HashMap for reuse on reconnect
1348 // The connection object persists and will be reused when retry_disconnected_relays 1348 // The connection object persists and will be reused when retry_disconnected_relays
1349 // calls try_connect_relay -> connection.connect_and_subscribe() 1349 // calls try_connect_relay -> connection.connect()
1350 tracing::debug!( 1350 tracing::debug!(
1351 relay = %relay_url, 1351 relay = %relay_url,
1352 "Keeping RelayConnection in HashMap for reconnection" 1352 "Keeping RelayConnection in HashMap for reconnection"
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs
index fdb32cb..fa229c4 100644
--- a/src/sync/relay_connection.rs
+++ b/src/sync/relay_connection.rs
@@ -18,7 +18,6 @@
18use nostr_sdk::prelude::*; 18use nostr_sdk::prelude::*;
19use tokio::sync::mpsc; 19use tokio::sync::mpsc;
20 20
21use super::filters::build_announcement_filter;
22use crate::nostr::builder::SharedDatabase; 21use crate::nostr::builder::SharedDatabase;
23 22
24/// Events from a relay connection 23/// Events from a relay connection
@@ -107,28 +106,24 @@ impl RelayConnection {
107 } 106 }
108 } 107 }
109 108
110 /// Connect to the relay and subscribe to Layer 1 (announcements) 109 /// Connect to the relay
111 /// 110 ///
112 /// This method: 111 /// This method:
113 /// 1. Adds the relay to the client 112 /// 1. Adds the relay to the client
114 /// 2. Establishes the WebSocket connection 113 /// 2. Establishes the WebSocket connection
115 /// 3. Verifies connection was established 114 /// 3. Verifies connection was established
116 /// 4. Subscribes to Layer 1 filter (kinds 30617 + 30618) 115 ///
116 /// Subscriptions are handled separately via handle_connect_or_reconnect.
117 /// 117 ///
118 /// # Arguments 118 /// # Arguments
119 /// * `since` - Optional timestamp for incremental sync on reconnect
120 /// * `connection_timeout_secs` - Timeout for the connection attempt in seconds. 119 /// * `connection_timeout_secs` - Timeout for the connection attempt in seconds.
121 /// Should be no larger than base_backoff_secs to ensure the connection attempt 120 /// Should be no larger than base_backoff_secs to ensure the connection attempt
122 /// completes before the next retry would be scheduled. 121 /// completes before the next retry would be scheduled.
123 /// 122 ///
124 /// # Returns 123 /// # Returns
125 /// * `Ok(SubscriptionId)` - The subscription ID on successful connection 124 /// * `Ok(())` - Connection established successfully
126 /// * `Err(String)` with error description on failure 125 /// * `Err(String)` with error description on failure
127 pub async fn connect_and_subscribe( 126 pub async fn connect(&self, connection_timeout_secs: u64) -> Result<(), String> {
128 &self,
129 since: Option<Timestamp>,
130 connection_timeout_secs: u64,
131 ) -> Result<SubscriptionId, String> {
132 // Add relay to client 127 // Add relay to client
133 self.client 128 self.client
134 .add_relay(&self.url) 129 .add_relay(&self.url)
@@ -157,17 +152,8 @@ impl RelayConnection {
157 .await 152 .await
158 .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; 153 .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?;
159 154
160 // Subscribe to Layer 1 (announcements) 155 tracing::info!(url = %self.url, "Connected to relay");
161 let filter = build_announcement_filter(since); 156 Ok(())
162 let output = self.client.subscribe(filter, None).await.map_err(|e| {
163 format!(
164 "Failed to subscribe to announcements on {}: {}",
165 self.url, e
166 )
167 })?;
168
169 tracing::info!(url = %self.url, sub_id = %output.val, "Connected and subscribed to Layer 1 (announcements)");
170 Ok(output.val)
171 } 157 }
172 158
173 /// Run the event loop, sending events through the provided channel 159 /// Run the event loop, sending events through the provided channel