mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
530 B
29 lines
530 B
4 years ago
|
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
|
||
|
}
|