1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 02:16:11 -04:00
v2fly/transport/internet/authenticators/srtp/srtp.go

52 lines
925 B
Go
Raw Normal View History

2016-08-06 16:52:02 -04:00
package srtp
2016-08-06 15:59:22 -04:00
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
}
2016-08-07 09:05:05 -04:00
type SRTP struct {
2016-08-06 15:59:22 -04:00
header uint16
number uint16
}
2016-08-07 09:05:05 -04:00
func (this *SRTP) Overhead() int {
2016-08-06 15:59:22 -04:00
return 4
}
2016-08-07 09:05:05 -04:00
func (this *SRTP) Open(payload *alloc.Buffer) bool {
2016-08-06 15:59:22 -04:00
payload.SliceFrom(this.Overhead())
return true
}
2016-08-07 09:05:05 -04:00
func (this *SRTP) Seal(payload *alloc.Buffer) {
2016-08-06 15:59:22 -04:00
this.number++
payload.PrependUint16(this.number)
payload.PrependUint16(this.header)
}
2016-08-07 09:05:05 -04:00
type SRTPFactory struct {
2016-08-06 15:59:22 -04:00
}
2016-08-07 09:05:05 -04:00
func (this SRTPFactory) Create(rawSettings internet.AuthenticatorConfig) internet.Authenticator {
return &SRTP{
2016-08-06 15:59:22 -04:00
header: 0xB5E8,
number: uint16(rand.Intn(65536)),
}
}
func init() {
2016-08-07 09:05:05 -04:00
internet.RegisterAuthenticator("srtp", SRTPFactory{}, func() interface{} { return new(Config) })
2016-08-06 15:59:22 -04:00
}