diff --git a/config/config.go b/config/config.go index b529ec1c51..cea8ef1314 100644 --- a/config/config.go +++ b/config/config.go @@ -178,12 +178,9 @@ func (cfg *Config) makeSwarm(eventBus event.Bus, enableMetrics bool) (*swarm.Swa if cfg.MultiaddrResolver != nil { opts = append(opts, swarm.WithMultiaddrResolver(cfg.MultiaddrResolver)) } - - dialRanker := cfg.DialRanker - if dialRanker == nil { - dialRanker = swarm.DefaultDialRanker + if cfg.DialRanker != nil { + opts = append(opts, swarm.WithDialRanker(cfg.DialRanker)) } - opts = append(opts, swarm.WithDialRanker(dialRanker)) if enableMetrics { opts = append(opts, diff --git a/options.go b/options.go index 3e072b950c..beb4930f7c 100644 --- a/options.go +++ b/options.go @@ -579,6 +579,7 @@ func PrometheusRegisterer(reg prometheus.Registerer) Option { // DialRanker configures libp2p to use d as the dial ranker. To enable smart // dialing use `swarm.DefaultDialRanker`. use `swarm.NoDelayDialRanker` to // disable smart dialing. +// Deprecated: use SwarmOpts(swarm.WithDialRanker(d)) instead func DialRanker(d network.DialRanker) Option { return func(cfg *Config) error { if cfg.DialRanker != nil { diff --git a/p2p/net/swarm/swarm.go b/p2p/net/swarm/swarm.go index 9dfab2d9c0..4bc16a7d31 100644 --- a/p2p/net/swarm/swarm.go +++ b/p2p/net/swarm/swarm.go @@ -103,6 +103,9 @@ func WithResourceManager(m network.ResourceManager) Option { // WithDialRanker configures swarm to use d as the DialRanker func WithDialRanker(d network.DialRanker) Option { return func(s *Swarm) error { + if d == nil { + return errors.New("swarm: dial ranker cannot be nil") + } s.dialRanker = d return nil }