From b1ef49475912b82928195e37e7966b839c112fff Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Tue, 9 May 2023 04:43:47 -0500 Subject: [PATCH] some server work --- proto/chat.proto | 2 +- server/src/main.rs | 11 ++++++----- server/src/mux.rs | 12 ++++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/proto/chat.proto b/proto/chat.proto index d1dad2d..c56b1bd 100644 --- a/proto/chat.proto +++ b/proto/chat.proto @@ -24,7 +24,7 @@ message User { string username = 1; } // RPC Messages -message JoinResponse {} +message RoomActionResponse {} message RoomAction { string roomId = 1; diff --git a/server/src/main.rs b/server/src/main.rs index 2c85e88..1337057 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -12,7 +12,7 @@ use tower::{Layer, Service}; use mraow_common::chat_proto::{ chat_server::{Chat, ChatServer}, - ChatMessage, JoinResponse, RoomList, User, UserList, + ChatMessage, RoomAction, RoomActionResponse, RoomList, User, UserList, }; type ResponseStream = @@ -23,12 +23,12 @@ pub struct ChatImpl {} #[tonic::async_trait] impl Chat for ChatImpl { - type receiveMsgStream = ResponseStream; + type receiveMsgsStream = ResponseStream; - async fn join( + async fn room_action( &self, - request: Request, - ) -> Result, Status> { + request: Request, + ) -> Result, Status> { println!("Join {request:?}"); todo!() } @@ -89,6 +89,7 @@ impl Chat for ChatImpl { #[tokio::main] async fn main() -> Result<(), Box> { + // https://git.mzhang.io/michael/mraow/issues/1 let addr = "[::1]:50051".parse().unwrap(); let greeter = ChatImpl::default(); diff --git a/server/src/mux.rs b/server/src/mux.rs index 70a6c58..a117078 100644 --- a/server/src/mux.rs +++ b/server/src/mux.rs @@ -14,7 +14,13 @@ use tokio::{ task::JoinHandle, }; -pub struct Mux {} +#[derive(Clone)] +pub struct SharedMux(Mutex); + +/// Shared server state +pub struct Mux { + rooms: HashMap, +} #[derive(Clone)] pub enum RoomMessage {} @@ -53,7 +59,9 @@ pub struct CompositeListener { impl CompositeListener {} -fn create_listener() -> ( +/// Create a "composite" listener that listens to multiple rooms / streams, and +/// is able to add more streams in the middle as well +pub fn create_listener() -> ( JoinHandle<()>, UnboundedSender, UnboundedReceiver,