trying to wrap client connections in a wrapper struct
This commit is contained in:
parent
d2985c3be8
commit
0f5dfb2c5c
3 changed files with 34 additions and 1 deletions
|
@ -4,7 +4,7 @@ use futures_util::FutureExt;
|
|||
use scct_model::{chats, messages, proto::c2s, users};
|
||||
use sea_orm::{ActiveModelTrait, ConnectionTrait, DatabaseConnection, EntityTrait, IntoActiveModel, ColumnTrait, QueryFilter, QueryOrder};
|
||||
use tokio::sync::Mutex;
|
||||
use transport::{Transport, TransportSink, TransportStream};
|
||||
use transport::{Transport, TransportSink, TransportStream, client_connection::ClientConnection};
|
||||
use uuid;
|
||||
|
||||
pub mod transport;
|
||||
|
@ -31,6 +31,7 @@ pub async fn serve(addr: &str, db_connection: DatabaseConnection) -> Result<(),
|
|||
|
||||
tracing::info!("listening for connections");
|
||||
while let Some((tx, rx)) = listener.recv().await {
|
||||
let client = ClientConnection::new((tx, rx));
|
||||
tracing::info!("new connection, starting handler");
|
||||
state.lock().await.push(tx);
|
||||
let _state = state.clone();
|
||||
|
|
30
server/src/transport/client_connection.rs
Normal file
30
server/src/transport/client_connection.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Wrapper around a (TransportStream, TransportSink) that represents a single
|
||||
// client connection. It's self-aware - it gets a uuid so we can distinguish
|
||||
// different connections and find the same one even if it's in different
|
||||
// variables.
|
||||
// Later into the life of a connection, it can be assigned a user uuid,
|
||||
// when a user logs in using that connection. That can also be unassigned
|
||||
// when the user logs out.
|
||||
// Basically lots of helper facilities.
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::{TransportSink, TransportStream};
|
||||
|
||||
pub struct ClientConnection {
|
||||
uuid: Uuid,
|
||||
tx: Box<dyn TransportSink>,
|
||||
rx: Box<dyn TransportStream>,
|
||||
user_uuid: Option<Uuid> // gets set if and only if a user is logged in with this connection
|
||||
}
|
||||
|
||||
impl ClientConnection {
|
||||
pub fn new((tx, rx): (impl TransportSink + 'static, impl TransportStream + 'static)) -> ClientConnection {
|
||||
ClientConnection {
|
||||
uuid: Uuid::new_v4(),
|
||||
tx: Box::new(tx),
|
||||
rx: Box::new(rx),
|
||||
user_uuid: None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,8 @@
|
|||
//!
|
||||
//! so basically most likely everything down here will get coupled more and merged with the rest
|
||||
|
||||
pub mod client_connection;
|
||||
|
||||
#[cfg(feature = "websocket")]
|
||||
pub mod websocket;
|
||||
|
||||
|
|
Loading…
Reference in a new issue