Skip to main content

Crate cfrp_detector

Crate cfrp_detector 

Source
Expand description

Cloudflare edge detection and network quality probing.

This crate implements a multi-layer detection pipeline to decide whether a given (IP, port) is actually a Cloudflare edge POP, and then optionally runs a multi-threaded throughput speed test against the host to measure real-world download speed.

§Architecture

The library is organised around a few core components:

  • Detector — orchestrator that pulls together every layer below and produces a DetectionResult with a Confidence score.
  • CloudflareRanges + LocationStore — cached data sources loaded from the official Cloudflare CIDR lists and a community-maintained colo code → geography mapping.
  • [ProbeEngine] (inside probe) — TLS + HTTP probes that check for Cloudflare-specific response headers and certificate fingerprints.
  • SpeedTester — multi-threaded byte-range downloader that measures effective throughput to a specific colo.
  • MasscanScanner (optional) — drives an external masscan process for large-scale SYN scans before feeding the results into batch detection.

§Example

// 1. 构建默认配置的检测器 (首次加载会下载 CF CIDR 和 colo 数据)
let detector = Detector::new(DetectorConfig::default()).await?;

// 2a. 用 Target::new 构造 (IP + port)
let cf_dns = Target::new(IpAddr::V4(Ipv4Addr::new(1, 1, 1, 1)), 443);

// 2b. 或者用 parse_target 从字符串解析
let cf_home = parse_target("104.16.132.229:443", 443).map_err(|e| e.to_string())?;

// 3. 单独探测
let res = detector.detect(&cf_home, None).await?;
let colo = res.edge_info.as_ref().and_then(|e| e.colo_code.as_deref()).unwrap_or("?");
println!("{:?}  colo={} edge={}", res.confidence, colo, res.is_cloudflare_edge);

Re-exports§

pub use cache::CacheConfig;
pub use cache::FileCache;
pub use cidr::CidrSource;
pub use cidr::CloudflareCidrs;
pub use cidr::CloudflareRanges;
pub use connector::ConnectorConfig;
pub use connector::HandshakeType;
pub use connector::PinnedClientConfig;
pub use connector::PinnedConnector;
pub use connector::PinnedDownload;
pub use connector::Timing;
pub use connector::build_rustls_client_config;
pub use connector::build_rustls_client_config_sized;
pub use connector::connect_tcp;
pub use connector::connect_tls;
pub use detector::AdaptiveConfig;
pub use detector::BatchProgress;
pub use detector::Detector;
pub use detector::DetectorConfig;
pub use detector::GovernorFeedback;
pub use error::DetectorError;
pub use error::Result;
pub use error::RetryConfig;
pub use error::is_retryable_error;
pub use governor::FdCounter;
pub use governor::GovernorSnapshot;
pub use governor::MockFdCounter;
pub use governor::ResourceGovernor;
pub use governor::ResourceGovernorConfig;
pub use governor::ResourceKind;
pub use governor::SystemFdCounter;
pub use governor::classify_resource_error;
pub use location::CfLocation;
pub use location::LocationSource;
pub use location::LocationStore;
pub use masscan::AsnTask;
pub use masscan::MasscanConfig;
pub use masscan::MasscanScanner;
pub use masscan::NetworkInterface;
pub use masscan::OpenPort;
pub use masscan::ScanMode;
pub use masscan::ScanPipelineConfig;
pub use masscan::clear_cache;
pub use masscan::parse_masscan_output;
pub use masscan_pipeline::MasscanPipeline;
pub use masscan_pipeline::PipelineAsnTask;
pub use masscan_pipeline::PipelineOptions;
pub use masscan_pipeline::PipelineOutput;
pub use masscan_pipeline::PipelineResult;
pub use masscan_pipeline::guess_tls_by_port;
pub use model::BatchResult;
pub use model::BatchTarget;
pub use model::Confidence;
pub use model::DetectionResult;
pub use model::EdgeInfo;
pub use model::Protocol;
pub use model::Target;
pub use model::parse_target;
pub use probe::ProbeConfig;
pub use speedtest::SpeedTestConfig;
pub use speedtest::SpeedTestResult;
pub use speedtest::SpeedTester;

Modules§

cache
Local day-rollover file cache for external data sources (CIDR ranges, colo JSON, ASN HTML).
cidr
Official Cloudflare CIDR range loading and IP-membership checks.
connector
PinnedConnector — direct TCP endpoint pinning + SNI-aware TLS.
detector
The primary Detector engine, batch processing, and adaptive concurrency.
error
Error types and retry helpers used across the library.
governor
ResourceGovernor — FD and OS resource aware concurrency governor.
location
Cloudflare colo (edge POP) code → geographic location lookup.
masscan
Optional wrapper around the masscan binary for large-scale port enumeration.
masscan_pipeline
Full end-to-end pipeline: masscan port scan → Cloudflare edge detection → optional speed test → JSON/CSV report on disk.
model
Core data models for detection results, targets, and confidence levels.
probe
Low-level TLS and HTTP probe primitives used by the Detector.
speedtest
Multi-threaded download-based throughput measurement.