feat: app sniff options

This commit is contained in:
Toby 2024-06-29 16:27:57 -07:00
parent 16bfdc7720
commit 3412368d20
4 changed files with 38 additions and 6 deletions

View file

@ -15,6 +15,10 @@ import (
quicInternal "github.com/apernet/hysteria/extras/v2/sniff/internal/quic"
)
const (
sniffDefaultTimeout = 4 * time.Second
)
var _ server.RequestHook = (*Sniffer)(nil)
// Sniffer is a server core RequestHook that performs packet inspection and possibly
@ -62,7 +66,12 @@ func (h *Sniffer) Check(isUDP bool, reqAddr string) bool {
}
func (h *Sniffer) TCP(stream quic.Stream, reqAddr *string) ([]byte, error) {
err := stream.SetReadDeadline(time.Now().Add(h.Timeout))
var err error
if h.Timeout == 0 {
err = stream.SetReadDeadline(time.Now().Add(sniffDefaultTimeout))
} else {
err = stream.SetReadDeadline(time.Now().Add(h.Timeout))
}
if err != nil {
return nil, err
}