Expand description
§FortifyNet Proxy
A flexible and asynchronous proxy server library built with Rust.
This crate provides a robust foundation for building various proxy servers, including HTTP, HTTPS, and SOCKS5 proxies. It also features built-in metrics, caching, and a simple dashboard for monitoring.
§Features
- Asynchronous I/O: Built with
tokio
for efficient handling of concurrent connections. - HTTP/HTTPS Proxying: Handles both HTTP and HTTPS traffic using
hyper
andtokio-rustls
. - SOCKS5 Proxy Support: Supports proxying through SOCKS5 servers using
tokio-socks
. - Request Caching: Implements a simple in-memory cache for responses.
- Built-in Metrics: Provides real-time traffic statistics, error tracking, and response time analysis.
- Basic Dashboard: Includes a simple web-based dashboard using
warp
for live metrics. - Configurable: Highly configurable through the
ProxyConfig
struct.
§Getting Started
To use this library, add the following to your Cargo.toml
:
[dependencies]
fortifynet_proxy = "1.1.9" # Or the latest version
tokio = { version = "1", features = ["full"] }
hyper = { version = "0.14", features = ["client","http1","server","tcp"] }
log = "0.4"
env_logger = "0.10"
thiserror = "1"
anyhow = "1"
rustls = "0.21"
tokio-rustls = "0.24"
tokio-socks = "0.3"
url = "2.5"
warp = "0.3"
rustls-pemfile = "1.1"
Then, in your main.rs
or library code, use the start_proxy_server
function to start a proxy server.
use fortifynet_proxy::{start_proxy_server, ProxyConfig};
use log::info;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Create a proxy configuration with default values
let config = ProxyConfig {
ip_address: "127.0.0.1".to_string(),
port: 8080,
authentication: false,
username: "admin".to_string(),
password: "password".to_string(),
cache_enabled: true,
socks5_address: None,
https_enabled: false,
certificate_path: None,
private_key_path: None,
target_address: Some("http://www.example.com".to_string()),
};
info!("Starting Proxy server with configuration: {:?}", config);
// Start the proxy server with the provided configuration
start_proxy_server(config).await?;
Ok(())
}
Structs§
- Metrics
- Struct to hold and manage metrics
- Proxy
Config - Configuration for the proxy server.
- Proxy
State - Structure for the global state of the proxy server
Functions§
- shutdown_
proxy_ server - Shuts down the proxy server
- start_
proxy_ server - Starts the proxy server