v2ray-core/transport/internet/headers/utp/utp.go

40 lines
672 B
Go
Raw Normal View History

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