Skip to content

Commit

Permalink
swarm: deprecate libp2p.DialRanker option (#2430)
Browse files Browse the repository at this point in the history
* swarm: deprecate libp2p.DialRanker option

* remove whitespace diff

* Apply suggestions from code review

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
  • Loading branch information
sukunrt and marten-seemann authored Jul 14, 2023
1 parent 70c19cb commit 381f230
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 381f230

Please sign in to comment.