diff --git a/conf/node.go b/conf/node.go index ee79cd1..7f4ed5f 100644 --- a/conf/node.go +++ b/conf/node.go @@ -83,6 +83,7 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) { } type Options struct { + Name string `json:"Name"` Core string `json:"Core"` ListenIP string `json:"ListenIP"` SendIP string `json:"SendIP"` diff --git a/example/config.json b/example/config.json index 9594457..b670399 100644 --- a/example/config.json +++ b/example/config.json @@ -21,7 +21,7 @@ // 同 SingBox ntp 部分配置 // VMess VLESS 建议开启 "Enable": true, - "Server": "time.apple.com", + "Server": "time.apple.com", "ServerPort": 0 } // More @@ -42,6 +42,9 @@ { // 写法1 + // Node标识名,便于查看日志,不填将通过下发的节点配置自动生成 + // 务必注意不要重复,否则会出现问题 + "Name": "sing_node1", // Core类型 "Core": "sing", // API接口地址 @@ -76,13 +79,14 @@ /*, { // 写法2 - + // 类似旧配置文件 ApiConfig 部分 "ApiConfig": { "ApiHost": "http://127.0.0.1", "ApiKey": "test", "NodeID": 33, "Timeout": 30, }, + // 类似旧配置文件 ControllerConfig 部分 "Options": { "Core": "sing", "EnableProxyProtocol": true, diff --git a/node/controller.go b/node/controller.go index 5c25085..79d7725 100644 --- a/node/controller.go +++ b/node/controller.go @@ -56,7 +56,11 @@ func (c *Controller) Start() error { if len(c.userList) == 0 { return errors.New("add users error: not have any user") } - c.tag = c.buildNodeTag(node) + if len(c.Options.Name) == 0 { + c.tag = c.buildNodeTag(node) + } else { + c.tag = c.Options.Name + } // add limiter l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList) diff --git a/node/task.go b/node/task.go index 639fc9e..51c12f2 100644 --- a/node/task.go +++ b/node/task.go @@ -75,7 +75,7 @@ func (c *Controller) nodeInfoMonitor() (err error) { c.userList = newU } c.traffic = make(map[string]int64) - // Remove old tag + // Remove old node log.WithField("tag", c.tag).Info("Node changed, reload") err = c.server.DelNode(c.tag) if err != nil { @@ -85,11 +85,26 @@ func (c *Controller) nodeInfoMonitor() (err error) { }).Error("Delete node failed") return nil } - // Remove Old limiter - limiter.DeleteLimiter(c.tag) - // Add new Limiter - c.tag = c.buildNodeTag(newN) - l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList) + + // Update limiter + if len(c.Options.Name) == 0 { + c.tag = c.buildNodeTag(newN) + // Remove Old limiter + limiter.DeleteLimiter(c.tag) + // Add new Limiter + l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList) + c.limiter = l + } + // Update rule + err = c.limiter.UpdateRule(&newN.Rules) + if err != nil { + log.WithFields(log.Fields{ + "tag": c.tag, + "err": err, + }).Error("Update Rule failed") + return nil + } + // check cert if newN.Security == panel.Tls { err = c.requestCert() @@ -122,15 +137,6 @@ func (c *Controller) nodeInfoMonitor() (err error) { }).Error("Add users failed") return nil } - err = l.UpdateRule(&newN.Rules) - if err != nil { - log.WithFields(log.Fields{ - "tag": c.tag, - "err": err, - }).Error("Update Rule failed") - return nil - } - c.limiter = l // Check interval if c.nodeInfoMonitorPeriodic.Interval != newN.PullInterval && newN.PullInterval != 0 {