Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swarm: deprecate libp2p.DialRanker option #2430

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
sukunrt marked this conversation as resolved.
Show resolved Hide resolved
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("dial ranker cannot be nil")
sukunrt marked this conversation as resolved.
Show resolved Hide resolved
}
s.dialRanker = d
return nil
}
Expand Down