mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 03:51:31 +00:00
Fix sniffer
This commit is contained in:
parent
edad4d1ce7
commit
6dcacf3b5e
|
@ -22,24 +22,30 @@ func PeekStream(ctx context.Context, conn net.Conn, buffer *buf.Buffer, timeout
|
||||||
if timeout == 0 {
|
if timeout == 0 {
|
||||||
timeout = C.ReadPayloadTimeout
|
timeout = C.ReadPayloadTimeout
|
||||||
}
|
}
|
||||||
err := conn.SetReadDeadline(time.Now().Add(timeout))
|
deadline := time.Now().Add(timeout)
|
||||||
|
var errors []error
|
||||||
|
|
||||||
|
for i := 0; i < 3; i++ {
|
||||||
|
err := conn.SetReadDeadline(deadline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, E.Cause(err, "set read deadline")
|
return nil, E.Cause(err, "set read deadline")
|
||||||
}
|
}
|
||||||
_, err = buffer.ReadOnceFrom(conn)
|
_, err = buffer.ReadOnceFrom(conn)
|
||||||
err = E.Errors(err, conn.SetReadDeadline(time.Time{}))
|
err = E.Errors(err, conn.SetReadDeadline(time.Time{}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if i > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
return nil, E.Cause(err, "read payload")
|
return nil, E.Cause(err, "read payload")
|
||||||
}
|
}
|
||||||
var metadata *adapter.InboundContext
|
|
||||||
var errors []error
|
|
||||||
for _, sniffer := range sniffers {
|
for _, sniffer := range sniffers {
|
||||||
metadata, err = sniffer(ctx, bytes.NewReader(buffer.Bytes()))
|
metadata, err := sniffer(ctx, bytes.NewReader(buffer.Bytes()))
|
||||||
if metadata != nil {
|
if metadata != nil {
|
||||||
return metadata, nil
|
return metadata, nil
|
||||||
}
|
}
|
||||||
errors = append(errors, err)
|
errors = append(errors, err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil, E.Errors(errors...)
|
return nil, E.Errors(errors...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue