diff --git a/config/config.go b/config/config.go index 500e3f7d6..5769c458b 100644 --- a/config/config.go +++ b/config/config.go @@ -674,6 +674,11 @@ type P2PConfig struct { //nolint: maligned // layer uses. Options are: "fifo" and "priority", // with the default being "priority". QueueType string `mapstructure:"queue-type"` + + // UseLibP2P switches to using the new networking layer based + // on libp2p. This option is unlikely to persist into a + // release of tendermint, but will ease the transition. + UseLibP2P bool `mapstructure:"experimental-use-lib-p2p"` } // DefaultP2PConfig returns a default configuration for the peer-to-peer layer diff --git a/internal/p2p/router.go b/internal/p2p/router.go index ca9536900..69f2b6277 100644 --- a/internal/p2p/router.go +++ b/internal/p2p/router.go @@ -72,6 +72,10 @@ type RouterOptions struct { // are used to dial peers. This defaults to the value of // runtime.NumCPU. NumConcurrentDials func() int + + // UseLibP2P toggles the use of the new networking layer + // within the router. + UseLibP2P bool } const ( @@ -191,6 +195,10 @@ func NewRouter( return nil, err } + if options.UseLibP2P { + return nil, errors.New("libp2p is not supported") + } + router := &Router{ logger: logger, metrics: metrics, diff --git a/internal/p2p/router_test.go b/internal/p2p/router_test.go index 7ef77a16d..67a47b44a 100644 --- a/internal/p2p/router_test.go +++ b/internal/p2p/router_test.go @@ -26,6 +26,34 @@ import ( "github.com/tendermint/tendermint/types" ) +func TestRouterConstruction(t *testing.T) { + opts := p2p.RouterOptions{UseLibP2P: true} + if err := opts.Validate(); err != nil { + t.Fatalf("options should validate: %v", err) + } + logger := log.NewNopLogger() + metrics := p2p.NopMetrics() + + router, err := p2p.NewRouter( + logger, + metrics, + nil, // privkey + nil, // peermanager + func() *types.NodeInfo { return &types.NodeInfo{} }, + []p2p.Transport{}, + []p2p.Endpoint{}, + opts, + ) + if err == nil { + t.Error("support for libp2p does not exist, and should prevent the router from being constructed") + } else if err.Error() != "libp2p is not supported" { + t.Errorf("incorrect error: %q", err.Error()) + } + if router != nil { + t.Error("router was constructed when it should not have been") + } +} + func echoReactor(ctx context.Context, channel *p2p.Channel) { iter := channel.Receive(ctx) for iter.Next(ctx) { diff --git a/node/node.go b/node/node.go index 5c63a3253..a3ded847e 100644 --- a/node/node.go +++ b/node/node.go @@ -716,6 +716,7 @@ func loadStateFromDBOrGenesisDocProvider(stateStore sm.Store, genDoc *types.Gene func getRouterConfig(conf *config.Config, appClient abciclient.Client) p2p.RouterOptions { opts := p2p.RouterOptions{ QueueType: conf.P2P.QueueType, + UseLibP2P: conf.P2P.UseLibP2P, } if conf.FilterPeers && appClient != nil {