Prechádzať zdrojové kódy

Bug fixes

- Always use concurrency-safe `constraints` in serverEntriesReporter.

- Don't try to parse empty SteeringIP in handshake response; log when an
  unexpected steering IP is received; change info notices to warnings.

- Add TargetAPIEncoding workaround to new clientlib test cases.

(cherry picked from commit 7929fd6ee94cd975ccc45046936130ff4983366e)
Rod Hynes 1 rok pred
rodič
commit
ba6e7df991

+ 30 - 0
ClientLibrary/clientlib/clientlib_test.go

@@ -259,6 +259,21 @@ func TestMultipleStartTunnel(t *testing.T) {
 		t.Skipf("error loading configuration file: %s", err)
 	}
 
+	var config map[string]interface{}
+	err = json.Unmarshal(configJSON, &config)
+	if err != nil {
+		t.Fatalf("json.Unmarshal failed: %v", err)
+	}
+
+	// Use the legacy encoding to both exercise that case, and facilitate a
+	// gradual network upgrade to new encoding support.
+	config["TargetAPIEncoding"] = protocol.PSIPHON_API_ENCODING_JSON
+
+	configJSON, err = json.Marshal(config)
+	if err != nil {
+		t.Fatalf("json.Marshal failed: %v", err)
+	}
+
 	testDataDirName, err := os.MkdirTemp("", "psiphon-clientlib-test")
 	if err != nil {
 		t.Fatalf("ioutil.TempDir failed: %v", err)
@@ -318,6 +333,21 @@ func TestPsiphonTunnel_Dial(t *testing.T) {
 		t.Skipf("error loading configuration file: %s", err)
 	}
 
+	var config map[string]interface{}
+	err = json.Unmarshal(configJSON, &config)
+	if err != nil {
+		t.Fatalf("json.Unmarshal failed: %v", err)
+	}
+
+	// Use the legacy encoding to both exercise that case, and facilitate a
+	// gradual network upgrade to new encoding support.
+	config["TargetAPIEncoding"] = protocol.PSIPHON_API_ENCODING_JSON
+
+	configJSON, err = json.Marshal(config)
+	if err != nil {
+		t.Fatalf("json.Marshal failed: %v", err)
+	}
+
 	testDataDirName, err := os.MkdirTemp("", "psiphon-clientlib-test")
 	if err != nil {
 		t.Fatalf("ioutil.TempDir failed: %v", err)

+ 1 - 1
psiphon/controller.go

@@ -719,7 +719,7 @@ loop:
 
 			NoticeCandidateServers(
 				controller.config.EgressRegion,
-				controller.protocolSelectionConstraints,
+				constraints,
 				response.initialCandidates,
 				response.candidates,
 				duration)

+ 27 - 21
psiphon/serverApi.go

@@ -390,7 +390,7 @@ func (serverContext *ServerContext) doHandshakeRequest(
 				err := serverContext.tunnel.config.SetParameters(
 					tacticsRecord.Tag, true, tacticsRecord.Tactics.Parameters)
 				if err != nil {
-					NoticeInfo("apply handshake tactics failed: %s", err)
+					NoticeWarning("apply handshake tactics failed: %s", err)
 				}
 				// The error will be due to invalid tactics values
 				// from the server. When SetParameters fails, all
@@ -399,28 +399,34 @@ func (serverContext *ServerContext) doHandshakeRequest(
 		}
 	}
 
-	if serverContext.tunnel.dialParams.steeringIPCacheKey != "" {
+	if handshakeResponse.SteeringIP != "" {
+
+		if serverContext.tunnel.dialParams.steeringIPCacheKey == "" {
+			NoticeWarning("unexpected steering IP")
 
-		// Cache any received steering IP, which will also extend the TTL for
-		// an existing entry.
-		//
-		// As typical tunnel duration is short and dialing can be challenging,
-		// this established tunnel is retained and the steering IP will be
-		// used on any subsequent dial to the same fronting provider,
-		// assuming the TTL has not expired.
-		//
-		// Note: to avoid TTL expiry for long-lived tunnels, the TTL could be
-		// set or extended at the end of the tunnel lifetime; however that
-		// may result in unintended steering.
-
-		IP := net.ParseIP(handshakeResponse.SteeringIP)
-		if IP != nil && !common.IsBogon(IP) {
-			serverContext.tunnel.dialParams.steeringIPCache.Set(
-				serverContext.tunnel.dialParams.steeringIPCacheKey,
-				handshakeResponse.SteeringIP,
-				lrucache.DefaultExpiration)
 		} else {
-			NoticeInfo("ignoring invalid steering IP")
+
+			// Cache any received steering IP, which will also extend the TTL for
+			// an existing entry.
+			//
+			// As typical tunnel duration is short and dialing can be challenging,
+			// this established tunnel is retained and the steering IP will be
+			// used on any subsequent dial to the same fronting provider,
+			// assuming the TTL has not expired.
+			//
+			// Note: to avoid TTL expiry for long-lived tunnels, the TTL could be
+			// set or extended at the end of the tunnel lifetime; however that
+			// may result in unintended steering.
+
+			IP := net.ParseIP(handshakeResponse.SteeringIP)
+			if IP != nil && !common.IsBogon(IP) {
+				serverContext.tunnel.dialParams.steeringIPCache.Set(
+					serverContext.tunnel.dialParams.steeringIPCacheKey,
+					handshakeResponse.SteeringIP,
+					lrucache.DefaultExpiration)
+			} else {
+				NoticeWarning("ignoring invalid steering IP")
+			}
 		}
 	}