aboutsummaryrefslogtreecommitdiff
path: root/net/src/transports
diff options
context:
space:
mode:
authorhozan23 <hozan23@proton.me>2023-11-30 22:52:53 +0300
committerhozan23 <hozan23@proton.me>2023-11-30 22:52:53 +0300
commit7d6c0e68a19ad5e2e4e05cfc219d446be6ff2286 (patch)
tree2f7bfc34ca033b059702fc26bc18170dc118c20e /net/src/transports
parent8c70a0d379b21541b5b2d1d37ff7fc61ca311cd4 (diff)
jsonrpc: Enhance the API and add support for TCP, Unix, and TLS protocols.
Diffstat (limited to 'net/src/transports')
-rw-r--r--net/src/transports/tcp.rs12
-rw-r--r--net/src/transports/tls.rs12
-rw-r--r--net/src/transports/udp.rs6
-rw-r--r--net/src/transports/unix.rs12
4 files changed, 42 insertions, 0 deletions
diff --git a/net/src/transports/tcp.rs b/net/src/transports/tcp.rs
index 37f00a7..37ad860 100644
--- a/net/src/transports/tcp.rs
+++ b/net/src/transports/tcp.rs
@@ -83,3 +83,15 @@ pub async fn listen_tcp(addr: &Addr, port: &Port) -> Result<TcpListener> {
let listener = TcpListener::bind(address).await?;
Ok(listener)
}
+
+impl From<TcpStream> for Box<dyn Connection> {
+ fn from(conn: TcpStream) -> Self {
+ Box::new(TcpConn::new(conn))
+ }
+}
+
+impl From<TcpListener> for Box<dyn Listener> {
+ fn from(listener: TcpListener) -> Self {
+ Box::new(listener)
+ }
+}
diff --git a/net/src/transports/tls.rs b/net/src/transports/tls.rs
index 01bb5aa..cbb3d99 100644
--- a/net/src/transports/tls.rs
+++ b/net/src/transports/tls.rs
@@ -138,3 +138,15 @@ pub async fn listen(
.await
.map(|l| Box::new(l) as Box<dyn Listener>)
}
+
+impl From<TlsStream<TcpStream>> for Box<dyn Connection> {
+ fn from(conn: TlsStream<TcpStream>) -> Self {
+ Box::new(TlsConn::new(conn.get_ref().0.clone(), conn))
+ }
+}
+
+impl From<TlsListener> for Box<dyn Listener> {
+ fn from(listener: TlsListener) -> Self {
+ Box::new(listener)
+ }
+}
diff --git a/net/src/transports/udp.rs b/net/src/transports/udp.rs
index 8a2fbec..9576876 100644
--- a/net/src/transports/udp.rs
+++ b/net/src/transports/udp.rs
@@ -73,3 +73,9 @@ pub async fn listen_udp(addr: &Addr, port: &Port) -> Result<UdpConn> {
let udp_conn = UdpConn::new(conn);
Ok(udp_conn)
}
+
+impl From<UdpSocket> for Box<dyn Connection> {
+ fn from(conn: UdpSocket) -> Self {
+ Box::new(UdpConn::new(conn))
+ }
+}
diff --git a/net/src/transports/unix.rs b/net/src/transports/unix.rs
index e504934..0698975 100644
--- a/net/src/transports/unix.rs
+++ b/net/src/transports/unix.rs
@@ -74,3 +74,15 @@ pub fn listen_unix(path: &String) -> Result<UnixListener> {
let listener = UnixListener::bind(path)?;
Ok(listener)
}
+
+impl From<UnixStream> for Box<dyn Connection> {
+ fn from(conn: UnixStream) -> Self {
+ Box::new(UnixConn::new(conn))
+ }
+}
+
+impl From<UnixListener> for Box<dyn Listener> {
+ fn from(listener: UnixListener) -> Self {
+ Box::new(listener)
+ }
+}