mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
尝试修复在线设备数上报后有概率被限制链接
This commit is contained in:
parent
173c48a76f
commit
8d7168c6a4
@ -24,7 +24,6 @@ type Client struct {
|
||||
nodeEtag string
|
||||
userEtag string
|
||||
responseBodyHash string
|
||||
LastReportOnline map[int]int
|
||||
UserList *UserListBody
|
||||
AliveMap *AliveMap
|
||||
}
|
||||
|
@ -101,8 +101,7 @@ func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) ReportNodeOnlineUsers(data *map[int][]string, reportOnline *map[int]int) error {
|
||||
c.LastReportOnline = *reportOnline
|
||||
func (c *Client) ReportNodeOnlineUsers(data *map[int][]string) error {
|
||||
const path = "/api/v1/server/UniProxy/alive"
|
||||
r, err := c.client.R().
|
||||
SetBody(data).
|
||||
|
@ -37,11 +37,12 @@ type Limiter struct {
|
||||
ProtocolRules []string
|
||||
SpeedLimit int
|
||||
UserOnlineIP *sync.Map // Key: Name, value: {Key: Ip, value: Uid}
|
||||
UUIDtoUID map[string]int // Key: UUID, value: UID
|
||||
OldUserOnline map[string]int // Key: Ip, value: Uid
|
||||
UUIDtoUID map[string]int // Key: UUID, value: Uid
|
||||
UserLimitInfo *sync.Map // Key: Uid value: UserLimitInfo
|
||||
ConnLimiter *ConnLimiter // Key: Uid value: ConnLimiter
|
||||
SpeedLimiter *sync.Map // key: Uid, value: *ratelimit.Bucket
|
||||
AliveList map[int]int // Key:Id, value:alive_ip
|
||||
AliveList map[int]int // Key: Uid, value: alive_ip
|
||||
}
|
||||
|
||||
type UserLimitInfo struct {
|
||||
@ -178,6 +179,8 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if l.OldUserOnline[ip] == uid {
|
||||
delete(l.OldUserOnline, ip)
|
||||
} else {
|
||||
if deviceLimit > 0 {
|
||||
if deviceLimit <= aliveIp {
|
||||
@ -204,17 +207,17 @@ func (l *Limiter) CheckLimit(taguuid string, ip string, isTcp bool, noSSUDP bool
|
||||
|
||||
func (l *Limiter) GetOnlineDevice() (*[]panel.OnlineUser, error) {
|
||||
var onlineUser []panel.OnlineUser
|
||||
|
||||
l.UserOnlineIP.Range(func(key, value interface{}) bool {
|
||||
email := key.(string)
|
||||
taguuid := key.(string)
|
||||
ipMap := value.(*sync.Map)
|
||||
ipMap.Range(func(key, value interface{}) bool {
|
||||
uid := value.(int)
|
||||
ip := key.(string)
|
||||
l.OldUserOnline[ip] = uid
|
||||
onlineUser = append(onlineUser, panel.OnlineUser{UID: uid, IP: ip})
|
||||
return true
|
||||
})
|
||||
l.UserOnlineIP.Delete(email) // Reset online device
|
||||
l.UserOnlineIP.Delete(taguuid) // Reset online device
|
||||
return true
|
||||
})
|
||||
|
||||
|
14
node/user.go
14
node/user.go
@ -14,11 +14,7 @@ func (c *Controller) reportUserTrafficTask() (err error) {
|
||||
up, down := c.server.GetUserTraffic(c.tag, c.userList[i].Uuid, true)
|
||||
if up > 0 || down > 0 {
|
||||
if c.LimitConfig.EnableDynamicSpeedLimit {
|
||||
if _, ok := c.traffic[c.userList[i].Uuid]; ok {
|
||||
c.traffic[c.userList[i].Uuid] += up + down
|
||||
} else {
|
||||
c.traffic[c.userList[i].Uuid] = up + down
|
||||
}
|
||||
c.traffic[c.userList[i].Uuid] += up + down
|
||||
}
|
||||
userTraffic = append(userTraffic, panel.UserTraffic{
|
||||
UID: (c.userList)[i].Id,
|
||||
@ -55,18 +51,12 @@ func (c *Controller) reportUserTrafficTask() (err error) {
|
||||
result = append(result, online)
|
||||
}
|
||||
}
|
||||
reportOnline := make(map[int]int)
|
||||
data := make(map[int][]string)
|
||||
for _, onlineuser := range result {
|
||||
// json structure: { UID1:["ip1","ip2"],UID2:["ip3","ip4"] }
|
||||
data[onlineuser.UID] = append(data[onlineuser.UID], onlineuser.IP)
|
||||
if _, ok := reportOnline[onlineuser.UID]; ok {
|
||||
reportOnline[onlineuser.UID]++
|
||||
} else {
|
||||
reportOnline[onlineuser.UID] = 1
|
||||
}
|
||||
}
|
||||
if err = c.apiClient.ReportNodeOnlineUsers(&data, &reportOnline); err != nil {
|
||||
if err = c.apiClient.ReportNodeOnlineUsers(&data); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"tag": c.tag,
|
||||
"err": err,
|
||||
|
Loading…
Reference in New Issue
Block a user