Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mfreeman451 committed Jan 30, 2025
1 parent 2697d5f commit c783d4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/scan/combined_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (s *CombinedScanner) Scan(ctx context.Context, targets []models.Target) (<-
if len(targets) == 0 {
empty := make(chan models.Result)
close(empty)

return empty, nil
}

Expand All @@ -64,6 +65,7 @@ func (s *CombinedScanner) Scan(ctx context.Context, targets []models.Target) (<-
for _, target := range targetsCopy {
uniqueHosts[target.Host] = struct{}{}
}

totalHosts := len(uniqueHosts)

// Separate targets based on the copy
Expand All @@ -76,12 +78,15 @@ func (s *CombinedScanner) Scan(ctx context.Context, targets []models.Target) (<-
if separated.tcp[i].Metadata == nil {
separated.tcp[i].Metadata = make(map[string]interface{})
}

separated.tcp[i].Metadata["total_hosts"] = totalHosts
}

for i := range separated.icmp {
if separated.icmp[i].Metadata == nil {
separated.icmp[i].Metadata = make(map[string]interface{})
}

separated.icmp[i].Metadata["total_hosts"] = totalHosts
}

Expand All @@ -96,32 +101,40 @@ func (s *CombinedScanner) Scan(ctx context.Context, targets []models.Target) (<-

func (s *CombinedScanner) handleMixedScanners(ctx context.Context, targets scanTargets) (<-chan models.Result, error) {
results := make(chan models.Result, len(targets.tcp)+len(targets.icmp))

var wg sync.WaitGroup

// Start TCP scanner if needed
if len(targets.tcp) > 0 {
wg.Add(1)

go func(tcpTargets []models.Target) {
defer wg.Done()

tcpResults, err := s.tcpScanner.Scan(ctx, tcpTargets)
if err != nil {
log.Printf("TCP scan error: %v", err)

return
}

s.forwardResults(ctx, tcpResults, results)
}(targets.tcp)
}

// Start ICMP scanner if available and needed
if s.icmpScanner != nil && len(targets.icmp) > 0 {
wg.Add(1)

go func(icmpTargets []models.Target) {
defer wg.Done()

icmpResults, err := s.icmpScanner.Scan(ctx, icmpTargets)
if err != nil {
log.Printf("ICMP scan error: %v", err)
return
}

s.forwardResults(ctx, icmpResults, results)
}(targets.icmp)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/scan/combined_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestCombinedScanner_Scan_Mock(t *testing.T) {

// Create wait group to synchronize result sending
var wg sync.WaitGroup

wg.Add(2)

// Make mocks send results
Expand Down

0 comments on commit c783d4e

Please sign in to comment.