support custom node name

This commit is contained in:
yuzuki999 2023-09-13 01:44:03 +08:00
parent 5286dfa244
commit da1870cc88
4 changed files with 33 additions and 18 deletions

View File

@ -83,6 +83,7 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) (err error) {
} }
type Options struct { type Options struct {
Name string `json:"Name"`
Core string `json:"Core"` Core string `json:"Core"`
ListenIP string `json:"ListenIP"` ListenIP string `json:"ListenIP"`
SendIP string `json:"SendIP"` SendIP string `json:"SendIP"`

View File

@ -21,7 +21,7 @@
// SingBox ntp // SingBox ntp
// VMess VLESS // VMess VLESS
"Enable": true, "Enable": true,
"Server": "time.apple.com", "Server": "time.apple.com",
"ServerPort": 0 "ServerPort": 0
} }
// More // More
@ -42,6 +42,9 @@
{ {
// 1 // 1
// Node便
//
"Name": "sing_node1",
// Core // Core
"Core": "sing", "Core": "sing",
// API // API
@ -76,13 +79,14 @@
/*, /*,
{ {
// 2 // 2
// ApiConfig
"ApiConfig": { "ApiConfig": {
"ApiHost": "http://127.0.0.1", "ApiHost": "http://127.0.0.1",
"ApiKey": "test", "ApiKey": "test",
"NodeID": 33, "NodeID": 33,
"Timeout": 30, "Timeout": 30,
}, },
// ControllerConfig
"Options": { "Options": {
"Core": "sing", "Core": "sing",
"EnableProxyProtocol": true, "EnableProxyProtocol": true,

View File

@ -56,7 +56,11 @@ func (c *Controller) Start() error {
if len(c.userList) == 0 { if len(c.userList) == 0 {
return errors.New("add users error: not have any user") 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 // add limiter
l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList) l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList)

View File

@ -75,7 +75,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
c.userList = newU c.userList = newU
} }
c.traffic = make(map[string]int64) c.traffic = make(map[string]int64)
// Remove old tag // Remove old node
log.WithField("tag", c.tag).Info("Node changed, reload") log.WithField("tag", c.tag).Info("Node changed, reload")
err = c.server.DelNode(c.tag) err = c.server.DelNode(c.tag)
if err != nil { if err != nil {
@ -85,11 +85,26 @@ func (c *Controller) nodeInfoMonitor() (err error) {
}).Error("Delete node failed") }).Error("Delete node failed")
return nil return nil
} }
// Remove Old limiter
limiter.DeleteLimiter(c.tag) // Update limiter
// Add new Limiter if len(c.Options.Name) == 0 {
c.tag = c.buildNodeTag(newN) c.tag = c.buildNodeTag(newN)
l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList) // 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 // check cert
if newN.Security == panel.Tls { if newN.Security == panel.Tls {
err = c.requestCert() err = c.requestCert()
@ -122,15 +137,6 @@ func (c *Controller) nodeInfoMonitor() (err error) {
}).Error("Add users failed") }).Error("Add users failed")
return nil 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 // Check interval
if c.nodeInfoMonitorPeriodic.Interval != newN.PullInterval && if c.nodeInfoMonitorPeriodic.Interval != newN.PullInterval &&
newN.PullInterval != 0 { newN.PullInterval != 0 {