From 5f9c1fec5aba7bef4d4313c7d9dac27b53561ec6 Mon Sep 17 00:00:00 2001 From: sukun Date: Sun, 8 Dec 2024 14:10:46 +0530 Subject: [PATCH] remove the pool for expiringAddrs --- p2p/host/peerstore/pstoremem/addr_book.go | 28 ++--------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/p2p/host/peerstore/pstoremem/addr_book.go b/p2p/host/peerstore/pstoremem/addr_book.go index 2520f6ef22..32758f2ab9 100644 --- a/p2p/host/peerstore/pstoremem/addr_book.go +++ b/p2p/host/peerstore/pstoremem/addr_book.go @@ -42,22 +42,6 @@ func ttlIsConnected(ttl time.Duration) bool { return ttl >= peerstore.ConnectedAddrTTL } -var expiringAddrPool = sync.Pool{New: func() any { return &expiringAddr{} }} - -func getExpiringAddrs() *expiringAddr { - a := expiringAddrPool.Get().(*expiringAddr) - a.heapIndex = -1 - return a -} - -func putExpiringAddrs(ea *expiringAddr) { - if ea == nil { - return - } - *ea = expiringAddr{} - expiringAddrPool.Put(ea) -} - type peerRecordState struct { Envelope *record.Envelope Seq uint64 @@ -280,7 +264,6 @@ func (mab *memoryAddrBook) gc() { if !ok { return } - putExpiringAddrs(ea) mab.maybeDeleteSignedPeerRecordUnlocked(ea.Peer) } } @@ -382,8 +365,7 @@ func (mab *memoryAddrBook) addAddrsUnlocked(p peer.ID, addrs []ma.Multiaddr, ttl a, found := mab.addrs.FindAddr(p, addr) if !found { // not found, announce it. - entry := getExpiringAddrs() - *entry = expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} + entry := &expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} mab.addrs.Insert(entry) mab.subManager.BroadcastAddr(p, addr) } else { @@ -433,7 +415,6 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du if ttl > 0 { if a.IsConnected() && !ttlIsConnected(ttl) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { a.Addr = addr a.Expiry = exp @@ -443,15 +424,13 @@ func (mab *memoryAddrBook) SetAddrs(p peer.ID, addrs []ma.Multiaddr, ttl time.Du } } else { mab.addrs.Delete(a) - putExpiringAddrs(a) } } else { if ttl > 0 { if !ttlIsConnected(ttl) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { continue } - entry := getExpiringAddrs() - *entry = expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} + entry := &expiringAddr{Addr: addr, Expiry: exp, TTL: ttl, Peer: p} mab.addrs.Insert(entry) mab.subManager.BroadcastAddr(p, addr) } @@ -472,12 +451,10 @@ func (mab *memoryAddrBook) UpdateAddrs(p peer.ID, oldTTL time.Duration, newTTL t if oldTTL == a.TTL { if newTTL == 0 { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { // We are over limit, drop these addresses. if ttlIsConnected(oldTTL) && !ttlIsConnected(newTTL) && mab.addrs.NumUnconnectedAddrs() >= mab.maxUnconnectedAddrs { mab.addrs.Delete(a) - putExpiringAddrs(a) } else { a.TTL = newTTL a.Expiry = exp @@ -541,7 +518,6 @@ func (mab *memoryAddrBook) ClearAddrs(p peer.ID) { delete(mab.signedPeerRecords, p) for _, a := range mab.addrs.Addrs[p] { mab.addrs.Delete(a) - putExpiringAddrs(a) } }