同上一次修复

This commit is contained in:
CN-JS-HuiBai
2026-04-14 23:45:27 +08:00
parent 65c0c47a8f
commit 950a5539e1

View File

@@ -44,10 +44,13 @@ type Service struct {
}
type XNodeConfig struct {
NodeType string `json:"node_type"`
Config struct {
Port int `json:"port"`
Protocol string `json:"protocol"`
Settings json.RawMessage `json:"settings"`
StreamSettings json.RawMessage `json:"streamSettings"`
} `json:"config"`
}
type XRealitySettings struct {
@@ -117,18 +120,24 @@ func (s *Service) setupNode() error {
inboundTag := "xboard-inbound"
protocol := config.Config.Protocol
if protocol == "" {
protocol = config.NodeType
}
s.logger.Info("Xboard protocol identified: ", protocol)
var inboundOptions any
switch config.Protocol {
switch protocol {
case "vless":
vlessOptions := option.VLESSInboundOptions{
ListenOptions: option.ListenOptions{
ListenPort: uint16(config.Port),
ListenPort: uint16(config.Config.Port),
},
}
// Handle Reality
var streamSettings XStreamSettings
json.Unmarshal(config.StreamSettings, &streamSettings)
json.Unmarshal(config.Config.StreamSettings, &streamSettings)
if streamSettings.Security == "reality" {
vlessOptions.TLS = &option.InboundTLSOptions{
Enabled: true,
@@ -138,7 +147,7 @@ func (s *Service) setupNode() error {
Handshake: option.InboundRealityHandshakeOptions{
ServerOptions: option.ServerOptions{
Server: streamSettings.RealitySettings.Dest,
ServerPort: 443, // Default for most reality setups
ServerPort: 443,
},
},
PrivateKey: streamSettings.RealitySettings.PrivateKey,
@@ -150,19 +159,33 @@ func (s *Service) setupNode() error {
case "vmess":
vmessOptions := option.VMessInboundOptions{
ListenOptions: option.ListenOptions{
ListenPort: uint16(config.Port),
ListenPort: uint16(config.Config.Port),
},
}
inboundOptions = vmessOptions
case "shadowsocks":
ssOptions := option.ShadowsocksInboundOptions{
ListenOptions: option.ListenOptions{
ListenPort: uint16(config.Config.Port),
},
}
inboundOptions = ssOptions
case "trojan":
trojanOptions := option.TrojanInboundOptions{
ListenOptions: option.ListenOptions{
ListenPort: uint16(config.Config.Port),
},
}
inboundOptions = trojanOptions
default:
return fmt.Errorf("unsupported protocol: %s", config.Protocol)
return fmt.Errorf("unsupported protocol: %s", protocol)
}
// Remove old if exists
s.inboundManager.Remove(inboundTag)
// Create new inbound
err = s.inboundManager.Create(s.ctx, nil, s.logger, inboundTag, config.Protocol, inboundOptions)
err = s.inboundManager.Create(s.ctx, nil, s.logger, inboundTag, protocol, inboundOptions)
if err != nil {
return err
}
@@ -182,7 +205,7 @@ func (s *Service) setupNode() error {
s.inboundTags = []string{inboundTag}
s.access.Unlock()
s.logger.Info("Xboard dynamic inbound [", inboundTag, "] created on port ", config.Port)
s.logger.Info("Xboard dynamic inbound [", inboundTag, "] created on port ", config.Config.Port, " (protocol: ", protocol, ")")
}
return nil