37 lines
601 B
Go
Raw Normal View History

2016-12-08 16:27:41 +01:00
package srtp
import (
2017-01-12 22:47:10 +01:00
"context"
2016-12-08 16:27:41 +01:00
2017-01-12 22:47:10 +01:00
"v2ray.com/core/common"
2017-02-14 22:29:44 +01:00
"v2ray.com/core/common/dice"
2016-12-08 16:27:41 +01:00
"v2ray.com/core/common/serial"
)
type SRTP struct {
header uint16
number uint16
}
func (v *SRTP) Size() int {
return 4
}
2016-12-09 12:08:25 +01:00
func (v *SRTP) Write(b []byte) (int, error) {
2016-12-08 16:27:41 +01:00
v.number++
2016-12-12 21:58:13 +01:00
serial.Uint16ToBytes(v.number, b[:0])
serial.Uint16ToBytes(v.number, b[:2])
2016-12-09 12:08:25 +01:00
return 4, nil
2016-12-08 16:27:41 +01:00
}
2017-01-12 22:47:10 +01:00
func NewSRTP(ctx context.Context, config interface{}) (interface{}, error) {
2016-12-08 16:27:41 +01:00
return &SRTP{
header: 0xB5E8,
2017-02-14 22:29:44 +01:00
number: dice.RandomUint16(),
2017-01-12 22:47:10 +01:00
}, nil
2016-12-08 16:27:41 +01:00
}
func init() {
2017-01-12 22:47:10 +01:00
common.Must(common.RegisterConfig((*Config)(nil), NewSRTP))
2016-12-08 16:27:41 +01:00
}