add timeout for sniffing
This commit is contained in:
@ -93,8 +93,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
var host string
|
var host string
|
||||||
var protocol string
|
var protocol string
|
||||||
if network == "tcp" && h.md.sniffing {
|
if network == "tcp" && h.md.sniffing {
|
||||||
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
||||||
|
}
|
||||||
rw, host, protocol, _ = forward.Sniffing(ctx, conn)
|
rw, host, protocol, _ = forward.Sniffing(ctx, conn)
|
||||||
log.Debugf("sniffing: host=%s, protocol=%s", host, protocol)
|
log.Debugf("sniffing: host=%s, protocol=%s", host, protocol)
|
||||||
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Time{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if protocol == forward.ProtoHTTP {
|
if protocol == forward.ProtoHTTP {
|
||||||
@ -152,11 +158,11 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
xnet.Transport(rw, cc)
|
xnet.Transport(rw, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
type metadata struct {
|
type metadata struct {
|
||||||
readTimeout time.Duration
|
readTimeout time.Duration
|
||||||
sniffing bool
|
sniffing bool
|
||||||
|
sniffingTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
@ -20,5 +21,6 @@ func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
|
|
||||||
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
||||||
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
||||||
|
h.md.sniffingTimeout = mdutil.GetDuration(md, "sniffing.timeout")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -93,8 +93,14 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
var host string
|
var host string
|
||||||
var protocol string
|
var protocol string
|
||||||
if network == "tcp" && h.md.sniffing {
|
if network == "tcp" && h.md.sniffing {
|
||||||
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
||||||
|
}
|
||||||
rw, host, protocol, _ = forward.Sniffing(ctx, conn)
|
rw, host, protocol, _ = forward.Sniffing(ctx, conn)
|
||||||
log.Debugf("sniffing: host=%s, protocol=%s", host, protocol)
|
log.Debugf("sniffing: host=%s, protocol=%s", host, protocol)
|
||||||
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Time{})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if protocol == forward.ProtoHTTP {
|
if protocol == forward.ProtoHTTP {
|
||||||
h.handleHTTP(ctx, rw, log)
|
h.handleHTTP(ctx, rw, log)
|
||||||
@ -148,11 +154,11 @@ func (h *forwardHandler) Handle(ctx context.Context, conn net.Conn, opts ...hand
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), target.Addr)
|
||||||
xnet.Transport(rw, cc)
|
xnet.Transport(rw, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), target.Addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
type metadata struct {
|
type metadata struct {
|
||||||
readTimeout time.Duration
|
readTimeout time.Duration
|
||||||
sniffing bool
|
sniffing bool
|
||||||
|
sniffingTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
@ -20,5 +21,6 @@ func (h *forwardHandler) parseMetadata(md mdata.Metadata) (err error) {
|
|||||||
|
|
||||||
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
h.md.readTimeout = mdutil.GetDuration(md, readTimeout)
|
||||||
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
||||||
|
h.md.sniffingTimeout = mdutil.GetDuration(md, "sniffing.timeout")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -218,11 +218,11 @@ func (h *httpHandler) handleRequest(ctx context.Context, conn net.Conn, req *htt
|
|||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -191,21 +191,21 @@ func (h *http2Handler) roundTrip(ctx context.Context, w http.ResponseWriter, req
|
|||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
log.Debugf("%s <-> %s", req.RemoteAddr, addr)
|
log.Infof("%s <-> %s", req.RemoteAddr, addr)
|
||||||
netpkg.Transport(xio.NewReadWriter(req.Body, flushWriter{w}), cc)
|
netpkg.Transport(xio.NewReadWriter(req.Body, flushWriter{w}), cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(start),
|
"duration": time.Since(start),
|
||||||
}).Debugf("%s >-< %s", req.RemoteAddr, addr)
|
}).Infof("%s >-< %s", req.RemoteAddr, addr)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,10 +98,16 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
|
|
||||||
var rw io.ReadWriter = conn
|
var rw io.ReadWriter = conn
|
||||||
if h.md.sniffing {
|
if h.md.sniffing {
|
||||||
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Now().Add(h.md.sniffingTimeout))
|
||||||
|
}
|
||||||
// try to sniff TLS traffic
|
// try to sniff TLS traffic
|
||||||
var hdr [dissector.RecordHeaderLen]byte
|
var hdr [dissector.RecordHeaderLen]byte
|
||||||
_, err := io.ReadFull(rw, hdr[:])
|
n, err := io.ReadFull(rw, hdr[:])
|
||||||
rw = xio.NewReadWriter(io.MultiReader(bytes.NewReader(hdr[:]), rw), rw)
|
if h.md.sniffingTimeout > 0 {
|
||||||
|
conn.SetReadDeadline(time.Time{})
|
||||||
|
}
|
||||||
|
rw = xio.NewReadWriter(io.MultiReader(bytes.NewReader(hdr[:n]), rw), rw)
|
||||||
if err == nil &&
|
if err == nil &&
|
||||||
hdr[0] == dissector.Handshake &&
|
hdr[0] == dissector.Handshake &&
|
||||||
binary.BigEndian.Uint16(hdr[1:3]) == tls.VersionTLS10 {
|
binary.BigEndian.Uint16(hdr[1:3]) == tls.VersionTLS10 {
|
||||||
@ -129,11 +135,11 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||||
netpkg.Transport(rw, cc)
|
netpkg.Transport(rw, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -170,11 +176,11 @@ func (h *redirectHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, radd
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", raddr, host)
|
log.Infof("%s <-> %s", raddr, host)
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", raddr, host)
|
}).Infof("%s >-< %s", raddr, host)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := req.Write(cc); err != nil {
|
if err := req.Write(cc); err != nil {
|
||||||
@ -239,11 +245,11 @@ func (h *redirectHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, rad
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", raddr, host)
|
log.Infof("%s <-> %s", raddr, host)
|
||||||
netpkg.Transport(xio.NewReadWriter(io.MultiReader(buf, rw), rw), cc)
|
netpkg.Transport(xio.NewReadWriter(io.MultiReader(buf, rw), rw), cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", raddr, host)
|
}).Infof("%s >-< %s", raddr, host)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,21 +1,25 @@
|
|||||||
package redirect
|
package redirect
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
mdata "github.com/go-gost/core/metadata"
|
mdata "github.com/go-gost/core/metadata"
|
||||||
mdutil "github.com/go-gost/core/metadata/util"
|
mdutil "github.com/go-gost/core/metadata/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type metadata struct {
|
type metadata struct {
|
||||||
sniffing bool
|
|
||||||
tproxy bool
|
tproxy bool
|
||||||
|
sniffing bool
|
||||||
|
sniffingTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *redirectHandler) parseMetadata(md mdata.Metadata) (err error) {
|
func (h *redirectHandler) parseMetadata(md mdata.Metadata) (err error) {
|
||||||
const (
|
const (
|
||||||
sniffing = "sniffing"
|
|
||||||
tproxy = "tproxy"
|
tproxy = "tproxy"
|
||||||
|
sniffing = "sniffing"
|
||||||
)
|
)
|
||||||
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
|
||||||
h.md.tproxy = mdutil.GetBool(md, tproxy)
|
h.md.tproxy = mdutil.GetBool(md, tproxy)
|
||||||
|
h.md.sniffing = mdutil.GetBool(md, sniffing)
|
||||||
|
h.md.sniffingTimeout = mdutil.GetDuration(md, "sniffing.timeout")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,11 +88,11 @@ func (h *redirectHandler) Handle(ctx context.Context, conn net.Conn, opts ...han
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), dstAddr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), dstAddr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -87,11 +87,11 @@ func (h *relayHandler) handleConnect(ctx context.Context, conn net.Conn, network
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), address)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||||
xnet.Transport(conn, cc)
|
xnet.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), address)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -133,11 +133,11 @@ func (h *sniHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, raddr net
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", raddr, host)
|
log.Infof("%s <-> %s", raddr, host)
|
||||||
defer func() {
|
defer func() {
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", raddr, host)
|
}).Infof("%s >-< %s", raddr, host)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := req.Write(cc); err != nil {
|
if err := req.Write(cc); err != nil {
|
||||||
@ -201,11 +201,11 @@ func (h *sniHandler) handleHTTPS(ctx context.Context, rw io.ReadWriter, raddr ne
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", raddr, host)
|
log.Infof("%s <-> %s", raddr, host)
|
||||||
netpkg.Transport(xio.NewReadWriter(io.MultiReader(buf, rw), rw), cc)
|
netpkg.Transport(xio.NewReadWriter(io.MultiReader(buf, rw), rw), cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", raddr, host)
|
}).Infof("%s >-< %s", raddr, host)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -147,11 +147,11 @@ func (h *socks4Handler) handleConnect(ctx context.Context, conn net.Conn, req *g
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -49,11 +49,11 @@ func (h *socks5Handler) handleConnect(ctx context.Context, conn net.Conn, networ
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), address)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), address)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), address)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), address)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -119,11 +119,11 @@ func (h *ssHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.H
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -112,10 +112,10 @@ func (h *ssuHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
log.Infof("%s <-> %s", conn.LocalAddr(), cc.LocalAddr())
|
||||||
h.relayPacket(pc, cc, log)
|
h.relayPacket(pc, cc, log)
|
||||||
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
log.WithFields(map[string]any{"duration": time.Since(t)}).
|
||||||
Debugf("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
Infof("%s >-< %s", conn.LocalAddr(), cc.LocalAddr())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -104,11 +104,11 @@ func (h *forwardHandler) handleDirectForward(ctx context.Context, conn *sshd_uti
|
|||||||
defer cc.Close()
|
defer cc.Close()
|
||||||
|
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
log.Debugf("%s <-> %s", cc.LocalAddr(), targetAddr)
|
log.Infof("%s <-> %s", cc.LocalAddr(), targetAddr)
|
||||||
netpkg.Transport(conn, cc)
|
netpkg.Transport(conn, cc)
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(t),
|
"duration": time.Since(t),
|
||||||
}).Debugf("%s >-< %s", cc.LocalAddr(), targetAddr)
|
}).Infof("%s >-< %s", cc.LocalAddr(), targetAddr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -212,11 +212,11 @@ func (h *forwardHandler) handleRemoteForward(ctx context.Context, conn *sshd_uti
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
tm := time.Now()
|
tm := time.Now()
|
||||||
log.Debugf("%s <-> %s", conn.RemoteAddr(), addr)
|
log.Infof("%s <-> %s", conn.RemoteAddr(), addr)
|
||||||
<-conn.Done()
|
<-conn.Done()
|
||||||
log.WithFields(map[string]any{
|
log.WithFields(map[string]any{
|
||||||
"duration": time.Since(tm),
|
"duration": time.Since(tm),
|
||||||
}).Debugf("%s >-< %s", conn.RemoteAddr(), addr)
|
}).Infof("%s >-< %s", conn.RemoteAddr(), addr)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ func Sniffing(ctx context.Context, rdw io.ReadWriter) (rw io.ReadWriter, host st
|
|||||||
|
|
||||||
// try to sniff TLS traffic
|
// try to sniff TLS traffic
|
||||||
var hdr [dissector.RecordHeaderLen]byte
|
var hdr [dissector.RecordHeaderLen]byte
|
||||||
_, err = io.ReadFull(rw, hdr[:])
|
n, err := io.ReadFull(rw, hdr[:])
|
||||||
rw = xio.NewReadWriter(io.MultiReader(bytes.NewReader(hdr[:]), rw), rw)
|
rw = xio.NewReadWriter(io.MultiReader(bytes.NewReader(hdr[:n]), rw), rw)
|
||||||
if err == nil &&
|
if err == nil &&
|
||||||
hdr[0] == dissector.Handshake &&
|
hdr[0] == dissector.Handshake &&
|
||||||
binary.BigEndian.Uint16(hdr[1:3]) == tls.VersionTLS10 {
|
binary.BigEndian.Uint16(hdr[1:3]) == tls.VersionTLS10 {
|
||||||
|
Reference in New Issue
Block a user