p2p: add libp2p feature flag (#8410)

This commit is contained in:
Sam Kleinman
2022-04-25 11:47:31 -04:00
committed by GitHub
parent a4190208a3
commit 19ba3c6375
4 changed files with 42 additions and 0 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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) {

View File

@@ -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 {