-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
51 lines (44 loc) · 2.08 KB
/
Copy pathconfig.go
File metadata and controls
51 lines (44 loc) · 2.08 KB
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
package netpipe
import "time"
const (
DefaultPort = 5000
DefaultProtocol = "tcp"
DefaultHost = "localhost"
)
// Config controls server or client behaviour.
// Every field has a sensible default - pass Config{} and it works out of the box.
type Config struct {
Host string // client only - defaults to "localhost"
Port int // defaults to 5000
Protocol string // defaults to "tcp" (also supports "udp")
EncryptionKey string // optional - server uses this to auto-decrypt incoming encrypted messages
// Stage 6 - Streaming
ChunkSize int // stream chunk size in bytes (default 64 KB)
MaxStreamsPerClient int // server only - 0 = unlimited. max concurrent incomplete streams per client
// Stage 7 - Robustness
MaxClients int // server only - 0 = unlimited
HeartbeatInterval time.Duration // server only - 0 = disabled. e.g. 10 * time.Second
HeartbeatTimeout time.Duration // server only - 0 = 2x interval. time to wait for pong before disconnect
IdleTimeout time.Duration // server only - 0 = disabled. disconnect clients with no data activity
ConnectTimeout time.Duration // server only - 0 = 30s default. max time a new client can sit before sending data
MaxConnsPerIP int // server only - 0 = unlimited. max simultaneous connections from one IP
DrainTimeout time.Duration // server only - 0 = 30s default. max wait time for Drain() to complete
AutoReconnect bool // client only - auto-reconnect on disconnect
MaxReconnectAttempts int // client only - 0 = infinite retries
ReconnectInterval time.Duration // client only - defaults to 2s (base for exponential backoff)
// Addons
EnableATC bool // enable the ATC visual dashboard addon. defaults to false
ATCPort int // ATC dashboard HTTP port. defaults to 5001
}
// applyDefaults fills any zero-value fields with defaults.
func (c *Config) applyDefaults() {
if c.Port == 0 {
c.Port = DefaultPort
}
if c.Protocol == "" {
c.Protocol = DefaultProtocol
}
if c.Host == "" {
c.Host = DefaultHost
}
}