option.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package srtp
  2. import (
  3. "github.com/pion/transport/replaydetector"
  4. )
  5. // ContextOption represents option of Context using the functional options pattern.
  6. type ContextOption func(*Context) error
  7. // SRTPReplayProtection sets SRTP replay protection window size.
  8. func SRTPReplayProtection(windowSize uint) ContextOption { // nolint:revive
  9. return func(c *Context) error {
  10. c.newSRTPReplayDetector = func() replaydetector.ReplayDetector {
  11. return replaydetector.WithWrap(windowSize, maxSequenceNumber)
  12. }
  13. return nil
  14. }
  15. }
  16. // SRTCPReplayProtection sets SRTCP replay protection window size.
  17. func SRTCPReplayProtection(windowSize uint) ContextOption {
  18. return func(c *Context) error {
  19. c.newSRTCPReplayDetector = func() replaydetector.ReplayDetector {
  20. return replaydetector.WithWrap(windowSize, maxSRTCPIndex)
  21. }
  22. return nil
  23. }
  24. }
  25. // SRTPNoReplayProtection disables SRTP replay protection.
  26. func SRTPNoReplayProtection() ContextOption { // nolint:revive
  27. return func(c *Context) error {
  28. c.newSRTPReplayDetector = func() replaydetector.ReplayDetector {
  29. return &nopReplayDetector{}
  30. }
  31. return nil
  32. }
  33. }
  34. // SRTCPNoReplayProtection disables SRTCP replay protection.
  35. func SRTCPNoReplayProtection() ContextOption {
  36. return func(c *Context) error {
  37. c.newSRTCPReplayDetector = func() replaydetector.ReplayDetector {
  38. return &nopReplayDetector{}
  39. }
  40. return nil
  41. }
  42. }
  43. type nopReplayDetector struct{}
  44. func (s *nopReplayDetector) Check(uint64) (func(), bool) {
  45. return func() {}, true
  46. }