Skip to content

Commit

Permalink
chore: remove unused peer state fields
Browse files Browse the repository at this point in the history
save some memory
  • Loading branch information
2color committed Dec 4, 2024
1 parent c812cf4 commit 8646f38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
10 changes: 3 additions & 7 deletions cached_addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ const (
)

type peerState struct {
lastConnTime time.Time // last time we successfully connected to this peer
lastConnAddr ma.Multiaddr // last address we connected to this peer on
returnCount int // number of times we've returned this peer from the cache
lastReturnTime time.Time // last time we returned this peer from the cache
connectFailures int // number of times we've failed to connect to this peer
lastConnTime time.Time // last time we successfully connected to this peer
returnCount int // number of times we've returned this peer from the cache
connectFailures int // number of times we've failed to connect to this peer
}

type cachedAddrBook struct {
Expand Down Expand Up @@ -140,7 +138,6 @@ func (cab *cachedAddrBook) background(ctx context.Context, host host.Host) {
peerStateSize.Set(float64(len(cab.peers)))
}
pState.lastConnTime = time.Now()
pState.lastConnAddr = ev.Conn.RemoteMultiaddr()
pState.connectFailures = 0 // reset connect failures on successful connection
cab.mu.Unlock()

Expand Down Expand Up @@ -265,7 +262,6 @@ func (cab *cachedAddrBook) GetCachedAddrs(p *peer.ID) []types.Multiaddr {
peerStateSize.Set(float64(len(cab.peers)))
}
cab.peers[*p].returnCount++
cab.peers[*p].lastReturnTime = time.Now()
cab.mu.Unlock()

var result []types.Multiaddr // convert to local Multiaddr type 🙃
Expand Down
2 changes: 0 additions & 2 deletions cached_addr_book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestGetCachedAddrs(t *testing.T) {

// Verify return count and time were updated
assert.Equal(t, 1, cab.peers[testPeer].returnCount)
assert.False(t, cab.peers[testPeer].lastReturnTime.IsZero())
}

func TestBackground(t *testing.T) {
Expand Down Expand Up @@ -122,7 +121,6 @@ func TestBackground(t *testing.T) {
peerState, exists := cab.peers[testPeer]
assert.True(t, exists)
assert.NotNil(t, peerState)
assert.Equal(t, addr, peerState.lastConnAddr)
cab.mu.RUnlock()
}

Expand Down

0 comments on commit 8646f38

Please sign in to comment.