forked from v2ray/v2ray-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utp.go
43 lines (34 loc) · 810 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
41
42
43
package utp
import (
"math/rand"
"v2ray.com/core/common/alloc"
"v2ray.com/core/common/loader"
"v2ray.com/core/transport/internet"
)
type UTP struct {
header byte
extension byte
connectionId uint16
}
func (this *UTP) Overhead() int {
return 4
}
func (this *UTP) Open(payload *alloc.Buffer) bool {
payload.SliceFrom(this.Overhead())
return true
}
func (this *UTP) Seal(payload *alloc.Buffer) {
payload.PrependUint16(this.connectionId)
payload.PrependBytes(this.header, this.extension)
}
type UTPFactory struct{}
func (this UTPFactory) Create(rawSettings interface{}) internet.Authenticator {
return &UTP{
header: 1,
extension: 0,
connectionId: uint16(rand.Intn(65536)),
}
}
func init() {
internet.RegisterAuthenticator(loader.GetType(new(Config)), UTPFactory{})
}