srtp.go 589 B

123456789101112131415161718192021222324252627282930313233343536
  1. package srtp
  2. import (
  3. "context"
  4. "math/rand"
  5. "v2ray.com/core/common"
  6. "v2ray.com/core/common/serial"
  7. )
  8. type SRTP struct {
  9. header uint16
  10. number uint16
  11. }
  12. func (v *SRTP) Size() int {
  13. return 4
  14. }
  15. func (v *SRTP) Write(b []byte) (int, error) {
  16. v.number++
  17. serial.Uint16ToBytes(v.number, b[:0])
  18. serial.Uint16ToBytes(v.number, b[:2])
  19. return 4, nil
  20. }
  21. func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) {
  22. return &SRTP{
  23. header: 0xB5E8,
  24. number: uint16(rand.Intn(65536)),
  25. }, nil
  26. }
  27. func init() {
  28. common.Must(common.RegisterConfig((*Config)(nil), NewSRTP))
  29. }