fix(network): relax connect args lifetime (#367)

This commit is contained in:
Santiago Carmuega 2023-12-23 15:31:24 -03:00 committed by GitHub
parent d9224eb780
commit eb3966540e

View file

@ -3,7 +3,7 @@ use std::path::Path;
use thiserror::Error; use thiserror::Error;
use tracing::error; use tracing::error;
use tokio::net::TcpListener; use tokio::net::{TcpListener, ToSocketAddrs};
#[cfg(unix)] #[cfg(unix)]
use tokio::net::{unix::SocketAddr as UnixSocketAddr, UnixListener}; use tokio::net::{unix::SocketAddr as UnixSocketAddr, UnixListener};
@ -66,7 +66,7 @@ impl PeerClient {
} }
} }
pub async fn connect(addr: &'static str, magic: u64) -> Result<Self, Error> { pub async fn connect(addr: impl ToSocketAddrs, magic: u64) -> Result<Self, Error> {
let bearer = Bearer::connect_tcp(addr) let bearer = Bearer::connect_tcp(addr)
.await .await
.map_err(Error::ConnectFailure)?; .map_err(Error::ConnectFailure)?;
@ -232,10 +232,7 @@ impl NodeClient {
} }
#[cfg(unix)] #[cfg(unix)]
pub async fn connect( pub async fn connect(path: impl AsRef<Path>, magic: u64) -> Result<Self, Error> {
path: impl AsRef<Path> + Send + 'static,
magic: u64,
) -> Result<Self, Error> {
let bearer = Bearer::connect_unix(path) let bearer = Bearer::connect_unix(path)
.await .await
.map_err(Error::ConnectFailure)?; .map_err(Error::ConnectFailure)?;