-
Notifications
You must be signed in to change notification settings - Fork 0
/
srtp.go
51 lines (41 loc) · 925 Bytes
/
srtp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package srtp
import (
"math/rand"
"github.com/v2ray/v2ray-core/common/alloc"
"github.com/v2ray/v2ray-core/transport/internet"
)
type Config struct {
Version byte
Padding bool
Extension bool
CSRCCount byte
Marker bool
PayloadType byte
}
type SRTP struct {
header uint16
number uint16
}
func (this *SRTP) Overhead() int {
return 4
}
func (this *SRTP) Open(payload *alloc.Buffer) bool {
payload.SliceFrom(this.Overhead())
return true
}
func (this *SRTP) Seal(payload *alloc.Buffer) {
this.number++
payload.PrependUint16(this.number)
payload.PrependUint16(this.header)
}
type SRTPFactory struct {
}
func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
return &SRTP{
header: 0xB5E8,
number: uint16(rand.Intn(65536)),
}
}
func init() {
internet.RegisterAuthenticator("srtp", SRTPFactory{}, func() interface{} { return new(Config) })
}