forked from v2fly/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utp.go
40 lines (33 loc) · 725 Bytes
/
utp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package utp
import (
"context"
"v2ray.com/core/common"
"v2ray.com/core/common/dice"
"v2ray.com/core/common/serial"
)
type UTP struct {
header byte
extension byte
connectionId uint16
}
func (*UTP) Size() int {
return 4
}
// Write implements io.Writer.
func (u *UTP) Write(b []byte) (int, error) {
serial.Uint16ToBytes(u.connectionId, b[:0])
b[2] = u.header
b[3] = u.extension
return 4, nil
}
// NewUTP creates a new UTP header for the given config.
func NewUTP(ctx context.Context, config interface{}) (interface{}, error) {
return &UTP{
header: 1,
extension: 0,
connectionId: dice.RollUint16(),
}, nil
}
func init() {
common.Must(common.RegisterConfig((*Config)(nil), NewUTP))
}