gui, lib/connections: Let the backend decide whether connection is local (fixes #8686) (#8694)

* lib/connections: Cache isLAN decision for later external access.

The check whether a remote device's address is on a local network
currently happens when handling the Hello message, to configure the
limiters.  Save the result to the ConnectionInfo and pass it out as
part of the model's ConnectionInfo struct in ConnectionStats().

* gui: Use provided connection attribute to distinguish LAN / WAN.

Replace the dumb IP address check which didn't catch common cases and
actually could contradict what the backend decided.  That could have
been confusing if the GUI says WAN, but the limiter is not actually
applied because the backend thinks it's a LAN.

Add strings for QUIC and relay connections to also differentiate
between LAN and WAN.

* gui: Redefine reception level icons for all connection types.

Move the mapping to the JS code, as it is much easier to handle
multiple switch cases by fall-through there.

QUIC is regarded no less than TCP anymore.  LAN and WAN make the
difference between levels 4 / 3 and 2 / 1:

{TCP,QUIC} LAN --> {TCP,QUIC} WAN --> Relay LAN --> Relay WAN -->
Disconnected.
This commit is contained in:
André Colomb
2022-11-28 09:28:33 +01:00
committed by GitHub
parent d16c0652f7
commit ab0eb909a2
9 changed files with 247 additions and 24 deletions
@@ -1203,24 +1203,27 @@ angular.module('syncthing.core')
$scope.rdConnType = function (deviceID) {
var conn = $scope.connections[deviceID];
if (!conn) return "-1";
if (conn.type.indexOf('relay') === 0) return "relay";
if (conn.type.indexOf('quic') === 0) return "quic";
if (conn.type.indexOf('tcp') === 0) return "tcp" + rdAddrType(conn.address);
return "disconnected";
}
var type = "disconnected";
if (conn.type.indexOf('relay') === 0) type = "relay";
else if (conn.type.indexOf('quic') === 0) type = "quic";
else if (conn.type.indexOf('tcp') === 0) type = "tcp";
else return type;
function rdAddrType(address) {
var re = /(^(?:127\.|0?10\.|172\.0?1[6-9]\.|172\.0?2[0-9]\.|172\.0?3[01]\.|192\.168\.|169\.254\.|::1|[fF][cCdD][0-9a-fA-F]{2}:|[fF][eE][89aAbB][0-9a-fA-F]:))/
if (re.test(address)) return "lan";
return "wan";
if (conn.isLocal) type += "lan";
else type += "wan";
return type;
}
$scope.rdConnTypeString = function (type) {
switch (type) {
case "relay":
return $translate.instant('Relay');
case "quic":
return $translate.instant('QUIC');
case "relaywan":
return $translate.instant('Relay WAN');
case "relaylan":
return $translate.instant('Relay LAN');
case "quicwan":
return $translate.instant('QUIC WAN');
case "quiclan":
return $translate.instant('QUIC LAN');
case "tcpwan":
return $translate.instant('TCP WAN');
case "tcplan":
@@ -1230,11 +1233,30 @@ angular.module('syncthing.core')
}
}
$scope.rdConnTypeIcon = function (type) {
switch (type) {
case "tcplan":
case "quiclan":
return "reception-4";
case "tcpwan":
case "quicwan":
return "reception-3";
case "relaylan":
return "reception-2";
case "relaywan":
return "reception-1";
case "disconnected":
return "reception-0";
}
}
$scope.rdConnDetails = function (type) {
switch (type) {
case "relay":
case "relaylan":
case "relaywan":
return $translate.instant('Connections via relays might be rate limited by the relay');
case "quic":
case "quiclan":
case "quicwan":
return $translate.instant('QUIC connections are in most cases considered suboptimal');
case "tcpwan":
return $translate.instant('Using a direct TCP connection over WAN');