mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 00:21:30 +00:00
Revert "Fix stream sniffer"
This commit is contained in:
parent
e2077009c4
commit
39d7127651
|
@ -40,22 +40,28 @@ func PeekStream(ctx context.Context, conn net.Conn, buffer *buf.Buffer, timeout
|
||||||
}
|
}
|
||||||
deadline := time.Now().Add(timeout)
|
deadline := time.Now().Add(timeout)
|
||||||
var errors []error
|
var errors []error
|
||||||
err := conn.SetReadDeadline(deadline)
|
for i := 0; ; i++ {
|
||||||
if err != nil {
|
err := conn.SetReadDeadline(deadline)
|
||||||
return nil, E.Cause(err, "set read deadline")
|
if err != nil {
|
||||||
}
|
return nil, E.Cause(err, "set read deadline")
|
||||||
defer conn.SetReadDeadline(time.Time{})
|
|
||||||
var metadata *adapter.InboundContext
|
|
||||||
for _, sniffer := range sniffers {
|
|
||||||
if buffer.IsEmpty() {
|
|
||||||
metadata, err = sniffer(ctx, io.TeeReader(conn, buffer))
|
|
||||||
} else {
|
|
||||||
metadata, err = sniffer(ctx, io.MultiReader(bytes.NewReader(buffer.Bytes()), io.TeeReader(conn, buffer)))
|
|
||||||
}
|
}
|
||||||
if metadata != nil {
|
_, err = buffer.ReadOnceFrom(conn)
|
||||||
return metadata, nil
|
_ = conn.SetReadDeadline(time.Time{})
|
||||||
|
if err != nil {
|
||||||
|
if i > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
return nil, E.Cause(err, "read payload")
|
||||||
|
}
|
||||||
|
errors = nil
|
||||||
|
var metadata *adapter.InboundContext
|
||||||
|
for _, sniffer := range sniffers {
|
||||||
|
metadata, err = sniffer(ctx, bytes.NewReader(buffer.Bytes()))
|
||||||
|
if 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