mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-07-29 21:34:15 +00:00
Change to TypedSyncMap
This commit is contained in:
parent
b6b51c51c8
commit
20825f6f1a
6 changed files with 29 additions and 31 deletions
|
@ -2,10 +2,10 @@ package vless
|
|||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/xtls/xray-core/common/errors"
|
||||
"github.com/xtls/xray-core/common/protocol"
|
||||
"github.com/xtls/xray-core/common/utils"
|
||||
"github.com/xtls/xray-core/common/uuid"
|
||||
)
|
||||
|
||||
|
@ -21,8 +21,8 @@ type Validator interface {
|
|||
// MemoryValidator stores valid VLESS users.
|
||||
type MemoryValidator struct {
|
||||
// Considering email's usage here, map + sync.Mutex/RWMutex may have better performance.
|
||||
email sync.Map
|
||||
users sync.Map
|
||||
email utils.TypedSyncMap[string, *protocol.MemoryUser]
|
||||
users utils.TypedSyncMap[uuid.UUID, *protocol.MemoryUser]
|
||||
}
|
||||
|
||||
// Add a VLESS user, Email must be empty or unique.
|
||||
|
@ -48,7 +48,7 @@ func (v *MemoryValidator) Del(e string) error {
|
|||
return errors.New("User ", e, " not found.")
|
||||
}
|
||||
v.email.Delete(le)
|
||||
v.users.Delete(u.(*protocol.MemoryUser).Account.(*MemoryAccount).ID.UUID())
|
||||
v.users.Delete(u.Account.(*MemoryAccount).ID.UUID())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ func (v *MemoryValidator) Del(e string) error {
|
|||
func (v *MemoryValidator) Get(id uuid.UUID) *protocol.MemoryUser {
|
||||
u, _ := v.users.Load(id)
|
||||
if u != nil {
|
||||
return u.(*protocol.MemoryUser)
|
||||
return u
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func (v *MemoryValidator) GetByEmail(email string) *protocol.MemoryUser {
|
|||
email = strings.ToLower(email)
|
||||
u, _ := v.email.Load(email)
|
||||
if u != nil {
|
||||
return u.(*protocol.MemoryUser)
|
||||
return u
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -74,8 +74,8 @@ func (v *MemoryValidator) GetByEmail(email string) *protocol.MemoryUser {
|
|||
// Get all users
|
||||
func (v *MemoryValidator) GetAll() []*protocol.MemoryUser {
|
||||
var u = make([]*protocol.MemoryUser, 0, 100)
|
||||
v.email.Range(func(key, value interface{}) bool {
|
||||
u = append(u, value.(*protocol.MemoryUser))
|
||||
v.email.Range(func(key string, value *protocol.MemoryUser) bool {
|
||||
u = append(u, value)
|
||||
return true
|
||||
})
|
||||
return u
|
||||
|
@ -84,7 +84,7 @@ func (v *MemoryValidator) GetAll() []*protocol.MemoryUser {
|
|||
// Get users count
|
||||
func (v *MemoryValidator) GetCount() int64 {
|
||||
var c int64 = 0
|
||||
v.email.Range(func(key, value interface{}) bool {
|
||||
v.email.Range(func(key string, value *protocol.MemoryUser) bool {
|
||||
c++
|
||||
return true
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue