mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-02-09 01:59:16 +08:00
support multiple local servers in configuration file
ref #452 - support `locals` in configuration file, running multiple local server instance simultaneously - support `unix://` in `dns` configuration BREAKING CHANGE: - `sslocal`'s `--dns-addr` is now only available in Android - shadowsocks-service's `Config` struct have lots of changes
This commit is contained in:
18
tests/dns.rs
18
tests/dns.rs
@@ -10,7 +10,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, ProtocolType},
|
||||
config::{Config, ConfigType},
|
||||
run_local,
|
||||
run_server,
|
||||
};
|
||||
@@ -19,10 +19,17 @@ use shadowsocks_service::{
|
||||
async fn dns_relay() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let mut local_config = Config::load_from_str(
|
||||
let local_config = Config::load_from_str(
|
||||
r#"{
|
||||
"local_port": 6110,
|
||||
"local_address": "127.0.0.1",
|
||||
"locals": [
|
||||
{
|
||||
"local_address": "127.0.0.1",
|
||||
"local_port": 6110,
|
||||
"protocol": "dns",
|
||||
"local_dns_address": "114.114.114.114",
|
||||
"remote_dns_address": "8.8.8.8"
|
||||
}
|
||||
],
|
||||
"server": "127.0.0.1",
|
||||
"server_port": 6120,
|
||||
"password": "password",
|
||||
@@ -31,9 +38,6 @@ async fn dns_relay() {
|
||||
ConfigType::Local,
|
||||
)
|
||||
.unwrap();
|
||||
local_config.local_protocol = ProtocolType::Dns;
|
||||
local_config.local_dns_addr = Some("114.114.114.114:53".parse().unwrap());
|
||||
local_config.remote_dns_addr = Some("8.8.8.8:53".parse().unwrap());
|
||||
|
||||
let server_config = Config::load_from_str(
|
||||
r#"{
|
||||
|
||||
@@ -9,7 +9,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, ProtocolType},
|
||||
config::{Config, ConfigType},
|
||||
run_local,
|
||||
run_server,
|
||||
};
|
||||
@@ -18,10 +18,15 @@ use shadowsocks_service::{
|
||||
async fn http_proxy() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let mut local_config = Config::load_from_str(
|
||||
let local_config = Config::load_from_str(
|
||||
r#"{
|
||||
"local_port": 5110,
|
||||
"local_address": "127.0.0.1",
|
||||
"locals": [
|
||||
{
|
||||
"local_port": 5110,
|
||||
"local_address": "127.0.0.1",
|
||||
"protocol": "http"
|
||||
}
|
||||
],
|
||||
"server": "127.0.0.1",
|
||||
"server_port": 5120,
|
||||
"password": "password",
|
||||
@@ -30,7 +35,6 @@ async fn http_proxy() {
|
||||
ConfigType::Local,
|
||||
)
|
||||
.unwrap();
|
||||
local_config.local_protocol = ProtocolType::Http;
|
||||
|
||||
let server_config = Config::load_from_str(
|
||||
r#"{
|
||||
|
||||
@@ -11,7 +11,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, ProtocolType},
|
||||
config::{Config, ConfigType, LocalConfig, ProtocolType},
|
||||
local::socks::client::Socks4TcpClient,
|
||||
run_local,
|
||||
run_server,
|
||||
@@ -45,9 +45,8 @@ impl Socks4TestServer {
|
||||
},
|
||||
cli_config: {
|
||||
let mut cfg = Config::new(ConfigType::Local);
|
||||
cfg.local_addr = Some(ServerAddr::from(local_addr));
|
||||
cfg.local = vec![LocalConfig::new(ServerAddr::from(local_addr), ProtocolType::Socks)];
|
||||
cfg.server = vec![ServerConfig::new(svr_addr, pwd.to_owned(), method)];
|
||||
cfg.local_protocol = ProtocolType::Socks;
|
||||
cfg
|
||||
},
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use tokio::{
|
||||
};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, Mode, ProtocolType},
|
||||
config::{Config, ConfigType, LocalConfig, Mode, ProtocolType},
|
||||
local::socks::client::socks5::Socks5TcpClient,
|
||||
run_local,
|
||||
run_server,
|
||||
@@ -47,10 +47,9 @@ impl Socks5TestServer {
|
||||
},
|
||||
cli_config: {
|
||||
let mut cfg = Config::new(ConfigType::Local);
|
||||
cfg.local_addr = Some(ServerAddr::from(local_addr));
|
||||
cfg.local = vec![LocalConfig::new(ServerAddr::from(local_addr), ProtocolType::Socks)];
|
||||
cfg.server = vec![ServerConfig::new(svr_addr, pwd.to_owned(), method)];
|
||||
cfg.mode = if enable_udp { Mode::TcpAndUdp } else { Mode::TcpOnly };
|
||||
cfg.local_protocol = ProtocolType::Socks;
|
||||
cfg
|
||||
},
|
||||
}
|
||||
|
||||
@@ -11,20 +11,26 @@ use tokio::{
|
||||
};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, ProtocolType},
|
||||
config::{Config, ConfigType},
|
||||
run_local,
|
||||
run_server,
|
||||
shadowsocks::relay::socks5::Address,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn tcp_tunnel() {
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let mut local_config = Config::load_from_str(
|
||||
let local_config = Config::load_from_str(
|
||||
r#"{
|
||||
"local_port": 9110,
|
||||
"local_address": "127.0.0.1",
|
||||
"locals": [
|
||||
{
|
||||
"local_port": 9110,
|
||||
"local_address": "127.0.0.1",
|
||||
"protocol": "tunnel",
|
||||
"forward_address": "www.example.com",
|
||||
"forward_port": 80
|
||||
}
|
||||
],
|
||||
"server": "127.0.0.1",
|
||||
"server_port": 9120,
|
||||
"password": "password",
|
||||
@@ -33,8 +39,6 @@ async fn tcp_tunnel() {
|
||||
ConfigType::Local,
|
||||
)
|
||||
.unwrap();
|
||||
local_config.local_protocol = ProtocolType::Tunnel;
|
||||
local_config.forward = Some("www.example.com:80".parse::<Address>().unwrap());
|
||||
|
||||
let server_config = Config::load_from_str(
|
||||
r#"{
|
||||
@@ -75,10 +79,17 @@ async fn udp_tunnel() {
|
||||
|
||||
let _ = env_logger::try_init();
|
||||
|
||||
let mut local_config = Config::load_from_str(
|
||||
let local_config = Config::load_from_str(
|
||||
r#"{
|
||||
"local_port": 9210,
|
||||
"local_address": "127.0.0.1",
|
||||
"locals": [
|
||||
{
|
||||
"local_port": 9210,
|
||||
"local_address": "127.0.0.1",
|
||||
"protocol": "tunnel",
|
||||
"forward_address": "8.8.8.8",
|
||||
"forward_port": 53
|
||||
}
|
||||
],
|
||||
"server": "127.0.0.1",
|
||||
"server_port": 9220,
|
||||
"password": "password",
|
||||
@@ -88,8 +99,6 @@ async fn udp_tunnel() {
|
||||
ConfigType::Local,
|
||||
)
|
||||
.unwrap();
|
||||
local_config.local_protocol = ProtocolType::Tunnel;
|
||||
local_config.forward = Some("8.8.8.8:53".parse::<Address>().unwrap());
|
||||
|
||||
let server_config = Config::load_from_str(
|
||||
r#"{
|
||||
|
||||
@@ -7,7 +7,7 @@ use log::debug;
|
||||
use tokio::time::{self, Duration};
|
||||
|
||||
use shadowsocks_service::{
|
||||
config::{Config, ConfigType, Mode, ProtocolType},
|
||||
config::{Config, ConfigType, LocalConfig, Mode, ProtocolType},
|
||||
local::socks::client::socks5::Socks5UdpClient,
|
||||
run_local,
|
||||
run_server,
|
||||
@@ -35,14 +35,13 @@ fn get_svr_config() -> Config {
|
||||
|
||||
fn get_cli_config() -> Config {
|
||||
let mut cfg = Config::new(ConfigType::Local);
|
||||
cfg.local_addr = Some(LOCAL_ADDR.parse().unwrap());
|
||||
cfg.local = vec![LocalConfig::new(LOCAL_ADDR.parse().unwrap(), ProtocolType::Socks)];
|
||||
cfg.server = vec![ServerConfig::new(
|
||||
SERVER_ADDR.parse::<SocketAddr>().unwrap(),
|
||||
PASSWORD.to_owned(),
|
||||
METHOD,
|
||||
)];
|
||||
cfg.mode = Mode::TcpAndUdp;
|
||||
cfg.local_protocol = ProtocolType::Socks;
|
||||
cfg
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user