1
0

config.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package client
  2. import (
  3. "context"
  4. "net"
  5. "time"
  6. "github.com/SenseUnit/dtlspipe/ciphers"
  7. "github.com/SenseUnit/dtlspipe/util"
  8. )
  9. type Config struct {
  10. BindAddress string
  11. RemoteDialFunc func(ctx context.Context) (net.PacketConn, net.Addr, error)
  12. Timeout time.Duration
  13. IdleTimeout time.Duration
  14. BaseContext context.Context
  15. PSKCallback func([]byte) ([]byte, error)
  16. PSKIdentity string
  17. MTU int
  18. CipherSuites ciphers.CipherList
  19. EllipticCurves ciphers.CurveList
  20. StaleMode util.StaleMode
  21. TimeLimitFunc func() time.Duration
  22. AllowFunc func(net.Addr) bool
  23. EnableCID bool
  24. }
  25. func (cfg *Config) populateDefaults() *Config {
  26. newCfg := new(Config)
  27. *newCfg = *cfg
  28. cfg = newCfg
  29. if cfg.BaseContext == nil {
  30. cfg.BaseContext = context.Background()
  31. }
  32. if cfg.IdleTimeout == 0 {
  33. cfg.IdleTimeout = 90 * time.Second
  34. }
  35. if cfg.CipherSuites == nil {
  36. cfg.CipherSuites = ciphers.DefaultCipherList
  37. }
  38. if cfg.EllipticCurves == nil {
  39. cfg.EllipticCurves = ciphers.DefaultCurveList
  40. }
  41. if cfg.TimeLimitFunc == nil {
  42. cfg.TimeLimitFunc = util.FixedTimeLimitFunc(0)
  43. }
  44. if cfg.AllowFunc == nil {
  45. cfg.AllowFunc = util.AllowAllFunc
  46. }
  47. return cfg
  48. }