1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
v2fly/proxy/trojan/validator.go
maskedeken e445d21f4b
Add trojan protocol support (#181)
* Add trojan protocol support

Co-authored-by: Eken Chan <ekenchan@msn.com>
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
2020-09-26 23:31:24 +08:00

29 lines
530 B
Go

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
}