Sfoglia il codice sorgente

Merge branch 'master' into staging-client

Rod Hynes 2 anni fa
parent
commit
a0367de39a

+ 6 - 0
psiphon/config.go

@@ -446,6 +446,12 @@ type Config struct {
 	// out, the tunnel is considered to have failed.
 	// out, the tunnel is considered to have failed.
 	DisablePeriodicSshKeepAlive bool
 	DisablePeriodicSshKeepAlive bool
 
 
+	// DeviceLocation is the optional, reported location the host device is
+	// running in. This input value should be a string representing location
+	// geohash. The device location is reported to the server in the connected
+	// request and recorded for Psiphon stats.
+	DeviceLocation string
+
 	// DeviceRegion is the optional, reported region the host device is
 	// DeviceRegion is the optional, reported region the host device is
 	// running in. This input value should be a ISO 3166-1 alpha-2 country
 	// running in. This input value should be a ISO 3166-1 alpha-2 country
 	// code. The device region is reported to the server in the connected
 	// code. The device region is reported to the server in the connected

+ 23 - 5
psiphon/server/api.go

@@ -534,10 +534,10 @@ var remoteServerListStatParams = append(
 		{"duration", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"duration", isIntString, requestParamOptional | requestParamLogStringAsInt},
 		{"authenticated", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"authenticated", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"fronting_provider_id", isAnyString, requestParamOptional},
 		{"fronting_provider_id", isAnyString, requestParamOptional},
-		{"meek_dial_address", isDialAddress, requestParamOptional | requestParamLogOnlyForFrontedMeekOrConjure},
-		{"meek_resolved_ip_address", isIPAddress, requestParamOptional | requestParamLogOnlyForFrontedMeekOrConjure},
+		{"meek_dial_address", isDialAddress, requestParamOptional},
+		{"meek_resolved_ip_address", isIPAddress, requestParamOptional},
 		{"meek_sni_server_name", isDomain, requestParamOptional},
 		{"meek_sni_server_name", isDomain, requestParamOptional},
-		{"meek_host_header", isHostHeader, requestParamOptional | requestParamNotLoggedForUnfrontedMeekNonTransformedHeader},
+		{"meek_host_header", isHostHeader, requestParamOptional},
 		{"meek_transformed_host_name", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"meek_transformed_host_name", isBooleanFlag, requestParamOptional | requestParamLogFlagAsBool},
 		{"user_agent", isAnyString, requestParamOptional},
 		{"user_agent", isAnyString, requestParamOptional},
 		{"tls_profile", isAnyString, requestParamOptional},
 		{"tls_profile", isAnyString, requestParamOptional},
@@ -549,8 +549,8 @@ var remoteServerListStatParams = append(
 // the remote_server_list_stats entries. Use the values from the outer status
 // the remote_server_list_stats entries. Use the values from the outer status
 // request as an approximation (these values reflect the client at persistent
 // request as an approximation (these values reflect the client at persistent
 // stat shipping time, which may differ from the client at persistent stat
 // stat shipping time, which may differ from the client at persistent stat
-// recording time). Note that all but client_build_rev and device_region are
-// required fields.
+// recording time). Note that all but client_build_rev, device_region, and
+// device_location are required fields.
 var remoteServerListStatBackwardsCompatibilityParamNames = []string{
 var remoteServerListStatBackwardsCompatibilityParamNames = []string{
 	"session_id",
 	"session_id",
 	"propagation_channel_id",
 	"propagation_channel_id",
@@ -559,6 +559,7 @@ var remoteServerListStatBackwardsCompatibilityParamNames = []string{
 	"client_platform",
 	"client_platform",
 	"client_build_rev",
 	"client_build_rev",
 	"device_region",
 	"device_region",
+	"device_location",
 }
 }
 
 
 var failedTunnelStatParams = append(
 var failedTunnelStatParams = append(
@@ -881,6 +882,7 @@ var baseParams = []requestParamSpec{
 	{"client_features", isAnyString, requestParamOptional | requestParamArray},
 	{"client_features", isAnyString, requestParamOptional | requestParamArray},
 	{"client_build_rev", isHexDigits, requestParamOptional},
 	{"client_build_rev", isHexDigits, requestParamOptional},
 	{"device_region", isAnyString, requestParamOptional},
 	{"device_region", isAnyString, requestParamOptional},
+	{"device_location", isGeoHashString, requestParamOptional},
 }
 }
 
 
 // baseSessionParams adds to baseParams the required session_id parameter. For
 // baseSessionParams adds to baseParams the required session_id parameter. For
@@ -1556,3 +1558,19 @@ func isISO8601Date(_ *Config, value string) bool {
 func isLastConnected(_ *Config, value string) bool {
 func isLastConnected(_ *Config, value string) bool {
 	return value == "None" || isISO8601Date(nil, value)
 	return value == "None" || isISO8601Date(nil, value)
 }
 }
+
+const geohashAlphabet = "0123456789bcdefghjkmnpqrstuvwxyz"
+
+func isGeoHashString(_ *Config, value string) bool {
+	// Verify that the string is between 1 and 12 characters long
+	// and contains only characters from the geohash alphabet.
+	if len(value) < 1 || len(value) > 12 {
+		return false
+	}
+	for _, c := range value {
+		if strings.Index(geohashAlphabet, string(c)) == -1 {
+			return false
+		}
+	}
+	return true
+}

+ 4 - 0
psiphon/server/server_test.go

@@ -1006,6 +1006,7 @@ func runServer(t *testing.T, runConfig *runServerConfig) {
         "ClientFeatures" : %s,
         "ClientFeatures" : %s,
         "SponsorId" : "0",
         "SponsorId" : "0",
         "PropagationChannelId" : "0",
         "PropagationChannelId" : "0",
+        "DeviceLocation" : "gzzzz",
         "DeviceRegion" : "US",
         "DeviceRegion" : "US",
         "DisableRemoteServerListFetcher" : true,
         "DisableRemoteServerListFetcher" : true,
         "EstablishTunnelPausePeriodSeconds" : 1,
         "EstablishTunnelPausePeriodSeconds" : 1,
@@ -1634,6 +1635,7 @@ func checkExpectedServerTunnelLogFields(
 		"client_features",
 		"client_features",
 		"relay_protocol",
 		"relay_protocol",
 		"device_region",
 		"device_region",
+		"device_location",
 		"ssh_client_version",
 		"ssh_client_version",
 		"server_entry_region",
 		"server_entry_region",
 		"server_entry_source",
 		"server_entry_source",
@@ -2109,6 +2111,7 @@ func checkExpectedUniqueUserLogFields(
 		"sponsor_id",
 		"sponsor_id",
 		"client_platform",
 		"client_platform",
 		"device_region",
 		"device_region",
+		"device_location",
 	} {
 	} {
 		if fields[name] == nil || fmt.Sprintf("%s", fields[name]) == "" {
 		if fields[name] == nil || fmt.Sprintf("%s", fields[name]) == "" {
 			return fmt.Errorf("missing expected field '%s'", name)
 			return fmt.Errorf("missing expected field '%s'", name)
@@ -2128,6 +2131,7 @@ func checkExpectedDomainBytesLogFields(
 		"sponsor_id",
 		"sponsor_id",
 		"client_platform",
 		"client_platform",
 		"device_region",
 		"device_region",
+		"device_location",
 		"domain",
 		"domain",
 		"bytes",
 		"bytes",
 	} {
 	} {

+ 1 - 0
psiphon/server/tunnelServer.go

@@ -3189,6 +3189,7 @@ var blocklistHitsStatParams = []requestParamSpec{
 	{"client_features", isAnyString, requestParamOptional | requestParamArray},
 	{"client_features", isAnyString, requestParamOptional | requestParamArray},
 	{"client_build_rev", isHexDigits, requestParamOptional},
 	{"client_build_rev", isHexDigits, requestParamOptional},
 	{"device_region", isAnyString, requestParamOptional},
 	{"device_region", isAnyString, requestParamOptional},
+	{"device_location", isGeoHashString, requestParamOptional},
 	{"egress_region", isRegionCode, requestParamOptional},
 	{"egress_region", isRegionCode, requestParamOptional},
 	{"session_id", isHexDigits, 0},
 	{"session_id", isHexDigits, 0},
 	{"last_connected", isLastConnected, requestParamOptional},
 	{"last_connected", isLastConnected, requestParamOptional},

+ 6 - 0
psiphon/serverApi.go

@@ -699,6 +699,9 @@ func RecordRemoteServerListStat(
 	if config.DeviceRegion != "" {
 	if config.DeviceRegion != "" {
 		params["device_region"] = config.DeviceRegion
 		params["device_region"] = config.DeviceRegion
 	}
 	}
+	if config.DeviceLocation != "" {
+		params["device_location"] = config.DeviceLocation
+	}
 
 
 	params["client_download_timestamp"] = common.TruncateTimestampToHour(common.GetCurrentTimestamp())
 	params["client_download_timestamp"] = common.TruncateTimestampToHour(common.GetCurrentTimestamp())
 	tunneledStr := "0"
 	tunneledStr := "0"
@@ -938,6 +941,9 @@ func getBaseAPIParameters(
 	if config.DeviceRegion != "" {
 	if config.DeviceRegion != "" {
 		params["device_region"] = config.DeviceRegion
 		params["device_region"] = config.DeviceRegion
 	}
 	}
+	if config.DeviceLocation != "" {
+		params["device_location"] = config.DeviceLocation
+	}
 
 
 	if filter == baseParametersAll {
 	if filter == baseParametersAll {