@@ -7,7 +7,7 @@ use std::ops::Deref;
77use std:: sync:: Arc ;
88
99use nostr:: prelude:: * ;
10- use nostr_gossip:: { BestRelaySelection , NostrGossip } ;
10+ use nostr_gossip:: { BestRelaySelection , GossipAllowedRelays , NostrGossip } ;
1111
1212use crate :: client:: options:: GossipRelayLimits ;
1313use crate :: client:: Error ;
@@ -48,15 +48,18 @@ impl GossipWrapper {
4848 & self ,
4949 public_keys : I ,
5050 selection : BestRelaySelection ,
51+ allowed : GossipAllowedRelays ,
5152 ) -> Result < HashSet < RelayUrl > , Error >
5253 where
5354 I : IntoIterator < Item = & ' a PublicKey > ,
5455 {
5556 let mut urls: HashSet < RelayUrl > = HashSet :: new ( ) ;
5657
5758 for public_key in public_keys. into_iter ( ) {
58- let relays: HashSet < RelayUrl > =
59- self . gossip . get_best_relays ( public_key, selection) . await ?;
59+ let relays: HashSet < RelayUrl > = self
60+ . gossip
61+ . get_best_relays ( public_key, selection, allowed)
62+ . await ?;
6063 urls. extend ( relays) ;
6164 }
6265
@@ -67,15 +70,18 @@ impl GossipWrapper {
6770 & self ,
6871 public_keys : I ,
6972 selection : BestRelaySelection ,
73+ allowed : GossipAllowedRelays ,
7074 ) -> Result < HashMap < RelayUrl , BTreeSet < PublicKey > > , Error >
7175 where
7276 I : IntoIterator < Item = & ' a PublicKey > ,
7377 {
7478 let mut urls: HashMap < RelayUrl , BTreeSet < PublicKey > > = HashMap :: new ( ) ;
7579
7680 for public_key in public_keys. into_iter ( ) {
77- let relays: HashSet < RelayUrl > =
78- self . gossip . get_best_relays ( public_key, selection) . await ?;
81+ let relays: HashSet < RelayUrl > = self
82+ . gossip
83+ . get_best_relays ( public_key, selection, allowed)
84+ . await ?;
7985
8086 for url in relays. into_iter ( ) {
8187 urls. entry ( url)
@@ -95,6 +101,7 @@ impl GossipWrapper {
95101 filter : Filter ,
96102 pattern : GossipFilterPattern ,
97103 limits : & GossipRelayLimits ,
104+ allowed : GossipAllowedRelays ,
98105 ) -> Result < BrokenDownFilters , Error > {
99106 // Extract `p` tag from generic tags and parse public key hex
100107 let p_tag: Option < BTreeSet < PublicKey > > = filter. generic_tags . get ( & P_TAG ) . map ( |s| {
@@ -113,6 +120,7 @@ impl GossipWrapper {
113120 BestRelaySelection :: Write {
114121 limit : limits. write_relays_per_user ,
115122 } ,
123+ allowed,
116124 )
117125 . await ?;
118126
@@ -123,6 +131,7 @@ impl GossipWrapper {
123131 BestRelaySelection :: Hints {
124132 limit : limits. hint_relays_per_user ,
125133 } ,
134+ allowed,
126135 )
127136 . await ?;
128137
@@ -133,6 +142,7 @@ impl GossipWrapper {
133142 BestRelaySelection :: MostReceived {
134143 limit : limits. most_used_relays_per_user ,
135144 } ,
145+ allowed,
136146 )
137147 . await ?;
138148
@@ -148,6 +158,7 @@ impl GossipWrapper {
148158 BestRelaySelection :: PrivateMessage {
149159 limit : limits. nip17_relays ,
150160 } ,
161+ allowed,
151162 )
152163 . await ?;
153164
@@ -181,6 +192,7 @@ impl GossipWrapper {
181192 BestRelaySelection :: Read {
182193 limit : limits. read_relays_per_user ,
183194 } ,
195+ allowed,
184196 )
185197 . await ?;
186198
@@ -191,6 +203,7 @@ impl GossipWrapper {
191203 BestRelaySelection :: Hints {
192204 limit : limits. hint_relays_per_user ,
193205 } ,
206+ allowed,
194207 )
195208 . await ?;
196209
@@ -201,6 +214,7 @@ impl GossipWrapper {
201214 BestRelaySelection :: MostReceived {
202215 limit : limits. most_used_relays_per_user ,
203216 } ,
217+ allowed,
204218 )
205219 . await ?;
206220
@@ -217,6 +231,7 @@ impl GossipWrapper {
217231 BestRelaySelection :: PrivateMessage {
218232 limit : limits. nip17_relays ,
219233 } ,
234+ allowed,
220235 )
221236 . await ?;
222237
@@ -257,6 +272,7 @@ impl GossipWrapper {
257272 hints : limits. hint_relays_per_user ,
258273 most_received : limits. most_used_relays_per_user ,
259274 } ,
275+ allowed,
260276 )
261277 . await ?;
262278
@@ -269,6 +285,7 @@ impl GossipWrapper {
269285 BestRelaySelection :: PrivateMessage {
270286 limit : limits. nip17_relays ,
271287 } ,
288+ allowed,
272289 )
273290 . await ?;
274291
@@ -400,6 +417,7 @@ mod tests {
400417 filter. clone ( ) ,
401418 GossipFilterPattern :: Nip65 ,
402419 & GossipRelayLimits :: default ( ) ,
420+ GossipAllowedRelays :: default ( ) ,
403421 )
404422 . await
405423 . unwrap ( )
@@ -420,6 +438,7 @@ mod tests {
420438 authors_filter. clone ( ) ,
421439 GossipFilterPattern :: Nip65 ,
422440 & GossipRelayLimits :: default ( ) ,
441+ GossipAllowedRelays :: default ( ) ,
423442 )
424443 . await
425444 . unwrap ( )
@@ -455,6 +474,7 @@ mod tests {
455474 search_filter. clone ( ) ,
456475 GossipFilterPattern :: Nip65 ,
457476 & GossipRelayLimits :: default ( ) ,
477+ GossipAllowedRelays :: default ( ) ,
458478 )
459479 . await
460480 . unwrap ( )
@@ -472,6 +492,7 @@ mod tests {
472492 p_tag_filter. clone ( ) ,
473493 GossipFilterPattern :: Nip65 ,
474494 & GossipRelayLimits :: default ( ) ,
495+ GossipAllowedRelays :: default ( ) ,
475496 )
476497 . await
477498 . unwrap ( )
@@ -497,6 +518,7 @@ mod tests {
497518 filter. clone ( ) ,
498519 GossipFilterPattern :: Nip65 ,
499520 & GossipRelayLimits :: default ( ) ,
521+ GossipAllowedRelays :: default ( ) ,
500522 )
501523 . await
502524 . unwrap ( )
@@ -521,6 +543,7 @@ mod tests {
521543 filter. clone ( ) ,
522544 GossipFilterPattern :: Nip65 ,
523545 & GossipRelayLimits :: default ( ) ,
546+ GossipAllowedRelays :: default ( ) ,
524547 )
525548 . await
526549 . unwrap ( )
0 commit comments