Skip to content

Commit

Permalink
FMT
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohit Kulkarni committed Oct 6, 2024
1 parent 92d7ff4 commit 4a81f76
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
9 changes: 6 additions & 3 deletions src/io/compat/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use super::Compat;
use crate::io::AsyncSocket;

impl<S> AsyncSocket for Compat<S>
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<IoResult<usize>> {
AsyncRead::poll_read(Pin::new(&mut self.0), cx, buf)
Expand All @@ -22,15 +23,17 @@ where S: AsyncRead + AsyncWrite + Unpin
}

impl<S> AsyncRead for Compat<S>
where S: AsyncRead + Unpin
where
S: AsyncRead + Unpin,
{
fn poll_read(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<IoResult<usize>> {
AsyncRead::poll_read(Pin::new(&mut self.0), cx, buf)
}
}

impl<S> AsyncWrite for Compat<S>
where S: AsyncWrite + Unpin
where
S: AsyncWrite + Unpin,
{
fn poll_write(mut self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<IoResult<usize>> {
AsyncWrite::poll_write(Pin::new(&mut self.0), cx, buf)
Expand Down
14 changes: 10 additions & 4 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: AsyncSocket> 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,
Expand All @@ -50,7 +54,9 @@ impl<S: AsyncSocket> 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 }
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/io/tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use super::AsyncSocket;

impl<S> 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<IoResult<usize>> {
let mut buf = ReadBuf::new(buf);
Expand Down
34 changes: 21 additions & 13 deletions src/tcp/socks4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -113,7 +110,8 @@ impl Socks4Stream<TcpStream> {
}

impl<S> Socks4Stream<S>
where S: AsyncSocket + Unpin
where
S: AsyncSocket + Unpin,
{
/// Connects to a target server through a SOCKS4 proxy given a socket to it.
///
Expand All @@ -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<Socks4Stream<S>>
where T: IntoTargetAddr<'t> {
where
T: IntoTargetAddr<'t>,
{
Self::execute_command_with_socket(socket, target, None, CommandV4::Connect).await
}

Expand Down Expand Up @@ -205,7 +205,8 @@ pub struct Socks4Connector<'a, 't, S> {
}

impl<'a, 't, S> Socks4Connector<'a, 't, S>
where S: Stream<Item = Result<SocketAddr>> + Unpin
where
S: Stream<Item = Result<SocketAddr>> + Unpin,
{
fn new(user_id: Option<&'a str>, command: CommandV4, proxy: Fuse<S>, target: TargetAddr<'t>) -> Self {
Socks4Connector {
Expand Down Expand Up @@ -400,7 +401,8 @@ impl Socks4Listener<TcpStream> {
}

impl<S> Socks4Listener<S>
where S: AsyncSocket + Unpin
where
S: AsyncSocket + Unpin,
{
/// Initiates a BIND request to the specified proxy using the given socket
/// to it.
Expand All @@ -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<Socks4Listener<S>>
where T: IntoTargetAddr<'t> {
where
T: IntoTargetAddr<'t>,
{
Self::bind_to_target_with_socket(None, socket, target).await
}

Expand Down Expand Up @@ -493,7 +497,8 @@ where S: AsyncSocket + Unpin

#[cfg(feature = "tokio")]
impl<T> tokio::io::AsyncRead for Socks4Stream<T>
where T: tokio::io::AsyncRead + Unpin
where
T: tokio::io::AsyncRead + Unpin,
{
fn poll_read(
mut self: Pin<&mut Self>,
Expand All @@ -506,7 +511,8 @@ where T: tokio::io::AsyncRead + Unpin

#[cfg(feature = "tokio")]
impl<T> tokio::io::AsyncWrite for Socks4Stream<T>
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<io::Result<usize>> {
tokio::io::AsyncWrite::poll_write(Pin::new(&mut self.socket), cx, buf)
Expand All @@ -523,7 +529,8 @@ where T: tokio::io::AsyncWrite + Unpin

#[cfg(feature = "futures-io")]
impl<T> futures_io::AsyncRead for Socks4Stream<T>
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<io::Result<usize>> {
futures_io::AsyncRead::poll_read(Pin::new(&mut self.socket), cx, buf)
Expand All @@ -532,7 +539,8 @@ where T: futures_io::AsyncRead + Unpin

#[cfg(feature = "futures-io")]
impl<T> futures_io::AsyncWrite for Socks4Stream<T>
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<io::Result<usize>> {
futures_io::AsyncWrite::poll_write(Pin::new(&mut self.socket), cx, buf)
Expand Down
7 changes: 4 additions & 3 deletions tests/common/futures_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -76,7 +75,9 @@ impl Runtime {
}

pub fn block_on<F, T>(&self, future: F) -> T
where F: Future<Output = T> {
where
F: Future<Output = T>,
{
smol::block_on(future)
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/common/tokio_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ use tokio::{
};
use tokio_socks::{
tcp::{socks4::Socks4Listener, socks5::Socks5Listener},
Error,
Result,
Error, Result,
};

use super::*;
Expand Down

0 comments on commit 4a81f76

Please sign in to comment.