Skip to content

Commit

Permalink
QUIC sniffer: handle multiple initial packets (#3802)
Browse files Browse the repository at this point in the history
* QUIC sniffer: handle multiple initial packets
Basically copied from Vigilans/v2ray-core@8f33db0

Co-Authored-By: Vigilans <[email protected]>

* Remove unnecessary file

---------

Co-authored-by: Vigilans <[email protected]>
  • Loading branch information
Fangliding and Vigilans authored Sep 13, 2024
1 parent 7970f24 commit 781aaee
Show file tree
Hide file tree
Showing 3 changed files with 204 additions and 165 deletions.
10 changes: 8 additions & 2 deletions app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ func (r *cachedReader) Cache(b *buf.Buffer) {
if !mb.IsEmpty() {
r.cache, _ = buf.MergeMulti(r.cache, mb)
}
b.Clear()
rawBytes := b.Extend(buf.Size)
cacheLen := r.cache.Len()
if cacheLen <= b.Cap() {
b.Clear()
} else {
b.Release()
*b = *buf.NewWithSize(cacheLen)
}
rawBytes := b.Extend(cacheLen)
n := r.cache.Copy(rawBytes)
b.Resize(0, int32(n))
r.Unlock()
Expand Down
15 changes: 15 additions & 0 deletions common/buf/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,21 @@ func (b *Buffer) Len() int32 {
return b.end - b.start
}

// Cap returns the capacity of the buffer content.
func (b *Buffer) Cap() int32 {
if b == nil {
return 0
}
return int32(len(b.v))
}

// NewWithSize creates a Buffer with 0 length and capacity with at least the given size.
func NewWithSize(size int32) *Buffer {
return &Buffer{
v: bytespool.Alloc(size),
}
}

// IsEmpty returns true if the buffer is empty.
func (b *Buffer) IsEmpty() bool {
return b.Len() == 0
Expand Down
Loading

0 comments on commit 781aaee

Please sign in to comment.