pub use giterated_models as model; use std::{fmt::Debug, net::SocketAddr}; use deadpool::managed::{BuildError, Pool}; use giterated_models::instance::Instance; use pool::GiteratedConnectionPool; use tokio::net::TcpStream; use tokio_tungstenite::{MaybeTlsStream, WebSocketStream}; pub mod daemon_backend; mod handshake; mod pool; type Socket = WebSocketStream>; #[macro_use] extern crate tracing; #[derive(Clone)] pub struct DaemonConnectionPool(Pool); impl Debug for DaemonConnectionPool { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("DaemonConnectionPool").finish() } } impl DaemonConnectionPool { pub fn connect( instance: impl ToOwned, ) -> Result> { let instance = instance.to_owned(); Ok(Self( Pool::builder(GiteratedConnectionPool { socket_addr: None, target_instance: instance.to_owned(), }) .build()?, )) } pub fn connect_other( instance_identity: impl ToOwned, connection_addr: SocketAddr, ) -> Result> { Ok(Self( Pool::builder(GiteratedConnectionPool { target_instance: instance_identity.to_owned(), socket_addr: Some(connection_addr), }) .build()?, )) } }