Skip to content

Commit

Permalink
⚗️ Update experimental code
Browse files Browse the repository at this point in the history
  • Loading branch information
czy-29 committed Dec 15, 2024
1 parent 64b2431 commit b5f5727
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
25 changes: 22 additions & 3 deletions tracing-surreal/src/stop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::tracing_msg::{current_exe_name, ClientHandshake, MsgFormat, Role};
use crate::tracing_msg::{current_exe_name, ClientHandshake, ClientRole, MsgFormat};
use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use serde_json::Value;
Expand Down Expand Up @@ -28,6 +28,25 @@ struct RID {
id: RecordId,
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[serde(rename_all = "lowercase")]
enum Role {
Host,
Pusher,
Observer,
Director,
}

impl From<ClientRole> for Role {
fn from(value: ClientRole) -> Self {
match value {
ClientRole::Pusher => Self::Pusher,
ClientRole::Observer => Self::Observer,
ClientRole::Director => Self::Director,
}
}
}

impl<C: Connection> Stop<C> {
pub async fn init(db: Surreal<C>, app: &str) -> Result<Self, StopError> {
db.use_db(format!("app-tracing-{}", app)).await?;
Expand Down Expand Up @@ -94,7 +113,7 @@ impl<C: Connection> Stop<C> {
pub async fn client_handshake(
&self,
client_info: ClientHandshake,
client_role: Role,
client_role: ClientRole,
client_addr: SocketAddr,
query_map: Option<HashMap<String, String>>,
) -> surrealdb::Result<Self> {
Expand All @@ -103,7 +122,7 @@ impl<C: Connection> Stop<C> {
&self.session_id,
&self.formatted_timestamp,
&client_info.client_name,
client_role,
client_role.into(),
&client_info.proc_name,
client_info.proc_id,
Some(client_info.msg_format),
Expand Down
14 changes: 7 additions & 7 deletions tracing-surreal/src/tmp/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{stop::Stop, tracing_msg::Role};
use crate::{stop::Stop, tracing_msg::ClientRole};
use est::task::CloseAndWait;
use std::{
collections::HashMap,
Expand Down Expand Up @@ -270,7 +270,7 @@ impl<C: Connection + Clone> ServerBuilder<C> {
query,
auth_args.pusher_token,
role_send,
Role::Pusher,
ClientRole::Pusher,
resp
);
}
Expand All @@ -280,7 +280,7 @@ impl<C: Connection + Clone> ServerBuilder<C> {
query,
auth_args.observer_token,
role_send,
Role::Observer,
ClientRole::Observer,
resp
);
}
Expand All @@ -290,7 +290,7 @@ impl<C: Connection + Clone> ServerBuilder<C> {
query,
auth_args.director_token,
role_send,
Role::Director,
ClientRole::Director,
resp
);
}
Expand All @@ -313,7 +313,7 @@ impl<C: Connection + Clone> ServerBuilder<C> {
};

println!("inner_stream: {:?}", stream);
println!("inner_role: {:?}", role);
println!("client_role: {:?}", role);
println!("query_map: {:?}", query_map);
});
}
Expand Down Expand Up @@ -358,8 +358,8 @@ impl<C: Connection + Clone> BuildServerDefault<C> for Stop<C> {
fn token_auth(
query: Option<Result<HashMap<String, String>, serde_qs::Error>>,
token_need: Option<String>,
role_send: oneshot::Sender<Role>,
role: Role,
role_send: oneshot::Sender<ClientRole>,
role: ClientRole,
resp: Response,
) -> Result<Response, ErrorResponse> {
if let Some(token_need) = token_need {
Expand Down
5 changes: 3 additions & 2 deletions tracing-surreal/src/tracing_msg.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum Role {
Host,
#[serde(rename_all = "lowercase")]
pub enum ClientRole {
Pusher,
Observer,
Director,
}

#[derive(Serialize, Deserialize, Default, Debug, Copy, Clone, Eq, PartialEq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum MsgFormat {
Json,
#[default]
Expand Down

0 comments on commit b5f5727

Please sign in to comment.