@@ -100,12 +100,12 @@ export class PersistentStore {
100
100
const buf = await this . datastore . get ( key )
101
101
const peer = PeerPB . decode ( buf )
102
102
103
- if ( this . #peerIsExpired( peer ) ) {
103
+ if ( this . #peerIsExpired( peerId , peer ) ) {
104
104
await this . datastore . delete ( key )
105
105
throw new NotFoundError ( )
106
106
}
107
107
108
- return pbToPeer ( peerId , peer , this . maxAddressAge )
108
+ return pbToPeer ( peerId , peer , this . peerId . equals ( peerId ) ? Infinity : this . maxAddressAge )
109
109
}
110
110
111
111
async save ( peerId : PeerId , data : PeerData ) : Promise < PeerUpdate > {
@@ -152,12 +152,12 @@ export class PersistentStore {
152
152
const peer = PeerPB . decode ( value )
153
153
154
154
// remove expired peer
155
- if ( this . #peerIsExpired( peer ) ) {
155
+ if ( this . #peerIsExpired( peerId , peer ) ) {
156
156
await this . datastore . delete ( key )
157
157
continue
158
158
}
159
159
160
- yield pbToPeer ( peerId , peer , this . maxAddressAge )
160
+ yield pbToPeer ( peerId , peer , this . peerId . equals ( peerId ) ? Infinity : this . maxAddressAge )
161
161
}
162
162
}
163
163
@@ -168,7 +168,7 @@ export class PersistentStore {
168
168
const peerPB = PeerPB . decode ( buf )
169
169
170
170
// remove expired peer
171
- if ( this . #peerIsExpired( peerPB ) ) {
171
+ if ( this . #peerIsExpired( peerId , peerPB ) ) {
172
172
await this . datastore . delete ( key )
173
173
throw new NotFoundError ( )
174
174
}
@@ -198,11 +198,15 @@ export class PersistentStore {
198
198
}
199
199
}
200
200
201
- #peerIsExpired ( peer : PeerPB ) : boolean {
201
+ #peerIsExpired ( peerId : PeerId , peer : PeerPB ) : boolean {
202
202
if ( peer . updated == null ) {
203
203
return true
204
204
}
205
205
206
+ if ( this . peerId . equals ( peerId ) ) {
207
+ return false
208
+ }
209
+
206
210
const expired = peer . updated < ( Date . now ( ) - this . maxPeerAge )
207
211
const minAddressObserved = Date . now ( ) - this . maxAddressAge
208
212
const addrs = peer . addresses . filter ( addr => {
0 commit comments