Skip to content

Commit 2cb2840

Browse files
doublegateclaude
andcommitted
fix(tui): add ProgressTracker to execute_scan_ports for Metrics/Network Graph
Root cause: execute_scan_ports() never published ProgressUpdate events during the actual port scanning loop. Only ScanStarted/ScanCompleted were published, leaving Metrics dashboard and Network Graph without real-time data. Changes: - Add ProgressTracker to execute_scan_ports() for real-time progress updates - Publish ProgressUpdate events every 250ms during port scanning - Track completed port count and calculate accurate throughput - Enable Network Graph to receive ThroughputSamples for visualization - Enable Metrics dashboard to show current throughput and completed count This is Part 3 of the comprehensive TUI event flow fix series: - Part 1: Event aggregation and progress tracking (cdad62c) - Part 2: EventBus attachment to TCP scanner (2a051ad) - Part 2b: Service detection, duration, Network Graph (b3776e7) - Part 3: ProgressUpdate in execute_scan_ports (this commit) Testing: All 276 prtip-tui tests pass, clean clippy 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b3776e7 commit 2cb2840

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- **Fix:** Track scan_start_time in ScanState, set on ScanStarted event for duration calculation
2323
- **Fix:** Add TCP Connect scan progress tracking (was only SYN/UDP/Stealth before)
2424
- **Fix:** Improve Network Graph data calculations (packets_received, ports_per_second)
25+
- **Root Cause 6:** execute_scan_ports() never published ProgressUpdate events during scan
26+
- **Fix:** Add ProgressTracker to execute_scan_ports() for real-time Metrics/Network Graph updates
2527
- **Impact:** All TUI tabs now display real-time data (Port Table, Service Table, Metrics, Network Graph)
2628

2729
## [0.5.8] - 2025-11-27

crates/prtip-scanner/src/scheduler.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,14 @@ impl ScanScheduler {
794794
ports.count()
795795
);
796796

797+
// Generate scan_id for this scan (used by events and progress tracker)
798+
let scan_id = Uuid::new_v4();
799+
797800
// Publish ScanStarted event for TUI
798801
if let Some(ref event_bus) = self.config.scan.event_bus {
799802
use prtip_core::events::{ScanEvent, ScanStage};
800803
use std::time::SystemTime;
801-
use uuid::Uuid;
802804

803-
let scan_id = Uuid::new_v4();
804805
let timestamp = SystemTime::now();
805806

806807
event_bus
@@ -867,6 +868,10 @@ impl ScanScheduler {
867868
// (must be before the loop where total_ports gets shadowed)
868869
let total_scan_ports = total_ports;
869870

871+
// Create progress tracker for TUI updates (Sprint 6.8 fix)
872+
// Uses same scan_id as ScanStarted event
873+
let mut progress_tracker = ProgressTracker::new(scan_id, total_ports);
874+
870875
for target in targets {
871876
let original_hosts = target.expand_hosts();
872877

@@ -985,6 +990,13 @@ impl ScanScheduler {
985990
// Wait for progress bridge to finish
986991
let _ = bridge_handle.await;
987992

993+
// Update progress tracker for TUI (Sprint 6.8 fix)
994+
for _ in 0..ports_vec.len() {
995+
progress_tracker
996+
.increment(&self.config.scan.event_bus)
997+
.await;
998+
}
999+
9881000
// Push results to lock-free aggregator (zero contention!)
9891001
for result in results.iter() {
9901002
// Try to push result
@@ -1176,13 +1188,15 @@ impl ScanScheduler {
11761188
// Complete progress bar
11771189
progress.finish("Scan complete");
11781190

1191+
// Publish final ProgressUpdate event to ensure 100% completion (Sprint 6.8 fix)
1192+
progress_tracker.publish(&self.config.scan.event_bus).await;
1193+
11791194
// Publish ScanCompleted event for TUI
11801195
if let Some(ref event_bus) = self.config.scan.event_bus {
11811196
use prtip_core::events::{ScanEvent, ScanStage};
11821197
use std::time::{Duration, SystemTime};
1183-
use uuid::Uuid;
11841198

1185-
let scan_id = Uuid::new_v4();
1199+
// Use same scan_id as ScanStarted/ProgressUpdate events
11861200
let timestamp = SystemTime::now();
11871201

11881202
// Calculate port counts

0 commit comments

Comments
 (0)