1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-19 10:26:10 -04:00
v2fly/transport/internet/headers/utp/utp.go

40 lines
688 B
Go
Raw Normal View History

2016-12-08 10:27:41 -05:00
package utp
import (
"math/rand"
"v2ray.com/core/common/loader"
"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
}
func (v *UTP) Write(b []byte) int {
b = serial.Uint16ToBytes(v.connectionId, b[:0])
b = append(b, v.header, v.extension)
return 4
}
type UTPFactory struct{}
func (v UTPFactory) Create(rawSettings interface{}) internet.PacketHeader {
return &UTP{
header: 1,
extension: 0,
connectionId: uint16(rand.Intn(65536)),
}
}
func init() {
internet.RegisterPacketHeader(loader.GetType(new(Config)), UTPFactory{})
}