github.com/EagleQL/Xray-core@v1.4.3/transport/internet/headers/utp/utp.go (about) 1 package utp 2 3 import ( 4 "context" 5 "encoding/binary" 6 7 "github.com/xtls/xray-core/common" 8 "github.com/xtls/xray-core/common/dice" 9 ) 10 11 type UTP struct { 12 header byte 13 extension byte 14 connectionID uint16 15 } 16 17 func (*UTP) Size() int32 { 18 return 4 19 } 20 21 // Serialize implements PacketHeader. 22 func (u *UTP) Serialize(b []byte) { 23 binary.BigEndian.PutUint16(b, u.connectionID) 24 b[2] = u.header 25 b[3] = u.extension 26 } 27 28 // New creates a new UTP header for the given config. 29 func New(ctx context.Context, config interface{}) (interface{}, error) { 30 return &UTP{ 31 header: 1, 32 extension: 0, 33 connectionID: dice.RollUint16(), 34 }, nil 35 } 36 37 func init() { 38 common.Must(common.RegisterConfig((*Config)(nil), New)) 39 }