From 950a5539e1772434886e155aab2f09444b4e053d Mon Sep 17 00:00:00 2001 From: CN-JS-HuiBai Date: Tue, 14 Apr 2026 23:45:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E4=B8=8A=E4=B8=80=E6=AC=A1=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/xboard/service.go | 47 +++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/service/xboard/service.go b/service/xboard/service.go index facd1c48..39a62d26 100644 --- a/service/xboard/service.go +++ b/service/xboard/service.go @@ -44,10 +44,13 @@ type Service struct { } type XNodeConfig struct { - Port int `json:"port"` - Protocol string `json:"protocol"` - Settings json.RawMessage `json:"settings"` - StreamSettings json.RawMessage `json:"streamSettings"` + 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