mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-06 03:54:22 -04:00
47 lines
880 B
Go
47 lines
880 B
Go
package utp
|
|
|
|
import (
|
|
"math/rand"
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
"github.com/v2ray/v2ray-core/transport/internet"
|
|
)
|
|
|
|
type Config struct {
|
|
Version byte
|
|
}
|
|
|
|
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 internet.AuthenticatorConfig) internet.Authenticator {
|
|
return &UTP{
|
|
header: 1,
|
|
extension: 0,
|
|
connectionId: uint16(rand.Intn(65536)),
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
internet.RegisterAuthenticator("utp", UTPFactory{}, func() interface{} { return new(Config) })
|
|
}
|