mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
Refactor endpoint listen
This commit is contained in:
@@ -152,13 +152,17 @@ func (e *Endpoint) Start(resolve bool) error {
|
||||
return nil
|
||||
}
|
||||
var bind conn.Bind
|
||||
wgListener, isWgListener := common.Cast[dialer.WireGuardListener](e.options.Dialer)
|
||||
if isWgListener {
|
||||
stdBind := conn.NewStdNetBind(wgListener.WireGuardControl())
|
||||
wireGuardListener, isWireGuardListener := common.Cast[dialer.WireGuardListener](e.options.Dialer)
|
||||
if isWireGuardListener {
|
||||
wireGuardControl, _ := wireGuardListener.WireGuardControl()
|
||||
standardBind := conn.NewStdNetBind(wireGuardControl).(*conn.StdNetBind)
|
||||
if e.options.ListenPort == 0 && len(e.peers) == 1 && e.peers[0].endpoint.IsValid() {
|
||||
stdBind.(*conn.StdNetBind).SetSinglePeerMode()
|
||||
standardBind.SetSinglePeerMode()
|
||||
}
|
||||
bind = stdBind
|
||||
if e.options.EgressPool != nil {
|
||||
standardBind.SetEgressProvider(e.options.EgressPool)
|
||||
}
|
||||
bind = standardBind
|
||||
} else {
|
||||
var (
|
||||
isConnect bool
|
||||
@@ -172,7 +176,7 @@ func (e *Endpoint) Start(resolve bool) error {
|
||||
}
|
||||
bind = NewClientBind(e.options.Context, e.options.Logger, e.options.Dialer, isConnect, connectAddr, reserved)
|
||||
}
|
||||
if isWgListener || len(e.peers) > 1 {
|
||||
if isWireGuardListener || len(e.peers) > 1 {
|
||||
for _, peer := range e.peers {
|
||||
if peer.reserved != [3]uint8{} {
|
||||
bind.SetReservedForEndpoint(peer.endpoint, peer.reserved)
|
||||
@@ -231,6 +235,9 @@ func (e *Endpoint) Close() error {
|
||||
e.pause.UnregisterCallback(e.pauseCallback)
|
||||
e.pauseCallback = nil
|
||||
}
|
||||
if e.options.EgressPool != nil {
|
||||
e.options.EgressPool.Close()
|
||||
}
|
||||
if e.device != nil {
|
||||
e.device.Down()
|
||||
e.device.Close()
|
||||
|
||||
@@ -24,6 +24,7 @@ type EndpointOptions struct {
|
||||
UDPNATMax uint32
|
||||
|
||||
InterfaceFinder control.InterfaceFinder
|
||||
EgressPool *tun.UDPEgressPool
|
||||
Dialer N.Dialer
|
||||
CreateDialer func(interfaceName string) N.Dialer
|
||||
Name string
|
||||
|
||||
Reference in New Issue
Block a user