@@ -24,8 +24,7 @@ pub(crate) enum GossipKind {
2424}
2525
2626impl GossipKind {
27- #[ allow( clippy:: wrong_self_convention) ]
28- pub ( crate ) fn to_event_kind ( self ) -> Kind {
27+ pub ( crate ) fn to_event_kind ( & self ) -> Kind {
2928 match self {
3029 Self :: Nip17 => Kind :: InboxRelays ,
3130 Self :: Nip65 => Kind :: RelayList ,
@@ -48,6 +47,8 @@ struct RelayList<T> {
4847 pub collection : T ,
4948 /// Timestamp of when the event metadata was created
5049 pub event_created_at : Timestamp ,
50+ /// Timestamp of the last check
51+ pub last_check : Option < Timestamp > ,
5152 /// Timestamp of when the metadata was updated
5253 pub last_update : Timestamp ,
5354}
@@ -56,8 +57,6 @@ struct RelayList<T> {
5657struct RelayLists {
5758 pub nip17 : RelayList < HashSet < RelayUrl > > ,
5859 pub nip65 : RelayList < HashMap < RelayUrl , Option < RelayMetadata > > > ,
59- /// Timestamp of the last check
60- pub last_check : Timestamp ,
6160}
6261
6362type PublicKeyMap = HashMap < PublicKey , RelayLists > ;
@@ -117,6 +116,7 @@ impl Gossip {
117116 MAX_RELAYS_PER_NIP65_MARKER ,
118117 ) ,
119118 event_created_at : event. created_at ,
119+ last_check : None ,
120120 last_update : Timestamp :: now ( ) ,
121121 } ;
122122 }
@@ -125,6 +125,7 @@ impl Gossip {
125125 nip65 : RelayList {
126126 collection : extract_nip65_relay_list ( event, MAX_RELAYS_PER_NIP65_MARKER ) ,
127127 event_created_at : event. created_at ,
128+ last_check : None ,
128129 last_update : Timestamp :: now ( ) ,
129130 } ,
130131 ..Default :: default ( )
@@ -141,6 +142,7 @@ impl Gossip {
141142 . cloned ( )
142143 . collect ( ) ,
143144 event_created_at : event. created_at ,
145+ last_check : None ,
144146 last_update : Timestamp :: now ( ) ,
145147 } ;
146148 }
@@ -152,6 +154,7 @@ impl Gossip {
152154 . cloned ( )
153155 . collect ( ) ,
154156 event_created_at : event. created_at ,
157+ last_check : None ,
155158 last_update : Timestamp :: now ( ) ,
156159 } ,
157160 ..Default :: default ( )
@@ -172,11 +175,7 @@ impl Gossip {
172175 for public_key in public_keys. into_iter ( ) {
173176 match map. get ( & public_key) {
174177 Some ( lists) => {
175- if lists. last_check + CHECK_OUTDATED_INTERVAL > now {
176- continue ;
177- }
178-
179- let ( empty, expired) = match kind {
178+ let ( last_check, empty, expired) = match kind {
180179 GossipKind :: Nip17 => {
181180 // Check if the collection is empty
182181 let empty: bool = lists. nip17 . collection . is_empty ( ) ;
@@ -185,7 +184,7 @@ impl Gossip {
185184 let expired: bool =
186185 lists. nip17 . last_update + PUBKEY_METADATA_OUTDATED_AFTER < now;
187186
188- ( empty, expired)
187+ ( lists . nip17 . last_check . unwrap_or_default ( ) , empty, expired)
189188 }
190189 GossipKind :: Nip65 => {
191190 // Check if the collection is empty
@@ -195,10 +194,14 @@ impl Gossip {
195194 let expired: bool =
196195 lists. nip65 . last_update + PUBKEY_METADATA_OUTDATED_AFTER < now;
197196
198- ( empty, expired)
197+ ( lists . nip65 . last_check . unwrap_or_default ( ) , empty, expired)
199198 }
200199 } ;
201200
201+ if last_check + CHECK_OUTDATED_INTERVAL > now {
202+ continue ;
203+ }
204+
202205 if empty || expired {
203206 outdated. insert ( public_key) ;
204207 }
@@ -213,7 +216,7 @@ impl Gossip {
213216 outdated
214217 }
215218
216- pub async fn update_last_check < I > ( & self , public_keys : I )
219+ pub async fn update_last_check < I > ( & self , public_keys : I , kind : & GossipKind )
217220 where
218221 I : IntoIterator < Item = PublicKey > ,
219222 {
@@ -222,12 +225,19 @@ impl Gossip {
222225
223226 for public_key in public_keys. into_iter ( ) {
224227 map. entry ( public_key)
225- . and_modify ( |lists| {
226- lists. last_check = now;
228+ . and_modify ( |lists| match kind {
229+ GossipKind :: Nip17 => lists. nip17 . last_check = Some ( now) ,
230+ GossipKind :: Nip65 => lists. nip65 . last_check = Some ( now) ,
227231 } )
228- . or_insert_with ( || RelayLists {
229- last_check : now,
230- ..Default :: default ( )
232+ . or_insert_with ( || {
233+ let mut lists = RelayLists :: default ( ) ;
234+
235+ match kind {
236+ GossipKind :: Nip17 => lists. nip17 . last_check = Some ( now) ,
237+ GossipKind :: Nip65 => lists. nip65 . last_check = Some ( now) ,
238+ }
239+
240+ lists
231241 } ) ;
232242 }
233243 }
0 commit comments