make sure that all static relay servers are used
@@ -24,6 +24,7 @@ type config struct {
maxAttempts int
// Number of relays we strive to obtain a reservation with.
desiredRelays int
+ setMinCandidates bool
}
var defaultConfig = config{
@@ -35,6 +36,8 @@ var defaultConfig = config{
desiredRelays: 2,
}
+var errStaticRelaysMinCandidates = errors.New("cannot use WithMinCandidates and WithStaticRelays")
+
// DefaultRelays are the known PL-operated v1 relays; will be decommissioned in 2022.
var DefaultRelays = []string{
"/ip4/147.75.80.110/tcp/4001/p2p/QmbFgm5zan8P6eWWmeyfncR5feYEMPbht5b1FW1C37aQ7y",
@@ -61,9 +64,13 @@ type Option func(*config) error
func WithStaticRelays(static []peer.AddrInfo) Option {
return func(c *config) error {
+ if c.setMinCandidates {
+ return errStaticRelaysMinCandidates
+ }
if len(c.staticRelays) > 0 {
return errors.New("can't set static relays, static relays already configured")
}
+ c.minCandidates = len(static)
c.staticRelays = static
return nil
}
@@ -101,7 +108,11 @@ func WithMaxCandidates(n int) Option {
// This is to make sure that we don't just randomly connect to the first candidate that we discover.
func WithMinCandidates(n int) Option {
return func(c *config) error {
+ if len(c.staticRelays) > 0 {
+ return errStaticRelaysMinCandidates
+ }
c.minCandidates = n
+ c.setMinCandidates = true
return nil
}
}
