mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-19 10:56:06 -05:00
38 lines
799 B
Go
38 lines
799 B
Go
// Package vmess contains protocol definition, io lib for VMess.
|
|
package vmess
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
// VMessInput implements the input message of VMess protocol. It only contains
|
|
// the header of a input message. The data part will be handled by conection
|
|
// handler directly, in favor of data streaming.
|
|
type VMessInput struct {
|
|
version byte
|
|
userHash [16]byte
|
|
respKey [16]byte
|
|
iv [16]byte
|
|
respHead [4]byte
|
|
command byte
|
|
port uint16
|
|
target [256]byte
|
|
}
|
|
|
|
func Read(reader io.Reader) (input *VMessInput, err error) {
|
|
buffer := make([]byte, 17 /* version + user hash */)
|
|
nBytes, err := reader.Read(buffer)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if nBytes != len(buffer) {
|
|
err = fmt.Errorf("Unexpected length of header %d", nBytes)
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
type VMessOutput [4]byte
|