Prechádzať zdrojové kódy

Fix for empty packets

v2ray 9 rokov pred
rodič
commit
b9c3f2cb75
2 zmenil súbory, kde vykonal 35 pridanie a 10 odobranie
  1. 14 10
      proxy/vmess/outbound/outbound.go
  2. 21 0
      shell/point/point.go

+ 14 - 10
proxy/vmess/outbound/outbound.go

@@ -76,6 +76,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
 
 	input := ray.OutboundInput()
 	output := ray.OutboundOutput()
+
 	var requestFinish, responseFinish sync.Mutex
 	requestFinish.Lock()
 	responseFinish.Lock()
@@ -110,20 +111,23 @@ func handleRequest(conn net.Conn, request *protocol.VMessRequest, firstPacket v2
 	firstChunk := firstPacket.Chunk()
 	moreChunks := firstPacket.MoreChunks()
 
-	if firstChunk == nil && moreChunks {
+	for firstChunk == nil && moreChunks {
 		firstChunk, moreChunks = <-input
 	}
 
-	if firstChunk != nil {
-		aesStream.XORKeyStream(firstChunk.Value, firstChunk.Value)
-		buffer.Append(firstChunk.Value)
-		firstChunk.Release()
+	if firstChunk == nil && !moreChunks {
+		log.Warning("VMessOut: Nothing to send. Existing...")
+		return
+	}
 
-		_, err = conn.Write(buffer.Value)
-		if err != nil {
-			log.Error("VMessOut: Failed to write VMess request: %v", err)
-			return
-		}
+	aesStream.XORKeyStream(firstChunk.Value, firstChunk.Value)
+	buffer.Append(firstChunk.Value)
+	firstChunk.Release()
+
+	_, err = conn.Write(buffer.Value)
+	if err != nil {
+		log.Error("VMessOut: Failed to write VMess request: %v", err)
+		return
 	}
 
 	if moreChunks {

+ 21 - 0
shell/point/point.go

@@ -171,3 +171,24 @@ func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet)
 	go this.och.Dispatch(packet, direct)
 	return direct
 }
+
+func (this *Point) FilterPacketAndDispatch(packet v2net.Packet, link ray.OutboundRay, dispatcher proxy.OutboundConnectionHandler) {
+	// Filter empty packets
+	chunk := packet.Chunk()
+	moreChunks := packet.MoreChunks()
+	changed := false
+	for chunk == nil && moreChunks {
+		changed = true
+		chunk, moreChunks = <-link.OutboundInput()
+	}
+	if chunk == nil && !moreChunks {
+		close(link.OutboundOutput())
+		return
+	}
+
+	if changed {
+		packet = v2net.NewPacket(packet.Destination(), chunk, moreChunks)
+	}
+
+	dispatcher.Dispatch(packet, link)
+}