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 {
Name string `json:"Name"`
Core string `json:"Core"`
ListenIP string `json:"ListenIP"`
SendIP string `json:"SendIP"`

View File

@ -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,

View File

@ -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)

View File

@ -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 {