2016-12-08 15:27:41 +00:00
|
|
|
package srtp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/rand"
|
|
|
|
|
|
|
|
"v2ray.com/core/common/serial"
|
|
|
|
"v2ray.com/core/transport/internet"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SRTP struct {
|
|
|
|
header uint16
|
|
|
|
number uint16
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *SRTP) Size() int {
|
|
|
|
return 4
|
|
|
|
}
|
|
|
|
|
2016-12-09 11:08:25 +00:00
|
|
|
func (v *SRTP) Write(b []byte) (int, error) {
|
2016-12-08 15:27:41 +00:00
|
|
|
v.number++
|
2016-12-12 20:58:13 +00:00
|
|
|
serial.Uint16ToBytes(v.number, b[:0])
|
|
|
|
serial.Uint16ToBytes(v.number, b[:2])
|
2016-12-09 11:08:25 +00:00
|
|
|
return 4, nil
|
2016-12-08 15:27:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type SRTPFactory struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v SRTPFactory) Create(rawSettings interface{}) internet.PacketHeader {
|
|
|
|
return &SRTP{
|
|
|
|
header: 0xB5E8,
|
|
|
|
number: uint16(rand.Intn(65536)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-12-15 10:51:09 +00:00
|
|
|
internet.RegisterPacketHeader(serial.GetMessageType(new(Config)), SRTPFactory{})
|
2016-12-08 15:27:41 +00:00
|
|
|
}
|