upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sync/subscription.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-05 16:37:09 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-05 16:37:09 +0000
commitb4da09689ee0bd6ac327a6ed7ffb01e2175e2596 (patch)
treecb662fb7da60568a959c75526c501ba76c0f4043 /src/sync/subscription.rs
parentb7aa7b72c189290b45fb388ec1826862bc8dda49 (diff)
remove stupid tests and methods
Diffstat (limited to 'src/sync/subscription.rs')
-rw-r--r--src/sync/subscription.rs71
1 files changed, 11 insertions, 60 deletions
diff --git a/src/sync/subscription.rs b/src/sync/subscription.rs
index c37404f..bbeaa2a 100644
--- a/src/sync/subscription.rs
+++ b/src/sync/subscription.rs
@@ -26,12 +26,6 @@ use super::filter::FilterService;
26/// Maximum number of filters before consolidation is triggered 26/// Maximum number of filters before consolidation is triggered
27const CONSOLIDATION_THRESHOLD: usize = 150; 27const CONSOLIDATION_THRESHOLD: usize = 150;
28 28
29/// Kind 30617 - Repository Announcement (NIP-34)
30const KIND_REPOSITORY_ANNOUNCEMENT: u16 = 30617;
31
32/// Kind 30618 - Maintainer List (NIP-34)
33const KIND_MAINTAINER_LIST: u16 = 30618;
34
35/// Manages subscriptions for a single relay connection 29/// Manages subscriptions for a single relay connection
36/// 30///
37/// Tracks which announcements and events have been subscribed to, 31/// Tracks which announcements and events have been subscribed to,
@@ -113,10 +107,7 @@ impl SubscriptionManager {
113 107
114 // Build Layer 3 filter for this event 108 // Build Layer 3 filter for this event
115 // Layer 3 filters target events with 'e' tags pointing to this event 109 // Layer 3 filters target events with 'e' tags pointing to this event
116 let filter = Filter::new().custom_tag( 110 let filter = Filter::new().custom_tag(SingleLetterTag::lowercase(Alphabet::E), event_id);
117 SingleLetterTag::lowercase(Alphabet::E),
118 event_id,
119 );
120 111
121 Some(vec![filter]) 112 Some(vec![filter])
122 } 113 }
@@ -212,67 +203,27 @@ impl SubscriptionManager {
212 } 203 }
213 }; 204 };
214 205
215 // Determine the kind for the coordinate 206 // Verify this is an announcement kind
216 let kind = event.kind.as_u16(); 207 if !matches!(event.kind, Kind::GitRepoAnnouncement | Kind::RepoState) {
217 if kind != KIND_REPOSITORY_ANNOUNCEMENT && kind != KIND_MAINTAINER_LIST {
218 tracing::warn!( 208 tracing::warn!(
219 "Event {} is not an announcement (kind {}), cannot build Layer 2 filter", 209 "Event {} is not an announcement (kind {}), cannot build Layer 2 filter",
220 event.id.to_hex(), 210 event.id.to_hex(),
221 kind 211 event.kind
222 ); 212 );
223 return Vec::new(); 213 return Vec::new();
224 } 214 }
225 215
226 // Build the addressable coordinate: kind:pubkey:identifier 216 // Build the addressable coordinate: kind:pubkey:identifier
227 let coord = format!("{}:{}:{}", kind, event.pubkey.to_hex(), identifier); 217 let coord = format!(
218 "{}:{}:{}",
219 event.kind.as_u16(),
220 event.pubkey.to_hex(),
221 identifier
222 );
228 223
229 // Create filter with 'a' tag for this coordinate 224 // Create filter with 'a' tag for this coordinate
230 let filter = Filter::new().custom_tag( 225 let filter = Filter::new().custom_tag(SingleLetterTag::lowercase(Alphabet::A), coord);
231 SingleLetterTag::lowercase(Alphabet::A),
232 coord,
233 );
234 226
235 vec![filter] 227 vec![filter]
236 } 228 }
237
238 /// Check if an event kind is an announcement kind
239 pub fn is_announcement_kind(kind: u16) -> bool {
240 kind == KIND_REPOSITORY_ANNOUNCEMENT || kind == KIND_MAINTAINER_LIST
241 }
242
243 /// Check if an event kind is a PR/Issue/Patch kind that should trigger Layer 3
244 pub fn is_pr_issue_kind(kind: u16) -> bool {
245 matches!(
246 kind,
247 1617 | // Patch proposal (NIP-34)
248 1618 | // PR
249 1619 | // PR Update
250 1621 | // Issue
251 1622 // Reply
252 )
253 }
254} 229}
255
256#[cfg(test)]
257mod tests {
258 use super::SubscriptionManager;
259
260 #[test]
261 fn test_is_announcement_kind() {
262 assert!(SubscriptionManager::is_announcement_kind(30617));
263 assert!(SubscriptionManager::is_announcement_kind(30618));
264 assert!(!SubscriptionManager::is_announcement_kind(1));
265 assert!(!SubscriptionManager::is_announcement_kind(1617));
266 }
267
268 #[test]
269 fn test_is_pr_issue_kind() {
270 assert!(SubscriptionManager::is_pr_issue_kind(1617));
271 assert!(SubscriptionManager::is_pr_issue_kind(1618));
272 assert!(SubscriptionManager::is_pr_issue_kind(1619));
273 assert!(SubscriptionManager::is_pr_issue_kind(1621));
274 assert!(SubscriptionManager::is_pr_issue_kind(1622));
275 assert!(!SubscriptionManager::is_pr_issue_kind(30617));
276 assert!(!SubscriptionManager::is_pr_issue_kind(1));
277 }
278} \ No newline at end of file