Эх сурвалжийг харах

Add explicit EnableUpgradeDownload/EnableFeedbackUpload flags

Rod Hynes 2 жил өмнө
parent
commit
68fbee93a4

+ 22 - 8
psiphon/config.go

@@ -374,6 +374,12 @@ type Config struct {
 	// OnlyAfterAttempts = 0.
 	// OnlyAfterAttempts = 0.
 	ObfuscatedServerListRootURLs parameters.TransferURLs
 	ObfuscatedServerListRootURLs parameters.TransferURLs
 
 
+	// EnableUpgradeDownload indicates whether to check for and download
+	// upgrades. When set, UpgradeDownloadURLs and
+	// UpgradeDownloadClientVersionHeader must also be set. ClientPlatform
+	// and ClientVersion should also be set.
+	EnableUpgradeDownload bool
+
 	// UpgradeDownloadURLs is list of URLs which specify locations from which
 	// UpgradeDownloadURLs is list of URLs which specify locations from which
 	// to download a host client upgrade file, when one is available. The core
 	// to download a host client upgrade file, when one is available. The core
 	// tunnel controller provides a resumable download facility which
 	// tunnel controller provides a resumable download facility which
@@ -397,6 +403,11 @@ type Config struct {
 	// is used. This value is typical overridden for testing.
 	// is used. This value is typical overridden for testing.
 	FetchUpgradeRetryPeriodMilliseconds *int
 	FetchUpgradeRetryPeriodMilliseconds *int
 
 
+	// EnableFeedbackUpload indicates whether to enable uploading feedback
+	// data. When set, FeedbackUploadURLs and FeedbackEncryptionPublicKey
+	// must also be set.
+	EnableFeedbackUpload bool
+
 	// FeedbackUploadURLs is a list of SecureTransferURLs which specify
 	// FeedbackUploadURLs is a list of SecureTransferURLs which specify
 	// locations where feedback data can be uploaded, pairing with each
 	// locations where feedback data can be uploaded, pairing with each
 	// location a public key with which to encrypt the feedback data. This
 	// location a public key with which to encrypt the feedback data. This
@@ -1173,13 +1184,19 @@ func (config *Config) Commit(migrateFromLegacyFields bool) error {
 		}
 		}
 	}
 	}
 
 
-	if config.UpgradeDownloadURLs != nil {
+	if config.EnableUpgradeDownload {
+		if len(config.UpgradeDownloadURLs) == 0 {
+			return errors.TraceNew("missing UpgradeDownloadURLs")
+		}
 		if config.UpgradeDownloadClientVersionHeader == "" {
 		if config.UpgradeDownloadClientVersionHeader == "" {
 			return errors.TraceNew("missing UpgradeDownloadClientVersionHeader")
 			return errors.TraceNew("missing UpgradeDownloadClientVersionHeader")
 		}
 		}
 	}
 	}
 
 
-	if config.FeedbackUploadURLs != nil {
+	if config.EnableFeedbackUpload {
+		if len(config.FeedbackUploadURLs) == 0 {
+			return errors.TraceNew("missing FeedbackUploadURLs")
+		}
 		if config.FeedbackEncryptionPublicKey == "" {
 		if config.FeedbackEncryptionPublicKey == "" {
 			return errors.TraceNew("missing FeedbackEncryptionPublicKey")
 			return errors.TraceNew("missing FeedbackEncryptionPublicKey")
 		}
 		}
@@ -1622,16 +1639,13 @@ func (config *Config) makeConfigParameters() map[string]interface{} {
 
 
 	}
 	}
 
 
-	if config.UpgradeDownloadURLs != nil {
-		applyParameters[parameters.UpgradeDownloadClientVersionHeader] = config.UpgradeDownloadClientVersionHeader
+	if config.EnableUpgradeDownload {
 		applyParameters[parameters.UpgradeDownloadURLs] = config.UpgradeDownloadURLs
 		applyParameters[parameters.UpgradeDownloadURLs] = config.UpgradeDownloadURLs
+		applyParameters[parameters.UpgradeDownloadClientVersionHeader] = config.UpgradeDownloadClientVersionHeader
 	}
 	}
 
 
-	if len(config.FeedbackUploadURLs) > 0 {
+	if config.EnableFeedbackUpload {
 		applyParameters[parameters.FeedbackUploadURLs] = config.FeedbackUploadURLs
 		applyParameters[parameters.FeedbackUploadURLs] = config.FeedbackUploadURLs
-	}
-
-	if config.FeedbackEncryptionPublicKey != "" {
 		applyParameters[parameters.FeedbackEncryptionPublicKey] = config.FeedbackEncryptionPublicKey
 		applyParameters[parameters.FeedbackEncryptionPublicKey] = config.FeedbackEncryptionPublicKey
 	}
 	}
 
 

+ 1 - 1
psiphon/controller.go

@@ -290,7 +290,7 @@ func (controller *Controller) Run(ctx context.Context) {
 		}
 		}
 	}
 	}
 
 
-	if controller.config.UpgradeDownloadURLs != nil {
+	if controller.config.EnableUpgradeDownload {
 		controller.runWaitGroup.Add(1)
 		controller.runWaitGroup.Add(1)
 		go controller.upgradeDownloader()
 		go controller.upgradeDownloader()
 	}
 	}

+ 4 - 1
psiphon/controller_test.go

@@ -541,6 +541,9 @@ func controllerRun(t *testing.T, runConfig *controllerRunConfig) {
 		modifyConfig["LimitTunnelProtocols"] = protocol.TunnelProtocols{runConfig.protocol}
 		modifyConfig["LimitTunnelProtocols"] = protocol.TunnelProtocols{runConfig.protocol}
 	}
 	}
 
 
+	modifyConfig["EnableUpgradeDownload"] = true
+	modifyConfig["EnableFeedbackUpload"] = false
+
 	// Override client retry throttle values to speed up automated
 	// Override client retry throttle values to speed up automated
 	// tests and ensure tests complete within fixed deadlines.
 	// tests and ensure tests complete within fixed deadlines.
 	modifyConfig["FetchRemoteServerListRetryPeriodMilliseconds"] = 250
 	modifyConfig["FetchRemoteServerListRetryPeriodMilliseconds"] = 250
@@ -548,7 +551,7 @@ func controllerRun(t *testing.T, runConfig *controllerRunConfig) {
 	modifyConfig["EstablishTunnelPausePeriodSeconds"] = 1
 	modifyConfig["EstablishTunnelPausePeriodSeconds"] = 1
 
 
 	if runConfig.disableUntunneledUpgrade {
 	if runConfig.disableUntunneledUpgrade {
-		// Disable untunneled upgrade downloader to ensure tunneled case is tested
+		// Break untunneled upgrade downloader to ensure tunneled case is tested
 		modifyConfig["UpgradeDownloadClientVersionHeader"] = "invalid-value"
 		modifyConfig["UpgradeDownloadClientVersionHeader"] = "invalid-value"
 	}
 	}
 
 

+ 4 - 0
psiphon/feedback.go

@@ -101,6 +101,10 @@ func encryptFeedback(diagnostics, b64EncodedPublicKey string) ([]byte, error) {
 // the routine will sleep and retry multiple times.
 // the routine will sleep and retry multiple times.
 func SendFeedback(ctx context.Context, config *Config, diagnostics, uploadPath string) error {
 func SendFeedback(ctx context.Context, config *Config, diagnostics, uploadPath string) error {
 
 
+	if !config.EnableFeedbackUpload {
+		return errors.TraceNew("feedback upload not enabled")
+	}
+
 	if len(diagnostics) == 0 {
 	if len(diagnostics) == 0 {
 		return errors.TraceNew("error diagnostics empty")
 		return errors.TraceNew("error diagnostics empty")
 	}
 	}

+ 4 - 0
psiphon/feedback_test.go

@@ -55,6 +55,10 @@ func TestFeedbackUpload(t *testing.T) {
 		t.Fatalf("error loading configuration file: %s", err)
 		t.Fatalf("error loading configuration file: %s", err)
 	}
 	}
 
 
+	if !config.EnableFeedbackUpload {
+		config.EnableFeedbackUpload = true
+	}
+
 	if config.ClientPlatform == "" {
 	if config.ClientPlatform == "" {
 		config.ClientPlatform = testClientPlatform
 		config.ClientPlatform = testClientPlatform
 	}
 	}