mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
Fix for empty packets
This commit is contained in:
parent
7c64093a7a
commit
b9c3f2cb75
@ -76,6 +76,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
|
|||||||
|
|
||||||
input := ray.OutboundInput()
|
input := ray.OutboundInput()
|
||||||
output := ray.OutboundOutput()
|
output := ray.OutboundOutput()
|
||||||
|
|
||||||
var requestFinish, responseFinish sync.Mutex
|
var requestFinish, responseFinish sync.Mutex
|
||||||
requestFinish.Lock()
|
requestFinish.Lock()
|
||||||
responseFinish.Lock()
|
responseFinish.Lock()
|
||||||
@ -110,20 +111,23 @@ func handleRequest(conn net.Conn, request *protocol.VMessRequest, firstPacket v2
|
|||||||
firstChunk := firstPacket.Chunk()
|
firstChunk := firstPacket.Chunk()
|
||||||
moreChunks := firstPacket.MoreChunks()
|
moreChunks := firstPacket.MoreChunks()
|
||||||
|
|
||||||
if firstChunk == nil && moreChunks {
|
for firstChunk == nil && moreChunks {
|
||||||
firstChunk, moreChunks = <-input
|
firstChunk, moreChunks = <-input
|
||||||
}
|
}
|
||||||
|
|
||||||
if firstChunk != nil {
|
if firstChunk == nil && !moreChunks {
|
||||||
aesStream.XORKeyStream(firstChunk.Value, firstChunk.Value)
|
log.Warning("VMessOut: Nothing to send. Existing...")
|
||||||
buffer.Append(firstChunk.Value)
|
return
|
||||||
firstChunk.Release()
|
}
|
||||||
|
|
||||||
_, err = conn.Write(buffer.Value)
|
aesStream.XORKeyStream(firstChunk.Value, firstChunk.Value)
|
||||||
if err != nil {
|
buffer.Append(firstChunk.Value)
|
||||||
log.Error("VMessOut: Failed to write VMess request: %v", err)
|
firstChunk.Release()
|
||||||
return
|
|
||||||
}
|
_, err = conn.Write(buffer.Value)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("VMessOut: Failed to write VMess request: %v", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if moreChunks {
|
if moreChunks {
|
||||||
|
@ -171,3 +171,24 @@ func (this *Point) DispatchToOutbound(context app.Context, packet v2net.Packet)
|
|||||||
go this.och.Dispatch(packet, direct)
|
go this.och.Dispatch(packet, direct)
|
||||||
return 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…
x
Reference in New Issue
Block a user