lib/connections: Refactor

1. Removes separate relay lists and relay clients/services, just makes it a listen address
2. Easier plugging-in of other transports
3. Allows "hot" disabling and enabling NAT services
4. Allows "hot" listen address changes
5. Changes listen address list with a preferable "default" value just like for discovery
6. Debounces global discovery announcements as external addresses change (which it might alot upon starting)
7. Stops this whole "pick other peers relay by latency". This information is no longer available,
   but I don't think it matters as most of the time other peer only has one relay.
8. Rename ListenAddress to ListenAddresses, as well as in javascript land.
9. Stop serializing deprecated values to JSON

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/2982
This commit is contained in:
Audrius Butkevicius
2016-05-04 19:38:12 +00:00
committed by Jakob Borg
parent 09832abe50
commit 674fc566bb
45 changed files with 1683 additions and 1707 deletions

View File

@@ -25,6 +25,7 @@ type dynamicClient struct {
timeout time.Duration
mut sync.RWMutex
err error
client RelayClient
stop chan struct{}
}
@@ -61,6 +62,7 @@ func (c *dynamicClient) Serve() {
data, err := http.Get(uri.String())
if err != nil {
l.Debugln(c, "failed to lookup dynamic relays", err)
c.setError(err)
return
}
@@ -69,6 +71,7 @@ func (c *dynamicClient) Serve() {
data.Body.Close()
if err != nil {
l.Debugln(c, "failed to lookup dynamic relays", err)
c.setError(err)
return
}
@@ -89,6 +92,7 @@ func (c *dynamicClient) Serve() {
select {
case <-c.stop:
l.Debugln(c, "stopping")
c.setError(nil)
return
default:
ruri, err := url.Parse(addr)
@@ -112,6 +116,7 @@ func (c *dynamicClient) Serve() {
}
}
l.Debugln(c, "could not find a connectable relay")
c.setError(fmt.Errorf("could not find a connectable relay"))
}
func (c *dynamicClient) Stop() {
@@ -124,13 +129,13 @@ func (c *dynamicClient) Stop() {
c.client.Stop()
}
func (c *dynamicClient) StatusOK() bool {
func (c *dynamicClient) Error() error {
c.mut.RLock()
defer c.mut.RUnlock()
if c.client == nil {
return false
return c.err
}
return c.client.StatusOK()
return c.client.Error()
}
func (c *dynamicClient) Latency() time.Duration {
@@ -150,7 +155,7 @@ func (c *dynamicClient) URI() *url.URL {
c.mut.RLock()
defer c.mut.RUnlock()
if c.client == nil {
return c.pooladdr
return nil
}
return c.client.URI()
}
@@ -171,6 +176,12 @@ func (c *dynamicClient) cleanup() {
c.mut.Unlock()
}
func (c *dynamicClient) setError(err error) {
c.mut.Lock()
c.err = err
c.mut.Unlock()
}
// This is the announcement recieved from the relay server;
// {"relays": [{"url": "relay://10.20.30.40:5060"}, ...]}
type dynamicAnnouncement struct {