mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 10:01:30 +00:00
Fixed user flow in vless server
This commit is contained in:
parent
6da1460795
commit
1f5f8a7dde
|
@ -55,6 +55,8 @@ func NewVLESS(ctx context.Context, router adapter.Router, logger log.ContextLogg
|
||||||
return index
|
return index
|
||||||
}), common.Map(inbound.users, func(it option.VLESSUser) string {
|
}), common.Map(inbound.users, func(it option.VLESSUser) string {
|
||||||
return it.UUID
|
return it.UUID
|
||||||
|
}), common.Map(inbound.users, func(it option.VLESSUser) string {
|
||||||
|
return it.Flow
|
||||||
}))
|
}))
|
||||||
inbound.service = service
|
inbound.service = service
|
||||||
var err error
|
var err error
|
||||||
|
|
|
@ -10,6 +10,7 @@ type VLESSInboundOptions struct {
|
||||||
type VLESSUser struct {
|
type VLESSUser struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
UUID string `json:"uuid"`
|
UUID string `json:"uuid"`
|
||||||
|
Flow string `json:"flow,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type VLESSOutboundOptions struct {
|
type VLESSOutboundOptions struct {
|
||||||
|
|
|
@ -18,10 +18,11 @@ import (
|
||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Service[T any] struct {
|
type Service[T comparable] struct {
|
||||||
userMap map[[16]byte]T
|
userMap map[[16]byte]T
|
||||||
logger logger.Logger
|
userFlow map[T]string
|
||||||
handler Handler
|
logger logger.Logger
|
||||||
|
handler Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
|
@ -30,23 +31,26 @@ type Handler interface {
|
||||||
E.Handler
|
E.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService[T any](logger logger.Logger, handler Handler) *Service[T] {
|
func NewService[T comparable](logger logger.Logger, handler Handler) *Service[T] {
|
||||||
return &Service[T]{
|
return &Service[T]{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service[T]) UpdateUsers(userList []T, userUUIDList []string) {
|
func (s *Service[T]) UpdateUsers(userList []T, userUUIDList []string, userFlowList []string) {
|
||||||
userMap := make(map[[16]byte]T)
|
userMap := make(map[[16]byte]T)
|
||||||
|
userFlowMap := make(map[T]string)
|
||||||
for i, userName := range userList {
|
for i, userName := range userList {
|
||||||
userID := uuid.FromStringOrNil(userUUIDList[i])
|
userID := uuid.FromStringOrNil(userUUIDList[i])
|
||||||
if userID == uuid.Nil {
|
if userID == uuid.Nil {
|
||||||
userID = uuid.NewV5(uuid.Nil, userUUIDList[i])
|
userID = uuid.NewV5(uuid.Nil, userUUIDList[i])
|
||||||
}
|
}
|
||||||
userMap[userID] = userName
|
userMap[userID] = userName
|
||||||
|
userFlowMap[userName] = userFlowList[i]
|
||||||
}
|
}
|
||||||
s.userMap = userMap
|
s.userMap = userMap
|
||||||
|
s.userFlow = userFlowMap
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ N.TCPConnectionHandler = (*Service[int])(nil)
|
var _ N.TCPConnectionHandler = (*Service[int])(nil)
|
||||||
|
@ -63,8 +67,13 @@ func (s *Service[T]) NewConnection(ctx context.Context, conn net.Conn, metadata
|
||||||
ctx = auth.ContextWithUser(ctx, user)
|
ctx = auth.ContextWithUser(ctx, user)
|
||||||
metadata.Destination = request.Destination
|
metadata.Destination = request.Destination
|
||||||
|
|
||||||
|
userFlow := s.userFlow[user]
|
||||||
|
if request.Flow != userFlow {
|
||||||
|
return E.New("flow mismatch: expected ", userFlow, ", but got ", request.Flow)
|
||||||
|
}
|
||||||
|
|
||||||
protocolConn := conn
|
protocolConn := conn
|
||||||
switch request.Flow {
|
switch userFlow {
|
||||||
case "":
|
case "":
|
||||||
case FlowVision:
|
case FlowVision:
|
||||||
protocolConn, err = NewVisionConn(conn, request.UUID, s.logger)
|
protocolConn, err = NewVisionConn(conn, request.UUID, s.logger)
|
||||||
|
|
Loading…
Reference in a new issue