4 use crate::StitchConnection;
5 use async_std::net::{TcpStream, ToSocketAddrs};
7 impl StitchConnection {
8 pub fn tcp_client<A: ToSocketAddrs + std::fmt::Display>(
10 ) -> anyhow::Result<StitchConnection> {
11 let read_stream = task::block_on(TcpStream::connect(&ip_addrs))?;
12 info!("Established client TCP connection to {}", ip_addrs);
14 Ok(Self::from(read_stream))
18 impl From<TcpStream> for StitchConnection {
19 fn from(stream: TcpStream) -> Self {
20 let write_stream = stream.clone();
22 let local_addr = stream
24 .expect("Local address could not be retrieved");
26 let peer_addr = stream
28 .expect("Peer address could not be retrieved");
34 Box::new(write_stream),