1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-09 19:56:44 -05:00
v2fly/proxy/trojan/validator.go

29 lines
530 B
Go
Raw Normal View History

package trojan
import (
"sync"
"v2ray.com/core/common/protocol"
)
// Validator stores valid trojan users
type Validator struct {
users sync.Map
}
// Add a trojan user
func (v *Validator) Add(u *protocol.MemoryUser) error {
user := u.Account.(*MemoryAccount)
v.users.Store(hexString(user.Key), u)
return nil
}
// Get user with hashed key, nil if user doesn't exist.
func (v *Validator) Get(hash string) *protocol.MemoryUser {
u, _ := v.users.Load(hash)
if u != nil {
return u.(*protocol.MemoryUser)
}
return nil
}