|
|
@ -2,7 +2,8 @@ |
|
|
|
package vmess |
|
|
|
package vmess |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"net" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"io" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// VMessInput implements the input message of VMess protocol. It only contains
|
|
|
|
// VMessInput implements the input message of VMess protocol. It only contains
|
|
|
@ -19,19 +20,19 @@ type VMessInput struct { |
|
|
|
target [256]byte |
|
|
|
target [256]byte |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type VMessReader struct { |
|
|
|
func Read(reader io.Reader) (input *VMessInput, err error) { |
|
|
|
conn *net.Conn |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewVMessReader creates a new VMessReader
|
|
|
|
return |
|
|
|
func NewVMessReader(conn *net.Conn) (VMessReader, error) { |
|
|
|
|
|
|
|
var reader VMessReader |
|
|
|
|
|
|
|
reader.conn = conn |
|
|
|
|
|
|
|
return reader, nil |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Read reads data from current connection and form a VMessInput if possible.
|
|
|
|
type VMessOutput [4]byte |
|
|
|
func (*VMessReader) Read() (VMessInput, error) { |
|
|
|
|
|
|
|
var input VMessInput |
|
|
|
|
|
|
|
return input, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|