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

40 lines
722 B
Go
Raw Normal View History

2016-12-08 10:27:41 -05:00
package utp
import (
2017-01-12 16:47:10 -05:00
"context"
2018-11-02 13:20:02 -04:00
"encoding/binary"
2016-12-08 10:27:41 -05:00
2021-02-16 15:31:50 -05:00
"github.com/v2fly/v2ray-core/v4/common"
"github.com/v2fly/v2ray-core/v4/common/dice"
2016-12-08 10:27:41 -05:00
)
type UTP struct {
header byte
extension byte
connectionID uint16
2016-12-08 10:27:41 -05:00
}
2018-04-02 14:00:50 -04:00
func (*UTP) Size() int32 {
2016-12-08 10:27:41 -05:00
return 4
}
2018-11-02 16:34:04 -04:00
// Serialize implements PacketHeader.
func (u *UTP) Serialize(b []byte) {
binary.BigEndian.PutUint16(b, u.connectionID)
2017-04-13 16:17:58 -04:00
b[2] = u.header
b[3] = u.extension
2016-12-08 10:27:41 -05:00
}
2017-12-16 17:31:05 -05:00
// New creates a new UTP header for the given config.
func New(ctx context.Context, config interface{}) (interface{}, error) {
2016-12-08 10:27:41 -05:00
return &UTP{
header: 1,
extension: 0,
connectionID: dice.RollUint16(),
2017-01-12 16:47:10 -05:00
}, nil
2016-12-08 10:27:41 -05:00
}
func init() {
2017-12-16 17:31:05 -05:00
common.Must(common.RegisterConfig((*Config)(nil), New))
2016-12-08 10:27:41 -05:00
}