A combined Proxy + BitTorrent service that fetches content through an isolated proxy/VPN, packages it into torrents, and seeds it for requesting clients.
- Secure Fetching: Fetch content through configurable SOCKS5/HTTP proxies or VPN
- Torrent Packaging: Automatically create private torrents from fetched content
- Content Seeding: Built-in BitTorrent seeder using libtorrent
- Authentication: HMAC-SHA256 or Bearer token authentication
- Rate Limiting: Per-user and per-IP rate limits
- Content Deduplication: Content-addressable storage with SHA256 hashing
- Async Processing: Background task queue for efficient request handling
- Docker Support: Fully containerized with docker-compose
- API (FastAPI): REST endpoints for request management
- Task Queue: Async worker pool for processing fetch requests
- Fetcher: HTTP client with proxy support and security validation
- Packager: Torrent creation and content storage
- Seeder: BitTorrent session for distributing content
- Storage: Content-addressable filesystem storage
Client → POST /v1/requests → Queue → Fetcher (via Proxy) → Packager → Seeder → Ready
↓
Client ← GET /v1/requests/{id}/torrent ←──────────────────────────────────────────┘
A comprehensive Russian-language handbook is available at docs/handbook/. The handbook covers:
- Миссия и цели проекта — why ProxyTorrent exists and what problems it solves
- Архитектура системы — detailed architecture with Mermaid diagrams
- Жизненный цикл запроса — complete request processing flow
- API справочник — all REST endpoints with examples
- Конфигурация — comprehensive guide to all settings from
.env.example - Модель данных — database schema and content-addressable storage
- Безопасность — authentication, authorization, and security best practices
- Развёртывание — step-by-step deployment guides for dev/staging/production
- Тестирование — testing strategy, running tests, and CI/CD
- Roadmap — known limitations and future plans
- История изменений — PR-based changelog with results and validation
- Docker and Docker Compose
- Python 3.11+ (for local development)
- Clone the repository:
git clone https://github.com/NickScherbakov/proxytorrent.git
cd proxytorrent- Create environment file (optional):
cat > .env << EOF
# Security
HMAC_SECRET=your-secret-key-here
SECURITY__AUTH_ENABLED=false
# Proxy (optional)
PROXY_ENABLED=false
PROXY_TYPE=socks5
PROXY_HOST=your-proxy-host
PROXY_PORT=1080
# Logging
LOG_LEVEL=INFO
EOF- Start the service:
docker-compose up -d- Check health:
curl http://localhost:8000/v1/health- Install dependencies:
pip install -r requirements.txt
pip install -r requirements-dev.txt- Run the service:
cd src
uvicorn app.main:app --reloadThe service supports two authentication methods:
# Compute signature
BODY='{"url":"http://example.com","method":"GET","ttl":3600}'
SIGNATURE=$(echo -n "$BODY" | openssl dgst -sha256 -hmac "your-secret-key" | cut -d' ' -f2)
# Make request
curl -X POST http://localhost:8000/v1/requests \
-H "Content-Type: application/json" \
-H "X-Signature: $SIGNATURE" \
-d "$BODY"curl -X POST http://localhost:8000/v1/requests \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-token-here" \
-d '{"url":"http://example.com","method":"GET","ttl":3600}'POST /v1/requestsRequest:
{
"url": "http://example.com",
"method": "GET",
"headers": {
"User-Agent": "Custom-Agent"
},
"body": null,
"ttl": 3600
}Response:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "queued",
"estimated_ready": 60,
"created_at": "2025-10-20T19:00:00Z"
}GET /v1/requests/{id}Response:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "ready",
"url": "http://example.com",
"method": "GET",
"created_at": "2025-10-20T19:00:00Z",
"updated_at": "2025-10-20T19:01:00Z",
"completed_at": "2025-10-20T19:01:00Z",
"infohash": "abcdef1234567890abcdef1234567890abcdef12",
"content_hash": "sha256hash...",
"content_size": 1024,
"content_type": "text/html",
"progress": 100
}GET /v1/requests/{id}/torrentDownloads the .torrent file for completed requests.
GET /v1/requests/{id}/magnetResponse:
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"magnet_link": "magnet:?xt=urn:btih:abcdef1234567890abcdef1234567890abcdef12",
"infohash": "abcdef1234567890abcdef1234567890abcdef12"
}DELETE /v1/requests/{id}Cancels a pending request or marks it as cancelled.
GET /v1/healthResponse:
{
"status": "healthy",
"version": "0.1.0",
"uptime": 3600.0,
"checks": {
"database": {"status": "healthy"},
"storage": {"status": "healthy"},
"task_queue": {"status": "healthy", "queue_size": 0}
}
}Configuration is managed through environment variables or a .env file.
SECURITY__AUTH_ENABLED: Enable authentication (default: true)SECURITY__HMAC_SECRET: HMAC secret for request signingSECURITY__BEARER_TOKENS: Comma-separated list of valid bearer tokens
PROXY__PROXY_ENABLED: Enforce proxy usage (default: true)PROXY__PROXY_TYPE: Proxy type (http, https, socks5)PROXY__PROXY_HOST: Proxy hostPROXY__PROXY_PORT: Proxy portPROXY__PROXY_USERNAME: Proxy username (optional)PROXY__PROXY_PASSWORD: Proxy password (optional)
FETCHER__CONNECT_TIMEOUT: Connection timeout in seconds (default: 10)FETCHER__READ_TIMEOUT: Read timeout in seconds (default: 30)FETCHER__MAX_SIZE: Maximum response size in bytes (default: 52428800)FETCHER__MIME_WHITELIST: Allowed MIME types (JSON array)FETCHER__VERIFY_SSL: Verify SSL certificates (default: true)
TORRENT__PRIVATE_TRACKER: Create private torrents (default: true)TORRENT__PIECE_SIZE: Torrent piece size in bytes (default: 262144)TORRENT__ANNOUNCE_URL: Tracker announce URL (optional)TORRENT__ENCRYPTION_ENABLED: Enable torrent encryption (default: true)TORRENT__UPLOAD_RATE_LIMIT: Upload rate limit in bytes/sec (default: 0=unlimited)
STORAGE__BASE_PATH: Base storage path (default: ./data)STORAGE__CONTENT_PATH: Content storage pathSTORAGE__TORRENT_PATH: Torrent file storage pathSTORAGE__RESUME_PATH: Resume data storage path
RATE_LIMIT__RATE_LIMIT_ENABLED: Enable rate limiting (default: true)RATE_LIMIT__REQUESTS_PER_MINUTE: Max requests per minute per user (default: 60)RATE_LIMIT__REQUESTS_PER_HOUR: Max requests per hour per user (default: 1000)RATE_LIMIT__REQUESTS_PER_IP_MINUTE: Max requests per minute per IP (default: 100)
- Prepare Server:
# Update system
apt-get update && apt-get upgrade -y
# Install Docker
curl -fsSL https://get.docker.com | sh
# Install Docker Compose
apt-get install docker-compose-plugin- Clone and Configure:
git clone https://github.com/NickScherbakov/proxytorrent.git
cd proxytorrent
# Create production .env
cp .env.example .env
nano .env # Edit configuration- Start Service:
docker-compose up -d- Configure Reverse Proxy (Nginx):
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}Configure proxy settings in .env:
PROXY__PROXY_ENABLED=true
PROXY__PROXY_TYPE=socks5
PROXY__PROXY_HOST=vpn-gateway
PROXY__PROXY_PORT=1080Uncomment the VPN service in docker-compose.yml and mount your VPN config:
vpn:
image: dperson/openvpn-client
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
volumes:
- ./vpn:/vpn:ro
restart: unless-stopped
proxytorrent:
network_mode: "service:vpn" # Route through VPN# Install dev dependencies
pip install -r requirements-dev.txt
# Run tests
pytest src/app/tests/ -v
# Run with coverage
pytest src/app/tests/ -v --cov=app --cov-report=html# Run ruff
ruff check src/
# Run mypy
mypy src/# Format with black
black src/
# Sort imports
isort src/- Always enable authentication in production: Set
SECURITY__AUTH_ENABLED=true - Use strong HMAC secrets: Generate with
openssl rand -hex 32 - Enable SSL/TLS: Use a reverse proxy with HTTPS
- Enforce proxy usage: Set
PROXY__PROXY_ENABLED=trueto ensure all requests go through proxy - Limit MIME types: Configure
FETCHER__MIME_WHITELISTto only allow required content types - Set rate limits: Adjust rate limiting settings based on your use case
- Private torrents: Keep
TORRENT__PRIVATE_TRACKER=truefor security - SSL verification: Keep
FETCHER__VERIFY_SSL=trueto prevent MITM attacks
# View logs
docker-compose logs -f proxytorrent
# View specific component logs
docker-compose logs -f proxytorrent | grep "Fetcher"Prometheus metrics are available at /metrics (if enabled).
Regular health checks ensure service availability:
curl http://localhost:8000/v1/health-
Libtorrent import errors:
- Ensure libtorrent is properly installed
- Check Python version compatibility (3.11+)
-
Proxy connection failures:
- Verify proxy credentials
- Check network connectivity to proxy
- Review proxy logs
-
Database errors:
- Check database file permissions
- Ensure data directory exists and is writable
-
Torrent creation failures:
- Verify storage paths are writable
- Check disk space availability
MIT License - see LICENSE file for details.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
For issues and questions:
- GitHub Issues: https://github.com/NickScherbakov/proxytorrent/issues
- Documentation: See docs/ directory