1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//! Every fixed value the crate uses, in one place. None of these is part of
//! the public surface.
use Duration;
// Outgoing size (LIMIT-01). Size is only ever checked on commands the client
// sends. Received messages are already fully buffered when they arrive, so
// checking them bounds no memory and only discards data.
//
// The command bound is the server's transport ceiling: above it no plan can
// accept a command. Each plan's own, smaller cap on the whole encoded command
// is enforced by the server and surfaces as a MessageSizeLimitError server
// error.
pub const MAXIMUM_COMMAND_BYTES: usize = 2 * 1024 * 1024;
// Equal to the command bound, so a maximum-size command always fits an empty
// writer and anything behind it waits for room.
pub const MAXIMUM_BUFFERED_BYTES: usize = MAXIMUM_COMMAND_BYTES;
// Bounds the writer and the publishes kept for a rate-limit resend, and is the
// default bound on the publishes that wait for the writer (publish queue size).
pub const MAXIMUM_PENDING_COMMANDS: usize = 64;
// Batching (BATCH-01). The writer sends the frames waiting for it in one `*N`
// frame of at most this many commands and bytes, header included. A command
// larger than the byte bound goes alone. The server refuses an array of more
// than 16 commands.
pub const MAXIMUM_BATCH_COMMANDS: usize = 16;
pub const MAXIMUM_BATCH_BYTES: usize = 64 * 1024;
// Outbound recovery (RESEND-01). A rate limit is reported without saying which
// frame it dropped, so whatever went out recently is resent.
//
// The server reports drops at most once a second, and a second more covers the
// round trip, so a report concerns only commands sent within this window.
pub const RATE_LIMIT_SUSPECT_WINDOW: Duration = from_secs;
// Resending waits at least this long, past the per-second window the dropped
// frames were counted in.
pub const RATE_LIMIT_COOLDOWN: Duration = from_secs;
// Bounds the extra load, and the extra usage, a rate limit can cause.
pub const MAXIMUM_PUBLISH_RESENDS: u32 = 1;
// After this many rate limits in a row the limit is treated as a used-up quota
// (per hour or per month): recent publishes are no longer resent, and recent
// subscriptions wait for a quota probe.
pub const MAXIMUM_CONSECUTIVE_RATE_LIMITS: u32 = 8;
// A used-up quota refuses every frame, so the subscriptions it dropped are
// re-sent rarely rather than abandoned: first after a minute, then doubling.
pub const QUOTA_PROBE_FIRST_DELAY: Duration = from_secs;
pub const QUOTA_PROBE_MAXIMUM_DELAY: Duration = from_secs;
// Generated message ids share every receiver's deduplication window with ids
// from other publishers, so they are random and long enough never to collide.
pub const MESSAGE_ID_RANDOM_BYTES: usize = 16;
// Every generated message id names the SDK that made it (RESEND-01): this
// crate's language and its version from Cargo.toml.
pub const SDK_LANGUAGE: &str = "rust";
pub const SDK_VERSION: &str = env!;
// Decoder bounds. These limit parsing work and recursion, not message size; no
// legitimate server message approaches them.
pub const MAXIMUM_FRAGMENTS: usize = 4096;
pub const MAXIMUM_DEPTH: usize = 32;
// "PRES_LIST_RESPONSE", the longest command the server sends.
pub const MAXIMUM_COMMAND_NAME_BYTES: usize = 18;
pub const MAXIMUM_ERROR_NAME_BYTES: usize = 64;
// Integer64 (`:`) carries timestamps; it is also the range of bulk and array
// lengths. "-9223372036854775808" is its widest value.
pub const MAXIMUM_INTEGER64_LINE_BYTES: usize = 20;
// Integer32 (`;`) carries every other integer. "-2147483648" is its widest
// value.
pub const MAXIMUM_INTEGER32_LINE_BYTES: usize = 11;
// The largest page a presence query may request.
pub const MAXIMUM_PRESENCE_PER_PAGE: i32 = 100;
// Connection defaults. Consumers do not configure where Celeris lives;
// overriding the base URL is for local stacks and other deployments
// (ENDPOINT-01).
pub const DEFAULT_BASE_URL: &str = "wss://realtime.useceleris.com";
pub const DEFAULT_CONNECT_TIMEOUT: Duration = from_secs;
pub const DEFAULT_PRESENCE_QUERY_TIMEOUT: Duration = from_secs;
// The shortest and the longest timeout an option accepts (CONFIG-01). Every SDK
// shares them, and the longest stays below the largest delay a JavaScript timer
// can count.
pub const MINIMUM_TIMEOUT: Duration = from_millis;
pub const MAXIMUM_TIMEOUT: Duration = from_secs;
pub const DEFAULT_SEGMENT_ID: &str = "default";
// The longest channel reference the server accepts.
pub const MAXIMUM_CHANNEL_REFERENCE_LENGTH: usize = 255;
// The command a presence query error names as its sub type (QUERY-01).
pub const PRESENCE_LIST_COMMAND: &str = "PRES_LIST";
// Recovery. The default maximum reconnect attempts.
pub const DEFAULT_MAXIMUM_RECONNECT_ATTEMPTS: u32 = 10;
// The largest maximum reconnect attempts an option accepts (CONFIG-01), so a
// channel that cannot reconnect reaches failed in a known time.
pub const MAXIMUM_RECONNECT_ATTEMPTS_CEILING: u32 = 100;
pub const RETRY_BUDGET_RESET: Duration = from_secs;
pub const RETRY_BASE_DELAY: Duration = from_millis;
pub const RETRY_DELAY_CAP: Duration = from_secs;
// A rate limit already in hand disproves recovery only if commands flowed
// unrefused for longer than the longest pause plus the report window; any
// sooner, it may be a late report of the frames that just went out.
pub const QUOTA_RETURN_CONFIRMATION: Duration =
RETRY_DELAY_CAP.saturating_add;
pub const REPLAY_OVERLAP: Duration = from_secs;
// The server's largest replay lookback: an unsigned 32-bit millisecond count.
pub const REPLAY_LOOKBACK_CAP: Duration = from_millis;
pub const CLOSE_BUDGET: Duration = from_secs;
// The server pings every 30 seconds and closes a connection from which it has
// received no ping or pong for 60 seconds; data frames do not count
// (HEARTBEAT-01). The client answers its pings only while the channel reads,
// so it pings on its own this often: every 60-second window holds at least two
// pings, so one can fail to go out.
pub const HEARTBEAT_INTERVAL: Duration = from_secs;
// A ping unanswered for this much reading time means the path is dead
// (HEARTBEAT-01), so a dead path is noticed within about 35 seconds. Pongs
// arrive only while the channel reads, so time a listener holds the reader
// never counts.
pub const HEARTBEAT_TIMEOUT: Duration = from_secs;
// The default deduplication window (deduplication window size).
pub const DEFAULT_DEDUPLICATION_WINDOW_SIZE: usize = 1024;