1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-05 01:38:24 -05:00
v2fly/common/protocol/user.go

58 lines
987 B
Go

package protocol
import (
"github.com/v2ray/v2ray-core/common/dice"
)
type UserLevel byte
const (
UserLevelAdmin = UserLevel(255)
UserLevelUntrusted = UserLevel(0)
)
type User struct {
ID *ID
AlterIDs []*ID
Level UserLevel
}
func NewUser(id *ID, level UserLevel, alterIdCount uint16) *User {
u := &User{
ID: id,
Level: level,
}
if alterIdCount > 0 {
u.AlterIDs = make([]*ID, alterIdCount)
prevId := id.UUID()
for idx, _ := range u.AlterIDs {
newid := prevId.Next()
// TODO: check duplicate
u.AlterIDs[idx] = NewID(newid)
prevId = newid
}
}
return u
}
func (this *User) AnyValidID() *ID {
if len(this.AlterIDs) == 0 {
return this.ID
}
return this.AlterIDs[dice.Roll(len(this.AlterIDs))]
}
type UserSettings struct {
PayloadReadTimeout int
}
func GetUserSettings(level UserLevel) UserSettings {
settings := UserSettings{
PayloadReadTimeout: 120,
}
if level > 0 {
settings.PayloadReadTimeout = 0
}
return settings
}