From cf5e50029c4b8a836de24a38bcd520a036ae332e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 15 Nov 2021 17:39:33 +1100 Subject: [PATCH] Use `TcpStream` to connect to address Not only this now automatically support IPv6, it is also shorter. --- daemon/src/connection.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/daemon/src/connection.rs b/daemon/src/connection.rs index 8b3b53a..bd51a43 100644 --- a/daemon/src/connection.rs +++ b/daemon/src/connection.rs @@ -5,6 +5,7 @@ use futures::{FutureExt, StreamExt}; use std::net::SocketAddr; use std::sync::{Arc, Mutex}; use std::time::{Duration, SystemTime}; +use tokio::net::TcpStream; use tokio::sync::watch; use tokio_util::codec::FramedRead; use xtra::prelude::MessageChannel; @@ -84,11 +85,11 @@ impl Actor { ctx: &mut xtra::Context, ) -> Result<()> { let (read, write, noise) = { - let socket = tokio::net::TcpSocket::new_v4().expect("Be able to create a socket"); - let mut connection = socket.connect(maker_addr).await?; + let mut connection = TcpStream::connect(&maker_addr).await?; let noise = noise::initiator_handshake(&mut connection, &self.identity_sk, &maker_identity_pk) .await?; + let (read, write) = connection.into_split(); (read, write, Arc::new(Mutex::new(noise))) };