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