Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/panel/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (c *Client) ReportNodeOnlineUsers(data *map[int][]string) error {
err = c.checkResponse(r, path, err)

if err != nil {
return nil
return err
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions limiter/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Init() {
}

type Limiter struct {
Nodetype string
DomainRules []*regexp.Regexp
ProtocolRules []string
SpeedLimit int
Expand All @@ -41,8 +42,9 @@ type UserLimitInfo struct {
OverLimit bool
}

func AddLimiter(tag string, l *conf.LimitConfig, users []panel.UserInfo, aliveList map[int]int) *Limiter {
func AddLimiter(nodetype string, tag string, l *conf.LimitConfig, users []panel.UserInfo, aliveList map[int]int) *Limiter {
info := &Limiter{
Nodetype: nodetype,
SpeedLimit: l.SpeedLimit,
UserOnlineIP: new(sync.Map),
UserLimitInfo: new(sync.Map),
Expand Down Expand Up @@ -150,7 +152,7 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
} else {
return nil, true
}
if noSSUDP {
if noSSUDP || l.Nodetype == "hysteria2" || l.Nodetype == "tuic" {
// Store online user for device limit
newipMap := new(sync.Map)
newipMap.Store(ip, uid)
Expand Down
2 changes: 1 addition & 1 deletion node/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Controller) Start() error {
}

// add limiter
l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList, c.aliveMap)
l := limiter.AddLimiter(node.Type, c.tag, &c.LimitConfig, c.userList, c.aliveMap)
// add rule limiter
if err = l.UpdateRule(&node.Rules); err != nil {
return fmt.Errorf("update rule error: %s", err)
Expand Down
5 changes: 4 additions & 1 deletion node/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ func (c *Controller) nodeInfoMonitor() (err error) {
// Remove Old limiter
limiter.DeleteLimiter(oldTag)
// Add new Limiter
l := limiter.AddLimiter(c.tag, &c.LimitConfig, c.userList, newA)
l := limiter.AddLimiter(newN.Type, c.tag, &c.LimitConfig, c.userList, newA)
c.limiter = l
}
if c.limiter != nil {
c.limiter.Nodetype = newN.Type
}
// update alive list
if newA != nil {
c.limiter.AliveList = newA
Expand Down
18 changes: 11 additions & 7 deletions node/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ func (c *Controller) reportUserTrafficTask() (err error) {
// json structure: { UID1:["ip1","ip2"],UID2:["ip3","ip4"] }
data[onlineuser.UID] = append(data[onlineuser.UID], onlineuser.IP)
}
if err = c.apiClient.ReportNodeOnlineUsers(&data); err != nil {
log.WithFields(log.Fields{
"tag": c.tag,
"err": err,
}).Info("Report online users failed")
if len(data) != 0 {
if err = c.apiClient.ReportNodeOnlineUsers(&data); err != nil {
log.WithFields(log.Fields{
"tag": c.tag,
"err": err,
}).Info("Report online users failed")
} else {
log.WithField("tag", c.tag).Infof("Total %d online users, %d Reported", len(*onlineDevice), len(result))
log.WithField("tag", c.tag).Debugf("Online users: %+v", data)
}
} else {
log.WithField("tag", c.tag).Infof("Total %d online users, %d Reported", len(*onlineDevice), len(result))
log.WithField("tag", c.tag).Debugf("Online users: %+v", data)
log.WithField("tag", c.tag).Debugf("Total %d online users, 0 Reported after DeviceOnlineMinTraffic filter", len(*onlineDevice))
}
}

Expand Down
Loading