mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 08:14:07 +00:00
Make clippy happy
This commit is contained in:
+1
-2
@@ -4,8 +4,7 @@
|
||||
//! or you could specify a configuration file. The format of configuration file is defined
|
||||
//! in mod `config`.
|
||||
|
||||
use std::io::Result as IoResult;
|
||||
use std::{net::SocketAddr, process};
|
||||
use std::{io::Result as IoResult, net::SocketAddr, process};
|
||||
|
||||
use clap::{App, Arg};
|
||||
use futures::{future::Either, Future};
|
||||
|
||||
+1
-2
@@ -7,8 +7,7 @@
|
||||
//! *It should be notice that the extented configuration file is not suitable for the server
|
||||
//! side.*
|
||||
|
||||
use std::io::Result as IoResult;
|
||||
use std::process;
|
||||
use std::{io::Result as IoResult, process};
|
||||
|
||||
use clap::{App, Arg};
|
||||
use futures::{future::Either, Future};
|
||||
|
||||
+13
-2
@@ -3,13 +3,24 @@
|
||||
use std::{mem, ptr};
|
||||
|
||||
use ring::aead::{
|
||||
open_in_place, seal_in_place, Aad, Nonce, OpeningKey, SealingKey, AES_128_GCM, AES_256_GCM, CHACHA20_POLY1305,
|
||||
open_in_place,
|
||||
seal_in_place,
|
||||
Aad,
|
||||
Nonce,
|
||||
OpeningKey,
|
||||
SealingKey,
|
||||
AES_128_GCM,
|
||||
AES_256_GCM,
|
||||
CHACHA20_POLY1305,
|
||||
};
|
||||
|
||||
use crate::crypto::{
|
||||
aead::{increase_nonce, make_skey},
|
||||
cipher::Error,
|
||||
AeadDecryptor, AeadEncryptor, CipherResult, CipherType,
|
||||
AeadDecryptor,
|
||||
AeadEncryptor,
|
||||
CipherResult,
|
||||
CipherType,
|
||||
};
|
||||
|
||||
use byte_string::ByteStr;
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub use self::ping::PingBalancer;
|
||||
pub use self::roundrobin::RoundRobin;
|
||||
pub use self::{ping::PingBalancer, roundrobin::RoundRobin};
|
||||
|
||||
use crate::config::ServerConfig;
|
||||
|
||||
|
||||
@@ -1,17 +1,24 @@
|
||||
use std::io;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::{Duration, Instant};
|
||||
use std::{
|
||||
io,
|
||||
sync::{
|
||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||
Arc,
|
||||
},
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
config::ServerConfig, context::SharedContext, relay::loadbalancing::server::LoadBalancer, relay::socks5::Address,
|
||||
relay::tcprelay::client::ServerClient,
|
||||
config::ServerConfig,
|
||||
context::SharedContext,
|
||||
relay::{loadbalancing::server::LoadBalancer, socks5::Address, tcprelay::client::ServerClient},
|
||||
};
|
||||
|
||||
use futures::{Future, Stream};
|
||||
use log::{debug, error};
|
||||
use tokio;
|
||||
use tokio::timer::{Interval, Timeout};
|
||||
use tokio::{
|
||||
self,
|
||||
timer::{Interval, Timeout},
|
||||
};
|
||||
|
||||
struct Server {
|
||||
config: Arc<ServerConfig>,
|
||||
|
||||
+32
-36
@@ -8,8 +8,7 @@ use std::{
|
||||
fmt::{self, Debug, Formatter},
|
||||
io::{self, Cursor, Read, Write},
|
||||
net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs},
|
||||
u8,
|
||||
vec,
|
||||
u8, vec,
|
||||
};
|
||||
|
||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||
@@ -19,10 +18,7 @@ use log::error;
|
||||
use tokio_io::{io::read_exact, try_nb, AsyncRead, AsyncWrite};
|
||||
|
||||
pub use self::consts::{
|
||||
SOCKS5_AUTH_METHOD_GSSAPI,
|
||||
SOCKS5_AUTH_METHOD_NONE,
|
||||
SOCKS5_AUTH_METHOD_NOT_ACCEPTABLE,
|
||||
SOCKS5_AUTH_METHOD_PASSWORD,
|
||||
SOCKS5_AUTH_METHOD_GSSAPI, SOCKS5_AUTH_METHOD_NONE, SOCKS5_AUTH_METHOD_NOT_ACCEPTABLE, SOCKS5_AUTH_METHOD_PASSWORD,
|
||||
};
|
||||
|
||||
use super::utils::{write_bytes, WriteBytes};
|
||||
@@ -231,7 +227,7 @@ impl Address {
|
||||
/// Writes to writer
|
||||
#[inline]
|
||||
pub fn write_to<W: AsyncWrite>(self, writer: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(writer, buf.freeze())
|
||||
}
|
||||
@@ -243,7 +239,7 @@ impl Address {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
get_addr_len(self)
|
||||
}
|
||||
}
|
||||
@@ -302,11 +298,11 @@ where
|
||||
}
|
||||
|
||||
enum ReadAddressState {
|
||||
ReadingType,
|
||||
ReadingIpv4,
|
||||
ReadingIpv6,
|
||||
ReadingDomainNameLength,
|
||||
ReadingDomainName,
|
||||
Type,
|
||||
Ipv4,
|
||||
Ipv6,
|
||||
DomainNameLength,
|
||||
DomainName,
|
||||
}
|
||||
|
||||
impl<R> Future for ReadAddress<R>
|
||||
@@ -321,23 +317,23 @@ where
|
||||
|
||||
loop {
|
||||
match self.state {
|
||||
ReadAddressState::ReadingType => {
|
||||
ReadAddressState::Type => {
|
||||
try_ready!(self.read_addr_type());
|
||||
}
|
||||
ReadAddressState::ReadingIpv4 => {
|
||||
ReadAddressState::Ipv4 => {
|
||||
let addr = try_ready!(self.read_ipv4());
|
||||
let reader = self.reader.take().unwrap();
|
||||
return Ok((reader, addr).into());
|
||||
}
|
||||
ReadAddressState::ReadingIpv6 => {
|
||||
ReadAddressState::Ipv6 => {
|
||||
let addr = try_ready!(self.read_ipv6());
|
||||
let reader = self.reader.take().unwrap();
|
||||
return Ok((reader, addr).into());
|
||||
}
|
||||
ReadAddressState::ReadingDomainNameLength => {
|
||||
ReadAddressState::DomainNameLength => {
|
||||
try_ready!(self.read_domain_name_length());
|
||||
}
|
||||
ReadAddressState::ReadingDomainName => {
|
||||
ReadAddressState::DomainName => {
|
||||
let addr = try_ready!(self.read_domain_name());
|
||||
let reader = self.reader.take().unwrap();
|
||||
return Ok((reader, addr).into());
|
||||
@@ -354,7 +350,7 @@ where
|
||||
fn new(r: R) -> ReadAddress<R> {
|
||||
ReadAddress {
|
||||
reader: Some(r),
|
||||
state: ReadAddressState::ReadingType,
|
||||
state: ReadAddressState::Type,
|
||||
buf: None,
|
||||
already_read: 0,
|
||||
}
|
||||
@@ -364,15 +360,15 @@ where
|
||||
let addr_type = try_nb!(self.reader.as_mut().unwrap().read_u8());
|
||||
match addr_type {
|
||||
consts::SOCKS5_ADDR_TYPE_IPV4 => {
|
||||
self.state = ReadAddressState::ReadingIpv4;
|
||||
self.state = ReadAddressState::Ipv4;
|
||||
self.alloc_buf(6);
|
||||
}
|
||||
consts::SOCKS5_ADDR_TYPE_IPV6 => {
|
||||
self.state = ReadAddressState::ReadingIpv6;
|
||||
self.state = ReadAddressState::Ipv6;
|
||||
self.alloc_buf(18);
|
||||
}
|
||||
consts::SOCKS5_ADDR_TYPE_DOMAIN_NAME => {
|
||||
self.state = ReadAddressState::ReadingDomainNameLength;
|
||||
self.state = ReadAddressState::DomainNameLength;
|
||||
}
|
||||
_ => {
|
||||
error!("Invalid address type {}", addr_type);
|
||||
@@ -418,7 +414,7 @@ where
|
||||
|
||||
fn read_domain_name_length(&mut self) -> Poll<(), Error> {
|
||||
let length = try_nb!(self.reader.as_mut().unwrap().read_u8());
|
||||
self.state = ReadAddressState::ReadingDomainName;
|
||||
self.state = ReadAddressState::DomainName;
|
||||
self.alloc_buf(length as usize + 2);
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
@@ -594,7 +590,7 @@ impl TcpRequestHeader {
|
||||
|
||||
/// Write data into a writer
|
||||
pub fn write_to<W: AsyncWrite>(self, w: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(w, buf.freeze())
|
||||
}
|
||||
@@ -612,8 +608,8 @@ impl TcpRequestHeader {
|
||||
|
||||
/// Length in bytes
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.address.len() + 3
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
self.address.serialized_len() + 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -671,7 +667,7 @@ impl TcpResponseHeader {
|
||||
|
||||
/// Write to a writer
|
||||
pub fn write_to<W: AsyncWrite>(self, w: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(w, buf.freeze())
|
||||
}
|
||||
@@ -685,8 +681,8 @@ impl TcpResponseHeader {
|
||||
|
||||
/// Length in bytes
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.address.len() + 3
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
self.address.serialized_len() + 3
|
||||
}
|
||||
}
|
||||
|
||||
@@ -732,7 +728,7 @@ impl HandshakeRequest {
|
||||
|
||||
/// Write to a writer
|
||||
pub fn write_to<W: AsyncWrite>(self, w: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(w, buf.freeze())
|
||||
}
|
||||
@@ -745,7 +741,7 @@ impl HandshakeRequest {
|
||||
}
|
||||
|
||||
/// Get length of bytes
|
||||
pub fn len(&self) -> usize {
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
2 + self.methods.len()
|
||||
}
|
||||
}
|
||||
@@ -789,7 +785,7 @@ impl HandshakeResponse {
|
||||
|
||||
/// Write to a writer
|
||||
pub fn write_to<W: AsyncWrite>(self, w: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(w, buf.freeze())
|
||||
}
|
||||
@@ -800,7 +796,7 @@ impl HandshakeResponse {
|
||||
}
|
||||
|
||||
/// Length in bytes
|
||||
pub fn len(&self) -> usize {
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
2
|
||||
}
|
||||
}
|
||||
@@ -846,7 +842,7 @@ impl UdpAssociateHeader {
|
||||
|
||||
/// Write to a writer
|
||||
pub fn write_to<W: AsyncWrite>(self, w: W) -> WriteBytes<W, Bytes> {
|
||||
let mut buf = BytesMut::with_capacity(self.len());
|
||||
let mut buf = BytesMut::with_capacity(self.serialized_len());
|
||||
self.write_to_buf(&mut buf);
|
||||
write_bytes(w, buf.freeze())
|
||||
}
|
||||
@@ -860,7 +856,7 @@ impl UdpAssociateHeader {
|
||||
|
||||
/// Length in bytes
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
3 + self.address.len()
|
||||
pub fn serialized_len(&self) -> usize {
|
||||
3 + self.address.serialized_len()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,14 @@ use tokio::net::TcpStream;
|
||||
use tokio_io::{io::flush, AsyncRead, AsyncWrite};
|
||||
|
||||
use crate::relay::socks5::{
|
||||
self, Address, Command, HandshakeRequest, HandshakeResponse, Reply, TcpRequestHeader, TcpResponseHeader,
|
||||
self,
|
||||
Address,
|
||||
Command,
|
||||
HandshakeRequest,
|
||||
HandshakeResponse,
|
||||
Reply,
|
||||
TcpRequestHeader,
|
||||
TcpResponseHeader,
|
||||
};
|
||||
|
||||
use crate::{config::ServerConfig, context::SharedContext};
|
||||
|
||||
@@ -11,7 +11,9 @@ use futures::{Async, Future, Poll};
|
||||
use tokio::timer::Delay;
|
||||
use tokio_io::{
|
||||
io::{copy, Copy},
|
||||
try_nb, AsyncRead, AsyncWrite,
|
||||
try_nb,
|
||||
AsyncRead,
|
||||
AsyncWrite,
|
||||
};
|
||||
|
||||
use super::{
|
||||
|
||||
@@ -309,7 +309,7 @@ where
|
||||
proxy_handshake(remote_stream, svr_cfg).and_then(move |(r_fut, w_fut)| {
|
||||
let w_fut = w_fut.and_then(move |enc_w| {
|
||||
// Send relay address to remote
|
||||
let mut buf = BytesMut::with_capacity(relay_addr.len());
|
||||
let mut buf = BytesMut::with_capacity(relay_addr.serialized_len());
|
||||
relay_addr.write_to_buf(&mut buf);
|
||||
|
||||
trace!(
|
||||
|
||||
@@ -34,12 +34,7 @@ use tokio_io::{
|
||||
use super::{
|
||||
context::{SharedTcpServerContext, TcpServerContext},
|
||||
monitor::TcpMonStream,
|
||||
proxy_handshake,
|
||||
try_timeout,
|
||||
tunnel,
|
||||
DecryptedHalf,
|
||||
EncryptedHalf,
|
||||
TcpStreamConnect,
|
||||
proxy_handshake, try_timeout, tunnel, DecryptedHalf, EncryptedHalf, TcpStreamConnect,
|
||||
};
|
||||
|
||||
/// Context for doing handshake with client
|
||||
@@ -222,8 +217,8 @@ fn handle_client(svr_context: SharedTcpServerContext, socket: TcpStream) -> impl
|
||||
|
||||
client
|
||||
.handshake()
|
||||
.and_then(|c| c.connect())
|
||||
.and_then(|c| c.tunnel())
|
||||
.and_then(TcpRelayClientPending::connect)
|
||||
.and_then(TcpRelayClientConnected::tunnel)
|
||||
.map_err(move |err| {
|
||||
error!("Failed to handle client ({}): {}", addr, err);
|
||||
})
|
||||
|
||||
@@ -14,7 +14,9 @@ use tokio::{self, net::UdpSocket};
|
||||
|
||||
use super::{
|
||||
crypto_io::{decrypt_payload, encrypt_payload},
|
||||
PacketStream, SendDgramRc, SharedUdpSocket,
|
||||
PacketStream,
|
||||
SendDgramRc,
|
||||
SharedUdpSocket,
|
||||
};
|
||||
use crate::{
|
||||
config::{ServerAddr, ServerConfig},
|
||||
|
||||
+3
-2
@@ -9,11 +9,12 @@ use dns_parser::{Builder, Packet, QueryClass, QueryType};
|
||||
use log::trace;
|
||||
use shadowsocks::{
|
||||
config::{Config, ConfigType},
|
||||
run_dns, run_server,
|
||||
run_dns,
|
||||
run_server,
|
||||
};
|
||||
use tokio::runtime::current_thread::Runtime;
|
||||
|
||||
const CONFIG: &'static str = r#"{
|
||||
const CONFIG: &str = r#"{
|
||||
"server": "127.0.0.1",
|
||||
"server_port": 8988,
|
||||
"local_port": 5030,
|
||||
|
||||
+8
-14
@@ -23,13 +23,7 @@ pub struct Socks5TestServer {
|
||||
}
|
||||
|
||||
impl Socks5TestServer {
|
||||
pub fn new<S, L>(
|
||||
svr_addr: S,
|
||||
local_addr: L,
|
||||
pwd: &'static str,
|
||||
method: CipherType,
|
||||
enable_udp: bool,
|
||||
) -> Socks5TestServer
|
||||
pub fn new<S, L>(svr_addr: S, local_addr: L, pwd: &str, method: CipherType, enable_udp: bool) -> Socks5TestServer
|
||||
where
|
||||
S: ToSocketAddrs,
|
||||
L: ToSocketAddrs,
|
||||
@@ -38,7 +32,7 @@ impl Socks5TestServer {
|
||||
let local_addr = local_addr.to_socket_addrs().unwrap().next().unwrap();
|
||||
|
||||
Socks5TestServer {
|
||||
local_addr: local_addr,
|
||||
local_addr,
|
||||
svr_config: {
|
||||
let mut cfg = Config::new(ConfigType::Server);
|
||||
cfg.server = vec![ServerConfig::basic(svr_addr, pwd.to_owned(), method)];
|
||||
@@ -82,10 +76,10 @@ impl Socks5TestServer {
|
||||
fn socks5_relay_stream() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
const SERVER_ADDR: &'static str = "127.0.0.1:8100";
|
||||
const LOCAL_ADDR: &'static str = "127.0.0.1:8200";
|
||||
const SERVER_ADDR: &str = "127.0.0.1:8100";
|
||||
const LOCAL_ADDR: &str = "127.0.0.1:8200";
|
||||
|
||||
const PASSWORD: &'static str = "test-password";
|
||||
const PASSWORD: &str = "test-password";
|
||||
const METHOD: CipherType = CipherType::Aes256Cfb;
|
||||
|
||||
let svr = Socks5TestServer::new(SERVER_ADDR, LOCAL_ADDR, PASSWORD, METHOD, false);
|
||||
@@ -114,10 +108,10 @@ fn socks5_relay_stream() {
|
||||
fn socks5_relay_aead() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
const SERVER_ADDR: &'static str = "127.0.0.1:8110";
|
||||
const LOCAL_ADDR: &'static str = "127.0.0.1:8210";
|
||||
const SERVER_ADDR: &str = "127.0.0.1:8110";
|
||||
const LOCAL_ADDR: &str = "127.0.0.1:8210";
|
||||
|
||||
const PASSWORD: &'static str = "test-password";
|
||||
const PASSWORD: &str = "test-password";
|
||||
const METHOD: CipherType = CipherType::Aes256Gcm;
|
||||
|
||||
let svr = Socks5TestServer::new(SERVER_ADDR, LOCAL_ADDR, PASSWORD, METHOD, false);
|
||||
|
||||
+6
-6
@@ -24,13 +24,13 @@ use shadowsocks::{
|
||||
run_server,
|
||||
};
|
||||
|
||||
const SERVER_ADDR: &'static str = "127.0.0.1:8093";
|
||||
const LOCAL_ADDR: &'static str = "127.0.0.1:8291";
|
||||
const SERVER_ADDR: &str = "127.0.0.1:8093";
|
||||
const LOCAL_ADDR: &str = "127.0.0.1:8291";
|
||||
|
||||
const UDP_ECHO_SERVER_ADDR: &'static str = "127.0.0.1:50403";
|
||||
const UDP_LOCAL_ADDR: &'static str = "127.0.0.1:9011";
|
||||
const UDP_ECHO_SERVER_ADDR: &str = "127.0.0.1:50403";
|
||||
const UDP_LOCAL_ADDR: &str = "127.0.0.1:9011";
|
||||
|
||||
const PASSWORD: &'static str = "test-password";
|
||||
const PASSWORD: &str = "test-password";
|
||||
const METHOD: CipherType = CipherType::Aes128Cfb;
|
||||
|
||||
fn get_svr_config() -> Config {
|
||||
@@ -144,7 +144,7 @@ fn udp_relay() {
|
||||
l.set_write_timeout(Some(Duration::from_secs(5))).unwrap();
|
||||
|
||||
let header = UdpAssociateHeader::new(0, remote_addr);
|
||||
let mut buf = BytesMut::with_capacity(header.len());
|
||||
let mut buf = BytesMut::with_capacity(header.serialized_len());
|
||||
header.write_to_buf(&mut buf);
|
||||
|
||||
let payload = b"HEllo WORld";
|
||||
|
||||
Reference in New Issue
Block a user