forked from VolantMQ/volantmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
147 lines (125 loc) · 2.62 KB
/
options.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package connection
import (
"errors"
"time"
"github.com/VolantMQ/vlapi/mqttp"
"github.com/VolantMQ/vlapi/plugin/auth"
"github.com/VolantMQ/vlapi/plugin/persistence"
"github.com/VolantMQ/volantmq/systree"
"github.com/VolantMQ/volantmq/transport"
)
// OnAuthCb ...
type OnAuthCb func(string, *AuthParams) (mqttp.IFace, error)
// Option callback for connection option
type Option func(*impl) error
// SetOptions set connection options
func (s *impl) SetOptions(opts ...Option) error {
for _, opt := range opts {
if err := opt(s); err != nil {
return err
}
}
return nil
}
// OfflineQoS0 if true QoS0 messages will be persisted when session is offline and durable
func OfflineQoS0(val bool) Option {
return func(t *impl) error {
wrOfflineQoS0(val)(t.tx)
return nil
}
}
// KeepAlive keep alive period
func KeepAlive(val int) Option {
return func(t *impl) error {
vl := time.Duration(val+(val/2)) * time.Second
rdKeepAlive(vl)(t.rx)
return nil
}
}
func Metric(val systree.PacketsMetric) Option {
return func(t *impl) error {
t.metric = val
wrMetric(val)(t.tx)
rdMetric(val)(t.rx)
return nil
}
}
func MaxRxPacketSize(val uint32) Option {
return func(t *impl) error {
rdMaxPacketSize(val)(t.rx)
return nil
}
}
func MaxTxPacketSize(val uint32) Option {
return func(t *impl) error {
wrMaxPacketSize(val)(t.tx)
return nil
}
}
func TxQuota(val int32) Option {
return func(t *impl) error {
wrQuota(val)(t.tx)
return nil
}
}
func RxQuota(val int32) Option {
return func(t *impl) error {
t.rxQuota = val
return nil
}
}
func MaxTxTopicAlias(val uint16) Option {
return func(t *impl) error {
wrTopicAliasMax(val)(t.tx)
return nil
}
}
func MaxRxTopicAlias(val uint16) Option {
return func(t *impl) error {
t.maxRxTopicAlias = val
return nil
}
}
func RetainAvailable(val bool) Option {
return func(t *impl) error {
t.retainAvailable = val
return nil
}
}
func OnAuth(val OnAuthCb) Option {
return func(t *impl) error {
t.signalAuth = val
return nil
}
}
func NetConn(val transport.Conn) Option {
return func(t *impl) error {
if t.conn != nil {
return errors.New("already set")
}
t.conn = val
wrConn(val)(t.tx)
rdConn(val)(t.rx)
return nil
}
}
func AttachSession(val SessionCallbacks) Option {
return func(t *impl) error {
if t.SessionCallbacks != nil {
return errors.New("already set")
}
t.SessionCallbacks = val
return nil
}
}
func Persistence(val persistence.Packets) Option {
return func(t *impl) error {
return wrPersistence(val)(t.tx)
}
}
func Permissions(val vlauth.Permissions) Option {
return func(t *impl) error {
t.permissions = val
return nil
}
}