-
Notifications
You must be signed in to change notification settings - Fork 61
/
conf.go
93 lines (81 loc) · 2.98 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
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
package qrpc
import (
"net"
"time"
"crypto/tls"
"github.com/go-kit/kit/metrics"
)
// CompressorCodec for compress
// **Important**: should try to do it in place if possible
type CompressorCodec interface {
Encode([]byte) ([]byte, error)
Decode([]byte) ([]byte, error)
}
// ServerLifecycleCallbacks for handling net.Con outside of handler
type ServerLifecycleCallbacks struct {
// connection will be rejected if OnAccept returns non nil error
OnAccept func(net.Conn) error
// called after connection is closed
OnClose func(net.Conn)
}
// ServerSubFunc for server subscribe callback
type ServerSubFunc func(*ConnectionInfo, *Frame)
// ServerBinding contains binding infos
type ServerBinding struct {
Addr string
Handler Handler // handler to invoke
DefaultReadTimeout int
DefaultWriteTimeout int
WBufSize int // best effort only, check log for error
RBufSize int // best effort only, check log for error
ReadFrameChSize int
WriteFrameChSize int
MaxFrameSize int
MaxCloseRate int // per second
MaxInboundFramePerSecond int
MaxInboundInflightStreamPerConn int32 // connection will be closed when exceeded
ListenFunc func(network, address string) (net.Listener, error)
Codec CompressorCodec
OverlayNetwork func(net.Listener, *tls.Config) Listener
SubFunc ServerSubFunc
OnKickCB func(w FrameWriter)
LatencyMetric metrics.Histogram
CounterMetric metrics.Counter
TLSConf *tls.Config
LifecycleCallbacks ServerLifecycleCallbacks
ln Listener
}
// SubFunc for client subscribe callback
type SubFunc func(*Connection, *Frame)
// ClientLifecycleCallbacks for Connection
type ClientLifecycleCallbacks struct {
OnConnect func(*Connection)
OnDisconnect func(*Connection)
}
// ConnectionConfig is conf for Connection
type ConnectionConfig struct {
WriteTimeout int
ReadTimeout int
DialTimeout time.Duration
WriteFrameChSize int
WBufSize int // best effort only, check log for error
RBufSize int // best effort only, check log for error
Handler Handler
OverlayNetwork func(address string, dialConfig DialConfig) (net.Conn, error)
Codec CompressorCodec
TLSConf *tls.Config
LifecycleCallbacks ClientLifecycleCallbacks
}
// DialConfig for dial
type DialConfig struct {
DialTimeout time.Duration
WBufSize int // best effort only, check log for error
RBufSize int // best effort only, check log for error
TLSConf *tls.Config
}
// KeepAliveListenerConfig is config for KeepAliveListener
type KeepAliveListenerConfig struct {
KeepAliveDuration time.Duration
WriteBufferSize int
ReadBufferSize int
}