Fix reset outbound

This commit is contained in:
世界
2022-11-06 10:36:19 +08:00
parent 0ad1bbea11
commit 1f63ce5dee
6 changed files with 63 additions and 17 deletions

View File

@@ -23,7 +23,10 @@ import (
N "github.com/sagernet/sing/common/network"
)
var _ adapter.Outbound = (*Hysteria)(nil)
var (
_ adapter.Outbound = (*Hysteria)(nil)
_ adapter.InterfaceUpdateListener = (*Hysteria)(nil)
)
type Hysteria struct {
myOutboundAdapter
@@ -236,6 +239,11 @@ func (h *Hysteria) udpRecvLoop(conn quic.Connection) {
}
}
func (h *Hysteria) InterfaceUpdated() error {
h.Close()
return nil
}
func (h *Hysteria) Close() error {
h.connAccess.Lock()
defer h.connAccess.Unlock()

View File

@@ -21,7 +21,10 @@ import (
"golang.org/x/crypto/ssh"
)
var _ adapter.Outbound = (*SSH)(nil)
var (
_ adapter.Outbound = (*SSH)(nil)
_ adapter.InterfaceUpdateListener = (*SSH)(nil)
)
type SSH struct {
myOutboundAdapter
@@ -149,6 +152,11 @@ func (s *SSH) connect() (*ssh.Client, error) {
return client, nil
}
func (s *SSH) InterfaceUpdated() error {
common.Close(s.clientConn)
return nil
}
func (s *SSH) Close() error {
return common.Close(s.clientConn)
}

View File

@@ -26,7 +26,10 @@ import (
"golang.zx2c4.com/wireguard/device"
)
var _ adapter.Outbound = (*WireGuard)(nil)
var (
_ adapter.Outbound = (*WireGuard)(nil)
_ adapter.InterfaceUpdateListener = (*WireGuard)(nil)
)
type WireGuard struct {
myOutboundAdapter
@@ -134,6 +137,11 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context
return outbound, nil
}
func (w *WireGuard) InterfaceUpdated() error {
w.bind.Reset()
return nil
}
func (w *WireGuard) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
switch network {
case N.NetworkTCP: