diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 17:12:17 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-18 17:12:17 +0000 |
| commit | d76003b629a4a03dba23a8a1c41da6e4ac4c30cf (patch) | |
| tree | 38412fdeed3e7996923603fe1964db4e5ce94bdc /src/nostr/policy | |
| parent | 806936e7d1aab5dfd0c2ad6b98a115122dc1785c (diff) | |
feat: upgrade repo to Full sync and trigger PR event subscription after announcement promotion
When git data arrives for a purgatory announcement and promotes it to the
database, the relay now:
1. Upgrades the announcement's sync level in RepoSyncIndex from StateOnly
to Full (git/sync.rs: process_purgatory_announcements)
2. Sends AddFilters actions to SyncManager for all connected relays, using
Full sync filters (Layer 2 #a/#A/#q) to subscribe to PR events
(purgatory/sync/context.rs: RealSyncContext.process_newly_available_git_data)
3. For user-submitted purgatory announcements, registers the repo in
RepoSyncIndex with StateOnly level and sends AddFilters to SyncManager
so it discovers and connects to relays listed in the announcement tags
(nostr/builder.rs: handle_announcement AcceptPurgatory path)
The RealSyncContext now accepts optional repo_sync_index and sync_action_tx
parameters. main.rs wires these up from SyncManager. PolicyContext gains
repo_sync_index and sync_action_tx fields for the write policy path.
Diffstat (limited to 'src/nostr/policy')
| -rw-r--r-- | src/nostr/policy/mod.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/nostr/policy/mod.rs b/src/nostr/policy/mod.rs index 1566b6c..78a09fc 100644 --- a/src/nostr/policy/mod.rs +++ b/src/nostr/policy/mod.rs | |||
| @@ -20,6 +20,7 @@ pub use crate::git::sync::AlignmentResult; | |||
| 20 | 20 | ||
| 21 | use super::SharedDatabase; | 21 | use super::SharedDatabase; |
| 22 | use crate::purgatory::Purgatory; | 22 | use crate::purgatory::Purgatory; |
| 23 | use crate::sync::{AddFilters, RepoSyncIndex}; | ||
| 23 | use nostr_relay_builder::LocalRelay; | 24 | use nostr_relay_builder::LocalRelay; |
| 24 | use std::sync::Arc; | 25 | use std::sync::Arc; |
| 25 | 26 | ||
| @@ -34,6 +35,16 @@ pub struct PolicyContext { | |||
| 34 | pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, | 35 | pub local_relay: Arc<std::sync::RwLock<Option<LocalRelay>>>, |
| 35 | /// Configuration reference for policy settings (includes blacklists) | 36 | /// Configuration reference for policy settings (includes blacklists) |
| 36 | pub config: crate::config::Config, | 37 | pub config: crate::config::Config, |
| 38 | /// Optional repo sync index for triggering relay discovery when announcements | ||
| 39 | /// go to purgatory via user submission (not via the sync path). | ||
| 40 | /// Wrapped in Arc<RwLock> for interior mutability (PolicyContext is Clone). | ||
| 41 | pub repo_sync_index: Arc<std::sync::RwLock<Option<RepoSyncIndex>>>, | ||
| 42 | /// Optional sender for AddFilters actions to SyncManager. | ||
| 43 | /// Used to trigger relay discovery when user-submitted purgatory announcements | ||
| 44 | /// are registered with StateOnly sync level. | ||
| 45 | /// Wrapped in Arc<RwLock> for interior mutability (PolicyContext is Clone). | ||
| 46 | pub sync_action_tx: | ||
| 47 | Arc<std::sync::RwLock<Option<tokio::sync::mpsc::Sender<AddFilters>>>>, | ||
| 37 | } | 48 | } |
| 38 | 49 | ||
| 39 | impl PolicyContext { | 50 | impl PolicyContext { |
| @@ -51,6 +62,8 @@ impl PolicyContext { | |||
| 51 | purgatory, | 62 | purgatory, |
| 52 | local_relay: Arc::new(std::sync::RwLock::new(None)), | 63 | local_relay: Arc::new(std::sync::RwLock::new(None)), |
| 53 | config, | 64 | config, |
| 65 | repo_sync_index: Arc::new(std::sync::RwLock::new(None)), | ||
| 66 | sync_action_tx: Arc::new(std::sync::RwLock::new(None)), | ||
| 54 | } | 67 | } |
| 55 | } | 68 | } |
| 56 | 69 | ||
| @@ -68,4 +81,28 @@ impl PolicyContext { | |||
| 68 | let guard = self.local_relay.read().unwrap(); | 81 | let guard = self.local_relay.read().unwrap(); |
| 69 | guard.clone() | 82 | guard.clone() |
| 70 | } | 83 | } |
| 84 | |||
| 85 | /// Set the repo sync index for relay discovery from user-submitted purgatory announcements. | ||
| 86 | pub fn set_repo_sync_index(&self, index: RepoSyncIndex) { | ||
| 87 | let mut guard = self.repo_sync_index.write().unwrap(); | ||
| 88 | *guard = Some(index); | ||
| 89 | } | ||
| 90 | |||
| 91 | /// Get a clone of the repo sync index if it's been set. | ||
| 92 | pub fn get_repo_sync_index(&self) -> Option<RepoSyncIndex> { | ||
| 93 | let guard = self.repo_sync_index.read().unwrap(); | ||
| 94 | guard.clone() | ||
| 95 | } | ||
| 96 | |||
| 97 | /// Set the sync action sender for sending AddFilters actions to SyncManager. | ||
| 98 | pub fn set_sync_action_tx(&self, tx: tokio::sync::mpsc::Sender<AddFilters>) { | ||
| 99 | let mut guard = self.sync_action_tx.write().unwrap(); | ||
| 100 | *guard = Some(tx); | ||
| 101 | } | ||
| 102 | |||
| 103 | /// Get a clone of the sync action sender if it's been set. | ||
| 104 | pub fn get_sync_action_tx(&self) -> Option<tokio::sync::mpsc::Sender<AddFilters>> { | ||
| 105 | let guard = self.sync_action_tx.read().unwrap(); | ||
| 106 | guard.clone() | ||
| 107 | } | ||
| 71 | } | 108 | } |