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: make black hole detection configurable #2403

Merged
merged 2 commits into from
Jul 7, 2023

Conversation

sukunrt
Copy link
Member

@sukunrt sukunrt commented Jun 29, 2023

fixes #2398

@@ -108,6 +108,28 @@ func WithDialRanker(d network.DialRanker) Option {
}
}

// WithUDPBlackHoleConfig configures swarm to use c as the config for UDP black hole detection
func WithUDPBlackHoleConfig(c *BlackHoleConfig) Option {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could just make these 3 function parameters:

func WithUDPBlackHoleConfig(enabled bool, n, min int)

and then make BlackHoleConfig an unexported struct.

options.go Outdated
Comment on lines 592 to 612
// UDPBlackHoleConfig configures libp2p to use c as the config for UDP black hole detection
func UDPBlackHoleConfig(c *swarm.BlackHoleConfig) Option {
return func(cfg *Config) error {
if c == nil {
return errors.New("udp black hole config cannot be nil")
}
cfg.UDPBlackHoleConfig = c
return nil
}
}

// IPv6BlackHoleConfig configures libp2p to use c as the config for IPv6 black hole detection
func IPv6BlackHoleConfig(c *swarm.BlackHoleConfig) Option {
return func(cfg *Config) error {
if c == nil {
return errors.New("ipv6 black hole config cannot be nil")
}
cfg.IPv6BlackHoleConfig = c
return nil
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about making this more general by having a SwarmOpts(opts ...swarm.Option) Option here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your suggestion is right. I did it this way because none of the other swarm.Options were exposed here. We should also fix the other cases like this one https://github.com/libp2p/go-libp2p/blob/master/config/config.go#L176

@marten-seemann marten-seemann merged commit 757bf59 into master Jul 7, 2023
19 checks passed
@MarcoPolo MarcoPolo mentioned this pull request Jul 14, 2023
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

swarm: add config options for blackhole detection
2 participants