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