Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 17, 2024
1 parent 9381b51 commit 9bed4bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions p2p/host/peerstore/pstoremem/addr_book.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func WithClock(clock clock) AddrBookOption {
}
}

// WithMaxAddresses sets the maximum number of unconnected addresses to store.
// The maximum number of connected addresses is bounded by the connection
// limits in the Connection Manager and Resource Manager.
func WithMaxAddresses(n int) AddrBookOption {
return func(b *memoryAddrBook) error {
b.maxUnconnectedAddrs = n
Expand Down
12 changes: 12 additions & 0 deletions p2p/host/peerstore/pstoremem/addr_book_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,18 @@ func TestPeerAddrsExpiry(t *testing.T) {
}
}

func TestPeerLimits(t *testing.T) {
ab := NewAddrBook()
defer ab.Close()
ab.maxUnconnectedAddrs = 1024

peers := peerAddrsInput(2048)
for _, p := range peers {
ab.AddAddr(p.Peer, p.Addr, p.TTL)
}
require.Equal(t, 1024, ab.addrs.NumUnconnectedAddrs())
}

func BenchmarkPeerAddrs(b *testing.B) {
sizes := [...]int{1, 10, 100, 1000, 10_000, 100_000, 1000_000}
for _, sz := range sizes {
Expand Down

0 comments on commit 9bed4bc

Please sign in to comment.