Skip to content

Commit aa69503

Browse files
committed
Rename timeout param to connect_timeout
1 parent cb8bd1f commit aa69503

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/v4.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,29 @@ pub mod client {
7070
proxy: T,
7171
target: &U,
7272
userid: &str,
73-
timeout: Option<Duration>,
73+
connect_timeout: Option<Duration>,
7474
) -> io::Result<Self>
7575
where
7676
T: ToSocketAddrs,
7777
U: ToTargetAddr,
7878
{
79-
Self::connect_raw(1, proxy, target, userid, timeout)
79+
Self::connect_raw(1, proxy, target, userid, connect_timeout)
8080
}
8181

8282
pub(super) fn connect_raw<T, U>(
8383
command: u8,
8484
proxy: T,
8585
target: &U,
8686
userid: &str,
87-
timeout: Option<Duration>,
87+
connect_timeout: Option<Duration>,
8888
) -> io::Result<Self>
8989
where
9090
T: ToSocketAddrs,
9191
U: ToTargetAddr,
9292
{
93-
let mut socket = match timeout {
93+
let mut socket = match connect_timeout {
9494
None => TcpStream::connect(proxy)?,
95-
// TODO: Should filter to ipv4 only? Since SOCKS4 only supports that.
95+
// TODO: Connect timeout for each address until one works?
9696
Some(t) => TcpStream::connect_timeout(
9797
&proxy
9898
.to_socket_addrs()?
@@ -222,13 +222,13 @@ pub mod bind {
222222
proxy: T,
223223
target: &U,
224224
userid: &str,
225-
timeout: Option<Duration>,
225+
connect_timeout: Option<Duration>,
226226
) -> io::Result<Self>
227227
where
228228
T: ToSocketAddrs,
229229
U: ToTargetAddr,
230230
{
231-
Socks4Stream::connect_raw(2, proxy, target, userid, timeout).map(Socks4Listener)
231+
Socks4Stream::connect_raw(2, proxy, target, userid, connect_timeout).map(Socks4Listener)
232232
}
233233

234234
/// The address of the proxy-side TCP listener.

src/v5.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,16 @@ pub mod client {
150150
///
151151
/// # Errors
152152
/// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
153-
pub fn connect<T, U>(proxy: T, target: &U, timeout: Option<Duration>) -> io::Result<Self>
153+
pub fn connect<T, U>(
154+
proxy: T,
155+
target: &U,
156+
connect_timeout: Option<Duration>,
157+
) -> io::Result<Self>
154158
where
155159
T: ToSocketAddrs,
156160
U: ToTargetAddr,
157161
{
158-
Self::connect_raw(1, proxy, target, &Authentication::None, timeout)
162+
Self::connect_raw(1, proxy, target, &Authentication::None, connect_timeout)
159163
}
160164

161165
/// Connects to a target server through a SOCKS5 proxy using given
@@ -168,29 +172,30 @@ pub mod client {
168172
target: &U,
169173
username: &str,
170174
password: &str,
171-
timeout: Option<Duration>,
175+
connect_timeout: Option<Duration>,
172176
) -> io::Result<Self>
173177
where
174178
T: ToSocketAddrs,
175179
U: ToTargetAddr,
176180
{
177181
let auth = Authentication::Password { username, password };
178-
Self::connect_raw(1, proxy, target, &auth, timeout)
182+
Self::connect_raw(1, proxy, target, &auth, connect_timeout)
179183
}
180184

181185
pub(super) fn connect_raw<T, U>(
182186
command: u8,
183187
proxy: T,
184188
target: &U,
185189
auth: &Authentication,
186-
timeout: Option<Duration>,
190+
connect_timeout: Option<Duration>,
187191
) -> io::Result<Self>
188192
where
189193
T: ToSocketAddrs,
190194
U: ToTargetAddr,
191195
{
192-
let mut socket = match timeout {
196+
let mut socket = match connect_timeout {
193197
None => TcpStream::connect(proxy)?,
198+
// TODO: Connect timeout for each address until one works?
194199
Some(t) => TcpStream::connect_timeout(
195200
&proxy
196201
.to_socket_addrs()?
@@ -384,12 +389,16 @@ pub mod bind {
384389
///
385390
/// # Errors
386391
/// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
387-
pub fn bind<T, U>(proxy: T, target: &U, timeout: Option<Duration>) -> io::Result<Self>
392+
pub fn bind<T, U>(
393+
proxy: T,
394+
target: &U,
395+
connect_timeout: Option<Duration>,
396+
) -> io::Result<Self>
388397
where
389398
T: ToSocketAddrs,
390399
U: ToTargetAddr,
391400
{
392-
Socks5Stream::connect_raw(2, proxy, target, &Authentication::None, timeout)
401+
Socks5Stream::connect_raw(2, proxy, target, &Authentication::None, connect_timeout)
393402
.map(Socks5Listener)
394403
}
395404
/// Initiates a BIND request to the specified proxy using given username
@@ -405,14 +414,14 @@ pub mod bind {
405414
target: &U,
406415
username: &str,
407416
password: &str,
408-
timeout: Option<Duration>,
417+
connect_timeout: Option<Duration>,
409418
) -> io::Result<Self>
410419
where
411420
T: ToSocketAddrs,
412421
U: ToTargetAddr,
413422
{
414423
let auth = Authentication::Password { username, password };
415-
Socks5Stream::connect_raw(2, proxy, target, &auth, timeout).map(Socks5Listener)
424+
Socks5Stream::connect_raw(2, proxy, target, &auth, connect_timeout).map(Socks5Listener)
416425
}
417426

418427
/// The address of the proxy-side TCP listener.
@@ -467,12 +476,12 @@ pub mod udp {
467476
///
468477
/// # Errors
469478
/// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
470-
pub fn bind<T, U>(proxy: T, addr: U, timeout: Option<Duration>) -> io::Result<Self>
479+
pub fn bind<T, U>(proxy: T, addr: U, connect_timeout: Option<Duration>) -> io::Result<Self>
471480
where
472481
T: ToSocketAddrs,
473482
U: ToSocketAddrs,
474483
{
475-
Self::bind_internal(proxy, addr, &Authentication::None, timeout)
484+
Self::bind_internal(proxy, addr, &Authentication::None, connect_timeout)
476485
}
477486

478487
/// Creates a UDP socket bound to the specified address which will have its
@@ -486,21 +495,21 @@ pub mod udp {
486495
addr: U,
487496
username: &str,
488497
password: &str,
489-
timeout: Option<Duration>,
498+
connect_timeout: Option<Duration>,
490499
) -> io::Result<Self>
491500
where
492501
T: ToSocketAddrs,
493502
U: ToSocketAddrs,
494503
{
495504
let auth = Authentication::Password { username, password };
496-
Self::bind_internal(proxy, addr, &auth, timeout)
505+
Self::bind_internal(proxy, addr, &auth, connect_timeout)
497506
}
498507

499508
fn bind_internal<T, U>(
500509
proxy: T,
501510
addr: U,
502511
auth: &Authentication,
503-
timeout: Option<Duration>,
512+
connect_timeout: Option<Duration>,
504513
) -> io::Result<Self>
505514
where
506515
T: ToSocketAddrs,
@@ -512,7 +521,7 @@ pub mod udp {
512521
Ipv4Addr::new(0, 0, 0, 0),
513522
0,
514523
)));
515-
let stream = Socks5Stream::connect_raw(3, proxy, &dst, auth, timeout)?;
524+
let stream = Socks5Stream::connect_raw(3, proxy, &dst, auth, connect_timeout)?;
516525

517526
let socket = UdpSocket::bind(addr)?;
518527
socket.connect(&stream.proxy_addr)?;
@@ -540,6 +549,7 @@ pub mod udp {
540549
// third byte is the fragment id at 0
541550
let len = write_addr(&mut header[3..], &addr)?;
542551

552+
// TODO: Use write_vectored?
543553
self.socket.writev([&header[..len + 3], buf])
544554
}
545555

@@ -549,6 +559,7 @@ pub mod udp {
549559
/// - `io::Error(std::io::ErrorKind::*, socks2::Error::*?)`
550560
pub fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, TargetAddr)> {
551561
let mut header = [0; MAX_ADDR_LEN + 3];
562+
// TODO: Use read_vectored?
552563
let len = self.socket.readv([&mut header, buf])?;
553564

554565
let overflow = len.saturating_sub(header.len());

0 commit comments

Comments
 (0)