Ver código fonte

cleanup socks log

v2ray 9 anos atrás
pai
commit
8f20933457
3 arquivos alterados com 30 adições e 30 exclusões
  1. 6 6
      proxy/socks/protocol/socks.go
  2. 16 16
      proxy/socks/socks.go
  3. 8 8
      proxy/socks/udp.go

+ 6 - 6
proxy/socks/protocol/socks.go

@@ -49,7 +49,7 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
 		return
 	}
 	if nBytes < 2 {
-		log.Info("Socks expected 2 bytes read, but only %d bytes read", nBytes)
+		log.Info("Socks: expected 2 bytes read, but only %d bytes read", nBytes)
 		err = transport.CorruptedPacket
 		return
 	}
@@ -65,20 +65,20 @@ func ReadAuthentication(reader io.Reader) (auth Socks5AuthenticationRequest, aut
 
 	auth.version = buffer.Value[0]
 	if auth.version != socksVersion {
-		log.Warning("Unknown protocol version %d", auth.version)
+		log.Warning("Socks: Unknown protocol version %d", auth.version)
 		err = proxy.InvalidProtocolVersion
 		return
 	}
 
 	auth.nMethods = buffer.Value[1]
 	if auth.nMethods <= 0 {
-		log.Info("Zero length of authentication methods")
+		log.Info("Socks: Zero length of authentication methods")
 		err = transport.CorruptedPacket
 		return
 	}
 
 	if nBytes-2 != int(auth.nMethods) {
-		log.Info("Unmatching number of auth methods, expecting %d, but got %d", auth.nMethods, nBytes)
+		log.Info("Socks: Unmatching number of auth methods, expecting %d, but got %d", auth.nMethods, nBytes)
 		err = transport.CorruptedPacket
 		return
 	}
@@ -227,7 +227,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
 		}
 
 		if nBytes != int(domainLength) {
-			log.Info("Unable to read domain with %d bytes, expecting %d bytes", nBytes, domainLength)
+			log.Info("Socks: Unable to read domain with %d bytes, expecting %d bytes", nBytes, domainLength)
 			err = transport.CorruptedPacket
 			return
 		}
@@ -242,7 +242,7 @@ func ReadRequest(reader io.Reader) (request *Socks5Request, err error) {
 			return
 		}
 	default:
-		log.Info("Unexpected address type %d", request.AddrType)
+		log.Info("Socks: Unexpected address type %d", request.AddrType)
 		err = transport.CorruptedPacket
 		return
 	}

+ 16 - 16
proxy/socks/socks.go

@@ -63,7 +63,7 @@ func (this *SocksServer) Listen(port v2net.Port) error {
 		Zone: "",
 	})
 	if err != nil {
-		log.Error("Socks failed to listen on port %d: %v", port, err)
+		log.Error("Socks: failed to listen on port %d: %v", port, err)
 		return err
 	}
 	this.accepting = true
@@ -87,7 +87,7 @@ func (this *SocksServer) AcceptConnections() {
 			}
 			connection, err := this.tcpListener.AcceptTCP()
 			if err != nil {
-				log.Error("Socks failed to accept new connection %v", err)
+				log.Error("Socks: failed to accept new connection %v", err)
 				return err
 			}
 			go this.HandleConnection(connection)
@@ -103,7 +103,7 @@ func (this *SocksServer) HandleConnection(connection *net.TCPConn) error {
 
 	auth, auth4, err := protocol.ReadAuthentication(reader)
 	if err != nil && err != protocol.Socks4Downgrade {
-		log.Error("Socks failed to read authentication: %v", err)
+		log.Error("Socks: failed to read authentication: %v", err)
 		return err
 	}
 
@@ -124,23 +124,23 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
 		authResponse := protocol.NewAuthenticationResponse(protocol.AuthNoMatchingMethod)
 		err := protocol.WriteAuthentication(writer, authResponse)
 		if err != nil {
-			log.Error("Socks failed to write authentication: %v", err)
+			log.Error("Socks: failed to write authentication: %v", err)
 			return err
 		}
-		log.Warning("Socks client doesn't support allowed any auth methods.")
+		log.Warning("Socks: client doesn't support allowed any auth methods.")
 		return UnsupportedAuthMethod
 	}
 
 	authResponse := protocol.NewAuthenticationResponse(expectedAuthMethod)
 	err := protocol.WriteAuthentication(writer, authResponse)
 	if err != nil {
-		log.Error("Socks failed to write authentication: %v", err)
+		log.Error("Socks: failed to write authentication: %v", err)
 		return err
 	}
 	if this.config.AuthType == AuthTypePassword {
 		upRequest, err := protocol.ReadUserPassRequest(reader)
 		if err != nil {
-			log.Error("Socks failed to read username and password: %v", err)
+			log.Error("Socks: failed to read username and password: %v", err)
 			return err
 		}
 		status := byte(0)
@@ -150,18 +150,18 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
 		upResponse := protocol.NewSocks5UserPassResponse(status)
 		err = protocol.WriteUserPassResponse(writer, upResponse)
 		if err != nil {
-			log.Error("Socks failed to write user pass response: %v", err)
+			log.Error("Socks: failed to write user pass response: %v", err)
 			return err
 		}
 		if status != byte(0) {
-			log.Warning("Invalid user account: %s", upRequest.AuthDetail())
+			log.Warning("Socks: Invalid user account: %s", upRequest.AuthDetail())
 			return proxy.InvalidAuthentication
 		}
 	}
 
 	request, err := protocol.ReadRequest(reader)
 	if err != nil {
-		log.Error("Socks failed to read request: %v", err)
+		log.Error("Socks: failed to read request: %v", err)
 		return err
 	}
 
@@ -180,10 +180,10 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
 		_, err = writer.Write(responseBuffer.Value)
 		responseBuffer.Release()
 		if err != nil {
-			log.Error("Socks failed to write response: %v", err)
+			log.Error("Socks: failed to write response: %v", err)
 			return err
 		}
-		log.Warning("Unsupported socks command %d", request.Command)
+		log.Warning("Socks: Unsupported socks command %d", request.Command)
 		return UnsupportedSocksCommand
 	}
 
@@ -199,12 +199,12 @@ func (this *SocksServer) handleSocks5(reader *v2net.TimeOutReader, writer io.Wri
 	_, err = writer.Write(responseBuffer.Value)
 	responseBuffer.Release()
 	if err != nil {
-		log.Error("Socks failed to write response: %v", err)
+		log.Error("Socks: failed to write response: %v", err)
 		return err
 	}
 
 	dest := request.Destination()
-	log.Info("TCP Connect request to %s", dest.String())
+	log.Info("Socks: TCP Connect request to %s", dest.String())
 
 	packet := v2net.NewPacket(dest, nil, true)
 	this.transport(reader, writer, packet)
@@ -233,7 +233,7 @@ func (this *SocksServer) handleUDP(reader *v2net.TimeOutReader, writer io.Writer
 	responseBuffer.Release()
 
 	if err != nil {
-		log.Error("Socks failed to write response: %v", err)
+		log.Error("Socks: failed to write response: %v", err)
 		return err
 	}
 
@@ -260,7 +260,7 @@ func (this *SocksServer) handleSocks4(reader io.Reader, writer io.Writer, auth p
 	responseBuffer.Release()
 
 	if result == protocol.Socks4RequestRejected {
-		log.Warning("Unsupported socks 4 command %d", auth.Command)
+		log.Warning("Socks: Unsupported socks 4 command %d", auth.Command)
 		return UnsupportedSocksCommand
 	}
 

+ 8 - 8
proxy/socks/udp.go

@@ -17,7 +17,7 @@ func (this *SocksServer) ListenUDP(port v2net.Port) error {
 	}
 	conn, err := net.ListenUDP("udp", addr)
 	if err != nil {
-		log.Error("Socks failed to listen UDP on port %d: %v", port, err)
+		log.Error("Socks: failed to listen UDP on port %d: %v", port, err)
 		return err
 	}
 	this.udpMutex.Lock()
@@ -40,29 +40,29 @@ func (this *SocksServer) AcceptPackets() error {
 		nBytes, addr, err := this.udpConn.ReadFromUDP(buffer.Value)
 		this.udpMutex.RUnlock()
 		if err != nil {
-			log.Error("Socks failed to read UDP packets: %v", err)
+			log.Error("Socks: failed to read UDP packets: %v", err)
 			buffer.Release()
 			continue
 		}
-		log.Info("Client UDP connection from %v", addr)
+		log.Info("Socks: Client UDP connection from %v", addr)
 		request, err := protocol.ReadUDPRequest(buffer.Value[:nBytes])
 		buffer.Release()
 		if err != nil {
-			log.Error("Socks failed to parse UDP request: %v", err)
+			log.Error("Socks: failed to parse UDP request: %v", err)
 			continue
 		}
 		if request.Data == nil || request.Data.Len() == 0 {
 			continue
 		}
 		if request.Fragment != 0 {
-			log.Warning("Dropping fragmented UDP packets.")
+			log.Warning("Socks: Dropping fragmented UDP packets.")
 			// TODO handle fragments
 			request.Data.Release()
 			continue
 		}
 
 		udpPacket := v2net.NewPacket(request.Destination(), request.Data, false)
-		log.Info("Send packet to %s with %d bytes", udpPacket.Destination().String(), request.Data.Len())
+		log.Info("Socks: Send packet to %s with %d bytes", udpPacket.Destination().String(), request.Data.Len())
 		go this.handlePacket(udpPacket, addr, request.Address, request.Port)
 	}
 	return nil
@@ -79,7 +79,7 @@ func (this *SocksServer) handlePacket(packet v2net.Packet, clientAddr *net.UDPAd
 			Port:     port,
 			Data:     data,
 		}
-		log.Info("Writing back UDP response with %d bytes from %s to %s", data.Len(), targetAddr.String(), clientAddr.String())
+		log.Info("Socks: Writing back UDP response with %d bytes from %s to %s", data.Len(), targetAddr.String(), clientAddr.String())
 
 		udpMessage := alloc.NewSmallBuffer().Clear()
 		response.Write(udpMessage)
@@ -94,7 +94,7 @@ func (this *SocksServer) handlePacket(packet v2net.Packet, clientAddr *net.UDPAd
 		udpMessage.Release()
 		response.Data.Release()
 		if err != nil {
-			log.Error("Socks failed to write UDP message (%d bytes) to %s: %v", nBytes, clientAddr.String(), err)
+			log.Error("Socks: failed to write UDP message (%d bytes) to %s: %v", nBytes, clientAddr.String(), err)
 		}
 	}
 }