validator.go 530 B

12345678910111213141516171819202122232425262728
  1. package trojan
  2. import (
  3. "sync"
  4. "v2ray.com/core/common/protocol"
  5. )
  6. // Validator stores valid trojan users
  7. type Validator struct {
  8. users sync.Map
  9. }
  10. // Add a trojan user
  11. func (v *Validator) Add(u *protocol.MemoryUser) error {
  12. user := u.Account.(*MemoryAccount)
  13. v.users.Store(hexString(user.Key), u)
  14. return nil
  15. }
  16. // Get user with hashed key, nil if user doesn't exist.
  17. func (v *Validator) Get(hash string) *protocol.MemoryUser {
  18. u, _ := v.users.Load(hash)
  19. if u != nil {
  20. return u.(*protocol.MemoryUser)
  21. }
  22. return nil
  23. }