Skip to content

Modernize internals while preserving proxy compatibility - #4

Merged
by275 merged 49 commits into
masterfrom
modernize
Aug 22, 2026
Merged

by275 merged 49 commits into
masterfrom
modernize

Conversation

@by275

@by275 by275 commented Aug 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

This pull request modernizes the project internals while preserving the existing CLI, URI grammar, public factory API, and proxy wire compatibility for Python 3.12+ Git installations.

It focuses on compatibility-preserving refactoring, clearer module boundaries, lifecycle ownership, and reproducible validation.

Compatibility

  • Preserves pproxy.Connection, pproxy.Server, pproxy.Rule, and pproxy.DIRECT.
  • Preserves the pproxy.proto compatibility facade and legacy protocol class names.
  • Preserves existing HTTP, SOCKS4/5, Shadowsocks, SSR, Trojan, WebSocket, TCP, UDP, Unix socket, jump, authentication, rule, and scheduling behavior.
  • Keeps current cipher names and pure-Python fallbacks.
  • Keeps start_server(args) and the existing argument shape.
  • Adds lifecycle and observability APIs without changing legacy verbose output.

No intentional breaking change is included in this PR.

Main changes

Packaging and development

  • Adds PEP 517/621 metadata in pyproject.toml while retaining setup.py as a compatibility shim.
  • Adds reproducible Git/wheel installation metadata for Python 3.12+.
  • Adds core and optional dependency CI workflows.
  • Adds source-checkout and installed-package version reporting.

Protocol and transport boundaries

  • Converts transport helpers into the pproxy.transport package while preserving the legacy import path.
  • Adds pproxy.protocols modules for address parsing, base protocols, HTTP, SOCKS, transparent protocols, WebSocket, and registry dispatch.
  • Keeps pproxy.proto as a compatibility facade.
  • Adds a registry extension hook so optional protocol adapters can be added without coupling them to the core implementation.

Runtime lifecycle

  • Adds pproxy.runtime.TaskRegistry for owned background tasks.
  • Tracks runtime-created tasks in core and optional adapters.
  • Adds additive wait_closed(), aclose(), and async context-manager support where applicable.
  • Preserves synchronous close() and existing server startup behavior.

Correctness and safety

  • Fixes WebSocket protocol detection regression coverage.
  • Replaces optimized-away protocol validation paths with explicit validation errors.
  • Adds URI, parser, cipher, transport, relay, lifecycle, optional adapter, and WebSocket contract tests.
  • Adds structured logging as an opt-in API through pproxy.observability.

Performance

  • Removes duplicate timeout wrapping.
  • Avoids per-payload timeout/helper overhead in streaming hot paths.
  • Retains 256 KiB drain batching and UDP bookkeeping behavior.
  • Records repeated parser and loopback performance comparisons in docs/PERFORMANCE.md.

Final structural review against commit 8337a1b remained within the 5% proxy throughput gate:

  • HTTP loopback: 7030.8 -> 7046.9 req/s (+0.2%)
  • SOCKS5 loopback: 7404.2 -> 7497.1 req/s (+1.3%)
  • HTTP parser average: 30.26 -> 30.24 us (-0.1%)
  • WebSocket parser average: 26.66 -> 27.16 us (+1.9%)

Validation

  • 47 unittest contract cases pass under normal Python.
  • 47 unittest contract cases pass under python -O.
  • 47 pytest cases pass.
  • compileall passes.
  • Focused Ruff checks pass.
  • Clean detached-worktree wheel build includes protocol, transport, runtime, and observability subpackages.
  • Installed wheel CLI --version and -h checks pass.
  • Installed API import and facade identity checks pass.

Follow-up work

Further work can be handled separately after this compatibility-focused modernization, including expanded optional-backend integration coverage, deeper private asyncio/H2/H3/QUIC API isolation, and additional pyperf microbenchmarks after real workload profiling.

Review request

Please review this as an internal modernization and compatibility-preserving refactor. The intended merge strategy is squash merge into master.

by275 added 30 commits August 22, 2026 19:06
@by275
by275 merged commit 9f9f8bd into master Aug 22, 2026
12 checks passed
@by275
by275 deleted the modernize branch August 22, 2026 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant