1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
v2fly/common/protocol/user.go
2016-09-18 00:41:21 +02:00

45 lines
916 B
Go

package protocol
import (
"errors"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
)
var (
ErrUserMissing = errors.New("User is not specified.")
ErrAccountMissing = errors.New("Account is not specified.")
ErrNonMessageType = errors.New("Not a protobuf message.")
)
func (this *User) GetTypedAccount(account AsAccount) (Account, error) {
anyAccount := this.GetAccount()
if anyAccount == nil {
return nil, ErrAccountMissing
}
protoAccount, ok := account.(proto.Message)
if !ok {
return nil, ErrNonMessageType
}
err := ptypes.UnmarshalAny(anyAccount, protoAccount)
if err != nil {
return nil, err
}
return account.AsAccount()
}
func (this *User) GetSettings() UserSettings {
settings := UserSettings{
PayloadReadTimeout: 120,
}
if this.Level > 0 {
settings.PayloadReadTimeout = 0
}
return settings
}
type UserSettings struct {
PayloadReadTimeout uint32
}