mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
fix traffic counting
This commit is contained in:
@@ -12,15 +12,19 @@ type HookServer struct {
|
||||
}
|
||||
|
||||
func (h *HookServer) Log(id string, tx, rx uint64) (ok bool) {
|
||||
if c, ok := h.Counter.Load(h.Tag); ok {
|
||||
c.(*counter.TrafficCounter).Rx(id, int(rx))
|
||||
c.(*counter.TrafficCounter).Tx(id, int(rx))
|
||||
return true
|
||||
} else {
|
||||
c := counter.NewTrafficCounter()
|
||||
var c interface{}
|
||||
var exists bool
|
||||
|
||||
if c, exists = h.Counter.Load(h.Tag); !exists {
|
||||
c = counter.NewTrafficCounter()
|
||||
h.Counter.Store(h.Tag, c)
|
||||
c.Rx(id, int(rx))
|
||||
c.Tx(id, int(rx))
|
||||
}
|
||||
|
||||
if tc, ok := c.(*counter.TrafficCounter); ok {
|
||||
tc.Rx(id, int(rx))
|
||||
tc.Tx(id, int(tx))
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user