mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-28 10:00:21 +00:00
p2p: add libp2p feature flag (#8410)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user