From 3c476542d26bce7ff7a454dceed9173a4aec40b6 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sat, 28 Sep 2024 17:02:05 +0200 Subject: [PATCH] fix(ur): actually send usage report directly when enabled (#9736) There was a bug that the unique ID was not set when reporting was enabled, and thus the reports where rejected by the server. The unique ID got set only on startup, so next time Syncthing restarted. This makes sure to set the unique ID when blank. --- lib/config/config_test.go | 5 +++++ lib/config/optionsconfiguration.go | 5 +++++ lib/syncthing/syncthing.go | 6 ------ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/config/config_test.go b/lib/config/config_test.go index d90e01fb9..2b02967ab 100644 --- a/lib/config/config_test.go +++ b/lib/config/config_test.go @@ -305,6 +305,11 @@ func TestOverriddenValues(t *testing.T) { t.Error(err) } + if cfg.Options().URUniqueID == "" { + t.Error("expected usage reporting unique ID to be set since usage reporting is enabled") + } + expected.URUniqueID = cfg.Options().URUniqueID // it's random + if diff, equal := messagediff.PrettyDiff(expected, cfg.Options()); !equal { t.Errorf("Overridden config differs. Diff:\n%s", diff) } diff --git a/lib/config/optionsconfiguration.go b/lib/config/optionsconfiguration.go index 27e153790..1491682b5 100644 --- a/lib/config/optionsconfiguration.go +++ b/lib/config/optionsconfiguration.go @@ -65,6 +65,11 @@ func (opts *OptionsConfiguration) prepare(guiPWIsSet bool) { l.Warnln("Connection priority number for TCP over WAN must be worse (higher) than TCP over LAN. Correcting.") opts.ConnectionPriorityTCPWAN = opts.ConnectionPriorityTCPLAN + 1 } + + // If usage reporting is enabled we must have a unique ID. + if opts.URAccepted > 0 && opts.URUniqueID == "" { + opts.URUniqueID = rand.String(8) + } } // RequiresRestartOnly returns a copy with only the attributes that require diff --git a/lib/syncthing/syncthing.go b/lib/syncthing/syncthing.go index db88a0602..7d562abf7 100644 --- a/lib/syncthing/syncthing.go +++ b/lib/syncthing/syncthing.go @@ -36,7 +36,6 @@ import ( "github.com/syncthing/syncthing/lib/model" "github.com/syncthing/syncthing/lib/osutil" "github.com/syncthing/syncthing/lib/protocol" - "github.com/syncthing/syncthing/lib/rand" "github.com/syncthing/syncthing/lib/svcutil" "github.com/syncthing/syncthing/lib/tlsutil" "github.com/syncthing/syncthing/lib/upgrade" @@ -291,11 +290,6 @@ func (a *App) startup() error { // Unique ID will be set and config saved below if necessary. } } - - // If we are going to do usage reporting, ensure we have a valid unique ID. - if cfg.Options.URAccepted > 0 && cfg.Options.URUniqueID == "" { - cfg.Options.URUniqueID = rand.String(8) - } }) usageReportingSvc := ur.New(a.cfg, m, connectionsService, a.opts.NoUpgrade)