1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

remove use of small buffer

This commit is contained in:
v2ray 2016-08-01 17:47:20 +02:00
parent e6a61930d9
commit 283bafdd4a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -40,10 +40,9 @@ func (request *Socks5AuthenticationRequest) HasAuthMethod(method byte) bool {
} }
func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, auth4 Socks4AuthenticationRequest, err error) { func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, auth4 Socks4AuthenticationRequest, err error) {
buffer := alloc.NewSmallBuffer() buffer := make([]byte, 256)
defer buffer.Release()
nBytes, err := reader.Read(buffer.Value) nBytes, err := reader.Read(buffer)
if err != nil { if err != nil {
return return
} }
@ -53,23 +52,23 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
return return
} }
if buffer.Value[0] == socks4Version { if buffer[0] == socks4Version {
auth4.Version = buffer.Value[0] auth4.Version = buffer[0]
auth4.Command = buffer.Value[1] auth4.Command = buffer[1]
auth4.Port = v2net.PortFromBytes(buffer.Value[2:4]) auth4.Port = v2net.PortFromBytes(buffer[2:4])
copy(auth4.IP[:], buffer.Value[4:8]) copy(auth4.IP[:], buffer[4:8])
err = Socks4Downgrade err = Socks4Downgrade
return return
} }
auth.version = buffer.Value[0] auth.version = buffer[0]
if auth.version != socksVersion { if auth.version != socksVersion {
log.Warning("Socks: Unknown protocol version ", auth.version) log.Warning("Socks: Unknown protocol version ", auth.version)
err = proxy.ErrInvalidProtocolVersion err = proxy.ErrInvalidProtocolVersion
return return
} }
auth.nMethods = buffer.Value[1] auth.nMethods = buffer[1]
if auth.nMethods <= 0 { if auth.nMethods <= 0 {
log.Warning("Socks: Zero length of authentication methods") log.Warning("Socks: Zero length of authentication methods")
err = proxy.ErrInvalidAuthentication err = proxy.ErrInvalidAuthentication
@ -81,7 +80,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
err = proxy.ErrInvalidAuthentication err = proxy.ErrInvalidAuthentication
return return
} }
copy(auth.authMethods[:], buffer.Value[2:nBytes]) copy(auth.authMethods[:], buffer[2:nBytes])
return return
} }