Skip to content

Commit

Permalink
peerstore: reduce default protocol limit to 128
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Jul 3, 2024
1 parent b36d2a7 commit 05ae6ad
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoreds/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewProtoBook(meta pstore.PeerMetadata, opts ...ProtoBookOption) (*dsProtoBo
}
return ret
}(),
maxProtos: 1024,
maxProtos: 128,
}

for _, opt := range opts {
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/peerstore/pstoremem/protobook.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewProtoBook(opts ...ProtoBookOption) (*memoryProtoBook, error) {
}
return ret
}(),
maxProtos: 1024,
maxProtos: 128,
}

for _, opt := range opts {
Expand Down
16 changes: 13 additions & 3 deletions p2p/protocol/identify/id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"math/rand"
"slices"
"sync"
"testing"
Expand Down Expand Up @@ -730,6 +731,15 @@ func TestLargeIdentifyMessage(t *testing.T) {
}
}

func randString(n int) string {
chars := "abcdefghijklmnopqrstuvwxyz"
buf := make([]byte, n)
for i := 0; i < n; i++ {
buf[i] = chars[rand.Intn(len(chars))]
}
return string(buf)
}

func TestLargePushMessage(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand All @@ -738,9 +748,9 @@ func TestLargePushMessage(t *testing.T) {
h2 := blhost.NewBlankHost(swarmt.GenSwarm(t))

// add protocol strings to make the message larger
// about 2K of protocol strings
for i := 0; i < 500; i++ {
r := protocol.ID(fmt.Sprintf("rand%d", i))
// about 3K of protocol strings
for i := 0; i < 100; i++ {
r := protocol.ID(fmt.Sprintf("%s-%d", randString(30), i))
h1.SetStreamHandler(r, func(network.Stream) {})
h2.SetStreamHandler(r, func(network.Stream) {})
}
Expand Down

0 comments on commit 05ae6ad

Please sign in to comment.