mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
Adjust VLESS & Trojan Validator
This commit is contained in:
parent
24f688cc20
commit
3e87b187c4
@ -1,3 +1,5 @@
|
|||||||
|
// +build !confonly
|
||||||
|
|
||||||
package trojan
|
package trojan
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -7,14 +9,14 @@ import (
|
|||||||
"v2ray.com/core/common/protocol"
|
"v2ray.com/core/common/protocol"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validator stores valid trojan users
|
// Validator stores valid trojan users.
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
// Considering email's usage here, map + sync.Mutex/RWMutex may have better performance.
|
// Considering email's usage here, map + sync.Mutex/RWMutex may have better performance.
|
||||||
email sync.Map
|
email sync.Map
|
||||||
users sync.Map
|
users sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a trojan user
|
// Add a trojan user, Email must be empty or unique.
|
||||||
func (v *Validator) Add(u *protocol.MemoryUser) error {
|
func (v *Validator) Add(u *protocol.MemoryUser) error {
|
||||||
if u.Email != "" {
|
if u.Email != "" {
|
||||||
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
||||||
@ -26,7 +28,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Del a trojan user
|
// Del a trojan user with a non-empty Email.
|
||||||
func (v *Validator) Del(e string) error {
|
func (v *Validator) Del(e string) error {
|
||||||
if e == "" {
|
if e == "" {
|
||||||
return newError("Email must not be empty.")
|
return newError("Email must not be empty.")
|
||||||
@ -41,7 +43,7 @@ func (v *Validator) Del(e string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user with hashed key, nil if user doesn't exist.
|
// Get a trojan user with hashed key, nil if user doesn't exist.
|
||||||
func (v *Validator) Get(hash string) *protocol.MemoryUser {
|
func (v *Validator) Get(hash string) *protocol.MemoryUser {
|
||||||
u, _ := v.users.Load(hash)
|
u, _ := v.users.Load(hash)
|
||||||
if u != nil {
|
if u != nil {
|
||||||
|
@ -10,12 +10,14 @@ import (
|
|||||||
"v2ray.com/core/common/uuid"
|
"v2ray.com/core/common/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Validator stores valid VLESS users.
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
// Considering email's usage here, map + sync.Mutex/RWMutex may have better performance.
|
// Considering email's usage here, map + sync.Mutex/RWMutex may have better performance.
|
||||||
email sync.Map
|
email sync.Map
|
||||||
users sync.Map
|
users sync.Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add a VLESS user, Email must be empty or unique.
|
||||||
func (v *Validator) Add(u *protocol.MemoryUser) error {
|
func (v *Validator) Add(u *protocol.MemoryUser) error {
|
||||||
if u.Email != "" {
|
if u.Email != "" {
|
||||||
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
_, loaded := v.email.LoadOrStore(strings.ToLower(u.Email), u)
|
||||||
@ -27,6 +29,7 @@ func (v *Validator) Add(u *protocol.MemoryUser) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Del a VLESS user with a non-empty Email.
|
||||||
func (v *Validator) Del(e string) error {
|
func (v *Validator) Del(e string) error {
|
||||||
if e == "" {
|
if e == "" {
|
||||||
return newError("Email must not be empty.")
|
return newError("Email must not be empty.")
|
||||||
@ -41,6 +44,7 @@ func (v *Validator) Del(e string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get a VLESS user with UUID, nil if user doesn't exist.
|
||||||
func (v *Validator) Get(id uuid.UUID) *protocol.MemoryUser {
|
func (v *Validator) Get(id uuid.UUID) *protocol.MemoryUser {
|
||||||
u, _ := v.users.Load(id)
|
u, _ := v.users.Load(id)
|
||||||
if u != nil {
|
if u != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user