1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/protocol/user.go

45 lines
916 B
Go
Raw Normal View History

package protocol
2015-10-16 06:03:22 -04:00
2016-09-17 18:41:21 -04:00
import (
"errors"
2015-10-30 19:38:31 -04:00
2016-09-17 18:41:21 -04:00
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
2015-10-30 19:38:31 -04:00
)
2016-09-17 18:41:21 -04:00
var (
ErrUserMissing = errors.New("User is not specified.")
ErrAccountMissing = errors.New("Account is not specified.")
ErrNonMessageType = errors.New("Not a protobuf message.")
)
2016-09-17 18:41:21 -04:00
func (this *User) GetTypedAccount(account AsAccount) (Account, error) {
anyAccount := this.GetAccount()
if anyAccount == nil {
return nil, ErrAccountMissing
}
2016-09-17 18:41:21 -04:00
protoAccount, ok := account.(proto.Message)
if !ok {
return nil, ErrNonMessageType
}
err := ptypes.UnmarshalAny(anyAccount, protoAccount)
if err != nil {
return nil, err
}
return account.AsAccount()
2015-12-12 18:10:35 -05:00
}
2016-09-17 18:41:21 -04:00
func (this *User) GetSettings() UserSettings {
2015-10-31 09:08:13 -04:00
settings := UserSettings{
PayloadReadTimeout: 120,
}
2016-09-17 18:41:21 -04:00
if this.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
}