v2ray-core/common/protocol/user.go

45 lines
973 B
Go
Raw Normal View History

package protocol
2015-10-16 10:03:22 +00:00
2016-09-17 22:41:21 +00:00
import (
"errors"
2015-10-30 23:38:31 +00:00
)
2016-09-17 22:41:21 +00:00
var (
2016-10-16 12:22:21 +00:00
ErrUserMissing = errors.New("User is not specified.")
ErrAccountMissing = errors.New("Account is not specified.")
ErrNonMessageType = errors.New("Not a protobuf message.")
ErrUnknownAccountType = errors.New("Unknown account type.")
2016-09-17 22:41:21 +00:00
)
2016-10-16 12:22:21 +00:00
func (this *User) GetTypedAccount() (Account, error) {
if this.GetAccount() == nil {
2016-09-17 22:41:21 +00:00
return nil, ErrAccountMissing
}
2016-10-16 12:22:21 +00:00
rawAccount, err := this.Account.GetInstance()
2016-09-17 22:41:21 +00:00
if err != nil {
return nil, err
}
2016-10-16 12:22:21 +00:00
if asAccount, ok := rawAccount.(AsAccount); ok {
return asAccount.AsAccount()
}
if account, ok := rawAccount.(Account); ok {
return account, nil
}
return nil, errors.New("Unknown account type: " + this.Account.Type)
2015-12-12 23:10:35 +00:00
}
2016-09-17 22:41:21 +00:00
func (this *User) GetSettings() UserSettings {
2015-10-31 13:08:13 +00:00
settings := UserSettings{
PayloadReadTimeout: 120,
}
2016-09-17 22:41:21 +00:00
if this.Level > 0 {
2015-10-31 13:08:13 +00:00
settings.PayloadReadTimeout = 0
}
return settings
2015-10-16 10:03:22 +00:00
}
2016-09-17 22:41:21 +00:00
type UserSettings struct {
PayloadReadTimeout uint32
}