|
@@ -117,8 +117,10 @@ func NewDatabase(filename string) (*Database, error) {
|
|
|
|
|
|
|
|
// GetRandomizedHomepages returns a randomly ordered list of home pages
|
|
// GetRandomizedHomepages returns a randomly ordered list of home pages
|
|
|
// for the specified sponsor, region, and platform.
|
|
// for the specified sponsor, region, and platform.
|
|
|
-func (db *Database) GetRandomizedHomepages(sponsorID, clientRegion string, isMobilePlatform bool) []string {
|
|
|
|
|
- homepages := db.GetHomepages(sponsorID, clientRegion, isMobilePlatform)
|
|
|
|
|
|
|
+func (db *Database) GetRandomizedHomepages(
|
|
|
|
|
+ sponsorID, clientRegion, clientASN string, isMobilePlatform bool) []string {
|
|
|
|
|
+
|
|
|
|
|
+ homepages := db.GetHomepages(sponsorID, clientRegion, clientASN, isMobilePlatform)
|
|
|
if len(homepages) > 1 {
|
|
if len(homepages) > 1 {
|
|
|
shuffledHomepages := make([]string, len(homepages))
|
|
shuffledHomepages := make([]string, len(homepages))
|
|
|
perm := rand.Perm(len(homepages))
|
|
perm := rand.Perm(len(homepages))
|
|
@@ -132,7 +134,9 @@ func (db *Database) GetRandomizedHomepages(sponsorID, clientRegion string, isMob
|
|
|
|
|
|
|
|
// GetHomepages returns a list of home pages for the specified sponsor,
|
|
// GetHomepages returns a list of home pages for the specified sponsor,
|
|
|
// region, and platform.
|
|
// region, and platform.
|
|
|
-func (db *Database) GetHomepages(sponsorID, clientRegion string, isMobilePlatform bool) []string {
|
|
|
|
|
|
|
+func (db *Database) GetHomepages(
|
|
|
|
|
+ sponsorID, clientRegion, clientASN string, isMobilePlatform bool) []string {
|
|
|
|
|
+
|
|
|
db.ReloadableFile.RLock()
|
|
db.ReloadableFile.RLock()
|
|
|
defer db.ReloadableFile.RUnlock()
|
|
defer db.ReloadableFile.RUnlock()
|
|
|
|
|
|
|
@@ -163,7 +167,8 @@ func (db *Database) GetHomepages(sponsorID, clientRegion string, isMobilePlatfor
|
|
|
homePagesByRegion, ok := homePages[clientRegion]
|
|
homePagesByRegion, ok := homePages[clientRegion]
|
|
|
if ok {
|
|
if ok {
|
|
|
for _, homePage := range homePagesByRegion {
|
|
for _, homePage := range homePagesByRegion {
|
|
|
- sponsorHomePages = append(sponsorHomePages, strings.Replace(homePage.URL, "client_region=XX", "client_region="+clientRegion, 1))
|
|
|
|
|
|
|
+ sponsorHomePages = append(
|
|
|
|
|
+ sponsorHomePages, homepageQueryParameterSubstitution(homePage.URL, clientRegion, clientASN))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -173,7 +178,8 @@ func (db *Database) GetHomepages(sponsorID, clientRegion string, isMobilePlatfor
|
|
|
if ok {
|
|
if ok {
|
|
|
for _, homePage := range defaultHomePages {
|
|
for _, homePage := range defaultHomePages {
|
|
|
// client_region query parameter substitution
|
|
// client_region query parameter substitution
|
|
|
- sponsorHomePages = append(sponsorHomePages, strings.Replace(homePage.URL, "client_region=XX", "client_region="+clientRegion, 1))
|
|
|
|
|
|
|
+ sponsorHomePages = append(
|
|
|
|
|
+ sponsorHomePages, homepageQueryParameterSubstitution(homePage.URL, clientRegion, clientASN))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -181,6 +187,14 @@ func (db *Database) GetHomepages(sponsorID, clientRegion string, isMobilePlatfor
|
|
|
return sponsorHomePages
|
|
return sponsorHomePages
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+func homepageQueryParameterSubstitution(
|
|
|
|
|
+ url, clientRegion, clientASN string) string {
|
|
|
|
|
+
|
|
|
|
|
+ return strings.Replace(
|
|
|
|
|
+ strings.Replace(url, "client_region=XX", "client_region="+clientRegion, 1),
|
|
|
|
|
+ "client_asn=XX", "client_asn="+clientASN, 1)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// GetUpgradeClientVersion returns a new client version when an upgrade is
|
|
// GetUpgradeClientVersion returns a new client version when an upgrade is
|
|
|
// indicated for the specified client current version. The result is "" when
|
|
// indicated for the specified client current version. The result is "" when
|
|
|
// no upgrade is available. Caller should normalize clientPlatform.
|
|
// no upgrade is available. Caller should normalize clientPlatform.
|