Skip to content

Commit

Permalink
lib/config, lib/connections: Configurable protocol priority (ref #8626)…
Browse files Browse the repository at this point in the history
… (#8868)

This makes the various protocol priorities configurable among the other
options. With this, it's possible to prefer QUIC over TCP for WAN
connections, for example. Both sides need to be similarly configured for
this to work properly.

The default priority order remains the same as previously (TCP, QUIC,
Relay, with LAN better than WAN).

To make this happen I made each dialer & listener more priority aware,
and moved the check for whether a connection is LAN or not into the
dialer / listener -- this is the new "lanChecker" type that's passed
around.
  • Loading branch information
calmh committed Apr 16, 2023
1 parent c867a5f commit 9b660c1
Show file tree
Hide file tree
Showing 16 changed files with 622 additions and 361 deletions.
3 changes: 2 additions & 1 deletion gui/default/syncthing/core/syncthingController.js
Expand Up @@ -1256,8 +1256,9 @@ angular.module('syncthing.core')
case "relaywan":
return $translate.instant('Connections via relays might be rate limited by the relay');
case "quiclan":
return $translate.instant('Using a QUIC connection over LAN');
case "quicwan":
return $translate.instant('QUIC connections are in most cases considered suboptimal');
return $translate.instant('Using a QUIC connection over WAN');
case "tcpwan":
return $translate.instant('Using a direct TCP connection over WAN');
case "tcplan":
Expand Down
166 changes: 88 additions & 78 deletions lib/config/config_test.go
Expand Up @@ -47,44 +47,49 @@ func TestDefaultValues(t *testing.T) {
Version: CurrentVersion,
Folders: []FolderConfiguration{},
Options: OptionsConfiguration{
RawListenAddresses: []string{"default"},
RawGlobalAnnServers: []string{"default"},
GlobalAnnEnabled: true,
LocalAnnEnabled: true,
LocalAnnPort: 21027,
LocalAnnMCAddr: "[ff12::8384]:21027",
MaxSendKbps: 0,
MaxRecvKbps: 0,
ReconnectIntervalS: 60,
RelaysEnabled: true,
RelayReconnectIntervalM: 10,
StartBrowser: true,
NATEnabled: true,
NATLeaseM: 60,
NATRenewalM: 30,
NATTimeoutS: 10,
AutoUpgradeIntervalH: 12,
KeepTemporariesH: 24,
CacheIgnoredFiles: false,
ProgressUpdateIntervalS: 5,
LimitBandwidthInLan: false,
MinHomeDiskFree: Size{1, "%"},
URURL: "https://data.syncthing.net/newdata",
URInitialDelayS: 1800,
URPostInsecurely: false,
ReleasesURL: "https://upgrades.syncthing.net/meta.json",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: false,
TempIndexMinBlocks: 10,
UnackedNotificationIDs: []string{"authenticationUserAndPassword"},
SetLowPriority: true,
CRURL: "https://crash.syncthing.net/newcrash",
CREnabled: true,
StunKeepaliveStartS: 180,
StunKeepaliveMinS: 20,
RawStunServers: []string{"default"},
AnnounceLANAddresses: true,
FeatureFlags: []string{},
RawListenAddresses: []string{"default"},
RawGlobalAnnServers: []string{"default"},
GlobalAnnEnabled: true,
LocalAnnEnabled: true,
LocalAnnPort: 21027,
LocalAnnMCAddr: "[ff12::8384]:21027",
MaxSendKbps: 0,
MaxRecvKbps: 0,
ReconnectIntervalS: 60,
RelaysEnabled: true,
RelayReconnectIntervalM: 10,
StartBrowser: true,
NATEnabled: true,
NATLeaseM: 60,
NATRenewalM: 30,
NATTimeoutS: 10,
AutoUpgradeIntervalH: 12,
KeepTemporariesH: 24,
CacheIgnoredFiles: false,
ProgressUpdateIntervalS: 5,
LimitBandwidthInLan: false,
MinHomeDiskFree: Size{1, "%"},
URURL: "https://data.syncthing.net/newdata",
URInitialDelayS: 1800,
URPostInsecurely: false,
ReleasesURL: "https://upgrades.syncthing.net/meta.json",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: false,
TempIndexMinBlocks: 10,
UnackedNotificationIDs: []string{"authenticationUserAndPassword"},
SetLowPriority: true,
CRURL: "https://crash.syncthing.net/newcrash",
CREnabled: true,
StunKeepaliveStartS: 180,
StunKeepaliveMinS: 20,
RawStunServers: []string{"default"},
AnnounceLANAddresses: true,
FeatureFlags: []string{},
ConnectionPriorityTCPLAN: 10,
ConnectionPriorityQUICLAN: 20,
ConnectionPriorityTCPWAN: 30,
ConnectionPriorityQUICWAN: 40,
ConnectionPriorityRelay: 50,

This comment has been minimized.

Copy link
@AudriusButkevicius

AudriusButkevicius May 1, 2023

Member

I know it's too late, but this should have been it's own struct.
Or potentially even a struct of string to int mappings.

This comment has been minimized.

Copy link
@calmh

calmh May 2, 2023

Author Member

Ideally, yes, but then it wouldn't have been configurable in the advanced editor (I started out that way).

},
Defaults: Defaults{
Folder: FolderConfiguration{
Expand Down Expand Up @@ -239,45 +244,50 @@ func TestNoListenAddresses(t *testing.T) {

func TestOverriddenValues(t *testing.T) {
expected := OptionsConfiguration{
RawListenAddresses: []string{"tcp://:23000"},
RawGlobalAnnServers: []string{"udp4://syncthing.nym.se:22026"},
GlobalAnnEnabled: false,
LocalAnnEnabled: false,
LocalAnnPort: 42123,
LocalAnnMCAddr: "quux:3232",
MaxSendKbps: 1234,
MaxRecvKbps: 2341,
ReconnectIntervalS: 6000,
RelaysEnabled: false,
RelayReconnectIntervalM: 20,
StartBrowser: false,
NATEnabled: false,
NATLeaseM: 90,
NATRenewalM: 15,
NATTimeoutS: 15,
AutoUpgradeIntervalH: 24,
KeepTemporariesH: 48,
CacheIgnoredFiles: true,
ProgressUpdateIntervalS: 10,
LimitBandwidthInLan: true,
MinHomeDiskFree: Size{5.2, "%"},
URSeen: 8,
URAccepted: 4,
URURL: "https://localhost/newdata",
URInitialDelayS: 800,
URPostInsecurely: true,
ReleasesURL: "https://localhost/releases",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: true,
TempIndexMinBlocks: 100,
UnackedNotificationIDs: []string{"asdfasdf"},
SetLowPriority: false,
CRURL: "https://localhost/newcrash",
CREnabled: false,
StunKeepaliveStartS: 9000,
StunKeepaliveMinS: 900,
RawStunServers: []string{"foo"},
FeatureFlags: []string{"feature"},
RawListenAddresses: []string{"tcp://:23000"},
RawGlobalAnnServers: []string{"udp4://syncthing.nym.se:22026"},
GlobalAnnEnabled: false,
LocalAnnEnabled: false,
LocalAnnPort: 42123,
LocalAnnMCAddr: "quux:3232",
MaxSendKbps: 1234,
MaxRecvKbps: 2341,
ReconnectIntervalS: 6000,
RelaysEnabled: false,
RelayReconnectIntervalM: 20,
StartBrowser: false,
NATEnabled: false,
NATLeaseM: 90,
NATRenewalM: 15,
NATTimeoutS: 15,
AutoUpgradeIntervalH: 24,
KeepTemporariesH: 48,
CacheIgnoredFiles: true,
ProgressUpdateIntervalS: 10,
LimitBandwidthInLan: true,
MinHomeDiskFree: Size{5.2, "%"},
URSeen: 8,
URAccepted: 4,
URURL: "https://localhost/newdata",
URInitialDelayS: 800,
URPostInsecurely: true,
ReleasesURL: "https://localhost/releases",
AlwaysLocalNets: []string{},
OverwriteRemoteDevNames: true,
TempIndexMinBlocks: 100,
UnackedNotificationIDs: []string{"asdfasdf"},
SetLowPriority: false,
CRURL: "https://localhost/newcrash",
CREnabled: false,
StunKeepaliveStartS: 9000,
StunKeepaliveMinS: 900,
RawStunServers: []string{"foo"},
FeatureFlags: []string{"feature"},
ConnectionPriorityTCPLAN: 40,
ConnectionPriorityQUICLAN: 45,
ConnectionPriorityTCPWAN: 50,
ConnectionPriorityQUICWAN: 55,
ConnectionPriorityRelay: 9000,
}
expectedPath := "/media/syncthing"

Expand Down Expand Up @@ -514,7 +524,7 @@ func TestFolderCheckPath(t *testing.T) {
n := t.TempDir()
testFs := fs.NewFilesystem(fs.FilesystemTypeBasic, n)

err := os.MkdirAll(filepath.Join(n, "dir", ".stfolder"), os.FileMode(0777))
err := os.MkdirAll(filepath.Join(n, "dir", ".stfolder"), os.FileMode(0o777))
if err != nil {
t.Fatal(err)
}
Expand Down
9 changes: 9 additions & 0 deletions lib/config/optionsconfiguration.go
Expand Up @@ -55,6 +55,15 @@ func (opts *OptionsConfiguration) prepare(guiPWIsSet bool) {
if opts.ConnectionLimitMax < 0 {
opts.ConnectionLimitMax = 0
}

if opts.ConnectionPriorityQUICWAN <= opts.ConnectionPriorityQUICLAN {
l.Warnln("Connection priority number for QUIC over WAN must be worse (higher) than QUIC over LAN. Correcting.")
opts.ConnectionPriorityQUICWAN = opts.ConnectionPriorityQUICLAN + 1
}
if opts.ConnectionPriorityTCPWAN <= opts.ConnectionPriorityTCPLAN {
l.Warnln("Connection priority number for TCP over WAN must be worse (higher) than TCP over LAN. Correcting.")
opts.ConnectionPriorityTCPWAN = opts.ConnectionPriorityTCPLAN + 1
}
}

// RequiresRestartOnly returns a copy with only the attributes that require
Expand Down

0 comments on commit 9b660c1

Please sign in to comment.