Skip to content

Commit

Permalink
Add missing network type cases
Browse files Browse the repository at this point in the history
- WIRED was reported as UNKNOWN
  • Loading branch information
rod-hynes committed Dec 16, 2024
1 parent 9971168 commit d36db4f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions psiphon/common/inproxy/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ const (
NetworkTypeUnknown NetworkType = iota
NetworkTypeWiFi
NetworkTypeMobile
NetworkTypeWired
NetworkTypeVPN
)

// NetworkProtocol is an Internet protocol, such as TCP or UDP. This enum is
Expand Down Expand Up @@ -453,6 +455,10 @@ func GetNetworkType(packedBaseParams protocol.PackedAPIParameters) NetworkType {
return NetworkTypeWiFi
case "MOBILE":
return NetworkTypeMobile
case "WIRED":
return NetworkTypeWired
case "VPN":
return NetworkTypeVPN
}
return NetworkTypeUnknown
}
Expand Down
4 changes: 4 additions & 0 deletions psiphon/inproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -2501,6 +2501,10 @@ func getInproxyNetworkType(networkType string) inproxy.NetworkType {
return inproxy.NetworkTypeWiFi
case "MOBILE":
return inproxy.NetworkTypeMobile
case "WIRED":
return inproxy.NetworkTypeWired
case "VPN":
return inproxy.NetworkTypeVPN
}

return inproxy.NetworkTypeUnknown
Expand Down
3 changes: 3 additions & 0 deletions psiphon/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ type HasIPv6RouteGetter interface {
// - "WIRED" for a wired network
// - "VPN" for a VPN network
// - "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 {
GetNetworkID() string
}
Expand Down
9 changes: 6 additions & 3 deletions psiphon/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,17 @@ func GetNetworkType(networkID string) string {
// check for and use the common network type prefixes currently used in
// NetworkIDGetter implementations.

if strings.HasPrefix(networkID, "VPN") {
return "VPN"
}
if strings.HasPrefix(networkID, "WIFI") {
return "WIFI"
}
if strings.HasPrefix(networkID, "MOBILE") {
return "MOBILE"
}
if strings.HasPrefix(networkID, "WIRED") {
return "WIRED"
}
if strings.HasPrefix(networkID, "VPN") {
return "VPN"
}
return "UNKNOWN"
}

0 comments on commit d36db4f

Please sign in to comment.