CurlTransport
CurlTransport is a transport for bare-mux that implements end-to-end encryption using libcurl.js and Wisp. It allows developers to route traffic through SOCKS5, SOCKS4, and HTTP proxies, providing powerful proxy chaining capabilities.
Features
Section titled “Features”- End-to-End Encryption: Full TLS encryption using libcurl.js
- Wisp Protocol: Efficient WebSocket multiplexing
- Proxy Support: Route through SOCKS5, SOCKS4a, and HTTP proxies
- Wsproxy Alternative: Optional wsproxy transport mode
- Connection Management: Configurable connection pooling and limits
Installation
Section titled “Installation”npm install @mercuryworkshop/libcurl-transport
Basic Usage
Section titled “Basic Usage”import { BareMuxConnection } from "@mercuryworkshop/bare-mux";
const connection = new BareMuxConnection("/baremux/worker.js");
// Set CurlTransport with Wisp server
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/"
}]);
Proxy Routing
Section titled “Proxy Routing”CurlTransport allows you to route your traffic through intermediate proxies, enabling proxy chaining and advanced network configurations. This is powered by libcurl.js’s native proxy support.
Supported Proxy Types
Section titled “Supported Proxy Types”CurlTransport supports three major proxy protocols:
SOCKS5 (socks5h://)
Section titled “SOCKS5 (socks5h://)”- Full Name: Socket Secure version 5 with remote DNS
- Protocol: Established connection-based proxy protocol
- DNS Resolution: Remote (DNS queries are resolved by the proxy server)
- Use Cases: Tor integration, anonymity networks, bypassing DNS-based restrictions
- Port: Typically 1080 or 9050 (Tor)
SOCKS4A (socks4a://)
Section titled “SOCKS4A (socks4a://)”- Full Name: Socket Secure version 4A with remote DNS
- Protocol: Earlier version with remote DNS support
- DNS Resolution: Remote (DNS queries are resolved by the proxy server)
- Use Cases: Legacy proxy systems, older SOCKS implementations
- Port: Typically 1080
- Note: Less feature-rich than SOCKS5 but widely supported
HTTP (http://)
Section titled “HTTP (http://)”- Full Name: HTTP/HTTPS Proxy
- Protocol: HTTP CONNECT method for tunneling
- DNS Resolution: Can be local or remote depending on proxy configuration
- Use Cases: Corporate proxies, web filtering systems, CDN routing
- Port: Typically 8080, 3128, or 8888
- Note: Works with both HTTP and HTTPS traffic
Using a Proxy
Section titled “Using a Proxy”Add the proxy parameter with the proxy URL in the format protocol://host:port:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://proxy.example.com:1080"
}]);
Examples
Section titled “Examples”SOCKS5 Proxy (Recommended for most use cases):
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://127.0.0.1:9050" // Tor example
}]);
HTTP Proxy (Common in corporate environments):
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "http://proxy.example.com:8080"
}]);
SOCKS4A Proxy (Legacy systems):
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks4a://proxy.example.com:1080"
}]);
Proxy Authentication
Section titled “Proxy Authentication”If your proxy requires authentication, include credentials in the URL:
HTTP Proxy with Authentication:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "http://username:[email protected]:8080"
}]);
SOCKS5 Proxy with Authentication:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://username:[email protected]:1080"
}]);
Advanced Configuration
Section titled “Advanced Configuration”Using Wsproxy
Section titled “Using Wsproxy”If you prefer to use wsproxy instead of Wisp, set transport: "wsproxy". Wsproxy is similar to Wisp, but each TCP connection exists as a separate WebSocket instead of being multiplexed.
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wsproxy/",
transport: "wsproxy"
}]);
With Proxy:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wsproxy/",
transport: "wsproxy",
proxy: "socks5h://127.0.0.1:9050"
}]);
Connection Pooling
Section titled “Connection Pooling”Configure the maximum number of open connections for libcurl.js. The connections option is passed through to HTTPSession.set_connections in libcurl.js.
Format: [hard_limit, cache_limit, max_per_host]
hard_limit(default 60): Maximum active connectionscache_limit(default 50): Connection cache sizemax_per_host(default 6): Max connections per host
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
connections: [30, 20, 1] // Conservative settings
}]);
Example Configurations
Section titled “Example Configurations”High Performance:
connections: [100, 80, 10]
Conservative (Good for Tor/SOCKS):
connections: [30, 20, 1]
Default:
connections: [60, 50, 6]
Use Cases
Section titled “Use Cases”Tor Integration
Section titled “Tor Integration”Route traffic through Tor for anonymity:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://127.0.0.1:9050", // Tor SOCKS proxy
connections: [30, 20, 1] // Tor-friendly settings
}]);
Why SOCKS5 with Tor?
- Remote DNS resolution prevents DNS leaks
- Full protocol support for all connection types
- Better performance than HTTP proxies
- Native Tor compatibility
Corporate Proxy
Section titled “Corporate Proxy”Route through a corporate HTTP proxy:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "http://corporate-proxy.company.com:8080"
}]);
Common Corporate Scenarios:
- Authenticated proxies with credentials
- Multiple proxy servers for load balancing
- Proxy auto-configuration (PAC) support via manual URL
Proxy Chaining
Section titled “Proxy Chaining”Combine CurlTransport’s proxy support with your Wisp server’s routing capabilities for multi-hop proxy chains.
Example Multi-Hop Setup:
- Browser → CurlTransport
- CurlTransport → SOCKS5 Proxy
- SOCKS5 Proxy → Wisp Server
- Wisp Server → Destination
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://wisp-server.com/wisp/", // Wisp server as second hop
proxy: "socks5h://first-proxy.com:1080" // SOCKS5 as first hop
}]);
VPN Exit Nodes
Section titled “VPN Exit Nodes”Route traffic through VPN endpoints that expose SOCKS proxies:
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://vpn-exit-node.com:1080"
}]);
Geographic Routing
Section titled “Geographic Routing”Use region-specific proxies for geo-restricted content:
// Route through EU proxy
await connection.setTransport("/path/to/libcurl/index.mjs", [{
websocket: "wss://example.com/wisp/",
proxy: "socks5h://eu-proxy.example.com:1080"
}]);
Building from Source
Section titled “Building from Source”npm install
npm run build
Related Projects
Section titled “Related Projects”- bare-mux - Transport multiplexer that CurlTransport integrates with
- EpoxyTransport - Alternative encrypted transport
- libcurl.js - WebAssembly port of libcurl
- Wisp Protocol - WebSocket multiplexing protocol
Created and maintained by Mercury Workshop.