-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
59 lines (46 loc) · 1.32 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
package gimlet
import (
"github.com/Cyberax/gimlet/log"
"github.com/xtaci/smux"
"time"
)
// The safe packets-per-second amount
const safePps = 900
const resendTimeout = 1500 * time.Millisecond
type ConnInfo struct {
InstanceId string
Region string
Endpoint string
SessionId string
Token string
}
type ChannelOptions struct {
Log *log.GimletLogger
SmuxConfig *smux.Config
OnConnectionFailedFlagReceived func()
MaxPacketsPerSecond uint64
ResendTimeout time.Duration
}
func DefaultChannelOptions() ChannelOptions {
config := smux.DefaultConfig()
return ChannelOptions{
Log: log.NoLogging(),
SmuxConfig: config,
OnConnectionFailedFlagReceived: func() {},
MaxPacketsPerSecond: safePps,
ResendTimeout: resendTimeout,
}
}
// DebugChannelOptions creates channel options with enabled MGS protocol message logging. The
// default logging implementation uses the standard `log` package. Set `logPayloadData` to
// dump the data packets' payload and not just meta-information.
func DebugChannelOptions(logPayloadData bool) ChannelOptions {
config := smux.DefaultConfig()
return ChannelOptions{
Log: log.EnableAllLogs(logPayloadData),
SmuxConfig: config,
OnConnectionFailedFlagReceived: func() {},
MaxPacketsPerSecond: safePps,
ResendTimeout: resendTimeout,
}
}