srtp.go 794 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package srtp
  2. import (
  3. "math/rand"
  4. "v2ray.com/core/common/alloc"
  5. "v2ray.com/core/transport/internet"
  6. )
  7. type SRTP struct {
  8. header uint16
  9. number uint16
  10. }
  11. func (this *SRTP) Overhead() int {
  12. return 4
  13. }
  14. func (this *SRTP) Open(payload *alloc.Buffer) bool {
  15. payload.SliceFrom(this.Overhead())
  16. return true
  17. }
  18. func (this *SRTP) Seal(payload *alloc.Buffer) {
  19. this.number++
  20. payload.PrependUint16(this.number)
  21. payload.PrependUint16(this.header)
  22. }
  23. type SRTPFactory struct {
  24. }
  25. func (this SRTPFactory) Create(rawSettings interface{}) internet.Authenticator {
  26. return &SRTP{
  27. header: 0xB5E8,
  28. number: uint16(rand.Intn(65536)),
  29. }
  30. }
  31. func init() {
  32. internet.RegisterAuthenticator("srtp", SRTPFactory{})
  33. internet.RegisterAuthenticatorConfig("srtp", func() interface{} { return &Config{} })
  34. }