Parcourir la source

Add TargetApiProtocol config param

Rod Hynes il y a 9 ans
Parent
commit
fff1f0cbad
3 fichiers modifiés avec 17 ajouts et 1 suppressions
  1. 11 0
      psiphon/config.go
  2. 5 0
      psiphon/controller.go
  3. 1 1
      psiphon/serverApi.go

+ 11 - 0
psiphon/config.go

@@ -234,6 +234,12 @@ type Config struct {
 	// status, etc. This is used for special case temporary tunnels (Windows VPN mode).
 	DisableApi bool
 
+	// TargetApiProtocol specifies whether to force use of "ssh" or "web" API protocol.
+	// When blank, the default, the optimal API protocol is used. Note that this
+	// capability check is not applied before the "CandidateServers" count is emitted.
+	// This parameter is intended for testing and debugging only.
+	TargetApiProtocol string
+
 	// DisableRemoteServerListFetcher disables fetching remote server lists. This is
 	// used for special case temporary tunnels.
 	DisableRemoteServerListFetcher bool
@@ -470,6 +476,11 @@ func LoadConfig(configJson []byte) (*Config, error) {
 			errors.New("HostNameTransformer interface must be set at runtime"))
 	}
 
+	if !common.Contains([]string{"", "ssh", "web"}, config.TargetApiProtocol) {
+		return nil, common.ContextError(
+			errors.New("invalid TargetApiProtocol"))
+	}
+
 	if config.UpgradeDownloadUrl != "" &&
 		(config.UpgradeDownloadClientVersionHeader == "" || config.UpgradeDownloadFilename == "") {
 		return nil, common.ContextError(errors.New(

+ 5 - 0
psiphon/controller.go

@@ -1045,6 +1045,11 @@ loop:
 				break
 			}
 
+			if controller.config.TargetApiProtocol == "ssh" &&
+				!serverEntry.SupportsSSHAPIRequests() {
+				continue
+			}
+
 			// Disable impaired protocols. This is only done for the
 			// first iteration of the ESTABLISH_TUNNEL_WORK_TIME
 			// loop since (a) one iteration should be sufficient to

+ 1 - 1
psiphon/serverApi.go

@@ -87,7 +87,7 @@ func NewServerContext(tunnel *Tunnel, sessionId string) (*ServerContext, error)
 	// For legacy servers, set up psiphonHttpsClient for
 	// accessing the Psiphon API via the web service.
 	var psiphonHttpsClient *http.Client
-	if !tunnel.serverEntry.SupportsSSHAPIRequests() {
+	if !tunnel.serverEntry.SupportsSSHAPIRequests() || tunnel.config.TargetApiProtocol == "web" {
 		var err error
 		psiphonHttpsClient, err = makePsiphonHttpsClient(tunnel)
 		if err != nil {