pub mod authentication; pub mod handshake; pub mod repository; pub mod user; pub mod wrapper; use std::{any::type_name, collections::HashMap}; use anyhow::Error; use giterated_models::{ messages::ErrorMessage, model::instance::{Instance, InstanceMeta}, }; use serde::{de::DeserializeOwned, Serialize}; use tokio::{net::TcpStream, task::JoinHandle}; use tokio_tungstenite::WebSocketStream; #[derive(Debug, thiserror::Error)] pub enum ConnectionError { #[error("connection error message {0}")] ErrorMessage(#[from] ErrorMessage), #[error("connection should close")] Shutdown, #[error("internal error {0}")] InternalError(#[from] Error), } pub struct RawConnection { pub task: JoinHandle<()>, } pub struct InstanceConnection { pub instance: InstanceMeta, pub task: JoinHandle<()>, } /// Represents a connection which hasn't finished the handshake. pub struct UnestablishedConnection { pub socket: WebSocketStream, } #[derive(Default)] pub struct Connections { pub connections: Vec, pub instance_connections: HashMap, } #[derive(Debug, thiserror::Error)] #[error("handler did not handle")] pub struct HandlerUnhandled; pub trait MessageHandling { fn message_type() -> &'static str; } impl MessageHandling<(T1,), M, R> for F where F: FnOnce(T1) -> R, T1: Serialize + DeserializeOwned, { fn message_type() -> &'static str { type_name::() } } impl MessageHandling<(T1, T2), M, R> for F where F: FnOnce(T1, T2) -> R, T1: Serialize + DeserializeOwned, { fn message_type() -> &'static str { type_name::() } } impl MessageHandling<(T1, T2, T3), M, R> for F where F: FnOnce(T1, T2, T3) -> R, T1: Serialize + DeserializeOwned, { fn message_type() -> &'static str { type_name::() } } impl MessageHandling<(T1, T2, T3, T4), M, R> for F where F: FnOnce(T1, T2, T3, T4) -> R, T1: Serialize + DeserializeOwned, { fn message_type() -> &'static str { type_name::() } }