surrealcs_kernel/logging/messages/connections/
ping.rs

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
//! Defines the logging structure to capture the journey of a ping message.

/// The journey of a ping message.
///
/// This is used to log the journey of a ping message through the server.
///
/// # Fields
/// * `SentByActor`: the ping message was sent by the inital ping actor
/// * `RecievedByClientWriter`: the ping message was recieved by the client writer to be sent to the server
/// * `RecievedByServerReader`: the ping message was recieved by the server reader to be sent to the server router
/// * `RecievedByServerRouter`: the ping message was recieved by the server router to be sent to the server writer
/// * `RecievedByServerWriter`: the ping message was recieved by the server writer to be sent to the client reader
/// * `RecievedByClientReader`: the ping message was recieved by the client reader to be sent to the client router
/// * `RecievedByClientRouter`: the ping message was recieved by the client router to be sent to the inital ping actor
/// * `RecievedByActor`: the ping message was recieved by the inital ping actor
pub enum PingJourney {
	SentByActor,
	RecievedByClientWriter,
	RecievedByServerReader,
	RecievedByServerRouter,
	RecievedByServerWriter,
	RecievedByClientReader,
	RecievedByClientRouter,
	RecievedByActor,
}

impl PingJourney {
	/// Converts the ping journey step to a string for logging.
	///
	/// # Returns
	/// A string representation of the ping journey step.
	pub fn as_str(&self) -> &'static str {
		match self {
			PingJourney::SentByActor => "Sent by actor", // logged in client/src/utils/ping_actor.rs
			PingJourney::RecievedByClientWriter => "Recieved by client writer", // logged in client/src/connection/writer.rs
			PingJourney::RecievedByServerReader => "Recieved by server reader", // logged in server/src/connection/reader.rs
			PingJourney::RecievedByServerRouter => "Recieved by server router", // logged in server/src/connection/router.rs
			PingJourney::RecievedByServerWriter => "Recieved by server writer", // logged in server/src/connection/writer.rs
			PingJourney::RecievedByClientReader => "Recieved by client reader", // logged in client/src/connection/reader.rs
			PingJourney::RecievedByClientRouter => "Recieved by client router", // logged in client/src/connection/router.rs
			PingJourney::RecievedByActor => "Recieved by actor", // logged in client/src/utils/ping_actor.rs
		}
	}

	/// Converts the ping journey step to a string for logging.
	///
	/// # Arguments
	/// * `connection_id`: the ID of the connection that the ping message is associated with
	///
	/// # Returns
	/// A string representation of the ping journey step.
	pub fn to_log(&self, connection_id: &String) -> String {
		format!("connection ping: {} -> [{}]", self.as_str(), connection_id)
	}
}