diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 831d8610f..d4cf38ac9 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -86,7 +86,7 @@ func (this *FreedomConnection) Dispatch(destination v2net.Destination, payload * return nil }) if err != nil { - log.Error("Freedom: Failed to open connection to ", destination, ": ", err) + log.Warning("Freedom: Failed to open connection to ", destination, ": ", err) return err } defer conn.Close() diff --git a/proxy/http/server.go b/proxy/http/server.go index 4854737d1..965b486c7 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -71,7 +71,7 @@ func (this *Server) Listen(address v2net.Address, port v2net.Port) error { } tcpListener, err := hub.ListenTCP(address, port, this.handleConnection, tlsConfig) if err != nil { - log.Error("Http: Failed listen on port ", port, ": ", err) + log.Error("HTTP: Failed listen on port ", port, ": ", err) return err } this.Lock() @@ -110,7 +110,9 @@ func (this *Server) handleConnection(conn *hub.Connection) { request, err := http.ReadRequest(reader) if err != nil { - log.Warning("HTTP: Failed to read http request: ", err) + if err != io.EOF { + log.Warning("HTTP: Failed to read http request: ", err) + } return } log.Info("HTTP: Request to Method [", request.Method, "] Host [", request.Host, "] with URL [", request.URL, "]") diff --git a/proxy/shadowsocks/protocol.go b/proxy/shadowsocks/protocol.go index fc8a9e21d..bc9e0e4a2 100644 --- a/proxy/shadowsocks/protocol.go +++ b/proxy/shadowsocks/protocol.go @@ -43,8 +43,11 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err _, err := io.ReadFull(reader, buffer.Value[:1]) if err != nil { - log.Error("Shadowsocks: Failed to read address type: ", err) - return nil, transport.ErrorCorruptedPacket + if err != io.EOF { + log.Warning("Shadowsocks: Failed to read address type: ", err) + return nil, transport.ErrorCorruptedPacket + } + return nil, err } lenBuffer := 1 @@ -58,7 +61,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err case AddrTypeIPv4: _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+4]) if err != nil { - log.Error("Shadowsocks: Failed to read IPv4 address: ", err) + log.Warning("Shadowsocks: Failed to read IPv4 address: ", err) return nil, transport.ErrorCorruptedPacket } request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+4]) @@ -66,7 +69,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err case AddrTypeIPv6: _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+16]) if err != nil { - log.Error("Shadowsocks: Failed to read IPv6 address: ", err) + log.Warning("Shadowsocks: Failed to read IPv6 address: ", err) return nil, transport.ErrorCorruptedPacket } request.Address = v2net.IPAddress(buffer.Value[lenBuffer : lenBuffer+16]) @@ -74,26 +77,26 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err case AddrTypeDomain: _, err := io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+1]) if err != nil { - log.Error("Shadowsocks: Failed to read domain lenth: ", err) + log.Warning("Shadowsocks: Failed to read domain lenth: ", err) return nil, transport.ErrorCorruptedPacket } domainLength := int(buffer.Value[lenBuffer]) lenBuffer++ _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+domainLength]) if err != nil { - log.Error("Shadowsocks: Failed to read domain: ", err) + log.Warning("Shadowsocks: Failed to read domain: ", err) return nil, transport.ErrorCorruptedPacket } request.Address = v2net.DomainAddress(string(buffer.Value[lenBuffer : lenBuffer+domainLength])) lenBuffer += domainLength default: - log.Error("Shadowsocks: Unknown address type: ", addrType) + log.Warning("Shadowsocks: Unknown address type: ", addrType) return nil, transport.ErrorCorruptedPacket } _, err = io.ReadFull(reader, buffer.Value[lenBuffer:lenBuffer+2]) if err != nil { - log.Error("Shadowsocks: Failed to read port: ", err) + log.Warning("Shadowsocks: Failed to read port: ", err) return nil, transport.ErrorCorruptedPacket } @@ -105,7 +108,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err if udp { nBytes, err := reader.Read(buffer.Value[lenBuffer:]) if err != nil { - log.Error("Shadowsocks: Failed to read UDP payload: ", err) + log.Warning("Shadowsocks: Failed to read UDP payload: ", err) return nil, transport.ErrorCorruptedPacket } buffer.Slice(0, lenBuffer+nBytes) @@ -121,7 +124,7 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err authBytes = buffer.Value[lenBuffer : lenBuffer+AuthSize] _, err = io.ReadFull(reader, authBytes) if err != nil { - log.Error("Shadowsocks: Failed to read OTA: ", err) + log.Warning("Shadowsocks: Failed to read OTA: ", err) return nil, transport.ErrorCorruptedPacket } } @@ -130,7 +133,6 @@ func ReadRequest(reader io.Reader, auth *Authenticator, udp bool) (*Request, err if request.OTA { actualAuth := auth.Authenticate(nil, buffer.Value[0:lenBuffer]) if !bytes.Equal(actualAuth, authBytes) { - log.Debug("Shadowsocks: Invalid OTA. Expecting ", actualAuth, ", but got ", authBytes) log.Warning("Shadowsocks: Invalid OTA.") return nil, proxy.ErrorInvalidAuthentication } diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 873d4d6d4..6774fa986 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -107,8 +107,10 @@ func (this *Server) handlerUDPPayload(payload *alloc.Buffer, source v2net.Destin request, err := ReadRequest(reader, NewAuthenticator(HeaderKeyGenerator(key, iv)), true) if err != nil { - log.Access(source, "", log.AccessRejected, err) - log.Warning("Shadowsocks: Invalid request from ", source, ": ", err) + if err != io.EOF { + log.Access(source, "", log.AccessRejected, err) + log.Warning("Shadowsocks: Invalid request from ", source, ": ", err) + } return } //defer request.Release() @@ -173,8 +175,10 @@ func (this *Server) handleConnection(conn *hub.Connection) { ivLen := this.config.Cipher.IVSize() _, err := io.ReadFull(bufferedReader, buffer.Value[:ivLen]) if err != nil { - log.Access(conn.RemoteAddr(), "", log.AccessRejected, err) - log.Error("Shadowsocks: Failed to read IV: ", err) + if err != io.EOF { + log.Access(conn.RemoteAddr(), "", log.AccessRejected, err) + log.Warning("Shadowsocks: Failed to read IV: ", err) + } return } diff --git a/proxy/socks/server.go b/proxy/socks/server.go index 1b165a646..dfde068f1 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -106,7 +106,9 @@ func (this *Server) handleConnection(connection *hub.Connection) { auth, auth4, err := protocol.ReadAuthentication(reader) if err != nil && err != protocol.Socks4Downgrade { - log.Error("Socks: failed to read authentication: ", err) + if err != io.EOF { + log.Warning("Socks: failed to read authentication: ", err) + } return } @@ -128,7 +130,7 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe err := protocol.WriteAuthentication(writer, authResponse) writer.Flush() if err != nil { - log.Error("Socks: failed to write authentication: ", err) + log.Warning("Socks: failed to write authentication: ", err) return err } log.Warning("Socks: client doesn't support any allowed auth methods.") @@ -136,8 +138,8 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe } authResponse := protocol.NewAuthenticationResponse(expectedAuthMethod) - err := protocol.WriteAuthentication(writer, authResponse) - writer.Flush() + protocol.WriteAuthentication(writer, authResponse) + err := writer.Flush() if err != nil { log.Error("Socks: failed to write authentication: ", err) return err @@ -145,7 +147,7 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe if this.config.AuthType == AuthTypePassword { upRequest, err := protocol.ReadUserPassRequest(reader) if err != nil { - log.Error("Socks: failed to read username and password: ", err) + log.Warning("Socks: failed to read username and password: ", err) return err } status := byte(0) @@ -167,7 +169,7 @@ func (this *Server) handleSocks5(reader *v2io.BufferedReader, writer *v2io.Buffe request, err := protocol.ReadRequest(reader) if err != nil { - log.Error("Socks: failed to read request: ", err) + log.Warning("Socks: failed to read request: ", err) return err }