|
|
@@ -1150,12 +1150,19 @@ func UseStoredTactics(
|
|
|
// when there is an unexpired stored tactics record available. The
|
|
|
// caller is expected to set any overall timeout in the context input.
|
|
|
//
|
|
|
+// Limitation: it is assumed that the network ID obtained from getNetworkID
|
|
|
+// is the one that is active when the tactics request is received by the
|
|
|
+// server. However, it is remotely possible to switch networks
|
|
|
+// immediately after invoking the GetNetworkID callback and initiating
|
|
|
+// the request. This is partially mitigated by rechecking the network ID
|
|
|
+// after the request and failing if it differs from the initial network ID.
|
|
|
+//
|
|
|
// FetchTactics modifies the apiParams input.
|
|
|
func FetchTactics(
|
|
|
ctx context.Context,
|
|
|
clientParameters *parameters.ClientParameters,
|
|
|
storer Storer,
|
|
|
- networkID string,
|
|
|
+ getNetworkID func() string,
|
|
|
apiParams common.APIParameters,
|
|
|
endPointRegion string,
|
|
|
endPointProtocol string,
|
|
|
@@ -1163,6 +1170,8 @@ func FetchTactics(
|
|
|
encodedRequestObfuscatedKey string,
|
|
|
roundTripper RoundTripper) (*Record, error) {
|
|
|
|
|
|
+ networkID := getNetworkID()
|
|
|
+
|
|
|
record, err := getStoredTacticsRecord(storer, networkID)
|
|
|
if err != nil {
|
|
|
return nil, common.ContextError(err)
|
|
|
@@ -1196,6 +1205,10 @@ func FetchTactics(
|
|
|
return nil, common.ContextError(err)
|
|
|
}
|
|
|
|
|
|
+ if networkID != getNetworkID() {
|
|
|
+ return nil, common.ContextError(errors.New("network ID changed"))
|
|
|
+ }
|
|
|
+
|
|
|
err = AddSpeedTestSample(
|
|
|
clientParameters,
|
|
|
storer,
|
|
|
@@ -1251,6 +1264,10 @@ func FetchTactics(
|
|
|
return nil, common.ContextError(err)
|
|
|
}
|
|
|
|
|
|
+ if networkID != getNetworkID() {
|
|
|
+ return nil, common.ContextError(errors.New("network ID changed"))
|
|
|
+ }
|
|
|
+
|
|
|
// Process and store the response payload.
|
|
|
|
|
|
var payload *Payload
|