You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture.md
+26-5Lines changed: 26 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,15 +32,36 @@ The `GACAppCheck` class acts as the central coordinator.
32
32
* Any old token is overwritten.
33
33
5.**Completion:** The token (cached or new) is returned to the caller.
34
34
35
-
## Backoff Strategy
36
-
To prevent overwhelming the backend or Apple's servers during failures, `AppCheckCore` implements an exponential backoff strategy.
35
+
## Exponential Backoff Strategy
36
+
To prevent overwhelming the backend or Apple's servers during failures, `AppCheckCore` implements a robust exponential backoff strategy via `GACAppCheckBackoffWrapper`.
***Jitter:** A random multiplier between $1.0$ and $1.5$ (to prevent thundering herd problems).
45
+
***MaxInterval:** 4 hours.
46
+
47
+
### Error Policies
48
+
The backoff behavior depends on the error type, specifically HTTP status codes returned by the backend:
49
+
50
+
| HTTP Status Code | Backoff Type | Reason |
51
+
| :--- | :--- | :--- |
52
+
|**< 400**|**None**| Network errors or successful requests do not trigger backoff. |
53
+
|**400 (Bad Request)**<br>**404 (Not Found)**|**1 Day**| Indicates a project misconfiguration or outdated app version. Unlikely to resolve quickly. |
54
+
|**403 (Forbidden)**<br>**429 (Too Many Requests)**<br>**503 (Service Unavailable)**|**Exponential**| Indicates soft deletion, rate limiting, or server overload. Retrying later is appropriate. |
55
+
|**Other 5xx**|**Exponential**| Standard server errors. |
56
+
57
+
### Implementation
37
58
***Class:**`GACAppCheckBackoffWrapper`
38
59
***Usage:** Providers (`GACAppAttestProvider`, `GACDeviceCheckProvider`) wrap their network and attestation calls in this backoff mechanism.
39
-
***Behavior:**Retries with increasing delays on retryable errors (e.g., network timeouts, temporary server errors 503). Non-retryable errors (e.g., 403 Forbidden, 400 Bad Request) fail immediately.
60
+
***State:**The wrapper tracks the failure count and the last failure time. It resets to 0 upon a successful token fetch.
40
61
41
62
## Threading Model
42
63
***Concurrency:**`AppCheckCore` is designed to be thread-safe.
43
64
***Queues:**
44
-
***Main Queue:** Completion handlers are typically dispatched to the main queue (or a user-specified queue if the API supported it, but currently defaults to main for top-level APIs).
65
+
***Main Queue:** Completion handlers are typically dispatched to the main queue.
45
66
***Internal Queues:** Providers use private serial queues (e.g., `com.google.GACAppAttestProvider`) to manage state and sequentialize complex attestation flows (like generating a key, then attesting, then exchanging).
46
-
***Background:** Network requests are performed on background queues (`QOS_CLASS_DEFAULT` or `QOS_CLASS_UTILITY`).
67
+
***Background:** Network requests are performed on background queues (`QOS_CLASS_DEFAULT` or `QOS_CLASS_UTILITY`).
This document details the internal design and detailed flows of each App Check provider.
3
+
This document details the internal design and detailed flows of each App Check provider, including error handling, retries, and state resets.
4
4
5
5
## AppAttest Provider (`GACAppAttestProvider`)
6
6
The most complex provider, interacting with `DCAppAttestService`. It maintains a stable key pair on the device to sign assertions.
@@ -9,10 +9,12 @@ The most complex provider, interacting with `DCAppAttestService`. It maintains a
9
9
***Service:**`DCAppAttestService` (Apple's API).
10
10
***Storage:**
11
11
*`GACAppAttestKeyIDStorage`: Stores the generated App Attest Key ID.
12
-
*`GACAppAttestArtifactStorage`: Stores the "artifact" returned by the Firebase backend after a successful initial handshake. This artifact effectively links the on-device key to the backend session.
12
+
*`GACAppAttestArtifactStorage`: Stores the "artifact" returned by the Firebase backend after a successful initial handshake.
13
+
***Resiliency:**
14
+
***Automatic Retry:** The provider wraps the entire flow in a retry loop. If a specific "Rejection Error" occurs (e.g., invalid key), it resets its internal state and retries the flow from scratch.
13
15
14
16
### Flow 1: Initial Handshake (Attestation)
15
-
Occurs when the app runs for the first time or if the stored artifact is missing/corrupted.
17
+
Occurs when the app runs for the first time, or if the stored artifact is missing, or **after a reset**.
0 commit comments