From 4c9455b94432d879437cfaab637d31edd78e6724 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 16 Apr 2025 17:30:41 +0800 Subject: [PATCH] Fix wireguard endpoint --- protocol/wireguard/endpoint.go | 9 --------- protocol/wireguard/outbound.go | 9 --------- transport/wireguard/endpoint.go | 6 +----- 3 files changed, 1 insertion(+), 23 deletions(-) diff --git a/protocol/wireguard/endpoint.go b/protocol/wireguard/endpoint.go index c9751c36..2f6825fd 100644 --- a/protocol/wireguard/endpoint.go +++ b/protocol/wireguard/endpoint.go @@ -26,11 +26,6 @@ func RegisterEndpoint(registry *endpoint.Registry) { endpoint.Register[option.WireGuardEndpointOptions](registry, C.TypeWireGuard, NewEndpoint) } -var ( - _ adapter.Endpoint = (*Endpoint)(nil) - _ adapter.InterfaceUpdateListener = (*Endpoint)(nil) -) - type Endpoint struct { endpoint.Adapter ctx context.Context @@ -118,10 +113,6 @@ func (w *Endpoint) Close() error { return w.endpoint.Close() } -func (w *Endpoint) InterfaceUpdated() { - w.endpoint.BindUpdate() -} - func (w *Endpoint) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr) error { return w.router.PreMatch(adapter.InboundContext{ Inbound: w.Tag(), diff --git a/protocol/wireguard/outbound.go b/protocol/wireguard/outbound.go index 7a516598..808dade4 100644 --- a/protocol/wireguard/outbound.go +++ b/protocol/wireguard/outbound.go @@ -25,11 +25,6 @@ func RegisterOutbound(registry *outbound.Registry) { outbound.Register[option.LegacyWireGuardOutboundOptions](registry, C.TypeWireGuard, NewOutbound) } -var ( - _ adapter.Endpoint = (*Endpoint)(nil) - _ adapter.InterfaceUpdateListener = (*Endpoint)(nil) -) - type Outbound struct { outbound.Adapter ctx context.Context @@ -124,10 +119,6 @@ func (o *Outbound) Close() error { return o.endpoint.Close() } -func (o *Outbound) InterfaceUpdated() { - o.endpoint.BindUpdate() -} - func (o *Outbound) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) { switch network { case N.NetworkTCP: diff --git a/transport/wireguard/endpoint.go b/transport/wireguard/endpoint.go index 17a58a6c..bddd2a12 100644 --- a/transport/wireguard/endpoint.go +++ b/transport/wireguard/endpoint.go @@ -150,7 +150,7 @@ func (e *Endpoint) Start(resolve bool) error { connectAddr netip.AddrPort reserved [3]uint8 ) - if len(e.peers) == 1 { + if len(e.peers) == 1 && e.peers[0].endpoint.IsValid() { isConnect = true connectAddr = e.peers[0].endpoint reserved = e.peers[0].reserved @@ -208,10 +208,6 @@ func (e *Endpoint) ListenPacket(ctx context.Context, destination M.Socksaddr) (n return e.tunDevice.ListenPacket(ctx, destination) } -func (e *Endpoint) BindUpdate() error { - return e.device.BindUpdate() -} - func (e *Endpoint) Close() error { if e.device != nil { e.device.Close()