From cfb6c804aa3bb0c410adae177d76569dd3b788d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 13 Apr 2023 09:03:08 +0800 Subject: [PATCH] Print sniff result --- common/sniff/sniff.go | 4 ++-- route/router.go | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/sniff/sniff.go b/common/sniff/sniff.go index 8c7a0d3e..4d990092 100644 --- a/common/sniff/sniff.go +++ b/common/sniff/sniff.go @@ -24,12 +24,12 @@ func PeekStream(ctx context.Context, conn net.Conn, buffer *buf.Buffer, timeout } err := conn.SetReadDeadline(time.Now().Add(timeout)) if err != nil { - return nil, err + return nil, E.Cause(err, "set read deadline") } _, err = buffer.ReadOnceFrom(conn) err = E.Errors(err, conn.SetReadDeadline(time.Time{})) if err != nil { - return nil, err + return nil, E.Cause(err, "read payload") } var metadata *adapter.InboundContext var errors []error diff --git a/route/router.go b/route/router.go index dc778f66..71b2ef3f 100644 --- a/route/router.go +++ b/route/router.go @@ -631,7 +631,7 @@ func (r *Router) RouteConnection(ctx context.Context, conn net.Conn, metadata ad if metadata.InboundOptions.SniffEnabled { buffer := buf.NewPacket() buffer.FullReset() - sniffMetadata, _ := sniff.PeekStream(ctx, conn, buffer, time.Duration(metadata.InboundOptions.SniffTimeout), sniff.StreamDomainNameQuery, sniff.TLSClientHello, sniff.HTTPHost) + sniffMetadata, err := sniff.PeekStream(ctx, conn, buffer, time.Duration(metadata.InboundOptions.SniffTimeout), sniff.StreamDomainNameQuery, sniff.TLSClientHello, sniff.HTTPHost) if sniffMetadata != nil { metadata.Protocol = sniffMetadata.Protocol metadata.Domain = sniffMetadata.Domain @@ -646,6 +646,8 @@ func (r *Router) RouteConnection(ctx context.Context, conn net.Conn, metadata ad } else { r.logger.DebugContext(ctx, "sniffed protocol: ", metadata.Protocol) } + } else if err != nil { + r.logger.TraceContext(ctx, "sniffed no protocol: ", err) } if !buffer.IsEmpty() { conn = bufio.NewCachedConn(conn, buffer)