Browse Source

More docs

pull/27/head
V2Ray 9 years ago
parent
commit
0ce10e1f88
  1. 2
      proxy/vmess/config.go
  2. 22
      proxy/vmess/protocol/vmess.go

2
proxy/vmess/config.go

@ -9,6 +9,7 @@ import (
"github.com/v2ray/v2ray-core/proxy/vmess/protocol/user" "github.com/v2ray/v2ray-core/proxy/vmess/protocol/user"
) )
// VMessUser is an authenticated user account in VMess configuration.
type VMessUser struct { type VMessUser struct {
Id string `json:"id"` Id string `json:"id"`
Email string `json:"email"` Email string `json:"email"`
@ -21,6 +22,7 @@ func (u *VMessUser) ToUser() (user.User, error) {
}, err }, err
} }
// VMessInboundConfig is
type VMessInboundConfig struct { type VMessInboundConfig struct {
AllowedClients []VMessUser `json:"clients"` AllowedClients []VMessUser `json:"clients"`
} }

22
proxy/vmess/protocol/vmess.go

@ -36,10 +36,9 @@ var (
ErrorInvalidVerion = errors.New("Invalid Version") ErrorInvalidVerion = errors.New("Invalid Version")
) )
// VMessRequest implements the request message of VMess protocol. It only contains // VMessRequest implements the request message of VMess protocol. It only contains the header of a
// the header of a request message. The data part will be handled by conection // request message. The data part will be handled by conection handler directly, in favor of data
// handler directly, in favor of data streaming. // streaming.
type VMessRequest struct { type VMessRequest struct {
Version byte Version byte
UserId user.ID UserId user.ID
@ -50,6 +49,7 @@ type VMessRequest struct {
Address v2net.Address Address v2net.Address
} }
// Destination is the final destination of this request.
func (request *VMessRequest) Destination() v2net.Destination { func (request *VMessRequest) Destination() v2net.Destination {
if request.Command == CmdTCP { if request.Command == CmdTCP {
return v2net.NewTCPDestination(request.Address) return v2net.NewTCPDestination(request.Address)
@ -58,16 +58,19 @@ func (request *VMessRequest) Destination() v2net.Destination {
} }
} }
// VMessRequestReader is a parser to read VMessRequest from a byte stream.
type VMessRequestReader struct { type VMessRequestReader struct {
vUserSet user.UserSet vUserSet user.UserSet
} }
// NewVMessRequestReader creates a new VMessRequestReader with a given UserSet
func NewVMessRequestReader(vUserSet user.UserSet) *VMessRequestReader { func NewVMessRequestReader(vUserSet user.UserSet) *VMessRequestReader {
return &VMessRequestReader{ return &VMessRequestReader{
vUserSet: vUserSet, vUserSet: vUserSet,
} }
} }
// Read reads a VMessRequest from a byte stream.
func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) { func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
buffer := make([]byte, 256) buffer := make([]byte, 256)
@ -190,6 +193,7 @@ func (r *VMessRequestReader) Read(reader io.Reader) (*VMessRequest, error) {
return request, nil return request, nil
} }
// ToBytes returns a VMessRequest in the form of byte array.
func (request *VMessRequest) ToBytes(idHash user.CounterHash, randomRangeInt64 user.RandomInt64InRange) ([]byte, error) { func (request *VMessRequest) ToBytes(idHash user.CounterHash, randomRangeInt64 user.RandomInt64InRange) ([]byte, error) {
buffer := make([]byte, 0, 300) buffer := make([]byte, 0, 300)
@ -250,10 +254,14 @@ func (request *VMessRequest) ToBytes(idHash user.CounterHash, randomRangeInt64 u
return buffer, nil return buffer, nil
} }
// VMessResponse is the header of a TCP response in VMess format.
type VMessResponse [4]byte type VMessResponse [4]byte
// NewVMessResponse creates a VMessResponse from a given VMessRequest.
func NewVMessResponse(request *VMessRequest) *VMessResponse { func NewVMessResponse(request *VMessRequest) *VMessResponse {
response := new(VMessResponse) return &VMessResponse{
copy(response[:], request.ResponseHeader[:]) request.ResponseHeader[0],
return response request.ResponseHeader[1],
request.ResponseHeader[2],
request.ResponseHeader[3]}
} }

Loading…
Cancel
Save