From 3267da129230861debfdd9f4630bba2474fc42ed Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 13 Apr 2023 17:01:01 +0800 Subject: [PATCH] fix: wireguard reconnect failed --- adapter/outbound/wireguard.go | 10 +++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/adapter/outbound/wireguard.go b/adapter/outbound/wireguard.go index a2634be4..f96f2d6f 100644 --- a/adapter/outbound/wireguard.go +++ b/adapter/outbound/wireguard.go @@ -174,7 +174,7 @@ func NewWireGuard(option WireGuardOption) (*WireGuard, error) { connectAddr = option.Addr() } } - outbound.bind = wireguard.NewClientBind(context.Background(), outbound.dialer, isConnect, connectAddr, reserved) + outbound.bind = wireguard.NewClientBind(context.Background(), outbound, outbound.dialer, isConnect, connectAddr, reserved) var localPrefixes []netip.Prefix @@ -329,6 +329,14 @@ func NewWireGuard(option WireGuardOption) (*WireGuard, error) { return outbound, nil } +func (w *WireGuard) NewError(ctx context.Context, err error) { + if E.IsClosedOrCanceled(err) { + log.SingLogger.Debug(fmt.Sprintf("[WG](%s) connection closed: %s", w.Name(), err)) + return + } + log.SingLogger.Error(fmt.Sprintf("[WG](%s) %s", w.Name(), err)) +} + func closeWireGuard(w *WireGuard) { if w.device != nil { w.device.Close() diff --git a/go.mod b/go.mod index d6479643..180b0307 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/metacubex/quic-go v0.33.3-0.20230322045857-901b636b4594 github.com/metacubex/sing-shadowsocks v0.2.2-0.20230409073201-1ce3505114ae github.com/metacubex/sing-tun v0.1.3 - github.com/metacubex/sing-wireguard v0.0.0-20230402083957-d134f603ac98 + github.com/metacubex/sing-wireguard v0.0.0-20230413082948-e51777dcf025 github.com/miekg/dns v1.1.52 github.com/mroth/weightedrand/v2 v2.0.0 github.com/openacid/low v0.1.21 diff --git a/go.sum b/go.sum index 7b4d8379..8d4f564e 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/metacubex/sing-shadowsocks v0.2.2-0.20230409073201-1ce3505114ae h1:SN github.com/metacubex/sing-shadowsocks v0.2.2-0.20230409073201-1ce3505114ae/go.mod h1:JefDbbkQHCn8w+IcjFqMOMV2VmN9wvbYX4RaeBUkPwM= github.com/metacubex/sing-tun v0.1.3 h1:LCz8TlAZUWwnBYZxs1PEE04PyfLA9xdsye6CjHZlZGQ= github.com/metacubex/sing-tun v0.1.3/go.mod h1:kHkYHoRlYA4I12QPTt/ADyRGqy5YweLUfye1E1hC/q4= -github.com/metacubex/sing-wireguard v0.0.0-20230402083957-d134f603ac98 h1:Dr6A4drhVkjPaJ5lIf3DwhH2HSo+Qmf8fCQmJoDG5YU= -github.com/metacubex/sing-wireguard v0.0.0-20230402083957-d134f603ac98/go.mod h1:7mPG9qYln+CLKBcDt7Dk4c7b3S53VzEfexMVPe6T6FM= +github.com/metacubex/sing-wireguard v0.0.0-20230413082948-e51777dcf025 h1:itjCqEeem+BKZFiBEhQmWHDHKK4FgTGvnYCFS0JOb3A= +github.com/metacubex/sing-wireguard v0.0.0-20230413082948-e51777dcf025/go.mod h1:7mPG9qYln+CLKBcDt7Dk4c7b3S53VzEfexMVPe6T6FM= github.com/metacubex/uber-atomic v0.0.0-20230202125923-feb10b770370 h1:UkViS4DCESAUEYgbIEQdD02hyMacFt6Dny+1MOJtNIo= github.com/metacubex/uber-atomic v0.0.0-20230202125923-feb10b770370/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= github.com/miekg/dns v1.1.52 h1:Bmlc/qsNNULOe6bpXcUTsuOajd0DzRHwup6D9k1An0c=