Browse Source

Merge pull request #414 from rod-hynes/master

Fix: streaming embedded server entries replaced existing entries
Rod Hynes 8 years ago
parent
commit
54e4ad94ef
3 changed files with 12 additions and 24 deletions
  1. 6 1
      MobileLibrary/psi/psi.go
  2. 0 20
      psiphon/dataStore.go
  3. 6 3
      psiphon/remoteServerList.go

+ 6 - 1
MobileLibrary/psi/psi.go

@@ -194,7 +194,12 @@ func storeServerEntries(embeddedServerEntryListPath, embeddedServerEntryList str
 		}
 		defer serverEntriesFile.Close()
 
-		err = psiphon.StreamingStoreServerEntriesWithIOReader(serverEntriesFile, protocol.SERVER_ENTRY_SOURCE_EMBEDDED)
+		err = psiphon.StreamingStoreServerEntries(
+			protocol.NewStreamingServerEntryDecoder(
+				serverEntriesFile,
+				common.GetCurrentTimestamp(),
+				protocol.SERVER_ENTRY_SOURCE_EMBEDDED),
+			false)
 		if err != nil {
 			return fmt.Errorf("failed to store common remote server list: %s", common.ContextError(err))
 		}

+ 0 - 20
psiphon/dataStore.go

@@ -24,7 +24,6 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"io"
 	"math/rand"
 	"os"
 	"path/filepath"
@@ -269,25 +268,6 @@ func StoreServerEntries(serverEntries []*protocol.ServerEntry, replaceIfExists b
 	return nil
 }
 
-// StreamingStoreServerEntriesWithIOReader is a wrapper around StreamingStoreServerEntries
-// an io.Reader is passed instead of an instance of StreamingServerEntryDecoder
-func StreamingStoreServerEntriesWithIOReader(serverListReader io.Reader, serverEntrySource string) error {
-
-	serverEntries := protocol.NewStreamingServerEntryDecoder(
-		serverListReader,
-		common.GetCurrentTimestamp(),
-		serverEntrySource)
-
-	// TODO: record stats for newly discovered servers
-
-	err := StreamingStoreServerEntries(serverEntries, true)
-	if err != nil {
-		return common.ContextError(err)
-	}
-
-	return nil
-}
-
 // StreamingStoreServerEntries stores a list of server entries.
 // There is an independent transaction for each entry insert/update.
 func StreamingStoreServerEntries(

+ 6 - 3
psiphon/remoteServerList.go

@@ -77,7 +77,12 @@ func FetchCommonRemoteServerList(
 	}
 	defer serverListPayload.Close()
 
-	err = StreamingStoreServerEntriesWithIOReader(serverListPayload, protocol.SERVER_ENTRY_SOURCE_REMOTE)
+	err = StreamingStoreServerEntries(
+		protocol.NewStreamingServerEntryDecoder(
+			serverListPayload,
+			common.GetCurrentTimestamp(),
+			protocol.SERVER_ENTRY_SOURCE_REMOTE),
+		true)
 	if err != nil {
 		return fmt.Errorf("failed to store common remote server list: %s", common.ContextError(err))
 	}
@@ -368,8 +373,6 @@ func storeServerEntries(serverList, serverEntrySource string) error {
 		return common.ContextError(err)
 	}
 
-	// TODO: record stats for newly discovered servers
-
 	err = StoreServerEntries(serverEntries, true)
 	if err != nil {
 		return common.ContextError(err)