Skip to main content

I2P Proxy Tunnel with Python decorator support

Project description

I2P Tunnel

A Rust daemon with extensive logging that manages I2P HTTPS proxies, tests them in parallel for download speed, selects the fastest one, and provides a Python decorator interface for automatic request proxying.

Features

  • Fetches proxy list from http://outproxys.i2p/
  • Tests proxies in parallel for download speed
  • Automatically selects and uses the fastest proxy
  • Python decorator @i2p for seamless integration
  • Comprehensive logging with tracing
  • Automatic proxy rotation on failure
  • Periodic re-testing to maintain optimal performance

Installation

Prerequisites

  • Rust (latest stable version)
  • Python 3.8+
  • uv (fast Python package installer)

Install uv:

# On Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

# On macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

Build

Build the Rust library and Python extension using uv:

# Install maturin using uv
uv tool install maturin

# Build and install in development mode
uv run maturin develop --release

# Or build wheel and install
uv run maturin build --release
uv pip install target/wheels/i2ptunnel-*.whl

Or use uv's project management:

# Sync dependencies and build
uv sync
uv run maturin develop --release

Usage

Python Decorator

Use the @i2p decorator to automatically route HTTP requests through the fastest I2P proxy:

from i2p_proxy import i2p
import requests

@i2p
def fetch_data():
    response = requests.get("https://example.com")
    return response.json()

# All requests.get/post/etc. calls inside this function
# will automatically use the fastest I2P proxy
data = fetch_data()

Direct Usage

You can also use the daemon directly:

from i2ptunnel import I2PProxyDaemon

daemon = I2PProxyDaemon()

# Fetch available proxies
proxies = daemon.fetch_proxies()
print(f"Found {len(proxies)} proxies")

# Test proxies
results = daemon.test_proxies(proxies[:5])  # Test first 5
for result in results:
    if result["success"]:
        print(f"Proxy {result['proxy']}: {result['speed_bytes_per_sec']/1024:.2f} KB/s")

# Make a request through the fastest proxy
response = daemon.make_request(
    url="https://example.com",
    method="GET",
    headers=None,
    body=None
)

print(f"Status: {response['status']}")
print(f"Proxy used: {response['proxy_used']}")
print(f"Body: {response['body']}")

Using the I2PProxy class

from i2p_proxy import I2PProxy

proxy = I2PProxy()

# Make requests directly
response = proxy.get("https://example.com")
print(response.status_code)
print(response.text)

response = proxy.post("https://example.com/api", data=b"data")

Logging

The daemon uses extensive logging via the tracing crate. Set the log level with environment variables:

# Set log level (TRACE, DEBUG, INFO, WARN, ERROR)
export RUST_LOG=i2ptunnel=debug

# Or more verbose
export RUST_LOG=i2ptunnel=trace

Architecture

  • ProxyManager: Fetches and parses proxy list from http://outproxys.i2p/
  • ProxyTester: Tests proxies in parallel, measuring download speed and latency
  • ProxySelector: Tracks and selects the fastest proxy, handles failures
  • RequestHandler: Routes HTTP requests through the selected proxy
  • PyO3 Bridge: Exposes Rust functionality to Python

Configuration

The daemon automatically:

  • Fetches proxies from the I2P outproxy list
  • Tests proxies in parallel (up to 10 concurrent tests)
  • Selects the fastest proxy based on download speed
  • Re-tests proxies every 5 minutes (configurable)
  • Rotates to a new proxy on failure

Development

Build for development:

cargo build

Run tests:

cargo test

Build Python extension in development mode:

uv run maturin develop

Or using uv sync:

uv sync
uv run maturin develop

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

i2ptunnel-0.1.3.tar.gz (42.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

i2ptunnel-0.1.3-cp312-cp312-win_amd64.whl (5.3 MB view details)

Uploaded CPython 3.12Windows x86-64

File details

Details for the file i2ptunnel-0.1.3.tar.gz.

File metadata

  • Download URL: i2ptunnel-0.1.3.tar.gz
  • Upload date:
  • Size: 42.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for i2ptunnel-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c0c9097f50aec6f74c4131da789c746428faef673dfc8d55f10c9249c0862f55
MD5 ff97ee4d73b77069879ba73f9b365d85
BLAKE2b-256 409a11b69a06fb6bc8e1f757ea9ae6e19d795f0b6db4aeefcba89c1993c70715

See more details on using hashes here.

File details

Details for the file i2ptunnel-0.1.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: i2ptunnel-0.1.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for i2ptunnel-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a0cbd4b9393ee0c721238143d020c15ab4727ba93442853f80076c53ccb44a20
MD5 5d660969238c68d54bb9209519a96397
BLAKE2b-256 1588c690b2af9cde4f910cfc0b28f83a422faf6fa98910d96ef6bf91a98f7ac0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page