-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
p2p/net/swarm/swarm.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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
// 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 | ||
} | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
53bc6d2
to
74594e9
Compare
fixes #2398