xmtp_configuration/common/api.rs
1//! Backend connection values.
2
3pub const LOCALHOST: &str = "http://localhost";
4/// Maximum bytes in one gRPC payload.
5pub const GRPC_PAYLOAD_LIMIT: usize = 1024 * 1024 * 25;
6
7/// Local backend URL when no worktree environment is loaded.
8pub const BACKEND_TEST_URL_DEFAULT: &str = "http://localhost:5050";
9/// Local backend proxy URL when no worktree environment is loaded.
10pub const BACKEND_TEST_TOXIC_URL_DEFAULT: &str = "http://localhost:6010";
11
12/// Local backend URL for client tests.
13///
14/// Each worktree publishes the stack on its own ports, so the address comes
15/// from the environment. `dev/worktree-env` writes it and the `just` recipes
16/// export it. The constant above is the fallback for a bare `cargo test`.
17///
18/// Native reads the variable at run time. Wasm has no `std::env`, so the value
19/// is baked in at build time instead; build through `just wasm test` so the
20/// worktree's environment is loaded.
21pub fn backend_test_url() -> String {
22 #[cfg(not(target_arch = "wasm32"))]
23 {
24 std::env::var("XMTP_BACKEND_URL").unwrap_or_else(|_| BACKEND_TEST_URL_DEFAULT.to_string())
25 }
26 #[cfg(target_arch = "wasm32")]
27 {
28 option_env!("XMTP_BACKEND_URL")
29 .unwrap_or(BACKEND_TEST_URL_DEFAULT)
30 .to_string()
31 }
32}
33
34/// Local backend proxy URL for fault tests. See [`backend_test_url`].
35pub fn backend_test_toxic_url() -> String {
36 #[cfg(not(target_arch = "wasm32"))]
37 {
38 std::env::var("XMTP_BACKEND_TOXIC_URL")
39 .unwrap_or_else(|_| BACKEND_TEST_TOXIC_URL_DEFAULT.to_string())
40 }
41 #[cfg(target_arch = "wasm32")]
42 {
43 option_env!("XMTP_BACKEND_TOXIC_URL")
44 .unwrap_or(BACKEND_TEST_TOXIC_URL_DEFAULT)
45 .to_string()
46 }
47}
48
49/// Temporary test URL names. Remove with the Task 9 binding update.
50pub struct GrpcUrls;
51impl GrpcUrls {
52 pub fn node() -> String {
53 backend_test_url()
54 }
55 pub fn gateway() -> String {
56 backend_test_url()
57 }
58}
59
60/// Temporary fault-test URL name. Remove with the Task 9 binding update.
61pub struct GrpcUrlsToxic;
62impl GrpcUrlsToxic {
63 pub fn node() -> String {
64 backend_test_toxic_url()
65 }
66}
67
68/// Maximum consecutive credential rejections and callback failures.
69///
70/// This value must stay above the failures one caller request can produce, or
71/// a single API call locks the client out. `Retry::default()` makes 6 attempts
72/// (5 retries), and the auth middleware replays each attempt once with a fresh
73/// credential, so one call can count up to 12 failures. The limit is above
74/// that, so only repeated calls reach the lockout. Raise it together with the
75/// retry budget; `retry_budget_cannot_reach_the_auth_lockout` checks the
76/// relation.
77pub const MAX_CONSECUTIVE_AUTH_FAILURES: u32 = 13;
78/// Time before one authentication probe is allowed after lockout.
79pub const AUTH_LOCKOUT_COOLDOWN: std::time::Duration = std::time::Duration::from_secs(60);