From 55301897e046d78c7bce0d9c24226b62a0e2e157 Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sat, 11 Feb 2023 22:24:14 +0800 Subject: [PATCH] fix: fix dialer switching if only one node and fix ss+simple-obfs --- component/outbound/dialer/alive_dialer_set.go | 2 +- .../dialer/shadowsocks/shadowsocks.go | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/component/outbound/dialer/alive_dialer_set.go b/component/outbound/dialer/alive_dialer_set.go index a98a780..316191e 100644 --- a/component/outbound/dialer/alive_dialer_set.go +++ b/component/outbound/dialer/alive_dialer_set.go @@ -153,7 +153,7 @@ func (a *AliveDialerSet) NotifyLatencyChange(dialer *Dialer, alive bool) { a.minLatency.latency = latency a.minLatency.dialer = dialer } else if a.minLatency.dialer == dialer { - if latency > a.minLatency.latency { + if !alive || latency > a.minLatency.latency { // Latency increases. a.minLatency.latency = time.Hour a.minLatency.dialer = nil diff --git a/component/outbound/dialer/shadowsocks/shadowsocks.go b/component/outbound/dialer/shadowsocks/shadowsocks.go index 7d302ce..17d6f12 100644 --- a/component/outbound/dialer/shadowsocks/shadowsocks.go +++ b/component/outbound/dialer/shadowsocks/shadowsocks.go @@ -48,16 +48,8 @@ func (s *Shadowsocks) Dialer(option *dialer.GlobalOption, iOption dialer.Instanc default: return nil, fmt.Errorf("unsupported shadowsocks encryption method: %v", s.Cipher) } + var err error d := dialer.FullconeDirect // Shadowsocks Proxy supports full-cone. - d, err := protocol.NewDialer("shadowsocks", d, protocol.Header{ - ProxyAddress: net.JoinHostPort(s.Server, strconv.Itoa(s.Port)), - Cipher: s.Cipher, - Password: s.Password, - IsClient: true, - }) - if err != nil { - return nil, err - } switch s.Plugin.Name { case "simple-obfs": uSimpleObfs := url.URL{ @@ -74,7 +66,16 @@ func (s *Shadowsocks) Dialer(option *dialer.GlobalOption, iOption dialer.Instanc return nil, err } } - return dialer.NewDialer(d, option, iOption, s.Name, s.Protocol, s.ExportToURL()), nil + d, err = protocol.NewDialer("shadowsocks", d, protocol.Header{ + ProxyAddress: net.JoinHostPort(s.Server, strconv.Itoa(s.Port)), + Cipher: s.Cipher, + Password: s.Password, + IsClient: true, + }) + if err != nil { + return nil, err + } + return dialer.NewDialer(d, option, iOption, s.Name, s.Protocol, s.ExportToURL()), nil } func ParseSSURL(u string) (data *Shadowsocks, err error) {