-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 |
||
return func(s *Swarm) error { | ||
if c == nil { | ||
return errors.New("udp black hole config cannot be nil") | ||
} | ||
s.udpBlackHoleConfig = c | ||
return nil | ||
} | ||
} | ||
|
||
// WithIPv6BlackHoleConfig configures swarm to use c as the config for IPv6 black hole detection | ||
func WithIPv6BlackHoleConfig(c *BlackHoleConfig) Option { | ||
return func(s *Swarm) error { | ||
if c == nil { | ||
return errors.New("ipv6 black hole config cannot be nil") | ||
} | ||
s.ipv6BlackHoleConfig = c | ||
return nil | ||
} | ||
} | ||
|
||
// Swarm is a connection muxer, allowing connections to other peers to | ||
// be opened and closed, while still using the same Chan for all | ||
// communication. The Chan sends/receives Messages, which note the | ||
|
@@ -174,7 +196,9 @@ type Swarm struct { | |
|
||
dialRanker network.DialRanker | ||
|
||
bhd *blackHoleDetector | ||
udpBlackHoleConfig *BlackHoleConfig | ||
ipv6BlackHoleConfig *BlackHoleConfig | ||
bhd *blackHoleDetector | ||
} | ||
|
||
// NewSwarm constructs a Swarm. | ||
|
@@ -194,6 +218,12 @@ func NewSwarm(local peer.ID, peers peerstore.Peerstore, eventBus event.Bus, opts | |
dialTimeoutLocal: defaultDialTimeoutLocal, | ||
maResolver: madns.DefaultResolver, | ||
dialRanker: DefaultDialRanker, | ||
|
||
// A black hole is a binary property. On a network if UDP dials are blocked or there is | ||
// no IPv6 connectivity, all dials will fail. So a low success rate of 5 out 100 dials | ||
// is good enough. | ||
udpBlackHoleConfig: &BlackHoleConfig{Enabled: true, N: 100, MinSuccesses: 5}, | ||
ipv6BlackHoleConfig: &BlackHoleConfig{Enabled: true, N: 10, MinSuccesses: 5}, | ||
} | ||
|
||
s.conns.m = make(map[peer.ID][]*Conn) | ||
|
@@ -215,7 +245,7 @@ func NewSwarm(local peer.ID, peers peerstore.Peerstore, eventBus event.Bus, opts | |
s.limiter = newDialLimiter(s.dialAddr) | ||
s.backf.init(s.ctx) | ||
|
||
s.bhd = newBlackHoleDetector(true, true, s.metricsTracer) | ||
s.bhd = newBlackHoleDetector(s.udpBlackHoleConfig, s.ipv6BlackHoleConfig, s.metricsTracer) | ||
|
||
return s, nil | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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