2024-02-05 20:59:37 -05:00
|
|
|
package hy2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/InazumaV/V2bX/common/counter"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HookServer struct {
|
|
|
|
Tag string
|
|
|
|
Counter sync.Map
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *HookServer) Log(id string, tx, rx uint64) (ok bool) {
|
2024-02-16 07:46:23 -05:00
|
|
|
var c interface{}
|
|
|
|
var exists bool
|
|
|
|
|
|
|
|
if c, exists = h.Counter.Load(h.Tag); !exists {
|
|
|
|
c = counter.NewTrafficCounter()
|
2024-02-05 20:59:37 -05:00
|
|
|
h.Counter.Store(h.Tag, c)
|
2024-02-16 07:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if tc, ok := c.(*counter.TrafficCounter); ok {
|
|
|
|
tc.Rx(id, int(rx))
|
|
|
|
tc.Tx(id, int(tx))
|
2024-02-05 20:59:37 -05:00
|
|
|
return true
|
|
|
|
}
|
2024-02-16 07:46:23 -05:00
|
|
|
|
|
|
|
return false
|
2024-02-05 20:59:37 -05:00
|
|
|
}
|