Simplify construction of Socks5Stream

This commit is contained in:
Thomas Eizinger 2021-06-09 11:30:48 +10:00
parent ea0fd1eb53
commit 8bd6c9dcfc
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

View File

@ -7,7 +7,7 @@ use libp2p::core::Transport;
use libp2p::tcp::tokio::{Tcp, TcpStream};
use libp2p::tcp::{GenTcpConfig, TcpListenStream, TokioTcpConfig};
use std::io;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::net::Ipv4Addr;
use tokio_socks::tcp::Socks5Stream;
/// Represents the configuration for a Tor transport for libp2p.
@ -45,10 +45,12 @@ impl Transport for TorTcpConfig {
Ok(tor_address_string) => Ok(async move {
tracing::trace!("Connecting through Tor proxy to address: {}", addr);
let sock = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, self.socks_port));
let stream = Socks5Stream::connect(sock, tor_address_string)
.await
.map_err(|e| io::Error::new(io::ErrorKind::ConnectionRefused, e))?;
let stream = Socks5Stream::connect(
(Ipv4Addr::LOCALHOST, self.socks_port),
tor_address_string,
)
.await
.map_err(|e| io::Error::new(io::ErrorKind::ConnectionRefused, e))?;
tracing::trace!("Connection through Tor established");