From 183973e82317df2f33cf36a30768c605917aa7e1 Mon Sep 17 00:00:00 2001 From: Meta Date: Wed, 27 Apr 2022 15:22:42 +0800 Subject: [PATCH] chore: Adjust the tcp-concurrent and sniffer log --- .github/workflows/alpha.yml | 4 ++-- common/structure/structure.go | 4 ++-- component/dialer/dialer.go | 8 +++---- component/sniffer/dispatcher.go | 25 +++++++++++---------- listener/tun/ipstack/system/mars/nat/nat.go | 2 +- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 4e4efc72..b5a1a7f4 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -1,7 +1,7 @@ -name: Alpha +name: alpha on: [push] jobs: - Feature-build: + Build: if: ${{ !contains(github.event.head_commit.message, '[Skip CI]') }} runs-on: ubuntu-latest steps: diff --git a/common/structure/structure.go b/common/structure/structure.go index 31b07024..6b038bd2 100644 --- a/common/structure/structure.go +++ b/common/structure/structure.go @@ -31,7 +31,7 @@ func NewDecoder(option Option) *Decoder { // Decode transform a map[string]any to a struct func (d *Decoder) Decode(src map[string]any, dst any) error { if reflect.TypeOf(dst).Kind() != reflect.Ptr { - return fmt.Errorf("Decode must recive a ptr struct") + return fmt.Errorf("decode must recive a ptr struct") } t := reflect.TypeOf(dst).Elem() v := reflect.ValueOf(dst).Elem() @@ -291,7 +291,7 @@ func (d *Decoder) decodeStructFromMap(name string, dataVal, val reflect.Value) e field reflect.StructField val reflect.Value } - fields := []field{} + var fields []field for len(structs) > 0 { structVal := structs[0] structs = structs[1:] diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index 1766f4ad..61877095 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -238,8 +238,7 @@ func concurrentDialContext(ctx context.Context, network, address string, opt *op if ip.Is6() { v = "6" } - - log.Debugln("[%s] try use [%s] connected", host, ip.String()) + //log.Debugln("[%s] try use [%s] connected", host, ip.String()) result.Conn, result.error = dialContext(ctx, network+v, ip, port, opt) } @@ -255,12 +254,11 @@ func concurrentDialContext(ctx context.Context, network, address string, opt *op return res.Conn, nil } - log.Errorln("connect error:%v", res.error) + //log.Errorln("connect error:%v", res.error) if connCount == 0 { - log.Errorln("connect [%s] all ip failed", host) + //log.Errorln("connect [%s] all ip failed", host) break } } - return nil, errors.New("all ip tcp shakeHands failed") } diff --git a/component/sniffer/dispatcher.go b/component/sniffer/dispatcher.go index a712c1f0..b07614c2 100644 --- a/component/sniffer/dispatcher.go +++ b/component/sniffer/dispatcher.go @@ -23,15 +23,17 @@ var ( var Dispatcher SnifferDispatcher -type SnifferDispatcher struct { - enable bool +type ( + SnifferDispatcher struct { + enable bool - sniffers []C.Sniffer + sniffers []C.Sniffer - foreDomain *trie.DomainTrie[bool] - skipSNI *trie.DomainTrie[bool] - portRanges *[]utils.Range[uint16] -} + foreDomain *trie.DomainTrie[bool] + skipSNI *trie.DomainTrie[bool] + portRanges *[]utils.Range[uint16] + } +) func (sd *SnifferDispatcher) TCPSniff(conn net.Conn, metadata *C.Metadata) { bufConn, ok := conn.(*CN.BufferedConn) @@ -98,18 +100,17 @@ func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Meta if err != nil { _, ok := err.(*net.OpError) if ok { - log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String()) + //log.Errorln("[Sniffer] [%s] Maybe read timeout, Consider adding skip", metadata.DstIP.String()) conn.Close() } - - log.Errorln("[Sniffer] %v", err) + //log.Errorln("[Sniffer] %v", err) return "", err } bufferedLen := conn.Buffered() bytes, err := conn.Peek(bufferedLen) if err != nil { - log.Debugln("[Sniffer] the data length not enough") + //log.Debugln("[Sniffer] the data length not enough") continue } @@ -146,7 +147,7 @@ func NewSnifferDispatcher(needSniffer []C.SnifferType, forceDomain *trie.DomainT for _, snifferName := range needSniffer { sniffer, err := NewSniffer(snifferName) if err != nil { - log.Errorln("Sniffer name[%s] is error", snifferName) + //log.Errorln("Sniffer name[%s] is error", snifferName) return &SnifferDispatcher{enable: false}, err } diff --git a/listener/tun/ipstack/system/mars/nat/nat.go b/listener/tun/ipstack/system/mars/nat/nat.go index 9f6f57d2..4ff95db7 100644 --- a/listener/tun/ipstack/system/mars/nat/nat.go +++ b/listener/tun/ipstack/system/mars/nat/nat.go @@ -43,7 +43,7 @@ func Start(device io.ReadWriter, gateway, portal, broadcast netip.Addr) (*TCP, * for { n, err := device.Read(buf) if err != nil { - return + continue } raw := buf[:n]