mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 16:14:11 +00:00
Replaced deprecated deadline() with timeout()
This commit is contained in:
+19
-20
@@ -5,7 +5,7 @@ use std::iter::{IntoIterator, Iterator};
|
||||
use std::mem;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
|
||||
use config::{Config, ServerAddr, ServerConfig};
|
||||
use crypto::CipherCategory;
|
||||
@@ -209,15 +209,13 @@ impl<I: Iterator<Item = SocketAddr>> Future for TcpStreamConnect<I> {
|
||||
|
||||
match mem::replace(self, TcpStreamConnect::Empty) {
|
||||
TcpStreamConnect::Empty => unreachable!(),
|
||||
TcpStreamConnect::Connect { last_err, .. } => {
|
||||
match last_err {
|
||||
None => {
|
||||
let err = io::Error::new(ErrorKind::Other, "connect TCP without any addresses");
|
||||
Err(err)
|
||||
}
|
||||
Some(err) => Err(err),
|
||||
TcpStreamConnect::Connect { last_err, .. } => match last_err {
|
||||
None => {
|
||||
let err = io::Error::new(ErrorKind::Other, "connect TCP without any addresses");
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
Some(err) => Err(err),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,9 +233,9 @@ fn connect_proxy_server(config: Arc<Config>,
|
||||
ServerAddr::DomainName(ref domain, port) => {
|
||||
let fut = {
|
||||
try_timeout(resolve(config.clone(), &domain[..], port, false), timeout).and_then(move |vec_ipaddr| {
|
||||
let fut = TcpStreamConnect::new(vec_ipaddr.into_iter());
|
||||
try_timeout(fut, timeout)
|
||||
})
|
||||
let fut = TcpStreamConnect::new(vec_ipaddr.into_iter());
|
||||
try_timeout(fut, timeout)
|
||||
})
|
||||
};
|
||||
boxed_future(fut)
|
||||
}
|
||||
@@ -251,7 +249,7 @@ pub fn proxy_server_handshake(remote_stream: TcpStream,
|
||||
-> impl Future<Item = (DecryptedHalfFut, EncryptedHalfFut), Error = io::Error> + Send {
|
||||
let timeout = *svr_cfg.timeout();
|
||||
proxy_handshake(remote_stream, svr_cfg).and_then(move |(r_fut, w_fut)| {
|
||||
let w_fut = w_fut.and_then(move |enc_w| {
|
||||
let w_fut = w_fut.and_then(move |enc_w| {
|
||||
// Send relay address to remote
|
||||
let mut buf = BytesMut::with_capacity(relay_addr.len());
|
||||
relay_addr.write_to_buf(&mut buf);
|
||||
@@ -263,8 +261,8 @@ pub fn proxy_server_handshake(remote_stream: TcpStream,
|
||||
try_timeout(enc_w.write_all(buf), timeout).map(|(w, _)| w)
|
||||
});
|
||||
|
||||
Ok((r_fut, boxed_future(w_fut)))
|
||||
})
|
||||
Ok((r_fut, boxed_future(w_fut)))
|
||||
})
|
||||
}
|
||||
|
||||
/// ShadowSocks Client-Server handshake protocol
|
||||
@@ -378,7 +376,8 @@ pub fn tunnel<CF, CFI, SF, SFI>(addr: Address, c2s: CF, s2c: SF) -> impl Future<
|
||||
}
|
||||
});
|
||||
|
||||
c2s.select(s2c).and_then(move |(dir, _)| {
|
||||
c2s.select(s2c)
|
||||
.and_then(move |(dir, _)| {
|
||||
match dir {
|
||||
TunnelDirection::Server2Client => {
|
||||
trace!("Relay {} client <- server is closed, abort connection", addr)
|
||||
@@ -447,8 +446,8 @@ fn io_timeout<T, F>(fut: F, dur: Duration) -> impl Future<Item = T, Error = io::
|
||||
{
|
||||
use tokio::prelude::*;
|
||||
|
||||
fut.deadline(Instant::now() + dur).map_err(|err| match err.into_inner() {
|
||||
Some(e) => e,
|
||||
None => io::Error::new(io::ErrorKind::TimedOut, "connection timed out"),
|
||||
})
|
||||
fut.timeout(dur).map_err(|err| match err.into_inner() {
|
||||
Some(e) => e,
|
||||
None => io::Error::new(io::ErrorKind::TimedOut, "connection timed out"),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::io::{self, Cursor, ErrorKind, Read};
|
||||
use std::net::SocketAddr;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::{self, Future, Stream};
|
||||
|
||||
@@ -89,7 +89,7 @@ fn listen(config: Arc<Config>, l: UdpSocket) -> impl Future<Item = (), Error = i
|
||||
let to = timeout.unwrap_or(Duration::from_secs(5));
|
||||
let caddr = addr.clone();
|
||||
remote_udp.send_dgram(payload, &remote_addr)
|
||||
.deadline(Instant::now() + to)
|
||||
.timeout(to)
|
||||
.map_err(move |err| {
|
||||
match err.into_inner() {
|
||||
Some(e) => e,
|
||||
@@ -106,7 +106,7 @@ fn listen(config: Arc<Config>, l: UdpSocket) -> impl Future<Item = (), Error = i
|
||||
let to = timeout.unwrap_or(Duration::from_secs(5));
|
||||
let caddr = addr.clone();
|
||||
remote_udp.recv_dgram(buf)
|
||||
.deadline(Instant::now() + to)
|
||||
.timeout(to)
|
||||
.map_err(move |err| {
|
||||
match err.into_inner() {
|
||||
Some(e) => e,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use std::io::{self, Cursor, ErrorKind};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::{Duration, Instant};
|
||||
use std::time::Duration;
|
||||
|
||||
use futures::stream::futures_unordered;
|
||||
use futures::{self, Future, Stream};
|
||||
@@ -83,7 +83,7 @@ fn listen(config: Arc<Config>, svr_cfg: Arc<ServerConfig>) -> impl Future<Item =
|
||||
let to = timeout.unwrap_or(Duration::from_secs(5));
|
||||
let caddr = addr.clone();
|
||||
remote_udp.recv_dgram(buf)
|
||||
.deadline(Instant::now() + to)
|
||||
.timeout(to)
|
||||
.map_err(move |err| {
|
||||
match err.into_inner() {
|
||||
Some(e) => e,
|
||||
@@ -108,7 +108,7 @@ fn listen(config: Arc<Config>, svr_cfg: Arc<ServerConfig>) -> impl Future<Item =
|
||||
let to = timeout.unwrap_or(Duration::from_secs(5));
|
||||
let caddr = addr.clone();
|
||||
SendDgramRc::new(socket, buf, src)
|
||||
.deadline(Instant::now() + to)
|
||||
.timeout(to)
|
||||
.map_err(move |err| {
|
||||
match err.into_inner() {
|
||||
Some(e) => e,
|
||||
|
||||
Reference in New Issue
Block a user