github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/proxy/trojan/validator.go (about)

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