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

- Consistently truncate server_entry_timestamp

- Use fixed load-time timestamp to allow replay with
  TargetServerEntry

- Initialize tag for TargetServerEntry
Rod Hynes 6 лет назад
Родитель
Сommit
08c7e82bd7
4 измененных файлов с 14 добавлено и 4 удалено
  1. 1 1
      ClientLibrary/clientlib/clientlib.go
  2. 2 2
      MobileLibrary/psi/psi.go
  3. 5 0
      psiphon/config.go
  4. 6 1
      psiphon/dataStore.go

+ 1 - 1
ClientLibrary/clientlib/clientlib.go

@@ -168,7 +168,7 @@ func StartTunnel(ctx context.Context,
 	// Store embedded server entries
 	serverEntries, err := protocol.DecodeServerEntryList(
 		embeddedServerEntryList,
-		common.GetCurrentTimestamp(),
+		common.TruncateTimestampToHour(common.GetCurrentTimestamp()),
 		protocol.SERVER_ENTRY_SOURCE_EMBEDDED)
 	if err != nil {
 		return nil, common.ContextErrorMsg(err, "failed to decode server entry list")

+ 2 - 2
MobileLibrary/psi/psi.go

@@ -271,7 +271,7 @@ func storeServerEntries(
 			config,
 			protocol.NewStreamingServerEntryDecoder(
 				file,
-				common.GetCurrentTimestamp(),
+				common.TruncateTimestampToHour(common.GetCurrentTimestamp()),
 				protocol.SERVER_ENTRY_SOURCE_EMBEDDED),
 			false)
 		if err != nil {
@@ -282,7 +282,7 @@ func storeServerEntries(
 
 		serverEntries, err := protocol.DecodeServerEntryList(
 			embeddedServerEntryList,
-			common.GetCurrentTimestamp(),
+			common.TruncateTimestampToHour(common.GetCurrentTimestamp()),
 			protocol.SERVER_ENTRY_SOURCE_EMBEDDED)
 		if err != nil {
 			return fmt.Errorf("error decoding embedded server list: %s", err)

+ 5 - 0
psiphon/config.go

@@ -543,6 +543,8 @@ type Config struct {
 	networkIDGetter NetworkIDGetter
 
 	committed bool
+
+	loadTimestamp string
 }
 
 // LoadConfig parses a JSON format Psiphon config JSON string and returns a
@@ -561,6 +563,9 @@ func LoadConfig(configJson []byte) (*Config, error) {
 		return nil, common.ContextError(err)
 	}
 
+	config.loadTimestamp = common.TruncateTimestampToHour(
+		common.GetCurrentTimestamp())
+
 	return &config, nil
 }
 

+ 6 - 1
psiphon/dataStore.go

@@ -460,11 +460,16 @@ func NewTacticsServerEntryIterator(config *Config) (*ServerEntryIterator, error)
 func newTargetServerEntryIterator(config *Config, isTactics bool) (bool, *ServerEntryIterator, error) {
 
 	serverEntry, err := protocol.DecodeServerEntry(
-		config.TargetServerEntry, common.GetCurrentTimestamp(), protocol.SERVER_ENTRY_SOURCE_TARGET)
+		config.TargetServerEntry, config.loadTimestamp, protocol.SERVER_ENTRY_SOURCE_TARGET)
 	if err != nil {
 		return false, nil, common.ContextError(err)
 	}
 
+	if serverEntry.Tag == "" {
+		serverEntry.Tag = protocol.GenerateServerEntryTag(
+			serverEntry.IpAddress, serverEntry.WebServerSecret)
+	}
+
 	if isTactics {
 
 		if len(serverEntry.GetSupportedTacticsProtocols()) == 0 {