Refactor endpoint listen

This commit is contained in:
世界
2026-07-17 10:44:40 +08:00
parent c8ee3497b2
commit 704b57cf3e
9 changed files with 102 additions and 34 deletions
+18
View File
@@ -74,6 +74,23 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
udpTimeout = C.UDPTimeout
}
networkManager := service.FromContext[adapter.NetworkManager](ctx)
var egressPool *tun.UDPEgressPool
wireGuardListener, isWireGuardListener := common.Cast[dialer.WireGuardListener](outboundDialer)
if isWireGuardListener {
anchorControl, egressEnabled := wireGuardListener.WireGuardControl()
if egressEnabled {
egressPool = tun.NewUDPEgressPool(tun.UDPEgressPoolOptions{
Logger: logger,
Control: anchorControl,
InterfaceFinder: networkManager.InterfaceFinder(),
InterfaceMonitor: networkManager.InterfaceMonitor(),
ExcludeInterface: options.Name,
IsExempt: func() bool {
return networkManager.AutoRedirectOutputMark() != 0
},
})
}
}
wgEndpoint, err := wireguard.NewEndpoint(wireguard.EndpointOptions{
Context: ctx,
Logger: logger,
@@ -85,6 +102,7 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
UDPFiltering: tun.NATFiltering(options.UDPFiltering),
UDPNATMax: options.UDPNATMax,
InterfaceFinder: networkManager.InterfaceFinder(),
EgressPool: egressPool,
Dialer: outboundDialer,
CreateDialer: func(interfaceName string) N.Dialer {
return common.Must1(dialer.NewDefault(ctx, option.DialerOptions{