gui: Add addresses for disconnected devices (fixes #3340)
Also fixes an issue where the discovery cache call would only return the newest cache entry for a given device instead of the merged addresses from all cache entries (which is more useful). GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3344
This commit is contained in:
parent
b0d03d1f1c
commit
ac3b03881a
@ -544,13 +544,17 @@
|
|||||||
<th><span class="fa fa-fw fa-cloud-upload"></span> <span translate>Upload Rate</span></th>
|
<th><span class="fa fa-fw fa-cloud-upload"></span> <span translate>Upload Rate</span></th>
|
||||||
<td class="text-right">{{connections[deviceCfg.deviceID].outbps | binary}}B/s ({{connections[deviceCfg.deviceID].outBytesTotal | binary}}B)</td>
|
<td class="text-right">{{connections[deviceCfg.deviceID].outbps | binary}}B/s ({{connections[deviceCfg.deviceID].outBytesTotal | binary}}B)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr ng-if="connections[deviceCfg.deviceID].connected">
|
<tr>
|
||||||
<th><span class="fa fa-fw fa-link"></span> <span translate>Address</span></th>
|
<th><span class="fa fa-fw fa-link"></span> <span translate>Address</span></th>
|
||||||
<td class="text-right">
|
<td ng-if="connections[deviceCfg.deviceID].connected" class="text-right">
|
||||||
<span tooltip data-original-title="{{ connections[deviceCfg.deviceID].type.indexOf('Relay') > -1 ? '' : connections[deviceCfg.deviceID].type }}">
|
<span tooltip data-original-title="{{ connections[deviceCfg.deviceID].type.indexOf('Relay') > -1 ? '' : connections[deviceCfg.deviceID].type }}">
|
||||||
{{deviceAddr(deviceCfg)}}
|
{{deviceAddr(deviceCfg)}}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
<td ng-if="!connections[deviceCfg.deviceID].connected" class="text-right">
|
||||||
|
<span ng-repeat="addr in deviceCfg.addresses"><span tooltip data-original-title="{{'Configured' | translate}}">{{addr}}</span><br></span>
|
||||||
|
<span ng-repeat="addr in discoveryCache[deviceCfg.deviceID].addresses"><span tooltip data-original-title="{{'Discovered' | translate}}">{{addr}}</span><br></span>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr ng-if="connections[deviceCfg.deviceID].connected && connections[deviceCfg.deviceID].type.indexOf('Relay') > -1" tooltip data-original-title="Connections via relays might be rate limited by the relay">
|
<tr ng-if="connections[deviceCfg.deviceID].connected && connections[deviceCfg.deviceID].type.indexOf('Relay') > -1" tooltip data-original-title="Connections via relays might be rate limited by the relay">
|
||||||
<th><span class="fa fa-fw fa-warning text-danger"></span> <span translate>Connection Type</span></th>
|
<th><span class="fa fa-fw fa-warning text-danger"></span> <span translate>Connection Type</span></th>
|
||||||
|
|||||||
@ -29,6 +29,7 @@ angular.module('syncthing.core')
|
|||||||
$scope.myID = '';
|
$scope.myID = '';
|
||||||
$scope.devices = [];
|
$scope.devices = [];
|
||||||
$scope.deviceRejections = {};
|
$scope.deviceRejections = {};
|
||||||
|
$scope.discoveryCache = {};
|
||||||
$scope.folderRejections = {};
|
$scope.folderRejections = {};
|
||||||
$scope.protocolChanged = false;
|
$scope.protocolChanged = false;
|
||||||
$scope.reportData = {};
|
$scope.reportData = {};
|
||||||
@ -85,6 +86,7 @@ angular.module('syncthing.core')
|
|||||||
console.log('UIOnline');
|
console.log('UIOnline');
|
||||||
|
|
||||||
refreshSystem();
|
refreshSystem();
|
||||||
|
refreshDiscoveryCache();
|
||||||
refreshConfig();
|
refreshConfig();
|
||||||
refreshConnectionStats();
|
refreshConnectionStats();
|
||||||
refreshDeviceStats();
|
refreshDeviceStats();
|
||||||
@ -418,6 +420,22 @@ angular.module('syncthing.core')
|
|||||||
}).error($scope.emitHTTPError);
|
}).error($scope.emitHTTPError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function refreshDiscoveryCache() {
|
||||||
|
$http.get(urlbase + '/system/discovery').success(function (data) {
|
||||||
|
for (var device in data) {
|
||||||
|
for (var i = 0; i < data[device].addresses.length; i++) {
|
||||||
|
// Relay addresses are URLs with
|
||||||
|
// .../?foo=barlongstuff that we strip away here. We
|
||||||
|
// remove the final slash as well for symmetry with
|
||||||
|
// tcp://192.0.2.42:1234 type addresses.
|
||||||
|
data[device].addresses[i] = data[device].addresses[i].replace(/\/\?.*/, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$scope.discoveryCache = data;
|
||||||
|
console.log("refreshDiscoveryCache", data);
|
||||||
|
}).error($scope.emitHTTPError);
|
||||||
|
}
|
||||||
|
|
||||||
function recalcLocalStateTotal () {
|
function recalcLocalStateTotal () {
|
||||||
$scope.localStateTotal = {
|
$scope.localStateTotal = {
|
||||||
bytes: 0,
|
bytes: 0,
|
||||||
@ -609,6 +627,7 @@ angular.module('syncthing.core')
|
|||||||
|
|
||||||
$scope.refresh = function () {
|
$scope.refresh = function () {
|
||||||
refreshSystem();
|
refreshSystem();
|
||||||
|
refreshDiscoveryCache();
|
||||||
refreshConnectionStats();
|
refreshConnectionStats();
|
||||||
refreshErrors();
|
refreshErrors();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/protocol"
|
"github.com/syncthing/syncthing/lib/protocol"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
"github.com/thejerf/suture"
|
"github.com/thejerf/suture"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -165,12 +166,17 @@ func (m *cachingMux) Cache() map[protocol.DeviceID]CacheEntry {
|
|||||||
|
|
||||||
m.mut.RLock()
|
m.mut.RLock()
|
||||||
for i := range m.finders {
|
for i := range m.finders {
|
||||||
// Each finder[i] has a corresponding cache at cache[i]. Go through it
|
// Each finder[i] has a corresponding cache at cache[i]. Go through
|
||||||
// and populate the total, if it's newer than what's already in there.
|
// it and populate the total, appending any addresses and keeping
|
||||||
// We skip any negative cache entries.
|
// the newest "when" time. We skip any negative cache entries.
|
||||||
for k, v := range m.caches[i].Cache() {
|
for k, v := range m.caches[i].Cache() {
|
||||||
if v.found && v.when.After(res[k].when) {
|
if v.found {
|
||||||
res[k] = v
|
cur := res[k]
|
||||||
|
if v.when.After(cur.when) {
|
||||||
|
cur.when = v.when
|
||||||
|
}
|
||||||
|
cur.Addresses = append(cur.Addresses, v.Addresses...)
|
||||||
|
res[k] = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,13 +184,23 @@ func (m *cachingMux) Cache() map[protocol.DeviceID]CacheEntry {
|
|||||||
// finder is a global discovery client, it will have no cache. If it's
|
// finder is a global discovery client, it will have no cache. If it's
|
||||||
// a local discovery client, this will be it's current state.
|
// a local discovery client, this will be it's current state.
|
||||||
for k, v := range m.finders[i].Cache() {
|
for k, v := range m.finders[i].Cache() {
|
||||||
if v.found && v.when.After(res[k].when) {
|
if v.found {
|
||||||
res[k] = v
|
cur := res[k]
|
||||||
|
if v.when.After(cur.when) {
|
||||||
|
cur.when = v.when
|
||||||
|
}
|
||||||
|
cur.Addresses = append(cur.Addresses, v.Addresses...)
|
||||||
|
res[k] = cur
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.mut.RUnlock()
|
m.mut.RUnlock()
|
||||||
|
|
||||||
|
for k, v := range res {
|
||||||
|
v.Addresses = util.UniqueStrings(v.Addresses)
|
||||||
|
res[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -102,7 +103,7 @@ func (v Simple) Archive(filePath string) error {
|
|||||||
|
|
||||||
// Use all the found filenames. "~" sorts after "." so all old pattern
|
// Use all the found filenames. "~" sorts after "." so all old pattern
|
||||||
// files will be deleted before any new, which is as it should be.
|
// files will be deleted before any new, which is as it should be.
|
||||||
versions := uniqueSortedStrings(append(oldVersions, newVersions...))
|
versions := util.UniqueStrings(append(oldVersions, newVersions...))
|
||||||
|
|
||||||
if len(versions) > v.keep {
|
if len(versions) > v.keep {
|
||||||
for _, toRemove := range versions[:len(versions)-v.keep] {
|
for _, toRemove := range versions[:len(versions)-v.keep] {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"github.com/syncthing/syncthing/lib/osutil"
|
"github.com/syncthing/syncthing/lib/osutil"
|
||||||
"github.com/syncthing/syncthing/lib/sync"
|
"github.com/syncthing/syncthing/lib/sync"
|
||||||
|
"github.com/syncthing/syncthing/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -280,7 +281,7 @@ func (v Staggered) Archive(filePath string) error {
|
|||||||
|
|
||||||
// Use all the found filenames.
|
// Use all the found filenames.
|
||||||
versions := append(oldVersions, newVersions...)
|
versions := append(oldVersions, newVersions...)
|
||||||
v.expire(uniqueSortedStrings(versions))
|
v.expire(util.UniqueStrings(versions))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ package versioner
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Inserts ~tag just before the extension of the filename.
|
// Inserts ~tag just before the extension of the filename.
|
||||||
@ -32,17 +31,3 @@ func filenameTag(path string) string {
|
|||||||
}
|
}
|
||||||
return match[1]
|
return match[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
func uniqueSortedStrings(strings []string) []string {
|
|
||||||
seen := make(map[string]struct{}, len(strings))
|
|
||||||
unique := make([]string, 0, len(strings))
|
|
||||||
for _, str := range strings {
|
|
||||||
_, ok := seen[str]
|
|
||||||
if !ok {
|
|
||||||
seen[str] = struct{}{}
|
|
||||||
unique = append(unique, str)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(unique)
|
|
||||||
return unique
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user