Skip to main content

Crate hypertor

Crate hypertor 

Source
Expand description

§hypertor — Best-in-Class Tor Network Library

The Tor network library for Rust — consume AND host onion services with the simplicity of reqwest and axum.

§Quick Start

§Client (like reqwest)

use hypertor::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let client = TorClient::new().await?;
    let resp = client.get("http://example.onion")?.send().await?;
    println!("{}", resp.text()?);
    Ok(())
}

§Server (like axum)

use hypertor::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    let app = OnionApp::builder()
        .route("/", get(|_req| async { "Hello from .onion!" }))
        .build();
    app.run().await?;
    Ok(())
}

§Features

  • TorClient: HTTP client over Tor with connection pooling, retries, compression
  • OnionApp: FastAPI/axum-style onion service framework
  • Security: PoW DoS protection, client auth, website fingerprinting defense
  • Performance: HTTP/2 multiplexing, circuit prewarming, request batching
  • Privacy: Stream isolation, vanguards, traffic padding
  • Python: Full sync and async bindings via PyO3

Re-exports§

pub use body::Body;
pub use client::TorClient;
pub use client::TorClientBuilder;
pub use config::Config;
pub use config::ConfigBuilder;
pub use error::Error;
pub use error::Result;
pub use request::RequestBuilder;
pub use response::Response;
pub use serve::AppStats;
pub use serve::Handler;
pub use serve::Json;
pub use serve::MethodHandler;
pub use serve::OnionApp;
pub use serve::OnionAppConfig;
pub use serve::Request as ServeRequest;
pub use serve::Response as ServeResponse;
pub use serve::delete;
pub use serve::get;
pub use serve::head;
pub use serve::options;
pub use serve::patch;
pub use serve::post;
pub use serve::put;
pub use circuit::CircuitConfig;
pub use circuit::CircuitManager;
pub use circuit::CircuitStats;
pub use dns::DnsCache;
pub use dns::DnsResult;
pub use dns::TorDnsResolver;
pub use doh::DnsRecord;
pub use doh::DnsResponse;
pub use doh::DohConfig;
pub use doh::DohError;
pub use doh::DohFormat;
pub use doh::DohProvider;
pub use doh::DohResolver;
pub use doh::DohStats;
pub use doh::MultiDohResolver;
pub use doh::RecordData;
pub use doh::RecordType;
pub use isolation::IsolatedSession;
pub use isolation::IsolationLevel;
pub use isolation::IsolationToken;
pub use pool::ConnectionPool;
pub use pool::PoolConfig;
pub use proxy::ProxyConfig;
pub use proxy::ShutdownHandle;
pub use proxy::Socks5Proxy;
pub use adaptive::AdaptiveRetry;
pub use adaptive::AdaptiveRetryConfig;
pub use adaptive::AdaptiveRetryManager;
pub use adaptive::AdaptiveRetryStats;
pub use adaptive::AttemptOutcome;
pub use adaptive::RetryDecision;
pub use backpressure::BackpressureConfig;
pub use backpressure::BackpressureController;
pub use backpressure::BackpressureError;
pub use backpressure::BackpressurePermit;
pub use backpressure::BackpressureStats;
pub use backpressure::LoadShedder;
pub use breaker::BreakerConfig;
pub use breaker::BreakerManager;
pub use breaker::BreakerResult;
pub use breaker::BreakerState;
pub use breaker::CircuitBreaker;
pub use retry::RetryConfig;
pub use rotation::CircuitHealth;
pub use rotation::CircuitRotator;
pub use rotation::RotationConfig;
pub use rotation::RotationStats;
pub use batch::Batch;
pub use batch::BatchConfig;
pub use batch::BatchItem;
pub use batch::BatchProcessor;
pub use batch::Batcher;
pub use batch::BatcherStats;
pub use cache::CacheConfig;
pub use cache::CacheControl;
pub use cache::CachedResponse;
pub use cache::HttpCache;
pub use dedup::DedupConfig;
pub use dedup::Deduplicator;
pub use dedup::RequestKey;
pub use dedup::SharedResult;
pub use keepalive::ConnectionState;
pub use keepalive::KeepAliveConfig;
pub use keepalive::KeepAliveHints;
pub use prewarm::CircuitPrewarmer;
pub use prewarm::PrewarmConfig;
pub use queue::Priority;
pub use queue::PriorityQueue;
pub use queue::QueueConfig;
pub use queue::QueueStatistics;
pub use ratelimit::RateLimitConfig;
pub use ratelimit::RateLimitResult;
pub use ratelimit::RateLimiter;
pub use ratelimit::TokenBucket;
pub use security::ClientSecurityConfig;
pub use security::SecurityLevel;
pub use security::ServiceSecurityConfig;
pub use onion_service::ClientAuthKey as HsClientKey;
pub use onion_service::ClientAuthMode;
pub use onion_service::OnionService as HiddenService;
pub use onion_service::OnionServiceConfig as HsConfig;
pub use onion_service::OnionServiceWithEvents as HiddenServiceWithEvents;
pub use onion_service::OnionStream as HsStream;
pub use onion_service::RateLimit;
pub use onion_service::ServiceEvent as HsEvent;
pub use onion_service::ServiceState as HsState;
pub use onion_service::ServiceStats as HsStats;
pub use http2::ConnectionState as Http2ConnectionState;
pub use http2::ErrorCode as Http2ErrorCode;
pub use http2::Frame as Http2Frame;
pub use http2::FrameFlags;
pub use http2::FrameHeader;
pub use http2::FrameType;
pub use http2::Hpack;
pub use http2::Http2Config;
pub use http2::Http2Connection;
pub use http2::Http2Error;
pub use http2::Http2Stats;
pub use http2::SettingId;
pub use http2::Settings as Http2Settings;
pub use http2::Stream as Http2Stream;
pub use http2::StreamEvent;
pub use http2::StreamState as Http2StreamState;
pub use websocket::CloseCode;
pub use websocket::CloseFrame;
pub use websocket::EchoHandler;
pub use websocket::Frame;
pub use websocket::Message as WsMessage;
pub use websocket::Opcode;
pub use websocket::TorWebSocket;
pub use websocket::TorWebSocketBuilder;
pub use websocket::UpgradeRequest;
pub use websocket::UpgradeResponse;
pub use websocket::WebSocketClient;
pub use websocket::WebSocketConfig;
pub use websocket::WebSocketConnection;
pub use websocket::WebSocketError;
pub use websocket::WebSocketHandler;
pub use websocket::WebSocketServer;
pub use websocket::WebSocketState;
pub use websocket::WebSocketStats;
pub use websocket::generate_accept_key;
pub use websocket::generate_client_key;
pub use health::HealthCheck;
pub use health::HealthCheckConfig;
pub use health::HealthStatus;
pub use health::Metrics;
pub use hooks::ErrorHook;
pub use hooks::Hooks;
pub use hooks::PostResponseHook;
pub use hooks::PreRequestHook;
pub use metrics::Counter;
pub use metrics::Gauge;
pub use metrics::Histogram;
pub use metrics::HttpMetrics;
pub use metrics::MetricsReport;
pub use prometheus::HistogramTimer;
pub use prometheus::MetricsRegistry;
pub use prometheus::PrometheusCounter;
pub use prometheus::PrometheusGauge;
pub use prometheus::PrometheusHistogram;
pub use prometheus::PrometheusSummary;
pub use prometheus::TorMetrics;
pub use prometheus::default_latency_buckets;
pub use prometheus::export_metrics;
pub use prometheus::global_metrics;
pub use prometheus::labels;
pub use prometheus::size_buckets;
pub use prometheus::tor_latency_buckets;
pub use tracing::Span;
pub use tracing::SpanId;
pub use tracing::SpanKind;
pub use tracing::SpanStatus;
pub use tracing::TraceContext;
pub use tracing::TraceId;
pub use tracing::Tracer;
pub use compression::Compression;
pub use cookies::Cookie;
pub use cookies::CookieJar;
pub use middleware::HeaderMiddleware;
pub use middleware::LoggingMiddleware;
pub use middleware::MiddlewareStack;
pub use middleware::RateLimitMiddleware;
pub use redirect::RedirectAction;
pub use redirect::RedirectGuard;
pub use redirect::RedirectPolicy;
pub use session::Session;
pub use streaming::StreamingBody;
pub use streaming::StreamingResponseBuilder;
pub use timeout::Timeouts;
pub use intercept::FnRequestInterceptor;
pub use intercept::FnResponseInterceptor;
pub use intercept::HttpExchange;
pub use intercept::HttpHistory;
pub use intercept::InterceptConfig;
pub use intercept::InterceptId;
pub use intercept::InterceptProxy;
pub use intercept::InterceptedRequest;
pub use intercept::InterceptedResponse;
pub use intercept::ModifiedRequest;
pub use intercept::ModifiedResponse;
pub use intercept::RequestAction;
pub use intercept::RequestInterceptor;
pub use intercept::ResponseAction;
pub use intercept::ResponseInterceptor;

Modules§

adaptive
Adaptive retry strategy.
backpressure
Backpressure and flow control.
batch
Request batching for efficient bulk operations.
body
HTTP Body encoding utilities
breaker
Circuit breaker pattern for fault tolerance.
cache
HTTP response caching.
circuit
Circuit management for Tor connections
client
Core Tor HTTP client
compression
Compression support for HTTP responses.
config
Configuration for hypertor client
cookies
Cookie jar for session management.
dedup
Request deduplication and coalescing.
dns
DNS resolution over Tor.
doh
DNS-over-HTTPS (DoH) Support
error
Typed error handling for hypertor
health
Health checks and status monitoring
hooks
Request hooks and interceptors.
http2
HTTP/2 Protocol Support
intercept
HTTP Interception API (MITM Proxy).
isolation
Stream isolation for Tor circuits
keepalive
Connection keep-alive management.
metrics
Metrics collection and observability.
middleware
Middleware system for composable request/response processing.
observability
Unified Observability Abstraction
onion_service
Real Onion Service Hosting via Arti
pool
Connection pooling for Tor streams
prelude
Convenient re-exports for common hypertor usage.
prewarm
Circuit prewarming for reduced latency.
prometheus
Prometheus Metrics Export
proxy
SOCKS5 proxy server implementation.
queue
Request priority queue.
ratelimit
Token bucket rate limiter.
redirect
Redirect handling
request
HTTP Request builder
response
HTTP Response wrapper
retry
Retry middleware for automatic request retries
rotation
Circuit rotation and failover.
security
Security configuration presets for Tor client and onion services.
serve
FastAPI-like onion service framework.
session
Session-based HTTP client with cookies and redirects
stream
Zero-cost stream abstraction using enum dispatch
streaming
Streaming response body support.
timeout
Timeout configuration for fine-grained control.
tls
TLS abstraction layer
tracing
Distributed tracing support.
websocket
WebSocket over Tor support

Structs§

HsClientDescEncKey
Client authorization key for restricted discovery mode.

Enums§

VanguardMode
The kind of vanguards to use.

Constants§

VERSION
Library version