mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 05:44:12 +08:00
Fix wireguard endpoint
This commit is contained in:
parent
5fdc051a08
commit
4c9455b944
@ -26,11 +26,6 @@ func RegisterEndpoint(registry *endpoint.Registry) {
|
|||||||
endpoint.Register[option.WireGuardEndpointOptions](registry, C.TypeWireGuard, NewEndpoint)
|
endpoint.Register[option.WireGuardEndpointOptions](registry, C.TypeWireGuard, NewEndpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
_ adapter.Endpoint = (*Endpoint)(nil)
|
|
||||||
_ adapter.InterfaceUpdateListener = (*Endpoint)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Endpoint struct {
|
type Endpoint struct {
|
||||||
endpoint.Adapter
|
endpoint.Adapter
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@ -118,10 +113,6 @@ func (w *Endpoint) Close() error {
|
|||||||
return w.endpoint.Close()
|
return w.endpoint.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Endpoint) InterfaceUpdated() {
|
|
||||||
w.endpoint.BindUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *Endpoint) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr) error {
|
func (w *Endpoint) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr) error {
|
||||||
return w.router.PreMatch(adapter.InboundContext{
|
return w.router.PreMatch(adapter.InboundContext{
|
||||||
Inbound: w.Tag(),
|
Inbound: w.Tag(),
|
||||||
|
@ -25,11 +25,6 @@ func RegisterOutbound(registry *outbound.Registry) {
|
|||||||
outbound.Register[option.LegacyWireGuardOutboundOptions](registry, C.TypeWireGuard, NewOutbound)
|
outbound.Register[option.LegacyWireGuardOutboundOptions](registry, C.TypeWireGuard, NewOutbound)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
_ adapter.Endpoint = (*Endpoint)(nil)
|
|
||||||
_ adapter.InterfaceUpdateListener = (*Endpoint)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Outbound struct {
|
type Outbound struct {
|
||||||
outbound.Adapter
|
outbound.Adapter
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@ -124,10 +119,6 @@ func (o *Outbound) Close() error {
|
|||||||
return o.endpoint.Close()
|
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) {
|
func (o *Outbound) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||||
switch network {
|
switch network {
|
||||||
case N.NetworkTCP:
|
case N.NetworkTCP:
|
||||||
|
@ -150,7 +150,7 @@ func (e *Endpoint) Start(resolve bool) error {
|
|||||||
connectAddr netip.AddrPort
|
connectAddr netip.AddrPort
|
||||||
reserved [3]uint8
|
reserved [3]uint8
|
||||||
)
|
)
|
||||||
if len(e.peers) == 1 {
|
if len(e.peers) == 1 && e.peers[0].endpoint.IsValid() {
|
||||||
isConnect = true
|
isConnect = true
|
||||||
connectAddr = e.peers[0].endpoint
|
connectAddr = e.peers[0].endpoint
|
||||||
reserved = e.peers[0].reserved
|
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)
|
return e.tunDevice.ListenPacket(ctx, destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Endpoint) BindUpdate() error {
|
|
||||||
return e.device.BindUpdate()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *Endpoint) Close() error {
|
func (e *Endpoint) Close() error {
|
||||||
if e.device != nil {
|
if e.device != nil {
|
||||||
e.device.Close()
|
e.device.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user