feat: control API and Tor integration #1

Merged
username merged 9 commits from feat/control-api into main 2026-02-17 09:56:06 +00:00
Owner

Summary

  • Add built-in HTTP control API for runtime inspection and management (GET /status, /metrics, /pool, /config; POST /reload, /pool/test, /pool/refresh)
  • Add Tor control port client with NEWNYM support (password/cookie/bare auth, client-side rate limiting, periodic circuit rotation)
  • Add --tracemalloc [N] flag for memory profiling (orthogonal to --cprofile)

Changes

  • src/s5p/api.py -- lightweight asyncio HTTP handler, no new deps
  • src/s5p/tor.py -- async TCP client for Tor control protocol
  • src/s5p/cli.py -- --api, --tracemalloc flags
  • src/s5p/config.py -- api_host/api_port, TorConfig dataclass
  • src/s5p/server.py -- lifecycle wiring for API and Tor controller
  • 16 files changed, +1488 lines

Test plan

  • 113 tests pass (29 API + 15 Tor + existing)
  • ruff clean
  • Manual: --api flag, curl all endpoints
  • Manual: --tracemalloc output on shutdown
  • Manual: Tor NEWNYM via API
## Summary - Add built-in HTTP control API for runtime inspection and management (GET /status, /metrics, /pool, /config; POST /reload, /pool/test, /pool/refresh) - Add Tor control port client with NEWNYM support (password/cookie/bare auth, client-side rate limiting, periodic circuit rotation) - Add --tracemalloc [N] flag for memory profiling (orthogonal to --cprofile) ## Changes - `src/s5p/api.py` -- lightweight asyncio HTTP handler, no new deps - `src/s5p/tor.py` -- async TCP client for Tor control protocol - `src/s5p/cli.py` -- --api, --tracemalloc flags - `src/s5p/config.py` -- api_host/api_port, TorConfig dataclass - `src/s5p/server.py` -- lifecycle wiring for API and Tor controller - 16 files changed, +1488 lines ## Test plan - [x] 113 tests pass (29 API + 15 Tor + existing) - [x] ruff clean - [x] Manual: --api flag, curl all endpoints - [x] Manual: --tracemalloc output on shutdown - [x] Manual: Tor NEWNYM via API
username added 9 commits 2026-02-17 09:55:35 +00:00
Lightweight asyncio HTTP handler for runtime inspection and management.
Endpoints: /status, /metrics, /pool, /pool/alive, /config (GET) and
/reload, /pool/test, /pool/refresh (POST). Raw HTTP/1.1 parsing, JSON
responses, no new dependencies.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add api_host/api_port to Config dataclass, parse api_listen key in
load_config(), add --api [HOST:]PORT CLI flag. Start/stop API server
in serve() alongside the SOCKS5 listener.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
29 tests covering request parsing, JSON response format, all GET/POST
handlers with mock context, 404/405 error routing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add API section to README (features, CLI, config), PROJECT (architecture),
USAGE (full endpoint reference with examples), CHEATSHEET (curl one-liners).
Update TASKS and ROADMAP.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Async TCP client for the Tor control protocol (port 9051).
Supports password, cookie, and bare authentication. Provides
NEWNYM signaling with client-side 10s rate limiting and
optional periodic timer. Auto-reconnects on disconnect.

Adds TorConfig dataclass and YAML parsing to config module.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Start/stop TorController in serve() lifecycle when tor: config
is present. Adds GET /tor (status) and POST /tor/newnym (signal)
endpoints to the control API. Logs control address at startup.
Adds tor: section and api_listen to example config.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Covers: password/cookie/bare auth, auth failure, connect failure,
NEWNYM success/rate-limiting/reconnect, GETINFO multi-line parsing,
start/stop lifecycle, GET /tor status, POST /tor/newnym dispatch,
and TorConfig YAML parsing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds Tor control port section to USAGE.md covering config,
auth modes, rate limiting, and API endpoints. Updates README
feature line and config example, CHEATSHEET with tor snippets,
and marks the feature complete in TASKS.md and ROADMAP.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Uses Python's built-in tracemalloc module to show top N memory
allocators on exit. Orthogonal to --cprofile; both can run together.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
username merged commit e6c82ad3c0 into main 2026-02-17 09:56:06 +00:00
username deleted branch feat/control-api 2026-02-17 09:56:20 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: username/s5p#1