Ver código fonte

Pass inputs to psinet database lookups

Rod Hynes 9 anos atrás
pai
commit
11a4ec4620
2 arquivos alterados com 15 adições e 10 exclusões
  1. 12 7
      psiphon/server/api.go
  2. 3 3
      psiphon/server/psinet.go

+ 12 - 7
psiphon/server/api.go

@@ -105,8 +105,6 @@ func handshakeAPIRequestHandler(
 			baseRequestParams)).Info("API event")
 
 	// TODO: share struct definition with psiphon/serverApi.go?
-	// TODO: populate response data using psinet database
-
 	var handshakeResponse struct {
 		Homepages            []string            `json:"homepages"`
 		UpgradeClientVersion string              `json:"upgrade_client_version"`
@@ -117,19 +115,26 @@ func handshakeAPIRequestHandler(
 		ServerTimestamp      string              `json:"server_timestamp"`
 	}
 
+	// Ignoring errors as params are validated
+	sponsorID, _ := getStringRequestParam(params, "sponsor_id")
+	propagationChannelID, _ := getStringRequestParam(params, "propagation_channel_id")
+	clientVersion, _ := getStringRequestParam(params, "client_version")
+	clientPlatform, _ := getStringRequestParam(params, "client_platform")
+	clientRegion := geoIPData.Country
+
 	handshakeResponse.Homepages = psinetDatabase.GetHomepages(
-		"", "", "") // TODO: sponsorID, clientRegion, clientPlatform)
+		sponsorID, clientRegion, clientPlatform)
 
 	handshakeResponse.UpgradeClientVersion = psinetDatabase.GetUpgradeClientVersion(
-		"") // TODO: clientVersion)
+		clientVersion, clientPlatform)
 
 	handshakeResponse.HttpsRequestRegexes = psinetDatabase.GetHttpsRequestRegexes(
-		"", "", "") // TODO: sponsorID, clientRegion, clientPlatform)
+		sponsorID)
 
 	handshakeResponse.EncodedServerList = psinetDatabase.DiscoverServers(
-		"", 0) // TODO: propagationChannelID, discoveryValue)
+		propagationChannelID, geoIPData.DiscoveryValue)
 
-	handshakeResponse.ClientRegion = geoIPData.Country
+	handshakeResponse.ClientRegion = clientRegion
 
 	handshakeResponse.ServerTimestamp = psiphon.GetCurrentTimestamp()
 

+ 3 - 3
psiphon/server/psinet.go

@@ -48,7 +48,7 @@ func (psinet *PsinetDatabase) GetHomepages(sponsorID, clientRegion, clientPlatfo
 // GetUpgradeClientVersion returns a new client version when an upgrade is
 // indicated for the specified client current version. The result is "" when
 // no upgrade is available.
-func (psinet *PsinetDatabase) GetUpgradeClientVersion(clientVersion string) string {
+func (psinet *PsinetDatabase) GetUpgradeClientVersion(clientVersion, clientPlatform string) string {
 
 	// TODO: implement
 
@@ -56,8 +56,8 @@ func (psinet *PsinetDatabase) GetUpgradeClientVersion(clientVersion string) stri
 }
 
 // GetHttpsRequestRegexes returns bytes transferred stats regexes for the
-// specified client inputs.
-func (psinet *PsinetDatabase) GetHttpsRequestRegexes(sponsorID, clientRegion, clientPlatform string) []map[string]string {
+// specified sponsor.
+func (psinet *PsinetDatabase) GetHttpsRequestRegexes(sponsorID string) []map[string]string {
 
 	return make([]map[string]string, 0)
 }