mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-01-06 01:23:38 +08:00
fix: better wireguard error handle
This commit is contained in:
parent
dfc0ec995c
commit
16f8f77f5d
@ -36,6 +36,7 @@ type WireGuard struct {
|
|||||||
tunDevice wireguard.Device
|
tunDevice wireguard.Device
|
||||||
dialer *wgDialer
|
dialer *wgDialer
|
||||||
startOnce sync.Once
|
startOnce sync.Once
|
||||||
|
startErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
type WireGuardOption struct {
|
type WireGuardOption struct {
|
||||||
@ -198,10 +199,10 @@ func (w *WireGuard) DialContext(ctx context.Context, metadata *C.Metadata, opts
|
|||||||
w.dialer.options = opts
|
w.dialer.options = opts
|
||||||
var conn net.Conn
|
var conn net.Conn
|
||||||
w.startOnce.Do(func() {
|
w.startOnce.Do(func() {
|
||||||
err = w.tunDevice.Start()
|
w.startErr = w.tunDevice.Start()
|
||||||
})
|
})
|
||||||
if err != nil {
|
if w.startErr != nil {
|
||||||
return nil, err
|
return nil, w.startErr
|
||||||
}
|
}
|
||||||
if !metadata.Resolved() {
|
if !metadata.Resolved() {
|
||||||
var addrs []netip.Addr
|
var addrs []netip.Addr
|
||||||
@ -226,8 +227,11 @@ func (w *WireGuard) ListenPacketContext(ctx context.Context, metadata *C.Metadat
|
|||||||
w.dialer.options = opts
|
w.dialer.options = opts
|
||||||
var pc net.PacketConn
|
var pc net.PacketConn
|
||||||
w.startOnce.Do(func() {
|
w.startOnce.Do(func() {
|
||||||
err = w.tunDevice.Start()
|
w.startErr = w.tunDevice.Start()
|
||||||
})
|
})
|
||||||
|
if w.startErr != nil {
|
||||||
|
return nil, w.startErr
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -242,6 +246,9 @@ func (w *WireGuard) ListenPacketContext(ctx context.Context, metadata *C.Metadat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
if pc == nil {
|
||||||
|
return nil, E.New("packetConn is nil")
|
||||||
|
}
|
||||||
return newPacketConn(&wgPacketConn{pc, w}, w), nil
|
return newPacketConn(&wgPacketConn{pc, w}, w), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user