Explorar o código

Add missing network type cases

- WIRED was reported as UNKNOWN
Rod Hynes hai 1 ano
pai
achega
d36db4f344
Modificáronse 4 ficheiros con 19 adicións e 3 borrados
  1. 6 0
      psiphon/common/inproxy/api.go
  2. 4 0
      psiphon/inproxy.go
  3. 3 0
      psiphon/net.go
  4. 6 3
      psiphon/utils.go

+ 6 - 0
psiphon/common/inproxy/api.go

@@ -137,6 +137,8 @@ const (
 	NetworkTypeUnknown NetworkType = iota
 	NetworkTypeUnknown NetworkType = iota
 	NetworkTypeWiFi
 	NetworkTypeWiFi
 	NetworkTypeMobile
 	NetworkTypeMobile
+	NetworkTypeWired
+	NetworkTypeVPN
 )
 )
 
 
 // NetworkProtocol is an Internet protocol, such as TCP or UDP. This enum is
 // NetworkProtocol is an Internet protocol, such as TCP or UDP. This enum is
@@ -453,6 +455,10 @@ func GetNetworkType(packedBaseParams protocol.PackedAPIParameters) NetworkType {
 		return NetworkTypeWiFi
 		return NetworkTypeWiFi
 	case "MOBILE":
 	case "MOBILE":
 		return NetworkTypeMobile
 		return NetworkTypeMobile
+	case "WIRED":
+		return NetworkTypeWired
+	case "VPN":
+		return NetworkTypeVPN
 	}
 	}
 	return NetworkTypeUnknown
 	return NetworkTypeUnknown
 }
 }

+ 4 - 0
psiphon/inproxy.go

@@ -2501,6 +2501,10 @@ func getInproxyNetworkType(networkType string) inproxy.NetworkType {
 		return inproxy.NetworkTypeWiFi
 		return inproxy.NetworkTypeWiFi
 	case "MOBILE":
 	case "MOBILE":
 		return inproxy.NetworkTypeMobile
 		return inproxy.NetworkTypeMobile
+	case "WIRED":
+		return inproxy.NetworkTypeWired
+	case "VPN":
+		return inproxy.NetworkTypeVPN
 	}
 	}
 
 
 	return inproxy.NetworkTypeUnknown
 	return inproxy.NetworkTypeUnknown

+ 3 - 0
psiphon/net.go

@@ -179,6 +179,9 @@ type HasIPv6RouteGetter interface {
 // - "WIRED" for a wired network
 // - "WIRED" for a wired network
 // - "VPN" for a VPN network
 // - "VPN" for a VPN network
 // - "UNKNOWN" for when the network type cannot be determined
 // - "UNKNOWN" for when the network type cannot be determined
+//
+// Note that the functions psiphon.GetNetworkType, psiphon.getInproxyNetworkType,
+// and inproxy.GetNetworkType must all be updated when new network types are added.
 type NetworkIDGetter interface {
 type NetworkIDGetter interface {
 	GetNetworkID() string
 	GetNetworkID() string
 }
 }

+ 6 - 3
psiphon/utils.go

@@ -288,14 +288,17 @@ func GetNetworkType(networkID string) string {
 	// check for and use the common network type prefixes currently used in
 	// check for and use the common network type prefixes currently used in
 	// NetworkIDGetter implementations.
 	// NetworkIDGetter implementations.
 
 
-	if strings.HasPrefix(networkID, "VPN") {
-		return "VPN"
-	}
 	if strings.HasPrefix(networkID, "WIFI") {
 	if strings.HasPrefix(networkID, "WIFI") {
 		return "WIFI"
 		return "WIFI"
 	}
 	}
 	if strings.HasPrefix(networkID, "MOBILE") {
 	if strings.HasPrefix(networkID, "MOBILE") {
 		return "MOBILE"
 		return "MOBILE"
 	}
 	}
+	if strings.HasPrefix(networkID, "WIRED") {
+		return "WIRED"
+	}
+	if strings.HasPrefix(networkID, "VPN") {
+		return "VPN"
+	}
 	return "UNKNOWN"
 	return "UNKNOWN"
 }
 }