forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
44 lines (38 loc) · 916 Bytes
/
user.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
}