2016-02-03 05:58:42 -05:00
|
|
|
package protocol
|
2015-10-16 06:03:22 -04:00
|
|
|
|
2016-09-17 18:41:21 -04:00
|
|
|
import (
|
2016-12-04 03:10:47 -05:00
|
|
|
"v2ray.com/core/common/errors"
|
2015-10-30 19:38:31 -04:00
|
|
|
)
|
|
|
|
|
2016-09-17 18:41:21 -04:00
|
|
|
var (
|
2016-10-16 08:22:21 -04: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 18:41:21 -04:00
|
|
|
)
|
2016-01-15 06:43:06 -05:00
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *User) GetTypedAccount() (Account, error) {
|
|
|
|
if v.GetAccount() == nil {
|
2016-09-17 18:41:21 -04:00
|
|
|
return nil, ErrAccountMissing
|
2016-01-15 06:43:06 -05:00
|
|
|
}
|
2016-10-16 08:22:21 -04:00
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
rawAccount, err := v.Account.GetInstance()
|
2016-09-17 18:41:21 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-16 08:22:21 -04:00
|
|
|
if asAccount, ok := rawAccount.(AsAccount); ok {
|
|
|
|
return asAccount.AsAccount()
|
|
|
|
}
|
|
|
|
if account, ok := rawAccount.(Account); ok {
|
|
|
|
return account, nil
|
|
|
|
}
|
2016-12-04 03:10:47 -05:00
|
|
|
return nil, errors.New("Unknown account type: ", v.Account.Type)
|
2015-12-12 18:10:35 -05:00
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *User) GetSettings() UserSettings {
|
2015-10-31 09:08:13 -04:00
|
|
|
settings := UserSettings{
|
|
|
|
PayloadReadTimeout: 120,
|
|
|
|
}
|
2016-11-27 15:39:09 -05:00
|
|
|
if v.Level > 0 {
|
2015-10-31 09:08:13 -04:00
|
|
|
settings.PayloadReadTimeout = 0
|
|
|
|
}
|
|
|
|
return settings
|
2015-10-16 06:03:22 -04:00
|
|
|
}
|
2016-09-17 18:41:21 -04:00
|
|
|
|
|
|
|
type UserSettings struct {
|
|
|
|
PayloadReadTimeout uint32
|
|
|
|
}
|