From 4f8a466b4cf3da8df34ea2cf26b4045aa435f2bb Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 14 Sep 2022 21:01:55 +0300 Subject: [PATCH] noise: use a 2 kb buffer for all handshake operations --- p2p/security/noise/handshake.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/p2p/security/noise/handshake.go b/p2p/security/noise/handshake.go index db782aace6..f60fdaf975 100644 --- a/p2p/security/noise/handshake.go +++ b/p2p/security/noise/handshake.go @@ -10,8 +10,6 @@ import ( "runtime/debug" "time" - "golang.org/x/crypto/chacha20poly1305" - "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/security/noise/pb" @@ -73,12 +71,8 @@ func (s *secureSession) runHandshake(ctx context.Context) (err error) { } } - // We can re-use this buffer for all handshake messages as its size - // will be the size of the maximum handshake message for the Noise XX pattern. - // Also, since we prefix every noise handshake message with its length, we need to account for - // it when we fetch the buffer from the pool - maxMsgSize := 2*noise.DH25519.DHLen() + 2*chacha20poly1305.Overhead + 1024 /* payload */ - hbuf := pool.Get(maxMsgSize + LengthPrefixLength) + // We can re-use this buffer for all handshake messages. + hbuf := pool.Get(2 << 10) defer pool.Put(hbuf) if s.initiator {