feat: add xhttp transport, network monitoring and kernel auto-switch
This commit is contained in:
@@ -36,9 +36,38 @@ func ValidateNodeSpec(n *NodeSpec, kcfg config.KernelConfig) error {
|
||||
if err := ValidateCustomRouteRules(n.CustomRouteRules, kernelType, availableTags); err != nil {
|
||||
return fmt.Errorf("validate custom route rules: %w", err)
|
||||
}
|
||||
if err := validateTransportKernel(n.Network, kernelType); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// singboxUnsupportedTransports lists transport types that sing-box does not support.
|
||||
var singboxUnsupportedTransports = map[string]bool{
|
||||
"xhttp": true,
|
||||
"splithttp": true,
|
||||
}
|
||||
|
||||
func validateTransportKernel(network, kernelType string) error {
|
||||
net := strings.ToLower(strings.TrimSpace(network))
|
||||
if kernelType == "singbox" && singboxUnsupportedTransports[net] {
|
||||
return fmt.Errorf("transport %q is not supported by sing-box kernel; use xray kernel instead", net)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolveKernelForTransport returns the kernel type required by the given
|
||||
// transport. If the configured kernel cannot handle the transport, it returns
|
||||
// the kernel that can. Otherwise it returns configuredKernel unchanged.
|
||||
// This is used in machine mode to auto-switch kernel per node.
|
||||
func ResolveKernelForTransport(network, configuredKernel string) string {
|
||||
net := strings.ToLower(strings.TrimSpace(network))
|
||||
if configuredKernel == "singbox" && singboxUnsupportedTransports[net] {
|
||||
return "xray"
|
||||
}
|
||||
return configuredKernel
|
||||
}
|
||||
|
||||
func normalizeKernelType(value string) (string, error) {
|
||||
switch strings.ToLower(strings.TrimSpace(value)) {
|
||||
case "singbox", "sing-box":
|
||||
|
||||
Reference in New Issue
Block a user