1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

simplify socks input

This commit is contained in:
V2Ray 2015-09-15 21:40:40 +02:00
parent 6a8014dbef
commit ca79db0de1

View File

@ -5,7 +5,6 @@ import (
"encoding/binary"
"fmt"
"io"
_ "log"
v2net "github.com/v2ray/v2ray-core/net"
)
@ -36,7 +35,7 @@ func (request *Socks5AuthenticationRequest) HasAuthMethod(method byte) bool {
}
func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, err error) {
buffer := make([]byte, 2)
buffer := make([]byte, 256)
nBytes, err := reader.Read(buffer)
if err != nil {
return
@ -58,16 +57,11 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, err
return
}
buffer = make([]byte, auth.nMethods)
nBytes, err = reader.Read(buffer)
if err != nil {
return
}
if nBytes != int(auth.nMethods) {
if nBytes - 2 != int(auth.nMethods) {
err = fmt.Errorf("Unmatching number of auth methods, expecting %d, but got %d", auth.nMethods, nBytes)
return
}
copy(auth.authMethods[:nBytes], buffer)
copy(auth.authMethods[:], buffer[2:nBytes])
return
}
@ -84,10 +78,7 @@ func NewAuthenticationResponse(authMethod byte) *Socks5AuthenticationResponse {
}
func (r *Socks5AuthenticationResponse) ToBytes() []byte {
buffer := make([]byte, 2 /* size of Socks5AuthenticationResponse */)
buffer[0] = r.version
buffer[1] = r.authMethod
return buffer
return []byte{r.version, r.authMethod}
}
func WriteAuthentication(writer io.Writer, response *Socks5AuthenticationResponse) error {