diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 14:36:06 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-10 14:37:19 +0000 |
| commit | 8148c27a1350189046bc8e215f29f918dd8747f5 (patch) | |
| tree | 4630db969a5f5b3e288a806ff8f85cd507820dab /src/sync | |
| parent | e0eedf25f3218ee54563229257c1ce949bfafd10 (diff) | |
sync: fix connection registration issue
Diffstat (limited to 'src/sync')
| -rw-r--r-- | src/sync/mod.rs | 18 | ||||
| -rw-r--r-- | src/sync/relay_connection.rs | 1 | ||||
| -rw-r--r-- | src/sync/self_subscriber.rs | 17 |
3 files changed, 33 insertions, 3 deletions
diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 7a0a705..b38c4a9 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs | |||
| @@ -1300,6 +1300,16 @@ impl SyncManager { | |||
| 1300 | state.disconnected_at = None; | 1300 | state.disconnected_at = None; |
| 1301 | } | 1301 | } |
| 1302 | 1302 | ||
| 1303 | // Store connection in HashMap BEFORE sending notification | ||
| 1304 | // This ensures it's available when handle_connect_or_reconnect is called | ||
| 1305 | self.connections.insert(relay_url.clone(), connection); | ||
| 1306 | |||
| 1307 | tracing::info!( | ||
| 1308 | relay = %relay_url, | ||
| 1309 | is_bootstrap = is_bootstrap, | ||
| 1310 | "Spawned relay connection" | ||
| 1311 | ); | ||
| 1312 | |||
| 1303 | // Notify SyncManager of successful connection | 1313 | // Notify SyncManager of successful connection |
| 1304 | let _ = connect_tx | 1314 | let _ = connect_tx |
| 1305 | .send(ConnectNotification { | 1315 | .send(ConnectNotification { |
| @@ -1307,12 +1317,16 @@ impl SyncManager { | |||
| 1307 | }) | 1317 | }) |
| 1308 | .await; | 1318 | .await; |
| 1309 | 1319 | ||
| 1320 | // Clone the connection for the event loop spawn | ||
| 1321 | // The stored connection is used for subscription management | ||
| 1322 | let connection_for_loop = self.connections.get(&relay_url).unwrap().clone(); | ||
| 1323 | |||
| 1310 | // Create event channel | 1324 | // Create event channel |
| 1311 | let (event_tx, mut event_rx) = mpsc::channel::<RelayEvent>(1000); | 1325 | let (event_tx, mut event_rx) = mpsc::channel::<RelayEvent>(1000); |
| 1312 | 1326 | ||
| 1313 | // Spawn event loop | 1327 | // Spawn event loop with cloned connection |
| 1314 | tokio::spawn(async move { | 1328 | tokio::spawn(async move { |
| 1315 | connection.run_event_loop(event_tx).await; | 1329 | connection_for_loop.run_event_loop(event_tx).await; |
| 1316 | }); | 1330 | }); |
| 1317 | 1331 | ||
| 1318 | // Spawn event processor | 1332 | // Spawn event processor |
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index b0765e8..09c9887 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs | |||
| @@ -32,6 +32,7 @@ pub enum RelayEvent { | |||
| 32 | /// - Layer 1 subscription (announcements) | 32 | /// - Layer 1 subscription (announcements) |
| 33 | /// - Additional filter subscriptions (Layers 2 & 3) | 33 | /// - Additional filter subscriptions (Layers 2 & 3) |
| 34 | /// - Event notification loop | 34 | /// - Event notification loop |
| 35 | #[derive(Clone)] | ||
| 35 | pub struct RelayConnection { | 36 | pub struct RelayConnection { |
| 36 | /// The relay URL this connection is for | 37 | /// The relay URL this connection is for |
| 37 | url: String, | 38 | url: String, |
diff --git a/src/sync/self_subscriber.rs b/src/sync/self_subscriber.rs index e9e61ff..27e7e64 100644 --- a/src/sync/self_subscriber.rs +++ b/src/sync/self_subscriber.rs | |||
| @@ -443,6 +443,15 @@ impl SelfSubscriber { | |||
| 443 | "Processing batch of repo updates" | 443 | "Processing batch of repo updates" |
| 444 | ); | 444 | ); |
| 445 | 445 | ||
| 446 | // Log what repos and relays we discovered | ||
| 447 | for (repo_id, needs) in &updates { | ||
| 448 | tracing::info!( | ||
| 449 | repo_id = %repo_id, | ||
| 450 | relay_urls = ?needs.relays, | ||
| 451 | "Discovered repo with relay URLs" | ||
| 452 | ); | ||
| 453 | } | ||
| 454 | |||
| 446 | // Update RepoSyncIndex | 455 | // Update RepoSyncIndex |
| 447 | let mut index = self.repo_sync_index.write().await; | 456 | let mut index = self.repo_sync_index.write().await; |
| 448 | 457 | ||
| @@ -482,6 +491,10 @@ impl SelfSubscriber { | |||
| 482 | None, | 491 | None, |
| 483 | ); | 492 | ); |
| 484 | 493 | ||
| 494 | // Log before moving values | ||
| 495 | let repo_count = needs.repos.len(); | ||
| 496 | let event_count = needs.root_events.len(); | ||
| 497 | |||
| 485 | let action = AddFilters { | 498 | let action = AddFilters { |
| 486 | relay_url: relay_url.clone(), | 499 | relay_url: relay_url.clone(), |
| 487 | repos: needs.repos, | 500 | repos: needs.repos, |
| @@ -496,8 +509,10 @@ impl SelfSubscriber { | |||
| 496 | "Failed to send AddFilters action" | 509 | "Failed to send AddFilters action" |
| 497 | ); | 510 | ); |
| 498 | } else { | 511 | } else { |
| 499 | tracing::debug!( | 512 | tracing::info!( |
| 500 | relay = %relay_url, | 513 | relay = %relay_url, |
| 514 | repo_count = repo_count, | ||
| 515 | event_count = event_count, | ||
| 501 | "Sent AddFilters action to SyncManager" | 516 | "Sent AddFilters action to SyncManager" |
| 502 | ); | 517 | ); |
| 503 | } | 518 | } |