Skip to content

Commit

Permalink
Use NextExpiry instead of Peek
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Sep 14, 2024
1 parent f7be8ee commit d517ab9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions p2p/host/peerstore/pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ func (pa *peerAddrs) FindAddr(p peer.ID, addrBytes ma.Multiaddr) (*expiringAddr,
return nil, false
}

func (pa *peerAddrs) Peek() *expiringAddr {
return pa.expiringHeap[len(pa.expiringHeap)-1]
func (pa *peerAddrs) NextExpiry() time.Time {
if len(pa.expiringHeap) == 0 {
return time.Time{}
}
return pa.expiringHeap[len(pa.expiringHeap)-1].Expires
}

func (pa *peerAddrs) gc(now time.Time) {
for len(pa.expiringHeap) > 0 && pa.Peek().ExpiredBy(now) {
for len(pa.expiringHeap) > 0 && now.After(pa.NextExpiry()) {
heap.Pop(pa)
}
}
Expand Down

0 comments on commit d517ab9

Please sign in to comment.