chore: Adjust the tcp-concurrent and sniffer log
This commit is contained in:
parent
2e08a4b4e1
commit
183973e823
5 changed files with 21 additions and 22 deletions
4
.github/workflows/alpha.yml
vendored
4
.github/workflows/alpha.yml
vendored
|
@ -1,7 +1,7 @@
|
||||||
name: Alpha
|
name: alpha
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
Feature-build:
|
Build:
|
||||||
if: ${{ !contains(github.event.head_commit.message, '[Skip CI]') }}
|
if: ${{ !contains(github.event.head_commit.message, '[Skip CI]') }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -31,7 +31,7 @@ func NewDecoder(option Option) *Decoder {
|
||||||
// Decode transform a map[string]any to a struct
|
// Decode transform a map[string]any to a struct
|
||||||
func (d *Decoder) Decode(src map[string]any, dst any) error {
|
func (d *Decoder) Decode(src map[string]any, dst any) error {
|
||||||
if reflect.TypeOf(dst).Kind() != reflect.Ptr {
|
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()
|
t := reflect.TypeOf(dst).Elem()
|
||||||
v := reflect.ValueOf(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
|
field reflect.StructField
|
||||||
val reflect.Value
|
val reflect.Value
|
||||||
}
|
}
|
||||||
fields := []field{}
|
var fields []field
|
||||||
for len(structs) > 0 {
|
for len(structs) > 0 {
|
||||||
structVal := structs[0]
|
structVal := structs[0]
|
||||||
structs = structs[1:]
|
structs = structs[1:]
|
||||||
|
|
|
@ -238,8 +238,7 @@ func concurrentDialContext(ctx context.Context, network, address string, opt *op
|
||||||
if ip.Is6() {
|
if ip.Is6() {
|
||||||
v = "6"
|
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)
|
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
|
return res.Conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorln("connect error:%v", res.error)
|
//log.Errorln("connect error:%v", res.error)
|
||||||
if connCount == 0 {
|
if connCount == 0 {
|
||||||
log.Errorln("connect [%s] all ip failed", host)
|
//log.Errorln("connect [%s] all ip failed", host)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, errors.New("all ip tcp shakeHands failed")
|
return nil, errors.New("all ip tcp shakeHands failed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ var (
|
||||||
|
|
||||||
var Dispatcher SnifferDispatcher
|
var Dispatcher SnifferDispatcher
|
||||||
|
|
||||||
type SnifferDispatcher struct {
|
type (
|
||||||
|
SnifferDispatcher struct {
|
||||||
enable bool
|
enable bool
|
||||||
|
|
||||||
sniffers []C.Sniffer
|
sniffers []C.Sniffer
|
||||||
|
@ -31,7 +32,8 @@ type SnifferDispatcher struct {
|
||||||
foreDomain *trie.DomainTrie[bool]
|
foreDomain *trie.DomainTrie[bool]
|
||||||
skipSNI *trie.DomainTrie[bool]
|
skipSNI *trie.DomainTrie[bool]
|
||||||
portRanges *[]utils.Range[uint16]
|
portRanges *[]utils.Range[uint16]
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func (sd *SnifferDispatcher) TCPSniff(conn net.Conn, metadata *C.Metadata) {
|
func (sd *SnifferDispatcher) TCPSniff(conn net.Conn, metadata *C.Metadata) {
|
||||||
bufConn, ok := conn.(*CN.BufferedConn)
|
bufConn, ok := conn.(*CN.BufferedConn)
|
||||||
|
@ -98,18 +100,17 @@ func (sd *SnifferDispatcher) sniffDomain(conn *CN.BufferedConn, metadata *C.Meta
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_, ok := err.(*net.OpError)
|
_, ok := err.(*net.OpError)
|
||||||
if ok {
|
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()
|
conn.Close()
|
||||||
}
|
}
|
||||||
|
//log.Errorln("[Sniffer] %v", err)
|
||||||
log.Errorln("[Sniffer] %v", err)
|
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
bufferedLen := conn.Buffered()
|
bufferedLen := conn.Buffered()
|
||||||
bytes, err := conn.Peek(bufferedLen)
|
bytes, err := conn.Peek(bufferedLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugln("[Sniffer] the data length not enough")
|
//log.Debugln("[Sniffer] the data length not enough")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +147,7 @@ func NewSnifferDispatcher(needSniffer []C.SnifferType, forceDomain *trie.DomainT
|
||||||
for _, snifferName := range needSniffer {
|
for _, snifferName := range needSniffer {
|
||||||
sniffer, err := NewSniffer(snifferName)
|
sniffer, err := NewSniffer(snifferName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln("Sniffer name[%s] is error", snifferName)
|
//log.Errorln("Sniffer name[%s] is error", snifferName)
|
||||||
return &SnifferDispatcher{enable: false}, err
|
return &SnifferDispatcher{enable: false}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ func Start(device io.ReadWriter, gateway, portal, broadcast netip.Addr) (*TCP, *
|
||||||
for {
|
for {
|
||||||
n, err := device.Read(buf)
|
n, err := device.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
raw := buf[:n]
|
raw := buf[:n]
|
||||||
|
|
Loading…
Reference in a new issue