Skip to content

Commit

Permalink
update: wait for scanner runtime begin
Browse files Browse the repository at this point in the history
  • Loading branch information
Esonhugh committed Mar 21, 2024
1 parent 14dac88 commit 8b6f0a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/mutli/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mutli
import (
"net"
"sync"
"time"

"github.com/esonhugh/k8spider/define"
"github.com/esonhugh/k8spider/pkg"
Expand All @@ -22,18 +23,20 @@ func NewSubnetScanner() *SubnetScanner {

func (s *SubnetScanner) ScanSubnet(subnet *net.IPNet) <-chan []define.Record {
if subnet == nil {
log.Tracef("subnet is nil")
log.Debugf("subnet is nil")
return nil
}
out := make(chan []define.Record, 100)
go func() {
log.Debugf("splitting subnet into 16 pices")
if subnets, err := pkg.SubnetShift(subnet, 4); err != nil {
go s.scan(subnet, out)
} else {
for _, sn := range subnets {
go s.scan(sn, out)
}
}
time.Sleep(10 * time.Millisecond) // wait for all goroutines to start
s.wg.Wait()
close(out)
}()
Expand Down

0 comments on commit 8b6f0a9

Please sign in to comment.