From 6d43a96c311a553cc6796e3edccb8a1c0e263e2d Mon Sep 17 00:00:00 2001 From: Max Audron Date: Sun, 3 Oct 2021 12:40:32 +0200 Subject: statetracker: rewrite sync handling --- examples/statetracker/src/server.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'examples/statetracker/src/server.rs') diff --git a/examples/statetracker/src/server.rs b/examples/statetracker/src/server.rs index 6d56662..63b36f7 100644 --- a/examples/statetracker/src/server.rs +++ b/examples/statetracker/src/server.rs @@ -93,6 +93,12 @@ impl Data for Message { } } +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Direction { + ServerToClient, + ClientToServer, +} + impl Server { pub async fn init( &self, @@ -116,7 +122,7 @@ impl Server { mut sink: SplitSink, Vec>, mut state: ClientState, ctx: ExtEventSink, - direction: &str, + direction: Direction, ) { // Start event loop while let Some(msg) = stream.next().await { @@ -141,7 +147,7 @@ impl Server { async fn handle_login_message( buf: &[u8], state: &mut ClientState, - direction: &str, + direction: Direction, _ctx: ExtEventSink, ) -> Result { use libquassel::HandshakeDeserialize; @@ -149,7 +155,7 @@ impl Server { trace!(target: "handshakemessage", "Received bytes: {:x?}", buf); match HandshakeMessage::parse(buf) { Ok((_size, res)) => { - info!("{}: {:#?}", direction, res); + // info!("{}: {:#?}", direction, res); match res { HandshakeMessage::SessionInit(_) => *state = ClientState::Connected, @@ -165,7 +171,7 @@ impl Server { async fn handle_message( buf: &[u8], - _direction: &str, + direction: Direction, ctx: ExtEventSink, ) -> Result { use libquassel::deserialize::*; @@ -182,7 +188,7 @@ impl Server { "update" => ctx .submit_command( command::ALIASMANAGER_UPDATE, - SingleUse::new(msg), + SingleUse::new((direction, msg)), Target::Global, ) .unwrap(), -- cgit v1.2.3