FortifyNet Proxy v2

A powerful and flexible asynchronous proxy server library written in Rust for high-performance network applications

Features

Asynchronous Architecture

Built using tokio for handling numerous concurrent connections with optimal efficiency and performance.

HTTP/HTTPS Proxying

Seamlessly forwards HTTP and HTTPS traffic, ensuring compatibility and security using hyper and tokio-rustls.

SOCKS5 Proxy Support

Capable of routing traffic through SOCKS5 proxies using tokio-socks, enabling advanced network configurations.

Request Caching

Implements an in-memory cache to store responses for frequently accessed resources to reduce load and improve response times.

Real-Time Metrics

Provides built-in real-time traffic statistics, response time analysis, and error tracking for comprehensive monitoring.

Highly Configurable

Offers a flexible ProxyConfig struct to customize various proxy server settings to meet your specific requirements.

Installation

To use FortifyNet Proxy in your Rust project, follow these steps to set up your development environment and add the necessary dependencies.

1. Set Up Rust

Ensure you have Rust installed on your system. If not, visit https://www.rust-lang.org/tools/install for installation instructions.

2. Create a New Rust Project

Open your terminal and run 'cargo new your_project_name' to create a new Rust project.

3. Add Dependencies

Open your project's Cargo.toml file and add the following dependencies:

toml
1[dependencies]
2fortifynet_proxy = "2.0.0"
3tokio = { version = "1", features = ["full"] }
4hyper = { version = "0.14", features = ["client", "http1", "server", "tcp"] }
5log = "0.4"
6env_logger = "0.10"
7thiserror = "1"
8anyhow = "1"
9rustls = "0.21"
10tokio-rustls = "0.24"
11tokio-socks = "0.3"
12url = "2.5"
13warp = "0.3"
14rustls-pemfile = "1.1"

Dependency Breakdown

  • tokio: Asynchronous runtime for handling concurrent operations
  • hyper: HTTP implementation for request/response handling
  • rustls: TLS implementation for secure connections
  • tokio-socks: SOCKS protocol implementation

Usage

FortifyNet Proxy is designed to be easy to use while providing powerful functionality. Here's a step-by-step guide to get you started with a basic proxy server setup.

1. Import Modules

Start by importing the necessary modules from FortifyNet Proxy and other dependencies.

2. Configure Proxy

Create a ProxyConfig struct to customize your proxy server settings.

3. Start Server

Use the start_proxy_server function to launch your proxy server.

Complete Example

rust
1use fortifynet_proxy::{start_proxy_server, ProxyConfig};
2use log::info;
3
4#[tokio::main]
5async fn main() -> anyhow::Result<()> {
6    // Initialize the logger
7    env_logger::init();
8
9    // Create a proxy configuration
10    let config = ProxyConfig {
11        ip_address: "127.0.0.1".to_string(),
12        port: 8080,
13        authentication: false,
14        username: "admin".to_string(),
15        password: "password".to_string(),
16        cache_enabled: true,
17        socks5_address: None,
18        https_enabled: false,
19        certificate_path: None,
20        private_key_path: None,
21        target_address: Some("http://localhost".to_string())
22    };
23
24    // Log the configuration
25    info!("Starting Proxy server with configuration: {:?}", config);
26
27    // Start the proxy server
28    start_proxy_server(config).await?;
29
30    Ok(())
31}

Configuration Options

ip_address

IP address the proxy server will listen on

port

Port number for incoming connections

authentication

Enable/disable basic authentication

cache_enabled

Enable/disable response caching

Advanced

FortifyNet Proxy offers advanced features for more complex proxy configurations. Here are some examples of how to leverage these capabilities.

HTTPS Proxying

Enable HTTPS support for secure connections with TLS certificates.

rust
1let config = ProxyConfig {
2    https_enabled: true,
3    certificate_path: Some("/path/to/cert.pem".to_string()),
4    private_key_path: Some("/path/to/key.pem".to_string()),
5    // ... other fields
6};

HTTPS Implementation Details

The HTTPS implementation uses rustls for TLS, providing a secure and efficient connection. The certificate and private key paths must point to valid PEM files.

For testing purposes, you can generate self-signed certificates using OpenSSL:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

Authentication

Implement basic authentication for your proxy server to control access.

rust
1let config = ProxyConfig {
2    authentication: true,
3    username: "admin".to_string(),
4    password: "secure_password".to_string(),
5    // ... other fields
6};

SOCKS5 Proxy Chaining

Route traffic through a SOCKS5 proxy for additional anonymity or to bypass network restrictions.

rust
1let config = ProxyConfig {
2    socks5_address: Some("127.0.0.1:1080".to_string()),
3    // ... other fields
4};

Advanced Configuration Example

rust
1// Complete example with all advanced features
2let config = ProxyConfig {
3    ip_address: "0.0.0.0".to_string(),  // Listen on all interfaces
4    port: 8443,                         // HTTPS port
5    authentication: true,               // Enable authentication
6    username: "admin".to_string(),
7    password: "secure_password".to_string(),
8    cache_enabled: true,                // Enable response caching
9    socks5_address: Some("127.0.0.1:1080".to_string()),  // Chain through SOCKS5
10    https_enabled: true,                // Enable HTTPS
11    certificate_path: Some("/path/to/cert.pem".to_string()),
12    private_key_path: Some("/path/to/key.pem".to_string()),
13    target_address: None                // No specific target (general proxy)
14};

Metrics

FortifyNet Proxy provides comprehensive metrics and monitoring capabilities to help you understand your proxy server's performance and usage patterns in real-time.

Real-Time Dashboard

Access a live dashboard for instant insights into your proxy server's operations and performance metrics.

Available at: http://127.0.0.1:<port + 1000>

Traffic Statistics

Monitor incoming and outgoing traffic, including request counts and data transfer volumes.

Response Time Analysis

Track average response times and identify performance bottlenecks in your proxy connections.

Error Tracking

Log and categorize errors for quick troubleshooting and resolution of issues.

Metrics Dashboard

FortifyNet Proxy Metrics

Total Requests

24,582

Avg. Response Time

127ms

Cache Hit Rate

68%

[Response Time Graph Visualization]

Programmatic Access

rust
1// Example of accessing metrics programmatically
2use fortifynet_proxy::metrics::{get_total_requests, get_average_response_time, get_cache_hit_rate};
3
4async fn print_metrics() {
5    let total_requests = get_total_requests().await;
6    let avg_response_time = get_average_response_time().await;
7    let cache_hit_rate = get_cache_hit_rate().await;
8    
9    println!("Total Requests: {}", total_requests);
10    println!("Average Response Time: {} ms", avg_response_time);
11    println!("Cache Hit Rate: {}%", cache_hit_rate * 100.0);
12    
13    // You can also subscribe to real-time metrics updates
14    let mut metrics_stream = subscribe_to_metrics().await;
15    while let Some(metric) = metrics_stream.next().await {
16        println!("Metric update: {:?}", metric);
17    }
18}

Metrics Configuration

You can customize the metrics collection and dashboard by modifying the metrics configuration:

rust
1let config = ProxyConfig {
2    // ... other fields
3    metrics_enabled: true,
4    metrics_port: 9080,  // Custom port for metrics dashboard
5    detailed_logging: true,  // Enable detailed request/response logging
6};

Resources

Explore these resources to deepen your understanding of FortifyNet Proxy and stay updated with the latest developments and community contributions.

Official Documentation

Comprehensive guides, API references, and examples to help you get the most out of FortifyNet Proxy.

GitHub Repository

Source code, issue tracking, and contributions from the open-source community.

Crates.io Page

Latest version information, download statistics, and dependency details.

Community Support

Join discussions, get help, and share your experiences with other developers.