lib/config, lib/discover: Support new discovery cluster (ref #4618)

This adds one new feature, that discovery servers can have ?nolookup to
be used only for announces. The default set of discovery servers is
changed to:

- discovery.s.n used for lookups. This is dual stack load balanced over
  all discovery servers, and returns both IPv4 and IPV6 results when they
  exist.

- discovery-v4.s.n used for announces. This has IPv4 addresses only and
  the discovery servers will update the unspecified address with the IPv4
  source address, as usual.

- discovery-v6.s.n which is exactly the same for IPv6.

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4647
This commit is contained in:
Jakob Borg
2018-01-05 14:18:32 +00:00
committed by Audrius Butkevicius
parent e6551c8485
commit 992bb0a98c
2 changed files with 19 additions and 8 deletions

View File

@@ -30,6 +30,7 @@ type globalClient struct {
announceClient httpClient
queryClient httpClient
noAnnounce bool
noLookup bool
stop chan struct{}
errorHolder
}
@@ -52,6 +53,7 @@ type announcement struct {
type serverOptions struct {
insecure bool // don't check certificate
noAnnounce bool // don't announce
noLookup bool // don't use for lookups
id string // expected server device ID
}
@@ -119,15 +121,26 @@ func NewGlobal(server string, cert tls.Certificate, addrList AddressLister) (Fin
announceClient: announceClient,
queryClient: queryClient,
noAnnounce: opts.noAnnounce,
noLookup: opts.noLookup,
stop: make(chan struct{}),
}
cl.setError(errors.New("not announced"))
if !opts.noAnnounce {
// If we are supposed to annonce, it's an error until we've done so.
cl.setError(errors.New("not announced"))
}
return cl, nil
}
// Lookup returns the list of addresses where the given device is available
func (c *globalClient) Lookup(device protocol.DeviceID) (addresses []string, err error) {
if c.noLookup {
return nil, lookupError{
error: errors.New("lookups not supported"),
cacheFor: time.Hour,
}
}
qURL, err := url.Parse(c.server)
if err != nil {
return nil, err
@@ -201,7 +214,6 @@ func (c *globalClient) Serve() {
}
func (c *globalClient) sendAnnouncement(timer *time.Timer) {
var ann announcement
if c.addrList != nil {
ann.Addresses = c.addrList.ExternalAddresses()
@@ -287,6 +299,7 @@ func parseOptions(dsn string) (server string, opts serverOptions, err error) {
opts.id = q.Get("id")
opts.insecure = opts.id != "" || queryBool(q, "insecure")
opts.noAnnounce = queryBool(q, "noannounce")
opts.noLookup = queryBool(q, "nolookup")
// Check for disallowed combinations
if p.Scheme == "http" {