config.go 891 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package client
  2. import (
  3. "context"
  4. "time"
  5. "github.com/Snawoot/dtlspipe/ciphers"
  6. "github.com/Snawoot/dtlspipe/util"
  7. )
  8. type Config struct {
  9. BindAddress string
  10. RemoteAddress string
  11. Timeout time.Duration
  12. IdleTimeout time.Duration
  13. BaseContext context.Context
  14. PSKCallback func([]byte) ([]byte, error)
  15. PSKIdentity string
  16. MTU int
  17. CipherSuites ciphers.CipherList
  18. EllipticCurves ciphers.CurveList
  19. StaleMode util.StaleMode
  20. }
  21. func (cfg *Config) populateDefaults() *Config {
  22. newCfg := new(Config)
  23. *newCfg = *cfg
  24. cfg = newCfg
  25. if cfg.BaseContext == nil {
  26. cfg.BaseContext = context.Background()
  27. }
  28. if cfg.IdleTimeout == 0 {
  29. cfg.IdleTimeout = 90 * time.Second
  30. }
  31. if cfg.CipherSuites == nil {
  32. cfg.CipherSuites = ciphers.DefaultCipherList
  33. }
  34. if cfg.EllipticCurves == nil {
  35. cfg.EllipticCurves = ciphers.DefaultCurveList
  36. }
  37. return cfg
  38. }