From 82ef9f1e486e71e06d6e59a2b84d2bdee9517949 Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Thu, 4 Aug 2022 23:04:51 +0800 Subject: [PATCH] Bring Back Mplex (#11169) * bring back * fix mod --- beacon-chain/p2p/BUILD.bazel | 1 + beacon-chain/p2p/options.go | 3 +++ beacon-chain/p2p/options_test.go | 24 ++++++++++++++++++++++++ go.mod | 1 + go.sum | 1 + 5 files changed, 30 insertions(+) diff --git a/beacon-chain/p2p/BUILD.bazel b/beacon-chain/p2p/BUILD.bazel index b8823d000f57..7baae4fc7315 100644 --- a/beacon-chain/p2p/BUILD.bazel +++ b/beacon-chain/p2p/BUILD.bazel @@ -78,6 +78,7 @@ go_library( "@com_github_kr_pretty//:go_default_library", "@com_github_libp2p_go_libp2p//:go_default_library", "@com_github_libp2p_go_libp2p//config:go_default_library", + "@com_github_libp2p_go_libp2p//p2p/muxer/mplex:go_default_library", "@com_github_libp2p_go_libp2p//p2p/protocol/identify:go_default_library", "@com_github_libp2p_go_libp2p//p2p/security/noise:go_default_library", "@com_github_libp2p_go_libp2p//p2p/transport/tcp:go_default_library", diff --git a/beacon-chain/p2p/options.go b/beacon-chain/p2p/options.go index 3d88150d61a5..54edb82958a8 100644 --- a/beacon-chain/p2p/options.go +++ b/beacon-chain/p2p/options.go @@ -7,6 +7,7 @@ import ( "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/peer" + "github.com/libp2p/go-libp2p/p2p/muxer/mplex" noise "github.com/libp2p/go-libp2p/p2p/security/noise" "github.com/libp2p/go-libp2p/p2p/transport/tcp" ma "github.com/multiformats/go-multiaddr" @@ -47,6 +48,8 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt libp2p.UserAgent(version.BuildData()), libp2p.ConnectionGater(s), libp2p.Transport(tcp.NewTCPTransport), + libp2p.Muxer("/mplex/6.7.0", mplex.DefaultTransport), + libp2p.DefaultMuxers, } options = append(options, libp2p.Security(noise.ID, noise.New)) diff --git a/beacon-chain/p2p/options_test.go b/beacon-chain/p2p/options_test.go index 94a81b1b59ac..7d11b4b2bdc7 100644 --- a/beacon-chain/p2p/options_test.go +++ b/beacon-chain/p2p/options_test.go @@ -10,7 +10,9 @@ import ( gethCrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/enr" + "github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p-core/crypto" + mock "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing" "github.com/prysmaticlabs/prysm/config/params" ecdsaprysm "github.com/prysmaticlabs/prysm/crypto/ecdsa" "github.com/prysmaticlabs/prysm/testing/assert" @@ -74,3 +76,25 @@ func TestIPV6Support(t *testing.T) { t.Error("Multiaddress did not have ipv6 protocol") } } + +func TestDefaultMultiplexers(t *testing.T) { + var cfg libp2p.Config + _ = cfg + p2pCfg := &Config{ + TCPPort: 2000, + UDPPort: 2000, + StateNotifier: &mock.MockStateNotifier{}, + } + svc := &Service{cfg: p2pCfg} + var err error + svc.privKey, err = privKey(svc.cfg) + assert.NoError(t, err) + ipAddr := ipAddr() + opts := svc.buildOptions(ipAddr, svc.privKey) + err = cfg.Apply(append(opts, libp2p.FallbackDefaults)...) + assert.NoError(t, err) + + assert.Equal(t, "/mplex/6.7.0", cfg.Muxers[0].ID) + assert.Equal(t, "/yamux/1.0.0", cfg.Muxers[1].ID) + +} diff --git a/go.mod b/go.mod index 0fc55c70c585..1188983d97b0 100644 --- a/go.mod +++ b/go.mod @@ -161,6 +161,7 @@ require ( github.com/libp2p/go-libp2p-asn-util v0.2.0 // indirect github.com/libp2p/go-libp2p-resource-manager v0.3.0 // indirect github.com/libp2p/go-libp2p-testing v0.9.2 // indirect + github.com/libp2p/go-mplex v0.7.0 // indirect github.com/libp2p/go-msgio v0.2.0 // indirect github.com/libp2p/go-nat v0.1.0 // indirect github.com/libp2p/go-netroute v0.2.0 // indirect diff --git a/go.sum b/go.sum index 7772b1cb2ea2..d8480a38264f 100644 --- a/go.sum +++ b/go.sum @@ -800,6 +800,7 @@ github.com/libp2p/go-libp2p-transport-upgrader v0.7.0/go.mod h1:GIR2aTRp1J5yjVlk github.com/libp2p/go-libp2p-yamux v0.8.0/go.mod h1:yTkPgN2ib8FHyU1ZcVD7aelzyAqXXwEPbyx+aSKm9h8= github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU= github.com/libp2p/go-mplex v0.4.0/go.mod h1:y26Lx+wNVtMYMaPu300Cbot5LkEZ4tJaNYeHeT9dh6E= +github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY= github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.0.6/go.mod h1:4ecVB6d9f4BDSL5fqvPiC4A3KivjWn+Venn/1ALLMWA=