Fix sniffer errors override each others

* Fix sniffer errors override each others

* Do not return ErrNeedMoreData if header is not expected
This commit is contained in:
dyhkwong
2025-04-22 14:44:55 +08:00
committed by GitHub
parent c54d50fd36
commit f2bbf6b2aa
7 changed files with 102 additions and 10 deletions

View File

@@ -31,13 +31,18 @@ func BitTorrent(_ context.Context, metadata *adapter.InboundContext, reader io.R
return os.ErrInvalid
}
const header = "BitTorrent protocol"
var protocol [19]byte
_, err = reader.Read(protocol[:])
var n int
n, err = reader.Read(protocol[:])
if string(protocol[:n]) != header[:n] {
return os.ErrInvalid
}
if err != nil {
return E.Cause1(ErrNeedMoreData, err)
}
if string(protocol[:]) != "BitTorrent protocol" {
return os.ErrInvalid
if n < 19 {
return ErrNeedMoreData
}
metadata.Protocol = C.ProtocolBitTorrent