1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-05 19:44:32 -04:00
v2fly/transport/internet/authenticators/utp/utp.go

44 lines
810 B
Go
Raw Normal View History

2016-08-08 15:23:07 -04:00
package utp
import (
"math/rand"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common/alloc"
2016-10-16 08:22:21 -04:00
"v2ray.com/core/common/loader"
2016-08-20 14:55:45 -04:00
"v2ray.com/core/transport/internet"
2016-08-08 15:23:07 -04:00
)
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{}
2016-09-21 08:39:07 -04:00
func (this UTPFactory) Create(rawSettings interface{}) internet.Authenticator {
2016-08-08 15:23:07 -04:00
return &UTP{
header: 1,
extension: 0,
connectionId: uint16(rand.Intn(65536)),
}
}
func init() {
2016-10-16 08:22:21 -04:00
internet.RegisterAuthenticator(loader.GetType(new(Config)), UTPFactory{})
2016-08-08 15:23:07 -04:00
}