phantom_protocol/observability/
attrs.rs1use crate::transport::types::LegType;
28
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31pub enum Direction {
32 Send,
33 Recv,
34}
35
36impl Direction {
37 pub const fn as_str(self) -> &'static str {
38 match self {
39 Self::Send => "send",
40 Self::Recv => "recv",
41 }
42 }
43}
44
45pub fn leg_str(leg: LegType) -> &'static str {
55 match leg {
56 LegType::Kcp => "kcp",
57 LegType::Tcp => "tcp",
58 LegType::FakeTls => "faketls",
59 LegType::Udp => "udp",
60 }
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
65pub enum HandshakeOutcome {
66 Success,
67 Failure,
68}
69
70impl HandshakeOutcome {
71 pub const fn as_str(self) -> &'static str {
72 match self {
73 Self::Success => "success",
74 Self::Failure => "failure",
75 }
76 }
77}
78
79#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
84pub enum ProtocolVersion {
85 Current,
87}
88
89impl ProtocolVersion {
90 pub const fn as_str(self) -> &'static str {
91 match self {
92 Self::Current => "v1",
93 }
94 }
95}
96
97#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
99pub enum AeadAlgorithm {
100 Aes256Gcm,
101 ChaCha20Poly1305,
102}
103
104impl AeadAlgorithm {
105 pub const fn as_str(self) -> &'static str {
106 match self {
107 Self::Aes256Gcm => "aes-256-gcm",
108 Self::ChaCha20Poly1305 => "chacha20-poly1305",
109 }
110 }
111}
112
113#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
118pub enum ReplayReason {
119 Old,
121 Duplicate,
123}
124
125impl ReplayReason {
126 pub const fn as_str(self) -> &'static str {
127 match self {
128 Self::Old => "old",
129 Self::Duplicate => "duplicate",
130 }
131 }
132}
133
134#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
136pub enum CookieOutcome {
137 Issued,
138 ValidatedOk,
139 ValidatedMismatch,
140}
141
142impl CookieOutcome {
143 pub const fn as_str(self) -> &'static str {
144 match self {
145 Self::Issued => "issued",
146 Self::ValidatedOk => "validated_ok",
147 Self::ValidatedMismatch => "validated_mismatch",
148 }
149 }
150}
151
152#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
154pub enum PowOutcome {
155 Solved,
156 Rejected,
157}
158
159impl PowOutcome {
160 pub const fn as_str(self) -> &'static str {
161 match self {
162 Self::Solved => "solved",
163 Self::Rejected => "rejected",
164 }
165 }
166}
167
168#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
170pub enum EarlyDataOutcome {
171 Accepted,
172 RejectedUnknownTicket,
173 RejectedOversized,
174 RejectedAead,
175 RejectedReplay,
176}
177
178impl EarlyDataOutcome {
179 pub const fn as_str(self) -> &'static str {
180 match self {
181 Self::Accepted => "accepted",
182 Self::RejectedUnknownTicket => "rejected_unknown_ticket",
183 Self::RejectedOversized => "rejected_oversized",
184 Self::RejectedAead => "rejected_aead",
185 Self::RejectedReplay => "rejected_replay",
186 }
187 }
188}
189
190#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
192pub enum ResumptionMode {
193 OneRtt,
194 ZeroRtt,
195}
196
197impl ResumptionMode {
198 pub const fn as_str(self) -> &'static str {
199 match self {
200 Self::OneRtt => "1rtt",
201 Self::ZeroRtt => "0rtt",
202 }
203 }
204}
205
206#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
208pub enum PathValidationOutcome {
209 Success,
210 Failure,
211}
212
213impl PathValidationOutcome {
214 pub const fn as_str(self) -> &'static str {
215 match self {
216 Self::Success => "success",
217 Self::Failure => "failure",
218 }
219 }
220}
221
222#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
227pub enum FallbackReason {
228 LossThreshold,
229 RttThreshold,
230 PathFailure,
231 Explicit,
232}
233
234impl FallbackReason {
235 pub const fn as_str(self) -> &'static str {
236 match self {
237 Self::LossThreshold => "loss_threshold",
238 Self::RttThreshold => "rtt_threshold",
239 Self::PathFailure => "path_failure",
240 Self::Explicit => "explicit",
241 }
242 }
243}
244
245#[cfg(test)]
246mod tests {
247 use super::*;
248
249 #[test]
250 fn direction_strings_are_stable() {
251 assert_eq!(Direction::Send.as_str(), "send");
252 assert_eq!(Direction::Recv.as_str(), "recv");
253 }
254
255 #[test]
256 fn leg_str_covers_all_variants() {
257 assert_eq!(leg_str(LegType::Kcp), "kcp");
258 assert_eq!(leg_str(LegType::Tcp), "tcp");
259 assert_eq!(leg_str(LegType::FakeTls), "faketls");
260 assert_eq!(leg_str(LegType::Udp), "udp");
261 }
262
263 #[test]
264 fn protocol_version_strings() {
265 assert_eq!(ProtocolVersion::Current.as_str(), "v1");
266 }
267}