fix traffic counting

This commit is contained in:
wyx2685
2024-02-16 21:46:23 +09:00
parent 73f9b19222
commit 423ac622b5
5 changed files with 51 additions and 29 deletions

View File

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