optimize: sniffer

This commit is contained in:
mzz2017
2023-02-15 12:54:25 +08:00
parent ebdbf9a4a7
commit 6b68e74335
4 changed files with 29 additions and 5 deletions

View File

@ -9,6 +9,7 @@ import (
"errors"
"github.com/mzz2017/softwind/pool"
"github.com/v2rayA/dae/component/sniffing/internal/quicutils"
"io/fs"
)
const (
@ -54,6 +55,10 @@ func (s *Sniffer) SniffQuic() (d string, err error) {
}
return "", err
}
if errors.Is(err, fs.ErrClosed) {
// ConnectionClose sniffed.
return "", NotFoundError
}
// Error is not NotApplicableError, should be quic block.
isQuic = true
if len(nextBlock) == 0 {
@ -127,10 +132,10 @@ func sniffQuicBlock(buf []byte) (d string, next []byte, err error) {
firstByte := header[0]
rawPacketNumber := pool.Get(quicutils.MaxPacketNumberLength)
copy(rawPacketNumber, header[boundary-quicutils.MaxPacketNumberLength:])
defer pool.Put(rawPacketNumber)
defer func() {
header[0] = firstByte
copy(header[boundary-quicutils.MaxPacketNumberLength:], rawPacketNumber)
pool.Put(rawPacketNumber)
}()
plaintext, err := quicutils.DecryptQuicFromPool_(header, blockEnd, destConnId)
if err != nil {
@ -141,6 +146,9 @@ func sniffQuicBlock(buf []byte) (d string, next []byte, err error) {
// After here, we should not return NotApplicableError.
// And we should return nextFrame.
if d, err = extractSniFromQuicPayload(plaintext); err != nil {
if errors.Is(err, fs.ErrClosed) {
return "", nil, err
}
return "", buf[blockEnd:], NotFoundError
}
return d, buf[blockEnd:], nil