From df48f511fbca2c6fb18e1ebf03bf0888d41e46e7 Mon Sep 17 00:00:00 2001 From: eric Date: Sat, 19 Dec 2020 04:57:02 +0800 Subject: [PATCH] conf: Add Trojan over WebSocket over TLS (TLS + WebSockeet + Trojan) support --- README.zh.md | 12 ++++++++++++ leaf/src/config/conf/config.rs | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/README.zh.md b/README.zh.md index 5c1b99e..5dbae7d 100644 --- a/README.zh.md +++ b/README.zh.md @@ -56,22 +56,34 @@ iOS TF 测试公开链接:https://testflight.apple.com/join/std0FFCS loglevel = info dns-server = 114.114.114.114, 223.5.5.5 always-real-ip = tracker, apple.com + +# Local HTTP CONNECT proxy interface = 127.0.0.1 port = 1087 + +# Local SOCKS5 proxy with UDP Associate support socks-interface = 127.0.0.1 socks-port = 1086 [Proxy] Direct = direct Reject = reject + +# Shadowsocks SS = ss, 1.2.3.4, 8485, encrypt-method=chacha20-ietf-poly1305, password=123456 +# VMess VMess = vmess, my.domain.com, 8001, username=0eb5486e-e1b5-49c5-aa75-d15e54dfac9d +# VMess over WebSocket over TLS (TLS + WebSocket + VMess) VMessWSS = vmess, my.domain.com, 443, username=0eb5486e-e1b5-49c5-aa75-d15e54dfac9d, ws=true, tls=true, ws-path=/v2 +# Trojan (with TLS) Trojan = trojan, 4.3.2.1, 443, password=123456, sni=www.domain.com +# Trojan over WebSocket over TLS (TLS + WebSocket + Trojan) +TrojanWS = trojan, 4.3.2.1, 443, password=123456, sni=www.domain.com, ws=true, ws-path=/abc + [Proxy Group] # fallback 等效于 failover Fallback = fallback, Trojan, VMessWSS, SS, interval=600, timeout=5 diff --git a/leaf/src/config/conf/config.rs b/leaf/src/config/conf/config.rs index e7cb9ec..dc77e74 100644 --- a/leaf/src/config/conf/config.rs +++ b/leaf/src/config/conf/config.rs @@ -663,6 +663,20 @@ pub fn to_internal(conf: Config) -> Result { tls_outbound.settings = tls_settings; tls_outbound.tag = format!("{}_tls_xxx", ext_proxy.tag.clone()); + // ws + let mut ws_outbound = internal::Outbound::new(); + ws_outbound.protocol = "ws".to_string(); + ws_outbound.bind = ext_proxy.interface.clone(); + let mut ws_settings = internal::WebSocketOutboundSettings::new(); + if let Some(ext_ws_path) = &ext_proxy.ws_path { + ws_settings.path = ext_ws_path.clone(); + } else { + ws_settings.path = "/".to_string(); + } + let ws_settings = ws_settings.write_to_bytes().unwrap(); + ws_outbound.settings = ws_settings; + ws_outbound.tag = format!("{}_ws_xxx", ext_proxy.tag.clone()); + // plain trojan let mut settings = internal::TrojanOutboundSettings::new(); if let Some(ext_address) = &ext_proxy.address { @@ -683,6 +697,9 @@ pub fn to_internal(conf: Config) -> Result { chain_outbound.tag = ext_proxy.tag.clone(); let mut chain_settings = internal::ChainOutboundSettings::new(); chain_settings.actors.push(tls_outbound.tag.clone()); + if ext_proxy.ws.unwrap() { + chain_settings.actors.push(ws_outbound.tag.clone()); + } chain_settings.actors.push(outbound.tag.clone()); let chain_settings = chain_settings.write_to_bytes().unwrap(); chain_outbound.settings = chain_settings; @@ -693,6 +710,9 @@ pub fn to_internal(conf: Config) -> Result { // the chain outbound will be the default one to use outbounds.push(chain_outbound); outbounds.push(tls_outbound); + if ext_proxy.ws.unwrap() { + outbounds.push(ws_outbound); + } outbounds.push(outbound); } "vmess" => {