Protocol Support
Relevant source files
The following files were used as context for generating this wiki page:
ProxyBroker2 identifies, validates, and serves proxies across multiple network protocols. It manages connections for standard web traffic and specialized tunneling methods like SOCKS and HTTP CONNECT. The system uses a deterministic priority model to select the most efficient protocol available for a given proxy.
The core protocol logic resides in the Proxy and Server components. The Proxy class handles low-level negotiation, while the Server manages high-level protocol selection during request distribution. Sources: proxybroker/proxy.py, proxybroker/server.py, CLAUDE.md
Supported Protocols and Schemes
The system categorizes protocols into internal sets for HTTP and HTTPS compatibility. These sets determine which proxies can fulfill specific client requests.
| Protocol | Category | Description |
|---|---|---|
| HTTP | HTTP | Standard cleartext web proxying. |
| HTTPS | HTTPS | Encrypted web proxying via SSL/TLS. |
| SOCKS4 | Both | Binary protocol for IPv4 TCP tunneling. |
| SOCKS5 | Both | Advanced binary protocol with IPv6 and UDP support. |
| CONNECT:80 | HTTP | HTTP CONNECT method used for port 80 tunneling. |
| CONNECT:25 | Specialized | HTTP CONNECT method used for SMTP port 25 tunneling. |
Sources: proxybroker/proxy.py:22-23, proxybroker/proxy.py:92-100, README.md
Protocol Priority Selection
When the system serves a request, it chooses a protocol based on a deterministic priority order. This ensures that the most robust or specialized protocols are attempted before falling back to basic HTTP.
- SOCKS5
- SOCKS4
- CONNECT:80
- CONNECT:25
- HTTPS
- HTTP
Sources: CLAUDE.md, proxybroker/server.py:317-336
Protocol Negotiation Architecture
The system uses "Negotiators" (NGTRS) to handle protocol-specific handshakes. These components transform a raw TCP connection into a functional proxy tunnel.
Negotiation Process
When a proxy connection establishes, the Proxy object assigns a negotiator based on the required protocol. For tunneling protocols, the negotiator performs the handshake before data streaming begins.
The diagram shows how the system branches between direct streaming and specialized negotiation. Sources: proxybroker/proxy.py:214-235, proxybroker/server.py:265-285
SOCKS Protocol Implementation
SOCKS support varies significantly between versions. SOCKS5 provides first-class support for IPv6 destinations by using address type ATYP=0x04. SOCKS4 remains restricted to IPv4 as per the protocol specification.
- SOCKS5: Emits a 16-byte address for IPv6 origins.
- SOCKS4: Raises a
BadResponseErrorif an IPv6 destination is requested.
Sources: CHANGELOG.md, proxybroker/server.py:270-285
Server-Side Protocol Handling
The Server class implements the logic for identifying the required scheme from incoming client requests and selecting the best proxy protocol to fulfill them.
Scheme Identification
The server identifies the required scheme by inspecting the HTTP method of the incoming request.
- HTTPS: Triggered if the method is
CONNECT. - HTTP: Triggered for all other methods.
Sources: proxybroker/server.py:312-315
Protocol Choice Logic
The server filters available proxy protocols based on the identified scheme.
def _choice_proto(self, proxy, scheme):
if scheme == "HTTP":
if self._prefer_connect and ("CONNECT:80" in proxy.types):
return "CONNECT:80"
for proto in ["HTTP", "CONNECT:80", "SOCKS5", "SOCKS4"]:
if proto in proxy.types:
return proto
else: # HTTPS
for proto in ["HTTPS", "SOCKS5", "SOCKS4"]:
if proto in proxy.types:
return proto
Sources: proxybroker/server.py:317-336
Anonymity and Validation
The Checker module validates protocols by testing them against "Judge" servers. It determines the anonymity level of a protocol by checking if the proxy leaks the user's real IP address or adds identifying headers.
Anonymity Levels
| Level | Description |
|---|---|
| Transparent | Proxy leaks the real IP address in the response. |
| Anonymous | Proxy hides the real IP but adds headers like Via or Proxy-Connection. |
| High | Proxy hides the real IP and adds no identifying headers. |
Sources: proxybroker/checker.py:100-118, README.md
Validation Flow
The sequence shows the validation steps to determine protocol functionality and anonymity. Sources: proxybroker/checker.py, proxybroker/proxy.py:260-285
Summary of Protocol Behavior
ProxyBroker2 ensures technical accuracy by canonicalizing IP addresses across all protocols, using RFC 5952 for IPv6. It supports modern async patterns to handle thousands of concurrent protocol checks and maintains a strict priority list to optimize proxy performance for end-users. Sources: CHANGELOG.md, proxybroker/proxy.py:40-51