mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-22 17:46:48 +08:00
VLESS practice: Use user-sent VLESS UUID's 7th<<8 | 8th bytes as vlessRoute
instead
https://github.com/XTLS/Xray-core/pull/5009#issuecomment-3195718690
Replaces 105b306d07
This commit is contained in:
@@ -46,7 +46,7 @@ type Inbound struct {
|
|||||||
Name string
|
Name string
|
||||||
// User is the user that authenticates for the inbound. May be nil if the protocol allows anonymous traffic.
|
// User is the user that authenticates for the inbound. May be nil if the protocol allows anonymous traffic.
|
||||||
User *protocol.MemoryUser
|
User *protocol.MemoryUser
|
||||||
// VlessRoute is the user-sent VLESS UUID's last byte.
|
// VlessRoute is the user-sent VLESS UUID's 7th<<8 | 8th bytes.
|
||||||
VlessRoute net.Port
|
VlessRoute net.Port
|
||||||
// Used by splice copy. Conn is actually internet.Connection. May be nil.
|
// Used by splice copy. Conn is actually internet.Connection. May be nil.
|
||||||
Conn net.Conn
|
Conn net.Conn
|
||||||
|
@@ -41,7 +41,7 @@ type Context interface {
|
|||||||
// GetUser returns the user email from the connection content, if exists.
|
// GetUser returns the user email from the connection content, if exists.
|
||||||
GetUser() string
|
GetUser() string
|
||||||
|
|
||||||
// GetVlessRoute returns the user-sent VLESS UUID's last byte, if exists.
|
// GetVlessRoute returns the user-sent VLESS UUID's 7th<<8 | 8th bytes, if exists.
|
||||||
GetVlessRoute() net.Port
|
GetVlessRoute() net.Port
|
||||||
|
|
||||||
// GetAttributes returns extra attributes from the conneciont content.
|
// GetAttributes returns extra attributes from the conneciont content.
|
||||||
|
@@ -456,7 +456,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
|
|||||||
}
|
}
|
||||||
inbound.Name = "vless"
|
inbound.Name = "vless"
|
||||||
inbound.User = request.User
|
inbound.User = request.User
|
||||||
inbound.VlessRoute = net.Port(userSentID[15])
|
inbound.VlessRoute = net.PortFromBytes(userSentID[6:8])
|
||||||
|
|
||||||
account := request.User.Account.(*vless.MemoryAccount)
|
account := request.User.Account.(*vless.MemoryAccount)
|
||||||
|
|
||||||
|
@@ -18,6 +18,12 @@ type Validator interface {
|
|||||||
GetCount() int64
|
GetCount() int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ProcessUUID(id [16]byte) [16]byte {
|
||||||
|
id[6] = 0
|
||||||
|
id[7] = 0
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
// MemoryValidator stores valid VLESS users.
|
// MemoryValidator stores valid VLESS users.
|
||||||
type MemoryValidator struct {
|
type MemoryValidator 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.
|
||||||
@@ -33,7 +39,7 @@ func (v *MemoryValidator) Add(u *protocol.MemoryUser) error {
|
|||||||
return errors.New("User ", u.Email, " already exists.")
|
return errors.New("User ", u.Email, " already exists.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v.users.Store([15]byte(u.Account.(*MemoryAccount).ID.Bytes()), u)
|
v.users.Store(ProcessUUID(u.Account.(*MemoryAccount).ID.UUID()), u)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,13 +54,13 @@ func (v *MemoryValidator) Del(e string) error {
|
|||||||
return errors.New("User ", e, " not found.")
|
return errors.New("User ", e, " not found.")
|
||||||
}
|
}
|
||||||
v.email.Delete(le)
|
v.email.Delete(le)
|
||||||
v.users.Delete([15]byte(u.(*protocol.MemoryUser).Account.(*MemoryAccount).ID.Bytes()))
|
v.users.Delete(ProcessUUID(u.(*protocol.MemoryUser).Account.(*MemoryAccount).ID.UUID()))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a VLESS user with UUID, nil if user doesn't exist.
|
// Get a VLESS user with UUID, nil if user doesn't exist.
|
||||||
func (v *MemoryValidator) Get(id uuid.UUID) *protocol.MemoryUser {
|
func (v *MemoryValidator) Get(id uuid.UUID) *protocol.MemoryUser {
|
||||||
u, _ := v.users.Load([15]byte(id[:]))
|
u, _ := v.users.Load(ProcessUUID(id))
|
||||||
if u != nil {
|
if u != nil {
|
||||||
return u.(*protocol.MemoryUser)
|
return u.(*protocol.MemoryUser)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user