diff --git a/jarust/src/jaconnection.rs b/jarust/src/jaconnection.rs index 073a6c5..35bd95e 100644 --- a/jarust/src/jaconnection.rs +++ b/jarust/src/jaconnection.rs @@ -10,8 +10,8 @@ use crate::jasession::WeakJaSession; use crate::jatask; use crate::prelude::*; use crate::tmanager::TransactionManager; -use crate::transport::trans::Transport; use crate::transport::trans::TransportProtocol; +use crate::transport::trans::TransportSession; use jatask::AbortHandle; use serde_json::json; use serde_json::Value; @@ -31,7 +31,7 @@ struct Shared { #[derive(Debug)] struct Exclusive { router: JaRouter, - transport_protocol: TransportProtocol, + transport_session: TransportSession, receiver: JaResponseStream, sessions: HashMap, transaction_manager: TransactionManager, @@ -49,12 +49,15 @@ pub struct JaConnection { } impl JaConnection { - pub(crate) async fn open(config: JaConfig, transport: impl Transport) -> JaResult { + pub(crate) async fn open( + config: JaConfig, + transport: impl TransportProtocol, + ) -> JaResult { let (router, root_channel) = JaRouter::new(&config.namespace).await; let transaction_manager = TransactionManager::new(32); - let (transport_protocol, receiver) = - TransportProtocol::connect(transport, &config.uri).await?; + let (transport_session, receiver) = + TransportSession::connect(transport, &config.uri).await?; let demux_abort_handle = jatask::spawn({ let router = router.clone(); @@ -68,7 +71,7 @@ impl JaConnection { }; let safe = Exclusive { router, - transport_protocol, + transport_session, receiver: root_channel, sessions: HashMap::new(), transaction_manager, @@ -151,7 +154,7 @@ impl JaConnection { .create_transaction(transaction, &path) .await; tracing::debug!("Sending {message}"); - guard.transport_protocol.send(message.as_bytes()).await?; + guard.transport_session.send(message.as_bytes()).await?; Ok(transaction.into()) } diff --git a/jarust/src/lib.rs b/jarust/src/lib.rs index f29cc6d..0ccec7c 100644 --- a/jarust/src/lib.rs +++ b/jarust/src/lib.rs @@ -13,7 +13,7 @@ mod demuxer; mod jarouter; mod tmanager; -use crate::transport::trans::Transport; +use crate::transport::trans::TransportProtocol; use jaconfig::JaConfig; use jaconfig::TransportType; use jaconnection::JaConnection; @@ -56,7 +56,7 @@ pub async fn connect(jaconfig: JaConfig, transport_type: TransportType) -> JaRes #[tracing::instrument(level = Level::TRACE)] pub async fn connect_with_transport( jaconfig: JaConfig, - transport: impl Transport, + transport: impl TransportProtocol, ) -> JaResult { tracing::info!("Creating new connection"); JaConnection::open(jaconfig, transport).await diff --git a/jarust/src/transport/trans.rs b/jarust/src/transport/trans.rs index ce766a4..9f22586 100644 --- a/jarust/src/transport/trans.rs +++ b/jarust/src/transport/trans.rs @@ -6,7 +6,7 @@ use tokio::sync::mpsc; pub type MessageStream = mpsc::UnboundedReceiver; #[async_trait] -pub trait Transport: Debug + Send + Sync + 'static { +pub trait TransportProtocol: Debug + Send + Sync + 'static { /// Creates a new transport fn create_transport() -> Self where @@ -19,11 +19,11 @@ pub trait Transport: Debug + Send + Sync + 'static { async fn send(&mut self, data: &[u8]) -> JaResult<()>; } -pub struct TransportProtocol(Box); +pub struct TransportSession(Box); -impl TransportProtocol { +impl TransportSession { pub async fn connect( - mut transport: impl Transport, + mut transport: impl TransportProtocol, uri: &str, ) -> JaResult<(Self, MessageStream)> { let rx = transport.connect(uri).await?; @@ -36,7 +36,7 @@ impl TransportProtocol { } } -impl Debug for TransportProtocol { +impl Debug for TransportSession { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_tuple("TransportProtocol").finish() } diff --git a/jarust/src/transport/web_socket.rs b/jarust/src/transport/web_socket.rs index fd183d8..ea5d15a 100644 --- a/jarust/src/transport/web_socket.rs +++ b/jarust/src/transport/web_socket.rs @@ -4,7 +4,7 @@ compile_error!("Feature \"rustls\" and feature \"native-tls\" cannot be enabled #[cfg(not(any(feature = "use-rustls", feature = "use-native-tls")))] compile_error!("Either feature \"rustls\" or \"native-tls\" must be enabled for this crate"); -use super::trans::Transport; +use super::trans::TransportProtocol; use crate::jatask; use crate::jatask::AbortHandle; use crate::prelude::*; @@ -40,7 +40,7 @@ pub struct WebsocketTransport { } #[async_trait] -impl Transport for WebsocketTransport { +impl TransportProtocol for WebsocketTransport { fn create_transport() -> Self { Self { sender: None, diff --git a/jarust/tests/connection.rs b/jarust/tests/connection.rs index 9c503ba..6bb7332 100644 --- a/jarust/tests/connection.rs +++ b/jarust/tests/connection.rs @@ -8,7 +8,7 @@ use jarust::japrotocol::JaData; use jarust::japrotocol::JaResponse; use jarust::japrotocol::JaSuccessProtocol; use jarust::japrotocol::ResponseType; -use jarust::transport::trans::Transport; +use jarust::transport::trans::TransportProtocol; #[tokio::test] async fn test_connection() { diff --git a/jarust/tests/mocks/mock_transport.rs b/jarust/tests/mocks/mock_transport.rs index 2a92d86..8a63a91 100644 --- a/jarust/tests/mocks/mock_transport.rs +++ b/jarust/tests/mocks/mock_transport.rs @@ -2,7 +2,7 @@ use async_trait::async_trait; use jarust::jatask; use jarust::jatask::AbortHandle; use jarust::prelude::*; -use jarust::transport::trans::Transport; +use jarust::transport::trans::TransportProtocol; use std::fmt::Debug; use tokio::sync::mpsc; @@ -29,7 +29,7 @@ impl MockTransport { } #[async_trait] -impl Transport for MockTransport { +impl TransportProtocol for MockTransport { fn create_transport() -> Self where Self: Sized,