config.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package server
  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. RemoteAddress string
  12. Timeout time.Duration
  13. IdleTimeout time.Duration
  14. BaseContext context.Context
  15. PSKCallback func([]byte) ([]byte, error)
  16. MTU int
  17. SkipHelloVerify bool
  18. CipherSuites ciphers.CipherList
  19. EllipticCurves ciphers.CurveList
  20. StaleMode util.StaleMode
  21. TimeLimitFunc func() time.Duration
  22. AllowFunc func(net.Addr) bool
  23. }
  24. func (cfg *Config) populateDefaults() *Config {
  25. newCfg := new(Config)
  26. *newCfg = *cfg
  27. cfg = newCfg
  28. if cfg.BaseContext == nil {
  29. cfg.BaseContext = context.Background()
  30. }
  31. if cfg.IdleTimeout == 0 {
  32. cfg.IdleTimeout = 90 * time.Second
  33. }
  34. if cfg.CipherSuites == nil {
  35. cfg.CipherSuites = ciphers.DefaultCipherList
  36. }
  37. if cfg.EllipticCurves == nil {
  38. cfg.EllipticCurves = ciphers.DefaultCurveList
  39. }
  40. if cfg.TimeLimitFunc == nil {
  41. cfg.TimeLimitFunc = util.FixedTimeLimitFunc(0)
  42. }
  43. if cfg.AllowFunc == nil {
  44. cfg.AllowFunc = util.AllowAllFunc
  45. }
  46. return cfg
  47. }