-
Notifications
You must be signed in to change notification settings - Fork 25
/
conf.go
60 lines (53 loc) · 1.27 KB
/
conf.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
package migateway
import (
"time"
)
var (
DefaultConf = &Configure{
WhoisTimeOut: 3,
WhoisRetry: 5,
DevListTimeOut: 3,
DevListRetry: 5,
ReadTimeout: 3,
ReadRetry: 1,
ReportForwardTimeout: 1,
ReportAllMessages: false,
AESKey: "",
}
)
type Configure struct {
WhoisTimeOut int
WhoisRetry int
DevListTimeOut int
DevListRetry int
ReadTimeout int
ReadRetry int
ReportForwardTimeout int
ReportAllMessages bool
AESKey string
}
func NewConfig() *Configure {
return &Configure{
WhoisTimeOut: 3,
WhoisRetry: 5,
DevListTimeOut: 3,
DevListRetry: 5,
ReadTimeout: 3,
ReadRetry: 1,
ReportForwardTimeout: 1,
ReportAllMessages: false,
AESKey: "",
}
}
func (c *Configure) getRetryAndTimeout(req *Request) (int, time.Duration) {
if req.Cmd == CMD_WHOIS {
return c.WhoisRetry, time.Duration(c.WhoisTimeOut) * time.Second
} else if req.Cmd == CMD_DEVLIST {
return c.DevListRetry, time.Duration(c.DevListTimeOut) * time.Second
} else {
return c.ReadRetry, time.Duration(c.ReadTimeout) * time.Second
}
}
func (c *Configure) SetAESKey(key string) {
c.AESKey = key
}