-
Notifications
You must be signed in to change notification settings - Fork 10
/
config.go
51 lines (47 loc) · 1.17 KB
/
config.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
package client
import (
"context"
"net"
"time"
"github.com/SenseUnit/dtlspipe/ciphers"
"github.com/SenseUnit/dtlspipe/util"
)
type Config struct {
BindAddress string
RemoteDialFunc func(ctx context.Context, network string) (net.Conn, error)
Timeout time.Duration
IdleTimeout time.Duration
BaseContext context.Context
PSKCallback func([]byte) ([]byte, error)
PSKIdentity string
MTU int
CipherSuites ciphers.CipherList
EllipticCurves ciphers.CurveList
StaleMode util.StaleMode
TimeLimitFunc func() time.Duration
AllowFunc func(localAddr, remoteAddr net.Addr) bool
}
func (cfg *Config) populateDefaults() *Config {
newCfg := new(Config)
*newCfg = *cfg
cfg = newCfg
if cfg.BaseContext == nil {
cfg.BaseContext = context.Background()
}
if cfg.IdleTimeout == 0 {
cfg.IdleTimeout = 90 * time.Second
}
if cfg.CipherSuites == nil {
cfg.CipherSuites = ciphers.DefaultCipherList
}
if cfg.EllipticCurves == nil {
cfg.EllipticCurves = ciphers.DefaultCurveList
}
if cfg.TimeLimitFunc == nil {
cfg.TimeLimitFunc = util.FixedTimeLimitFunc(0)
}
if cfg.AllowFunc == nil {
cfg.AllowFunc = util.AllowAllFunc
}
return cfg
}