aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonrpc/src/server.rs4
-rw-r--r--net/src/lib.rs2
-rw-r--r--net/src/listener.rs9
-rw-r--r--net/src/transports/tcp.rs6
-rw-r--r--net/src/transports/tls.rs14
-rw-r--r--net/src/transports/unix.rs6
-rw-r--r--p2p/src/listener.rs6
7 files changed, 25 insertions, 22 deletions
diff --git a/jsonrpc/src/server.rs b/jsonrpc/src/server.rs
index 0038e89..44de336 100644
--- a/jsonrpc/src/server.rs
+++ b/jsonrpc/src/server.rs
@@ -25,7 +25,7 @@ pub struct ServerConfig {
/// Represents an RPC server
pub struct Server<'a> {
- listener: Box<dyn Listener>,
+ listener: Listener,
services: RwLock<HashMap<String, Box<dyn RPCService + 'a>>>,
task_group: TaskGroup<'a>,
config: ServerConfig,
@@ -33,7 +33,7 @@ pub struct Server<'a> {
impl<'a> Server<'a> {
/// Creates a new RPC server by passing a listener. It supports Tcp, Unix, and Tls.
- pub fn new(listener: Box<dyn Listener>, config: ServerConfig, ex: Executor<'a>) -> Arc<Self> {
+ pub fn new(listener: Listener, config: ServerConfig, ex: Executor<'a>) -> Arc<Self> {
Arc::new(Self {
listener,
services: RwLock::new(HashMap::new()),
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 61069ef..813a090 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -7,7 +7,7 @@ mod transports;
pub use {
connection::{dial, Conn, Connection},
endpoint::{Addr, Endpoint, Port},
- listener::{listen, Listener},
+ listener::{listen, ConnListener, Listener},
transports::{
tcp::{dial_tcp, listen_tcp, TcpConn},
tls,
diff --git a/net/src/listener.rs b/net/src/listener.rs
index c6c3d94..fcd1175 100644
--- a/net/src/listener.rs
+++ b/net/src/listener.rs
@@ -5,9 +5,12 @@ use crate::{
Conn, Endpoint, Error, Result,
};
-/// Listener is a generic network listener.
+/// Alias for `Box<dyn ConnListener>`
+pub type Listener = Box<dyn ConnListener>;
+
+/// ConnListener is a generic network listener.
#[async_trait]
-pub trait Listener: Send + Sync {
+pub trait ConnListener: Send + Sync {
fn local_endpoint(&self) -> Result<Endpoint>;
async fn accept(&self) -> Result<Conn>;
}
@@ -29,7 +32,7 @@ pub trait Listener: Send + Sync {
/// };
///
/// ```
-pub async fn listen(endpoint: &Endpoint) -> Result<Box<dyn Listener>> {
+pub async fn listen(endpoint: &Endpoint) -> Result<Box<dyn ConnListener>> {
match endpoint {
Endpoint::Tcp(addr, port) => Ok(Box::new(tcp::listen_tcp(addr, port).await?)),
Endpoint::Unix(addr) => Ok(Box::new(unix::listen_unix(addr)?)),
diff --git a/net/src/transports/tcp.rs b/net/src/transports/tcp.rs
index 37ad860..7cd7127 100644
--- a/net/src/transports/tcp.rs
+++ b/net/src/transports/tcp.rs
@@ -9,7 +9,7 @@ use smol::{
use crate::{
connection::Connection,
endpoint::{Addr, Endpoint, Port},
- listener::Listener,
+ listener::ConnListener,
Error, Result,
};
@@ -57,7 +57,7 @@ impl Connection for TcpConn {
}
#[async_trait]
-impl Listener for TcpListener {
+impl ConnListener for TcpListener {
fn local_endpoint(&self) -> Result<Endpoint> {
Ok(Endpoint::new_tcp_addr(&self.local_addr()?))
}
@@ -90,7 +90,7 @@ impl From<TcpStream> for Box<dyn Connection> {
}
}
-impl From<TcpListener> for Box<dyn Listener> {
+impl From<TcpListener> for Box<dyn ConnListener> {
fn from(listener: TcpListener) -> Self {
Box::new(listener)
}
diff --git a/net/src/transports/tls.rs b/net/src/transports/tls.rs
index cbb3d99..bc928b0 100644
--- a/net/src/transports/tls.rs
+++ b/net/src/transports/tls.rs
@@ -11,7 +11,7 @@ use smol::{
use crate::{
connection::Connection,
endpoint::{Addr, Endpoint, Port},
- listener::Listener,
+ listener::ConnListener,
Error, Result,
};
@@ -92,14 +92,14 @@ pub async fn dial(
.await
.map(|c| Box::new(c) as Box<dyn Connection>)
}
-/// Tls network listener implementation of the [`Listener`] trait.
+/// Tls network listener implementation of the `Listener` [`ConnListener`] trait.
pub struct TlsListener {
acceptor: TlsAcceptor,
listener: TcpListener,
}
#[async_trait]
-impl Listener for TlsListener {
+impl ConnListener for TlsListener {
fn local_endpoint(&self) -> Result<Endpoint> {
Ok(Endpoint::new_tls_addr(&self.listener.local_addr()?))
}
@@ -124,11 +124,11 @@ pub async fn listen_tls(
Ok(TlsListener { acceptor, listener })
}
-/// Listens on the given TLS endpoint, returns [`Listener`].
+/// Listens on the given TLS endpoint, returns `Listener` [`ConnListener`].
pub async fn listen(
endpoint: &Endpoint,
config: rustls::ServerConfig,
-) -> Result<Box<dyn Listener>> {
+) -> Result<Box<dyn ConnListener>> {
match endpoint {
Endpoint::Tcp(..) | Endpoint::Tls(..) => {}
_ => return Err(Error::InvalidEndpoint(endpoint.to_string())),
@@ -136,7 +136,7 @@ pub async fn listen(
listen_tls(endpoint.addr()?, endpoint.port()?, config)
.await
- .map(|l| Box::new(l) as Box<dyn Listener>)
+ .map(|l| Box::new(l) as Box<dyn ConnListener>)
}
impl From<TlsStream<TcpStream>> for Box<dyn Connection> {
@@ -145,7 +145,7 @@ impl From<TlsStream<TcpStream>> for Box<dyn Connection> {
}
}
-impl From<TlsListener> for Box<dyn Listener> {
+impl From<TlsListener> for Box<dyn ConnListener> {
fn from(listener: TlsListener) -> Self {
Box::new(listener)
}
diff --git a/net/src/transports/unix.rs b/net/src/transports/unix.rs
index 0698975..c546333 100644
--- a/net/src/transports/unix.rs
+++ b/net/src/transports/unix.rs
@@ -6,7 +6,7 @@ use smol::{
net::unix::{UnixListener, UnixStream},
};
-use crate::{connection::Connection, endpoint::Endpoint, listener::Listener, Error, Result};
+use crate::{connection::Connection, endpoint::Endpoint, listener::ConnListener, Error, Result};
/// Unix domain socket implementation of the [`Connection`] trait.
pub struct UnixConn {
@@ -52,7 +52,7 @@ impl Connection for UnixConn {
}
#[async_trait]
-impl Listener for UnixListener {
+impl ConnListener for UnixListener {
fn local_endpoint(&self) -> Result<Endpoint> {
Ok(Endpoint::new_unix_addr(&self.local_addr()?))
}
@@ -81,7 +81,7 @@ impl From<UnixStream> for Box<dyn Connection> {
}
}
-impl From<UnixListener> for Box<dyn Listener> {
+impl From<UnixListener> for Box<dyn ConnListener> {
fn from(listener: UnixListener) -> Self {
Box::new(listener)
}
diff --git a/p2p/src/listener.rs b/p2p/src/listener.rs
index 879f046..416a0d4 100644
--- a/p2p/src/listener.rs
+++ b/p2p/src/listener.rs
@@ -8,7 +8,7 @@ use karyons_core::{
GlobalExecutor,
};
-use karyons_net::{listen, tls, Conn, Endpoint, Listener as NetListener};
+use karyons_net::{listen, tls, Conn, ConnListener, Endpoint};
use crate::{
monitor::{ConnEvent, Monitor},
@@ -100,7 +100,7 @@ impl Listener {
async fn listen_loop<Fut>(
self: Arc<Self>,
- listener: Box<dyn NetListener>,
+ listener: Box<dyn ConnListener>,
callback: impl FnOnce(Conn) -> Fut + Clone + Send + 'static,
) where
Fut: Future<Output = Result<()>> + Send + 'static,
@@ -152,7 +152,7 @@ impl Listener {
}
}
- async fn listend(&self, endpoint: &Endpoint) -> Result<Box<dyn NetListener>> {
+ async fn listend(&self, endpoint: &Endpoint) -> Result<Box<dyn ConnListener>> {
if self.enable_tls {
let tls_config = tls_server_config(&self.key_pair)?;
tls::listen(endpoint, tls_config).await