2015-09-07 17:12:31 +02:00
|
|
|
// Package vmess contains protocol definition, io lib for VMess.
|
|
|
|
package vmess
|
2015-09-05 17:48:38 +02:00
|
|
|
|
|
|
|
import (
|
2015-09-07 23:21:47 +02:00
|
|
|
"fmt"
|
2015-09-07 23:13:55 +02:00
|
|
|
"io"
|
2015-09-05 17:48:38 +02:00
|
|
|
)
|
|
|
|
|
2015-09-07 15:10:37 +02:00
|
|
|
// 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.
|
2015-09-05 17:48:38 +02:00
|
|
|
type VMessInput struct {
|
2015-09-06 22:10:42 +02:00
|
|
|
version byte
|
|
|
|
userHash [16]byte
|
2015-09-08 18:21:15 +02:00
|
|
|
respKey [16]byte
|
2015-09-06 22:10:42 +02:00
|
|
|
iv [16]byte
|
2015-09-08 18:21:15 +02:00
|
|
|
respHead [4]byte
|
2015-09-06 22:10:42 +02:00
|
|
|
command byte
|
|
|
|
port uint16
|
|
|
|
target [256]byte
|
2015-09-05 17:48:38 +02:00
|
|
|
}
|
|
|
|
|
2015-09-07 23:13:55 +02:00
|
|
|
func Read(reader io.Reader) (input *VMessInput, err error) {
|
2015-09-07 23:21:47 +02:00
|
|
|
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
|
2015-09-05 17:48:38 +02:00
|
|
|
}
|
|
|
|
|
2015-09-07 23:13:55 +02:00
|
|
|
type VMessOutput [4]byte
|