How guangyu-yu/cloudflarest-rust works
Project Type and Purpose
• CloudflareST-Rust is a command-line, open-source network speed-testing tool rewritten in Rust. It generates or consumes lists of IPs/CIDRs, performs ping (ICMP or TCP) and HTTP-based latency tests, then (optionally) conducts download throughput tests against Cloudflare edge servers and outputs results to console and CSV.
High-Level Architectural Overview
• This is a single-binary CLI application. It comprises a linear data-processing pipeline with the following stages:
• Input/Configuration
• IP/CIDR Generation or Retrieval
• Concurrency Pool & Task Dispatch
• Latency Tests (ICMP ping, TCP ping via tcping, HTTPing)
• Filter & Threshold Logic
• Download Throughput Tests
• Progress Reporting & Metrics Aggregation
• Output (console table, CSV file)
Main Components and Modules
• CLI Argument Parser (src/args.rs)
• Reads -ip, -ipurl, -url, -httping, -hu, thresholds, thread count, timeout, output options.
• IP Source (src/ip.rs)
• Streams IPs from CIDRs or files/URLs in real time.
• Concurrency Pool (src/pool.rs)
• Manages a thread/work queue for parallelizing tests.
• Latency Testers
• ICMP Module (src/icmp.rs) – raw ping jobs.
• TCP Module (src/tcping.rs) – TCP ping on given port.
• HTTPing Module (src/httping.rs) – HTTP GET to /cdn-cgi/trace or custom URL, with or without TLS.
• Download Module (src/download.rs)
• Executes HTTP(S) file downloads, measures MB/s.
• CSV Output (src/csv.rs)
• Streams results into CSV writer.
• Common Utilities (src/common.rs)
• Shared types, data structures, error handling.
• Progress & Reporting (src/progress.rs)
• Renders real-time progress bars, aggregates metrics.
• Orchestration (src/main.rs)
• Glues all modules, applies thresholds (tn, tl, sl, tlr), triggers download phase after ping threshold reached.
Interactions and Data Flow
CLI Parser → IP Source → Concurrency Pool → [Latency Testers] → Filter/Threshold → (if threshold met) → Download Module → Aggregator → Outputs
• Feedback loop: once ping count (-tn) is reached, pool is signaled to stop issuing ping tasks and switch to download tasks.
Architectural Patterns and Principles
• Streaming Pipeline: IPs are generated, tested, and discarded/filtered on the fly; minimal memory footprint.
• Thread Pool: Bounded concurrency to maximize throughput without oversubscription.
• Modular Separation: Each protocol/test type implemented in its own module.
• Real-Time Reporting: Progress module decouples UI updates from test logic.