1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/common/protocol/user.go

45 lines
978 B
Go
Raw Normal View History

package protocol
2015-10-16 06:03:22 -04:00
2017-04-08 19:43:25 -04:00
import "time"
2015-10-30 19:38:31 -04:00
2016-09-17 18:41:21 -04:00
var (
2017-04-08 19:43:25 -04:00
ErrAccountMissing = newError("Account is not specified.")
ErrNonMessageType = newError("Not a protobuf message.")
ErrUnknownAccountType = newError("Unknown account type.")
2016-09-17 18:41:21 -04: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-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
}
2017-04-08 19:43:25 -04:00
return nil, newError("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 {
2017-01-31 11:46:39 -05: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 09:08:13 -04:00
}
return settings
2015-10-16 06:03:22 -04:00
}
2016-09-17 18:41:21 -04:00
type UserSettings struct {
2017-01-31 11:46:39 -05:00
PayloadTimeout time.Duration
2016-09-17 18:41:21 -04:00
}