surrealcs_kernel/logging/messages/connections/
ping.rs

1//! Defines the logging structure to capture the journey of a ping message.
2
3/// The journey of a ping message.
4///
5/// This is used to log the journey of a ping message through the server.
6///
7/// # Fields
8/// * `SentByActor`: the ping message was sent by the inital ping actor
9/// * `RecievedByClientWriter`: the ping message was recieved by the client writer to be sent to the server
10/// * `RecievedByServerReader`: the ping message was recieved by the server reader to be sent to the server router
11/// * `RecievedByServerRouter`: the ping message was recieved by the server router to be sent to the server writer
12/// * `RecievedByServerWriter`: the ping message was recieved by the server writer to be sent to the client reader
13/// * `RecievedByClientReader`: the ping message was recieved by the client reader to be sent to the client router
14/// * `RecievedByClientRouter`: the ping message was recieved by the client router to be sent to the inital ping actor
15/// * `RecievedByActor`: the ping message was recieved by the inital ping actor
16pub enum PingJourney {
17	SentByActor,
18	RecievedByClientWriter,
19	RecievedByServerReader,
20	RecievedByServerRouter,
21	RecievedByServerWriter,
22	RecievedByClientReader,
23	RecievedByClientRouter,
24	RecievedByActor,
25}
26
27impl PingJourney {
28	/// Converts the ping journey step to a string for logging.
29	///
30	/// # Returns
31	/// A string representation of the ping journey step.
32	pub fn as_str(&self) -> &'static str {
33		match self {
34			PingJourney::SentByActor => "Sent by actor", // logged in client/src/utils/ping_actor.rs
35			PingJourney::RecievedByClientWriter => "Recieved by client writer", // logged in client/src/connection/writer.rs
36			PingJourney::RecievedByServerReader => "Recieved by server reader", // logged in server/src/connection/reader.rs
37			PingJourney::RecievedByServerRouter => "Recieved by server router", // logged in server/src/connection/router.rs
38			PingJourney::RecievedByServerWriter => "Recieved by server writer", // logged in server/src/connection/writer.rs
39			PingJourney::RecievedByClientReader => "Recieved by client reader", // logged in client/src/connection/reader.rs
40			PingJourney::RecievedByClientRouter => "Recieved by client router", // logged in client/src/connection/router.rs
41			PingJourney::RecievedByActor => "Recieved by actor", // logged in client/src/utils/ping_actor.rs
42		}
43	}
44
45	/// Converts the ping journey step to a string for logging.
46	///
47	/// # Arguments
48	/// * `connection_id`: the ID of the connection that the ping message is associated with
49	///
50	/// # Returns
51	/// A string representation of the ping journey step.
52	pub fn to_log(&self, connection_id: &String) -> String {
53		format!("connection ping: {} -> [{}]", self.as_str(), connection_id)
54	}
55}