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:
committed by
Jakob Borg
parent
09832abe50
commit
674fc566bb
@@ -15,13 +15,13 @@ import (
|
||||
)
|
||||
|
||||
func TestCacheUnique(t *testing.T) {
|
||||
direct0 := []string{"tcp://192.0.2.44:22000", "tcp://192.0.2.42:22000"} // prio 0
|
||||
direct1 := []string{"tcp://192.0.2.43:22000", "tcp://192.0.2.42:22000"} // prio 1
|
||||
addresses0 := []string{"tcp://192.0.2.44:22000", "tcp://192.0.2.42:22000"} // prio 0
|
||||
addresses1 := []string{"tcp://192.0.2.43:22000", "tcp://192.0.2.42:22000"} // prio 1
|
||||
|
||||
// what we expect from just direct0
|
||||
direct0Sorted := []string{"tcp://192.0.2.42:22000", "tcp://192.0.2.44:22000"}
|
||||
// what we expect from just addresses0
|
||||
addresses0Sorted := []string{"tcp://192.0.2.42:22000", "tcp://192.0.2.44:22000"}
|
||||
|
||||
// what we expect from direct0+direct1
|
||||
// what we expect from addresses0+addresses1
|
||||
totalSorted := []string{
|
||||
// first prio 0, sorted
|
||||
"tcp://192.0.2.42:22000", "tcp://192.0.2.44:22000",
|
||||
@@ -30,8 +30,6 @@ func TestCacheUnique(t *testing.T) {
|
||||
// no duplicate .42
|
||||
}
|
||||
|
||||
relays := []Relay{{URL: "relay://192.0.2.44:443"}, {URL: "tcp://192.0.2.45:443"}}
|
||||
|
||||
c := NewCachingMux()
|
||||
c.(*cachingMux).ServeBackground()
|
||||
defer c.Stop()
|
||||
@@ -39,45 +37,38 @@ func TestCacheUnique(t *testing.T) {
|
||||
// Add a fake discovery service and verify we get it's answers through the
|
||||
// cache.
|
||||
|
||||
f1 := &fakeDiscovery{direct0, relays}
|
||||
f1 := &fakeDiscovery{addresses0}
|
||||
c.Add(f1, time.Minute, 0, 0)
|
||||
|
||||
dir, rel, err := c.Lookup(protocol.LocalDeviceID)
|
||||
addr, err := c.Lookup(protocol.LocalDeviceID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(dir, direct0Sorted) {
|
||||
t.Errorf("Incorrect direct; %+v != %+v", dir, direct0Sorted)
|
||||
}
|
||||
if !reflect.DeepEqual(rel, relays) {
|
||||
t.Errorf("Incorrect relays; %+v != %+v", rel, relays)
|
||||
if !reflect.DeepEqual(addr, addresses0Sorted) {
|
||||
t.Errorf("Incorrect addresses; %+v != %+v", addr, addresses0Sorted)
|
||||
}
|
||||
|
||||
// Add one more that answers in the same way and check that we don't
|
||||
// duplicate or otherwise mess up the responses now.
|
||||
|
||||
f2 := &fakeDiscovery{direct1, relays}
|
||||
f2 := &fakeDiscovery{addresses1}
|
||||
c.Add(f2, time.Minute, 0, 1)
|
||||
|
||||
dir, rel, err = c.Lookup(protocol.LocalDeviceID)
|
||||
addr, err = c.Lookup(protocol.LocalDeviceID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(dir, totalSorted) {
|
||||
t.Errorf("Incorrect direct; %+v != %+v", dir, totalSorted)
|
||||
}
|
||||
if !reflect.DeepEqual(rel, relays) {
|
||||
t.Errorf("Incorrect relays; %+v != %+v", rel, relays)
|
||||
if !reflect.DeepEqual(addr, totalSorted) {
|
||||
t.Errorf("Incorrect addresses; %+v != %+v", addr, totalSorted)
|
||||
}
|
||||
}
|
||||
|
||||
type fakeDiscovery struct {
|
||||
direct []string
|
||||
relays []Relay
|
||||
addresses []string
|
||||
}
|
||||
|
||||
func (f *fakeDiscovery) Lookup(deviceID protocol.DeviceID) (direct []string, relays []Relay, err error) {
|
||||
return f.direct, f.relays, nil
|
||||
func (f *fakeDiscovery) Lookup(deviceID protocol.DeviceID) (addresses []string, err error) {
|
||||
return f.addresses, nil
|
||||
}
|
||||
|
||||
func (f *fakeDiscovery) Error() error {
|
||||
@@ -126,10 +117,10 @@ type slowDiscovery struct {
|
||||
started chan struct{}
|
||||
}
|
||||
|
||||
func (f *slowDiscovery) Lookup(deviceID protocol.DeviceID) (direct []string, relays []Relay, err error) {
|
||||
func (f *slowDiscovery) Lookup(deviceID protocol.DeviceID) (addresses []string, err error) {
|
||||
close(f.started)
|
||||
time.Sleep(f.delay)
|
||||
return nil, nil, nil
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (f *slowDiscovery) Error() error {
|
||||
|
||||
Reference in New Issue
Block a user