diff --git a/src/error.rs b/src/error.rs index 84be098..223c540 100644 --- a/src/error.rs +++ b/src/error.rs @@ -71,7 +71,7 @@ pub enum Error { #[error("Request rejected because the client program and identd report different user-ids")] InvalidUserIdAuthFailure, - + #[error("Gssapi auth failure, code: {0}")] GssapiAuthFailure(u8), } diff --git a/src/io/compat/futures.rs b/src/io/compat/futures.rs index ddc3bee..ff75a24 100644 --- a/src/io/compat/futures.rs +++ b/src/io/compat/futures.rs @@ -10,7 +10,8 @@ use super::Compat; use crate::io::AsyncSocket; impl AsyncSocket for Compat -where S: AsyncRead + AsyncWrite + Unpin +where + S: AsyncRead + AsyncWrite + Unpin, { fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { AsyncRead::poll_read(Pin::new(&mut self.0), cx, buf) @@ -22,7 +23,8 @@ where S: AsyncRead + AsyncWrite + Unpin } impl AsyncRead for Compat -where S: AsyncRead + Unpin +where + S: AsyncRead + Unpin, { fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { AsyncRead::poll_read(Pin::new(&mut self.0), cx, buf) @@ -30,7 +32,8 @@ where S: AsyncRead + Unpin } impl AsyncWrite for Compat -where S: AsyncWrite + Unpin +where + S: AsyncWrite + Unpin, { fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { AsyncWrite::poll_write(Pin::new(&mut self.0), cx, buf) diff --git a/src/io/mod.rs b/src/io/mod.rs index efd45f2..142d5cc 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -32,15 +32,19 @@ pub trait AsyncSocket { pub(crate) trait AsyncSocketExt { fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> - where Self: Sized; + where + Self: Sized; fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> - where Self: Sized; + where + Self: Sized; } impl AsyncSocketExt for S { fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> - where Self: Sized { + where + Self: Sized, + { let capacity = buf.len(); ReadExact { reader: self, @@ -50,7 +54,9 @@ impl AsyncSocketExt for S { } fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAll<'a, Self> - where Self: Sized { + where + Self: Sized, + { WriteAll { writer: self, buf } } } diff --git a/src/io/tokio.rs b/src/io/tokio.rs index ecfc4f2..a002699 100644 --- a/src/io/tokio.rs +++ b/src/io/tokio.rs @@ -12,7 +12,8 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use super::AsyncSocket; impl AsyncSocket for S -where S: AsyncRead + AsyncWrite +where + S: AsyncRead + AsyncWrite, { fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { let mut buf = ReadBuf::new(buf); diff --git a/src/tcp/socks4.rs b/src/tcp/socks4.rs index 2ea1bf9..19fa659 100644 --- a/src/tcp/socks4.rs +++ b/src/tcp/socks4.rs @@ -15,10 +15,7 @@ use tokio::net::TcpStream; use crate::ToProxyAddrs; use crate::{ io::{AsyncSocket, AsyncSocketExt}, - Error, - IntoTargetAddr, - Result, - TargetAddr, + Error, IntoTargetAddr, Result, TargetAddr, }; #[repr(u8)] @@ -113,7 +110,8 @@ impl Socks4Stream { } impl Socks4Stream -where S: AsyncSocket + Unpin +where + S: AsyncSocket + Unpin, { /// Connects to a target server through a SOCKS4 proxy given a socket to it. /// @@ -122,7 +120,9 @@ where S: AsyncSocket + Unpin /// It propagates the error that occurs in the conversion from `T` to /// `TargetAddr`. pub async fn connect_with_socket<'t, T>(socket: S, target: T) -> Result> - where T: IntoTargetAddr<'t> { + where + T: IntoTargetAddr<'t>, + { Self::execute_command_with_socket(socket, target, None, CommandV4::Connect).await } @@ -205,7 +205,8 @@ pub struct Socks4Connector<'a, 't, S> { } impl<'a, 't, S> Socks4Connector<'a, 't, S> -where S: Stream> + Unpin +where + S: Stream> + Unpin, { fn new(user_id: Option<&'a str>, command: CommandV4, proxy: Fuse, target: TargetAddr<'t>) -> Self { Socks4Connector { @@ -400,7 +401,8 @@ impl Socks4Listener { } impl Socks4Listener -where S: AsyncSocket + Unpin +where + S: AsyncSocket + Unpin, { /// Initiates a BIND request to the specified proxy using the given socket /// to it. @@ -413,7 +415,9 @@ where S: AsyncSocket + Unpin /// It propagates the error that occurs in the conversion from `T` to /// `TargetAddr`. pub async fn bind_with_socket<'t, T>(socket: S, target: T) -> Result> - where T: IntoTargetAddr<'t> { + where + T: IntoTargetAddr<'t>, + { Self::bind_to_target_with_socket(None, socket, target).await } @@ -493,7 +497,8 @@ where S: AsyncSocket + Unpin #[cfg(feature = "tokio")] impl tokio::io::AsyncRead for Socks4Stream -where T: tokio::io::AsyncRead + Unpin +where + T: tokio::io::AsyncRead + Unpin, { fn poll_read( mut self: Pin<&mut Self>, @@ -506,7 +511,8 @@ where T: tokio::io::AsyncRead + Unpin #[cfg(feature = "tokio")] impl tokio::io::AsyncWrite for Socks4Stream -where T: tokio::io::AsyncWrite + Unpin +where + T: tokio::io::AsyncWrite + Unpin, { fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { tokio::io::AsyncWrite::poll_write(Pin::new(&mut self.socket), cx, buf) @@ -523,7 +529,8 @@ where T: tokio::io::AsyncWrite + Unpin #[cfg(feature = "futures-io")] impl futures_io::AsyncRead for Socks4Stream -where T: futures_io::AsyncRead + Unpin +where + T: futures_io::AsyncRead + Unpin, { fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll> { futures_io::AsyncRead::poll_read(Pin::new(&mut self.socket), cx, buf) @@ -532,7 +539,8 @@ where T: futures_io::AsyncRead + Unpin #[cfg(feature = "futures-io")] impl futures_io::AsyncWrite for Socks4Stream -where T: futures_io::AsyncWrite + Unpin +where + T: futures_io::AsyncWrite + Unpin, { fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll> { futures_io::AsyncWrite::poll_write(Pin::new(&mut self.socket), cx, buf) diff --git a/tests/common/futures_utils.rs b/tests/common/futures_utils.rs index 1f4a50a..cc012f5 100644 --- a/tests/common/futures_utils.rs +++ b/tests/common/futures_utils.rs @@ -11,8 +11,7 @@ use smol::net::{unix::UnixStream, TcpListener}; use tokio_socks::{ io::Compat, tcp::{socks4::Socks4Listener, socks5::Socks5Listener}, - Error, - Result, + Error, Result, }; use super::*; @@ -76,7 +75,9 @@ impl Runtime { } pub fn block_on(&self, future: F) -> T - where F: Future { + where + F: Future, + { smol::block_on(future) } } diff --git a/tests/common/tokio_utils.rs b/tests/common/tokio_utils.rs index aaf316b..fe5c1b8 100644 --- a/tests/common/tokio_utils.rs +++ b/tests/common/tokio_utils.rs @@ -12,8 +12,7 @@ use tokio::{ }; use tokio_socks::{ tcp::{socks4::Socks4Listener, socks5::Socks5Listener}, - Error, - Result, + Error, Result, }; use super::*;