@@ -8,7 +8,7 @@ use std::sync::atomic::{AtomicU64, Ordering};
88use std:: sync:: Arc ;
99
1010use nostr:: prelude:: * ;
11- use nostr_gossip:: { BestRelaySelection , NostrGossip } ;
11+ use nostr_gossip:: { BestRelaySelection , GossipAllowedRelays , NostrGossip } ;
1212
1313use crate :: client:: options:: GossipRelayLimits ;
1414use crate :: client:: Error ;
@@ -58,15 +58,18 @@ impl GossipWrapper {
5858 & self ,
5959 public_keys : I ,
6060 selection : BestRelaySelection ,
61+ allowed : GossipAllowedRelays ,
6162 ) -> Result < HashSet < RelayUrl > , Error >
6263 where
6364 I : IntoIterator < Item = & ' a PublicKey > ,
6465 {
6566 let mut urls: HashSet < RelayUrl > = HashSet :: new ( ) ;
6667
6768 for public_key in public_keys. into_iter ( ) {
68- let relays: HashSet < RelayUrl > =
69- self . gossip . get_best_relays ( public_key, selection) . await ?;
69+ let relays: HashSet < RelayUrl > = self
70+ . gossip
71+ . get_best_relays ( public_key, selection, allowed)
72+ . await ?;
7073 urls. extend ( relays) ;
7174 }
7275
@@ -77,15 +80,18 @@ impl GossipWrapper {
7780 & self ,
7881 public_keys : I ,
7982 selection : BestRelaySelection ,
83+ allowed : GossipAllowedRelays ,
8084 ) -> Result < HashMap < RelayUrl , BTreeSet < PublicKey > > , Error >
8185 where
8286 I : IntoIterator < Item = & ' a PublicKey > ,
8387 {
8488 let mut urls: HashMap < RelayUrl , BTreeSet < PublicKey > > = HashMap :: new ( ) ;
8589
8690 for public_key in public_keys. into_iter ( ) {
87- let relays: HashSet < RelayUrl > =
88- self . gossip . get_best_relays ( public_key, selection) . await ?;
91+ let relays: HashSet < RelayUrl > = self
92+ . gossip
93+ . get_best_relays ( public_key, selection, allowed)
94+ . await ?;
8995
9096 for url in relays. into_iter ( ) {
9197 urls. entry ( url)
@@ -105,6 +111,7 @@ impl GossipWrapper {
105111 filter : Filter ,
106112 pattern : GossipFilterPattern ,
107113 limits : & GossipRelayLimits ,
114+ allowed : GossipAllowedRelays ,
108115 ) -> Result < BrokenDownFilters , Error > {
109116 // Extract `p` tag from generic tags and parse public key hex
110117 let p_tag: Option < BTreeSet < PublicKey > > = filter. generic_tags . get ( & P_TAG ) . map ( |s| {
@@ -123,6 +130,7 @@ impl GossipWrapper {
123130 BestRelaySelection :: Write {
124131 limit : limits. write_relays_per_user ,
125132 } ,
133+ allowed,
126134 )
127135 . await ?;
128136
@@ -133,6 +141,7 @@ impl GossipWrapper {
133141 BestRelaySelection :: Hints {
134142 limit : limits. hint_relays_per_user ,
135143 } ,
144+ allowed,
136145 )
137146 . await ?;
138147
@@ -143,6 +152,7 @@ impl GossipWrapper {
143152 BestRelaySelection :: MostReceived {
144153 limit : limits. most_used_relays_per_user ,
145154 } ,
155+ allowed,
146156 )
147157 . await ?;
148158
@@ -158,6 +168,7 @@ impl GossipWrapper {
158168 BestRelaySelection :: PrivateMessage {
159169 limit : limits. nip17_relays ,
160170 } ,
171+ allowed,
161172 )
162173 . await ?;
163174
@@ -191,6 +202,7 @@ impl GossipWrapper {
191202 BestRelaySelection :: Read {
192203 limit : limits. read_relays_per_user ,
193204 } ,
205+ allowed,
194206 )
195207 . await ?;
196208
@@ -201,6 +213,7 @@ impl GossipWrapper {
201213 BestRelaySelection :: Hints {
202214 limit : limits. hint_relays_per_user ,
203215 } ,
216+ allowed,
204217 )
205218 . await ?;
206219
@@ -211,6 +224,7 @@ impl GossipWrapper {
211224 BestRelaySelection :: MostReceived {
212225 limit : limits. most_used_relays_per_user ,
213226 } ,
227+ allowed,
214228 )
215229 . await ?;
216230
@@ -227,6 +241,7 @@ impl GossipWrapper {
227241 BestRelaySelection :: PrivateMessage {
228242 limit : limits. nip17_relays ,
229243 } ,
244+ allowed,
230245 )
231246 . await ?;
232247
@@ -267,6 +282,7 @@ impl GossipWrapper {
267282 hints : limits. hint_relays_per_user ,
268283 most_received : limits. most_used_relays_per_user ,
269284 } ,
285+ allowed,
270286 )
271287 . await ?;
272288
@@ -279,6 +295,7 @@ impl GossipWrapper {
279295 BestRelaySelection :: PrivateMessage {
280296 limit : limits. nip17_relays ,
281297 } ,
298+ allowed,
282299 )
283300 . await ?;
284301
@@ -410,6 +427,7 @@ mod tests {
410427 filter. clone ( ) ,
411428 GossipFilterPattern :: Nip65 ,
412429 & GossipRelayLimits :: default ( ) ,
430+ GossipAllowedRelays :: default ( ) ,
413431 )
414432 . await
415433 . unwrap ( )
@@ -430,6 +448,7 @@ mod tests {
430448 authors_filter. clone ( ) ,
431449 GossipFilterPattern :: Nip65 ,
432450 & GossipRelayLimits :: default ( ) ,
451+ GossipAllowedRelays :: default ( ) ,
433452 )
434453 . await
435454 . unwrap ( )
@@ -465,6 +484,7 @@ mod tests {
465484 search_filter. clone ( ) ,
466485 GossipFilterPattern :: Nip65 ,
467486 & GossipRelayLimits :: default ( ) ,
487+ GossipAllowedRelays :: default ( ) ,
468488 )
469489 . await
470490 . unwrap ( )
@@ -482,6 +502,7 @@ mod tests {
482502 p_tag_filter. clone ( ) ,
483503 GossipFilterPattern :: Nip65 ,
484504 & GossipRelayLimits :: default ( ) ,
505+ GossipAllowedRelays :: default ( ) ,
485506 )
486507 . await
487508 . unwrap ( )
@@ -507,6 +528,7 @@ mod tests {
507528 filter. clone ( ) ,
508529 GossipFilterPattern :: Nip65 ,
509530 & GossipRelayLimits :: default ( ) ,
531+ GossipAllowedRelays :: default ( ) ,
510532 )
511533 . await
512534 . unwrap ( )
@@ -531,6 +553,7 @@ mod tests {
531553 filter. clone ( ) ,
532554 GossipFilterPattern :: Nip65 ,
533555 & GossipRelayLimits :: default ( ) ,
556+ GossipAllowedRelays :: default ( ) ,
534557 )
535558 . await
536559 . unwrap ( )
0 commit comments