mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-22 09:58:14 -05:00
2f1362067b
Some checks failed
Build and Release / build (386, freebsd) (push) Has been cancelled
Build and Release / build (386, linux) (push) Has been cancelled
Build and Release / build (386, windows) (push) Has been cancelled
Build and Release / build (amd64, darwin) (push) Has been cancelled
Build and Release / build (amd64, freebsd) (push) Has been cancelled
Build and Release / build (amd64, linux) (push) Has been cancelled
Build and Release / build (amd64, windows) (push) Has been cancelled
Build and Release / build (arm, 5, linux) (push) Has been cancelled
Build and Release / build (arm, 6, linux) (push) Has been cancelled
Build and Release / build (arm, 7, freebsd) (push) Has been cancelled
Build and Release / build (arm, 7, linux) (push) Has been cancelled
Build and Release / build (arm64, android) (push) Has been cancelled
Build and Release / build (arm64, darwin) (push) Has been cancelled
Build and Release / build (arm64, freebsd) (push) Has been cancelled
Build and Release / build (arm64, linux) (push) Has been cancelled
Build and Release / build (mips, linux) (push) Has been cancelled
Build and Release / build (mips64, linux) (push) Has been cancelled
Build and Release / build (mips64le, linux) (push) Has been cancelled
Build and Release / build (mipsle, linux) (push) Has been cancelled
Build and Release / build (ppc64, linux) (push) Has been cancelled
Build and Release / build (ppc64le, linux) (push) Has been cancelled
Build and Release / build (riscv64, linux) (push) Has been cancelled
Build and Release / build (s390x, linux) (push) Has been cancelled
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package hy2
|
|
|
|
import (
|
|
"net"
|
|
"sync"
|
|
|
|
"github.com/InazumaV/V2bX/api/panel"
|
|
"github.com/InazumaV/V2bX/common/counter"
|
|
vCore "github.com/InazumaV/V2bX/core"
|
|
"github.com/apernet/hysteria/core/v2/server"
|
|
)
|
|
|
|
var _ server.Authenticator = &V2bX{}
|
|
|
|
type V2bX struct {
|
|
usersMap map[string]int
|
|
mutex sync.Mutex
|
|
}
|
|
|
|
func (v *V2bX) Authenticate(addr net.Addr, auth string, tx uint64) (ok bool, id string) {
|
|
v.mutex.Lock()
|
|
defer v.mutex.Unlock()
|
|
if _, exists := v.usersMap[auth]; exists {
|
|
return true, auth
|
|
}
|
|
return false, ""
|
|
}
|
|
|
|
func (h *Hysteria2) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
|
var wg sync.WaitGroup
|
|
for _, user := range p.Users {
|
|
wg.Add(1)
|
|
go func(u panel.UserInfo) {
|
|
defer wg.Done()
|
|
h.Auth.mutex.Lock()
|
|
h.Auth.usersMap[u.Uuid] = u.Id
|
|
h.Auth.mutex.Unlock()
|
|
}(user)
|
|
}
|
|
wg.Wait()
|
|
return len(p.Users), nil
|
|
}
|
|
|
|
func (h *Hysteria2) DelUsers(users []panel.UserInfo, tag string, _ *panel.NodeInfo) error {
|
|
var wg sync.WaitGroup
|
|
for _, user := range users {
|
|
wg.Add(1)
|
|
go func(u panel.UserInfo) {
|
|
defer wg.Done()
|
|
h.Auth.mutex.Lock()
|
|
delete(h.Auth.usersMap, u.Uuid)
|
|
h.Auth.mutex.Unlock()
|
|
}(user)
|
|
}
|
|
wg.Wait()
|
|
return nil
|
|
}
|
|
|
|
func (h *Hysteria2) GetUserTraffic(tag string, uuid string, reset bool) (up int64, down int64) {
|
|
if v, ok := h.Hy2nodes[tag].TrafficLogger.(*HookServer).Counter.Load(tag); ok {
|
|
c := v.(*counter.TrafficCounter)
|
|
up = c.GetUpCount(uuid)
|
|
down = c.GetDownCount(uuid)
|
|
if reset {
|
|
c.Reset(uuid)
|
|
}
|
|
return up, down
|
|
}
|
|
return 0, 0
|
|
}
|