From fef81410410c8b246a11df49c3091a1373c218c4 Mon Sep 17 00:00:00 2001 From: millken Date: Tue, 30 Jan 2024 08:51:39 +0800 Subject: [PATCH] [p2p]Add p2p MaxMessageSize config (#4071) --- go.mod | 2 +- go.sum | 4 ++-- p2p/agent.go | 3 +++ p2p/agent_test.go | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2ef4239240..3a82316f2e 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/hashicorp/vault/api v1.1.0 github.com/holiman/uint256 v1.2.0 github.com/iotexproject/go-fsm v1.0.0 - github.com/iotexproject/go-p2p v0.3.5 + github.com/iotexproject/go-p2p v0.3.6 github.com/iotexproject/go-pkgs v0.1.13 github.com/iotexproject/iotex-address v0.2.8 github.com/iotexproject/iotex-antenna-go/v2 v2.5.1 diff --git a/go.sum b/go.sum index 590c5aad8c..d3dd8f2965 100644 --- a/go.sum +++ b/go.sum @@ -649,8 +649,8 @@ github.com/iotexproject/go-ethereum v1.7.4-0.20230806203205-6819e8158a5f h1:9+i3 github.com/iotexproject/go-ethereum v1.7.4-0.20230806203205-6819e8158a5f/go.mod h1:it7x0DWnTDMfVFdXcU6Ti4KEFQynLHVRarcSlPr0HBo= github.com/iotexproject/go-fsm v1.0.0 h1:Zrg9JnNDUZg4Anpj6oa0Tk4+sXbHTpJzI0v5/Cj5N6A= github.com/iotexproject/go-fsm v1.0.0/go.mod h1:t3aYXtCCcQxyS7oduQZyuUpPnVI4ddFTwbAagHN7fT0= -github.com/iotexproject/go-p2p v0.3.5 h1:F71XxYQtR25youD+dCXnMgtfiCKGUFh8KDIqU7u5xOk= -github.com/iotexproject/go-p2p v0.3.5/go.mod h1:P32N/mwLUWMQ/okMcNLlfBO7iD5ITyBOvN41roKdPdg= +github.com/iotexproject/go-p2p v0.3.6 h1:AhCq0d6ytoNlcT+tOcqZV0W0Slolsf1FoMbyxxgsAhM= +github.com/iotexproject/go-p2p v0.3.6/go.mod h1:P32N/mwLUWMQ/okMcNLlfBO7iD5ITyBOvN41roKdPdg= github.com/iotexproject/go-pkgs v0.1.5-0.20210604060651-be5ee19f2575/go.mod h1:ttXhcwrtODyh7JozpJlCml09CjP0pcKqTe2B0MbTGc8= github.com/iotexproject/go-pkgs v0.1.12/go.mod h1:t5X9kQ1VL5H+L+DC5GmohXnFKlcxaTcRnIBBuydcsTQ= github.com/iotexproject/go-pkgs v0.1.13 h1:bK48DVenkfYkC4TRoqL77RLFRBE1MUfscCW495kzcC8= diff --git a/p2p/agent.go b/p2p/agent.go index 8604abc4ff..16cca0ee2c 100644 --- a/p2p/agent.go +++ b/p2p/agent.go @@ -94,6 +94,7 @@ type ( EnableRateLimit bool `yaml:"enableRateLimit"` PrivateNetworkPSK string `yaml:"privateNetworkPSK"` MaxPeers int `yaml:"maxPeers"` + MaxMessageSize int `yaml:"maxMessageSize"` } // Agent is the agent to help the blockchain node connect into the P2P networks and send/receive messages @@ -143,6 +144,7 @@ var DefaultConfig = Config{ EnableRateLimit: true, PrivateNetworkPSK: "", MaxPeers: 30, + MaxMessageSize: p2p.DefaultConfig.MaxMessageSize, } // NewDummyAgent creates a dummy p2p agent @@ -214,6 +216,7 @@ func (p *agent) Start(ctx context.Context) error { p2p.DHTProtocolID(p.chainID), p2p.DHTGroupID(p.chainID), p2p.WithMaxPeer(uint32(p.cfg.MaxPeers)), + p2p.WithMaxMessageSize(p.cfg.MaxMessageSize), } if p.cfg.EnableRateLimit { opts = append(opts, p2p.WithRateLimit(p.cfg.RateLimit)) diff --git a/p2p/agent_test.go b/p2p/agent_test.go index 3ba93b8c35..b59246d044 100644 --- a/p2p/agent_test.go +++ b/p2p/agent_test.go @@ -82,6 +82,7 @@ func TestBroadcast(t *testing.T) { Port: port, BootstrapNodes: []string{bootnodeAddr[0].String()}, ReconnectInterval: 150 * time.Second, + MaxMessageSize: p2p.DefaultConfig.MaxMessageSize, }, 1, hash.ZeroHash256, b, u) agent.Start(ctx) agents = append(agents, agent)