Skip to content

Commit 65c259a

Browse files
committed
feat: add debug logging messages for session start, resume, authenticate and tunnel initiation
1 parent 38a290d commit 65c259a

6 files changed

Lines changed: 47 additions & 6 deletions

File tree

src/routes/server.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,16 @@ pub async fn handle_upgrade(
120120
}
121121
};
122122

123+
let id = Session::acquire_id();
124+
125+
debug!(
126+
"Session started (SID: {}, ASSOC: {:?}, ADDR: {})",
127+
id, association_id, addr
128+
);
129+
123130
let data = SessionData::new(addr, association_id);
124131

125-
Session::run(upgraded, data, router).await;
132+
Session::run(id, upgraded, data, router).await;
126133
}
127134

128135
/// GET /api/server/tunnel

src/services/tunnel/http_tunnel.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use self::codec::{TunnelCodec, TunnelMessage};
66
use futures_util::{Sink, Stream};
77
use hyper::upgrade::Upgraded;
88
use hyper_util::rt::TokioIo;
9-
use log::error;
9+
use log::{debug, error};
1010
use std::{
1111
future::Future,
1212
pin::Pin,
@@ -103,6 +103,11 @@ impl HttpTunnel {
103103
}
104104
};
105105

106+
debug!(
107+
"Session HTTP tunnel connected (ASSOC: {:?}, TUNNEL_ID: {})",
108+
association, tunnel_id
109+
);
110+
106111
// Spawn the tunnel task
107112
tokio::spawn(HttpTunnel {
108113
service,

src/services/tunnel/udp_tunnel.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ fn handle_message(
170170
}
171171
};
172172

173+
debug!(
174+
"Session UDP tunnel connected (ASSOC: {:?}, TUNNEL_ID: {})",
175+
association, tunnel_id
176+
);
177+
173178
let buffer = serialize_message(tunnel_id, &TunnelMessage::Initiated { tunnel_id });
174179

175180
_ = service.udp_tx.send(UdpTunnelMessage {

src/session/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,12 @@ impl SessionNotifyHandle {
9898
}
9999

100100
impl Session {
101-
pub async fn run(io: Upgraded, data: SessionData, router: Arc<BlazeRouter>) {
102-
// Obtain a session ID
103-
let id = SESSION_IDS.fetch_add(1, Ordering::AcqRel);
101+
/// Get an ID for a session
102+
pub fn acquire_id() -> u32 {
103+
SESSION_IDS.fetch_add(1, Ordering::AcqRel)
104+
}
104105

106+
pub async fn run(id: u32, io: Upgraded, data: SessionData, router: Arc<BlazeRouter>) {
105107
let (notify_handle, rx) = SessionNotifyHandle::new();
106108
let session = Arc::new(Self {
107109
id,

src/session/routes/auth.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ pub async fn handle_login(
6868

6969
let session_token: String = sessions.create_token(player.id);
7070

71+
debug!(
72+
"Session authenticated (REASON: LOGIN_PASSWORD, PID: {}, SID: {})",
73+
player.id, session.id
74+
);
75+
7176
Ok(Blaze(AuthResponse {
7277
player,
7378
session_token,
@@ -102,6 +107,11 @@ pub async fn handle_silent_login(
102107
// Update the session stored player
103108
let player = session.data.set_auth(player);
104109

110+
debug!(
111+
"Session authenticated (REASON: LOGIN_SILENT, PID: {}, SID: {})",
112+
player.id, session.id
113+
);
114+
105115
Ok(Blaze(AuthResponse {
106116
player,
107117
session_token: token,
@@ -141,6 +151,11 @@ pub async fn handle_origin_login(
141151

142152
let session_token: String = sessions.create_token(player.id);
143153

154+
debug!(
155+
"Session authenticated (REASON: LOGIN_ORIGIN, PID: {}, SID: {})",
156+
player.id, session.id
157+
);
158+
144159
Ok(Blaze(AuthResponse {
145160
player,
146161
session_token,
@@ -367,6 +382,11 @@ pub async fn handle_create_account(
367382

368383
let session_token = sessions.create_token(player.id);
369384

385+
debug!(
386+
"Session authenticated (REASON: CREATED_ACCOUNT, PID: {}, SID: {})",
387+
player.id, session.id
388+
);
389+
370390
Ok(Blaze(AuthResponse {
371391
player,
372392
session_token,

src/session/routes/user_sessions.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
},
1515
};
1616
use chrono::Utc;
17-
use log::error;
17+
use log::{debug, error};
1818
use sea_orm::DatabaseConnection;
1919
use std::sync::Arc;
2020

@@ -87,6 +87,8 @@ pub async fn handle_resume_session(
8787
let player = sessions.add_session(player, Arc::downgrade(&session));
8888
let player = session.data.set_auth(player);
8989

90+
debug!("Session resumed (PID: {}, SID: {})", player.id, session.id);
91+
9092
Ok(Blaze(AuthResponse {
9193
player,
9294
session_token,

0 commit comments

Comments
 (0)