Просмотр исходного кода

promote the first pulled server entry after migration to retain affinity; migrateEntries cannot fail fatally, so doesn't return errors; added comment to config.go about client_platforms that include 'windows' and client_version <= 44 failing; fixed typo in NoticeAlert and NoticeError godoc comments

Michael Goldberger 10 лет назад
Родитель
Сommit
88fac10852
4 измененных файлов с 23 добавлено и 11 удалено
  1. 3 0
      psiphon/config.go
  2. 1 4
      psiphon/dataStore_alt.go
  3. 17 5
      psiphon/migrateDataStore.go
  4. 2 2
      psiphon/notice.go

+ 3 - 0
psiphon/config.go

@@ -119,6 +119,9 @@ type Config struct {
 	// automatic updates.
 	// This value is supplied by and depends on the Psiphon Network, and is
 	// typically embedded in the client binary.
+	// Note that sending a ClientPlatform string which includes "windows"
+	// (case insensitive) and a ClientVersion of <= 44 will cause an
+	// error in processing the response to DoConnectedRequest calls.
 	ClientVersion string
 
 	// ClientPlatform is the client platform ("Windows", "Android", etc.) that

+ 1 - 4
psiphon/dataStore_alt.go

@@ -113,10 +113,7 @@ func InitDataStore(config *Config) (err error) {
 		// The migrateServerEntries function requires the data store is
 		// initialized prior to execution so that migrated entries can be stored
 		if len(migratableServerEntries) > 0 {
-			migrationFailures := migrateEntries(migratableServerEntries, filepath.Join(config.DataStoreDirectory, LEGACY_DATA_STORE_FILENAME))
-			if migrationFailures != nil {
-				NoticeAlert("initDataStore failed to migrate legacy server entries: %s", migrationFailures)
-			}
+			migrateEntries(migratableServerEntries, filepath.Join(config.DataStoreDirectory, LEGACY_DATA_STORE_FILENAME))
 		}
 	})
 

+ 17 - 5
psiphon/migrateDataStore.go

@@ -77,21 +77,33 @@ func prepareMigrationEntries(config *Config) ([]*ServerEntry, error) {
 	return migratableServerEntries, nil
 }
 
-func migrateEntries(serverEntries []*ServerEntry, legacyDataStoreFilename string) error {
+// migrateEntries calls the BoltDB data store method to shuffle
+// and store an array of server entries (StoreServerEntries)
+// Failing to migrate entries, or delete the legacy file is never fatal
+func migrateEntries(serverEntries []*ServerEntry, legacyDataStoreFilename string) {
 	checkInitDataStore()
 
 	err := StoreServerEntries(serverEntries, false)
 	if err != nil {
-		return err
+		NoticeAlert("failed to store migrated server entries: %s", err)
+	} else {
+		// Retain server affinity from old datastore by taking the first
+		// array element (previous top ranked server) and promoting it
+		// to the top rank before the server selection process begins
+		err = PromoteServerEntry(serverEntries[0].IpAddress)
+		if err != nil {
+			NoticeAlert("failed to promote server entry: %s", err)
+		}
+
+		NoticeAlert("%d server entries successfully migrated to new data store", len(serverEntries))
 	}
-	NoticeInfo("%d server entries successfully migrated to new data store", len(serverEntries))
 
 	err = os.Remove(legacyDataStoreFilename)
 	if err != nil {
-		NoticeInfo("failed to delete legacy data store file '%s': %s", legacyDataStoreFilename, err)
+		NoticeAlert("failed to delete legacy data store file '%s': %s", legacyDataStoreFilename, err)
 	}
 
-	return nil
+	return
 }
 
 // This code is copied from the dataStore.go code used to operate the legacy

+ 2 - 2
psiphon/notice.go

@@ -91,12 +91,12 @@ func NoticeInfo(format string, args ...interface{}) {
 	outputNotice("Info", false, "message", fmt.Sprintf(format, args...))
 }
 
-// NoticeInfo is an alert message; typically a recoverable error condition
+// NoticeAlert is an alert message; typically a recoverable error condition
 func NoticeAlert(format string, args ...interface{}) {
 	outputNotice("Alert", false, "message", fmt.Sprintf(format, args...))
 }
 
-// NoticeInfo is an error message; typically an unrecoverable error condition
+// NoticeError is an error message; typically an unrecoverable error condition
 func NoticeError(format string, args ...interface{}) {
 	outputNotice("Error", true, "message", fmt.Sprintf(format, args...))
 }