mirror of
https://github.com/XrayR-project/XrayR.git
synced 2025-06-26 22:29:50 +00:00
feat: not reset traffic when report failed
This commit is contained in:
parent
8991284e19
commit
f0610d09fd
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/xtls/xray-core/core"
|
"github.com/xtls/xray-core/core"
|
||||||
"github.com/xtls/xray-core/features/inbound"
|
"github.com/xtls/xray-core/features/inbound"
|
||||||
"github.com/xtls/xray-core/features/outbound"
|
"github.com/xtls/xray-core/features/outbound"
|
||||||
|
"github.com/xtls/xray-core/features/stats"
|
||||||
"github.com/xtls/xray-core/proxy"
|
"github.com/xtls/xray-core/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,21 +103,31 @@ func (c *Controller) removeUsers(users []string, tag string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) getTraffic(email string) (up int64, down int64) {
|
func (c *Controller) getTraffic(email string) (up int64, down int64, upCounter stats.Counter, downCounter stats.Counter) {
|
||||||
upName := "user>>>" + email + ">>>traffic>>>uplink"
|
upName := "user>>>" + email + ">>>traffic>>>uplink"
|
||||||
downName := "user>>>" + email + ">>>traffic>>>downlink"
|
downName := "user>>>" + email + ">>>traffic>>>downlink"
|
||||||
upCounter := c.stm.GetCounter(upName)
|
upCounter = c.stm.GetCounter(upName)
|
||||||
downCounter := c.stm.GetCounter(downName)
|
downCounter = c.stm.GetCounter(downName)
|
||||||
if upCounter != nil {
|
if upCounter != nil && upCounter.Value() != 0 {
|
||||||
up = upCounter.Value()
|
up = upCounter.Value()
|
||||||
|
} else {
|
||||||
|
upCounter = nil
|
||||||
|
}
|
||||||
|
if downCounter != nil && upCounter.Value() != 0 {
|
||||||
|
down = downCounter.Value()
|
||||||
|
} else {
|
||||||
|
downCounter = nil
|
||||||
|
}
|
||||||
|
return up, down, upCounter, downCounter
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Controller) resetTraffic(upCounterList *[]stats.Counter, downCounterList *[]stats.Counter) {
|
||||||
|
for _, upCounter := range *upCounterList {
|
||||||
upCounter.Set(0)
|
upCounter.Set(0)
|
||||||
}
|
}
|
||||||
if downCounter != nil {
|
for _, downCounter := range *downCounterList {
|
||||||
down = downCounter.Value()
|
|
||||||
downCounter.Set(0)
|
downCounter.Set(0)
|
||||||
}
|
}
|
||||||
return up, down
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo) error {
|
func (c *Controller) AddInboundLimiter(tag string, nodeSpeedLimit uint64, userList *[]api.UserInfo) error {
|
||||||
|
@ -427,21 +427,36 @@ func (c *Controller) userInfoMonitor() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get User traffic
|
// Get User traffic
|
||||||
userTraffic := make([]api.UserTraffic, 0)
|
var userTraffic []api.UserTraffic
|
||||||
|
var upCounterList []stats.Counter
|
||||||
|
var downCounterList []stats.Counter
|
||||||
for _, user := range *c.userList {
|
for _, user := range *c.userList {
|
||||||
up, down := c.getTraffic(c.buildUserTag(&user))
|
up, down, upCounter, downCounter := c.getTraffic(c.buildUserTag(&user))
|
||||||
if up > 0 || down > 0 {
|
if up > 0 || down > 0 {
|
||||||
userTraffic = append(userTraffic, api.UserTraffic{
|
userTraffic = append(userTraffic, api.UserTraffic{
|
||||||
UID: user.UID,
|
UID: user.UID,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Upload: up,
|
Upload: up,
|
||||||
Download: down})
|
Download: down})
|
||||||
|
|
||||||
|
if upCounter != nil {
|
||||||
|
upCounterList = append(upCounterList, upCounter)
|
||||||
|
}
|
||||||
|
if downCounter != nil {
|
||||||
|
downCounterList = append(downCounterList, downCounter)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(userTraffic) > 0 && !c.config.DisableUploadTraffic {
|
if len(userTraffic) > 0 {
|
||||||
err = c.apiClient.ReportUserTraffic(&userTraffic)
|
var err error // Define an empty error
|
||||||
|
if !c.config.DisableUploadTraffic {
|
||||||
|
err = c.apiClient.ReportUserTraffic(&userTraffic)
|
||||||
|
}
|
||||||
|
// If report traffic error, not clear the traffic
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
} else {
|
||||||
|
c.resetTraffic(&upCounterList, &downCounterList)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user