1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-16 04:35:24 +00:00
v2fly/common/protocol/headers.go

83 lines
1.6 KiB
Go
Raw Normal View History

2016-02-15 23:42:52 +00:00
package protocol
import (
2016-08-20 18:55:45 +00:00
v2net "v2ray.com/core/common/net"
"v2ray.com/core/common/uuid"
2016-02-15 23:42:52 +00:00
)
type RequestCommand byte
const (
RequestCommandTCP = RequestCommand(0x01)
RequestCommandUDP = RequestCommand(0x02)
)
2016-07-11 13:54:19 +00:00
type RequestOption byte
2016-02-15 23:42:52 +00:00
const (
2016-06-02 19:34:25 +00:00
RequestOptionChunkStream = RequestOption(0x01)
RequestOptionConnectionReuse = RequestOption(0x02)
2016-02-15 23:42:52 +00:00
)
2016-06-02 19:34:25 +00:00
func (this RequestOption) Has(option RequestOption) bool {
return (this & option) == option
}
func (this *RequestOption) Set(option RequestOption) {
*this = (*this | option)
}
func (this *RequestOption) Clear(option RequestOption) {
*this = (*this & (^option))
2016-02-27 15:41:21 +00:00
}
2016-02-15 23:42:52 +00:00
type RequestHeader struct {
Version byte
User *User
Command RequestCommand
Option RequestOption
Address v2net.Address
Port v2net.Port
}
2016-02-27 16:28:21 +00:00
func (this *RequestHeader) Destination() v2net.Destination {
if this.Command == RequestCommandUDP {
return v2net.UDPDestination(this.Address, this.Port)
}
return v2net.TCPDestination(this.Address, this.Port)
}
2016-06-02 19:34:25 +00:00
type ResponseOption byte
2016-07-11 13:54:19 +00:00
const (
2016-06-02 19:34:25 +00:00
ResponseOptionConnectionReuse = ResponseOption(1)
)
func (this *ResponseOption) Set(option ResponseOption) {
*this = (*this | option)
}
func (this ResponseOption) Has(option ResponseOption) bool {
return (this | option) == option
}
func (this *ResponseOption) Clear(option ResponseOption) {
*this = (*this & (^option))
}
2016-02-15 23:42:52 +00:00
type ResponseCommand interface{}
type ResponseHeader struct {
2016-06-02 19:34:25 +00:00
Option ResponseOption
2016-02-15 23:42:52 +00:00
Command ResponseCommand
}
2016-02-26 23:05:53 +00:00
type CommandSwitchAccount struct {
Host v2net.Address
Port v2net.Port
ID *uuid.UUID
2016-05-24 19:55:46 +00:00
AlterIds uint16
2016-02-26 23:05:53 +00:00
Level UserLevel
ValidMin byte
}