mirror of https://github.com/v2ray/v2ray-core
Fix for empty packets
parent
7c64093a7a
commit
b9c3f2cb75
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue