From 7cbe3b258d4941c0284a379d9ffab92feba69af9 Mon Sep 17 00:00:00 2001 From: Joseph Pollack Date: Thu, 13 Nov 2025 17:50:01 +0100 Subject: [PATCH] init --- ...etwork-disk-optimizations-1658c482.plan.md | 393 + .cursor/rules/bitTorrent-protocols.mdc | 181 +- .cursor/rules/cli-interface.mdc | 105 - .cursor/rules/development-patterns.mdc | 147 +- .cursor/rules/documentation-standards.mdc | 26 + .cursor/rules/project-structure.mdc | 27 + .cursor/rules/terminal_dashboard.mdc | 407 +- .cursor/rules/testing-patterns.mdc | 110 - .env.example | 334 + .github/ISSUE_TEMPLATE/bug_report.md | 58 + .github/ISSUE_TEMPLATE/compatibility_issue.md | 75 + .github/ISSUE_TEMPLATE/config.yml | 15 + .github/ISSUE_TEMPLATE/feature_request.md | 42 + .github/ISSUE_TEMPLATE/user_experience.md | 45 + .github/README.md | 77 + .github/release.yml | 40 + .github/workflows/benchmark.yml | 74 + .github/workflows/build.yml | 99 + .github/workflows/compatibility.yml | 88 + .github/workflows/deploy.yml | 98 + .github/workflows/docs.yml | 67 + .github/workflows/lint.yml | 61 + .github/workflows/pre-release.yml | 94 + .github/workflows/release.yml | 227 + .github/workflows/security.yml | 73 + .github/workflows/test.yml | 71 + .github/workflows/version-check.yml | 75 + .gitignore | 22 +- .pre-commit-config.yaml | 60 - .readthedocs.yaml | 0 CI_CD_IMPLEMENTATION_PLAN.md | 1711 ++ CI_CD_SETUP_STATUS.md | 129 + DAEMON_IMPLEMENTATION_ASSESSMENT.md | 253 + Makefile | 108 - README.md | 449 - ...c_file_writer.cpython-312-pytest-8.4.2.pyc | Bin 21888 -> 0 bytes .../test_async_file_writer.cpython-312.pyc | Bin 21775 -> 0 bytes ...comprehensive.cpython-312-pytest-8.4.2.pyc | Bin 25676 -> 0 bytes ..._file_writer_comprehensive.cpython-312.pyc | Bin 18234 -> 0 bytes ...ile_assembler.cpython-312-pytest-8.4.2.pyc | Bin 4557 -> 0 bytes ...gnosis_runner.cpython-312-pytest-8.4.2.pyc | Bin 15549 -> 0 bytes ...disk_io_fixed.cpython-312-pytest-8.4.2.pyc | Bin 3688 -> 0 bytes ...sk_io_manager.cpython-312-pytest-8.4.2.pyc | Bin 6294 -> 0 bytes ...isk_io_simple.cpython-312-pytest-8.4.2.pyc | Bin 4003 -> 0 bytes ...sk_io_timeout.cpython-312-pytest-8.4.2.pyc | Bin 6844 -> 0 bytes ...sembler_debug.cpython-312-pytest-8.4.2.pyc | Bin 9566 -> 0 bytes ...embler_simple.cpython-312-pytest-8.4.2.pyc | Bin 8598 -> 0 bytes ..._manager_fast.cpython-312-pytest-8.4.2.pyc | Bin 3114 -> 0 bytes ...imple_disk_io.cpython-312-pytest-8.4.2.pyc | Bin 5141 -> 0 bytes ...ile_assembler.cpython-312-pytest-8.4.2.pyc | Bin 8489 -> 0 bytes benchmarks/bench_disk.py | 426 - benchmarks/bench_hash_verification.py | 385 - benchmarks/bench_throughput.py | 309 - ccbt.toml | 247 + ccbt.toml copy.example | 382 + ccbt/__init__.py | 124 +- ccbt/__main__.py | 232 +- ccbt/__pycache__/__init__.cpython-312.pyc | Bin 6387 -> 0 bytes ccbt/__pycache__/__main__.cpython-312.pyc | Bin 9814 -> 0 bytes .../async_metadata_exchange.cpython-312.pyc | Bin 43495 -> 0 bytes .../async_peer_connection.cpython-312.pyc | Bin 44784 -> 0 bytes .../async_piece_manager.cpython-312.pyc | Bin 53938 -> 0 bytes ccbt/__pycache__/bencode.cpython-312.pyc | Bin 445 -> 0 bytes ccbt/__pycache__/buffers.cpython-312.pyc | Bin 20373 -> 0 bytes ccbt/__pycache__/checkpoint.cpython-312.pyc | Bin 37487 -> 0 bytes ccbt/__pycache__/config.cpython-312.pyc | Bin 19151 -> 0 bytes ccbt/__pycache__/dht.cpython-312.pyc | Bin 31063 -> 0 bytes ccbt/__pycache__/disk_io.cpython-312.pyc | Bin 42061 -> 0 bytes ccbt/__pycache__/events.cpython-312.pyc | Bin 28978 -> 0 bytes ccbt/__pycache__/exceptions.cpython-312.pyc | Bin 5600 -> 0 bytes .../file_assembler.cpython-312.pyc | Bin 26577 -> 0 bytes .../logging_config.cpython-312.pyc | Bin 9663 -> 0 bytes ccbt/__pycache__/magnet.cpython-312.pyc | Bin 5843 -> 0 bytes ccbt/__pycache__/metrics.cpython-312.pyc | Bin 15631 -> 0 bytes ccbt/__pycache__/models.cpython-312.pyc | Bin 30035 -> 0 bytes ccbt/__pycache__/peer.cpython-312.pyc | Bin 58044 -> 0 bytes .../peer_connection.cpython-312.pyc | Bin 35566 -> 0 bytes ccbt/__pycache__/pex.cpython-312.pyc | Bin 8635 -> 0 bytes .../__pycache__/piece_manager.cpython-312.pyc | Bin 17867 -> 0 bytes ccbt/__pycache__/session.cpython-312.pyc | Bin 69796 -> 0 bytes ccbt/__pycache__/torrent.cpython-312.pyc | Bin 10793 -> 0 bytes ccbt/__pycache__/tracker.cpython-312.pyc | Bin 31147 -> 0 bytes .../tracker_server_http.cpython-312.pyc | Bin 5293 -> 0 bytes .../tracker_udp_client.cpython-312.pyc | Bin 25362 -> 0 bytes ccbt/async_main.py | 11 +- ccbt/cli/__pycache__/__init__.cpython-312.pyc | Bin 620 -> 0 bytes .../advanced_commands.cpython-312.pyc | Bin 13704 -> 0 bytes .../config_commands.cpython-312.pyc | Bin 10767 -> 0 bytes .../__pycache__/interactive.cpython-312.pyc | Bin 64387 -> 0 bytes ccbt/cli/__pycache__/main.cpython-312.pyc | Bin 66977 -> 0 bytes .../monitoring_commands.cpython-312.pyc | Bin 16056 -> 0 bytes ccbt/cli/__pycache__/progress.cpython-312.pyc | Bin 12737 -> 0 bytes ccbt/cli/advanced_commands.py | 246 +- ccbt/cli/checkpoints.py | 189 + ccbt/cli/config_commands.py | 208 +- ccbt/cli/config_commands_extended.py | 496 +- ccbt/cli/config_utils.py | 316 + ccbt/cli/console.py | 84 + ccbt/cli/create_torrent.py | 280 + ccbt/cli/daemon_commands.py | 700 + ccbt/cli/diagnostics.py | 303 + ccbt/cli/downloads.py | 519 + ccbt/cli/file_commands.py | 355 + ccbt/cli/filter_commands.py | 424 + ccbt/cli/interactive.py | 1294 +- ccbt/cli/ipfs_commands.py | 392 + ccbt/cli/main.py | 1340 +- ccbt/cli/monitoring_commands.py | 76 +- ccbt/cli/monitoring_utils.py | 21 + ccbt/cli/nat_commands.py | 373 + ccbt/cli/overrides.py | 408 + ccbt/cli/progress.py | 46 +- ccbt/cli/proxy_commands.py | 350 + ccbt/cli/queue_commands.py | 408 + ccbt/cli/resume.py | 69 + ccbt/cli/scrape_commands.py | 171 + ccbt/cli/ssl_commands.py | 537 + ccbt/cli/status.py | 240 + ccbt/cli/utp_commands.py | 293 + ccbt/cli/xet_commands.py | 481 + ccbt/config/config.py | 501 +- ccbt/config/config_backup.py | 30 +- ccbt/config/config_capabilities.py | 264 +- ccbt/config/config_conditional.py | 16 +- ccbt/config/config_diff.py | 42 +- ccbt/config/config_migration.py | 10 + ccbt/config/config_schema.py | 44 +- ccbt/config/config_templates.py | 455 +- ccbt/core/bencode.py | 22 +- ccbt/core/magnet.py | 403 +- ccbt/core/torrent.py | 206 +- ccbt/core/torrent_attributes.py | 309 + ccbt/core/torrent_v2.py | 1772 ++ ccbt/daemon/__init__.py | 17 + ccbt/daemon/daemon_manager.py | 707 + ccbt/daemon/debug_utils.py | 181 + ccbt/daemon/ipc_client.py | 1575 ++ ccbt/daemon/ipc_protocol.py | 373 + ccbt/daemon/ipc_server.py | 2455 ++ ccbt/daemon/main.py | 977 + ccbt/daemon/state_manager.py | 461 + ccbt/daemon/state_models.py | 119 + ccbt/daemon/utils.py | 83 + ccbt/discovery/dht.py | 78 +- ccbt/discovery/dht_indexing.py | 465 + ccbt/discovery/dht_ipv6.py | 211 + ccbt/discovery/dht_multiaddr.py | 399 + ccbt/discovery/dht_readonly.py | 68 + ccbt/discovery/dht_storage.py | 491 + ccbt/discovery/pex.py | 238 +- ccbt/discovery/tracker.py | 1638 +- ccbt/discovery/tracker_server_http.py | 6 +- ccbt/discovery/tracker_server_udp.py | 10 +- ccbt/discovery/tracker_udp_client.py | 2250 +- ccbt/discovery/xet_cas.py | 736 + ccbt/executor/__init__.py | 33 + ccbt/executor/base.py | 94 + ccbt/executor/config_executor.py | 54 + ccbt/executor/executor.py | 84 + ccbt/executor/file_executor.py | 103 + ccbt/executor/manager.py | 287 + ccbt/executor/nat_executor.py | 154 + ccbt/executor/protocol_executor.py | 76 + ccbt/executor/queue_executor.py | 108 + ccbt/executor/registry.py | 62 + ccbt/executor/scrape_executor.py | 75 + ccbt/executor/security_executor.py | 256 + ccbt/executor/session_adapter.py | 1900 ++ ccbt/executor/session_executor.py | 46 + ccbt/executor/torrent_executor.py | 239 + .../__pycache__/__init__.cpython-312.pyc | Bin 817 -> 0 bytes .../__pycache__/compact.cpython-312.pyc | Bin 12440 -> 0 bytes .../__pycache__/dht.cpython-312.pyc | Bin 24023 -> 0 bytes .../__pycache__/fast.cpython-312.pyc | Bin 12494 -> 0 bytes .../__pycache__/pex.cpython-312.pyc | Bin 14478 -> 0 bytes .../__pycache__/protocol.cpython-312.pyc | Bin 12621 -> 0 bytes .../__pycache__/webseed.cpython-312.pyc | Bin 15382 -> 0 bytes ccbt/extensions/compact.py | 22 +- ccbt/extensions/dht.py | 58 +- ccbt/extensions/fast.py | 28 +- ccbt/extensions/manager.py | 227 +- ccbt/extensions/pex.py | 16 +- ccbt/extensions/protocol.py | 24 +- ccbt/extensions/ssl.py | 339 + ccbt/extensions/webseed.py | 124 +- ccbt/extensions/xet.py | 335 + ccbt/i18n/__init__.py | 135 + ccbt/i18n/extract.py | 82 + ccbt/i18n/fill_english.py | 30 + ccbt/i18n/locales/arc/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/en/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/es/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/eu/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/fa/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/fr/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/ha/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/hi/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/ja/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/ko/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/sw/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/th/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/locales/ur/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/yo/LC_MESSAGES/ccbt.po | 845 + ccbt/i18n/locales/zh/LC_MESSAGES/ccbt.po | 844 + ccbt/i18n/manager.py | 39 + ccbt/i18n/scripts/README.md | 255 + .../scripts/add_rich_markup_translations.py | 91 + ccbt/i18n/scripts/check_completeness.py | 84 + ccbt/i18n/scripts/check_coverage.py | 53 + ccbt/i18n/scripts/compile_all.py | 101 + .../scripts/comprehensive_translations.py | 1242 + ccbt/i18n/scripts/extract.py | 92 + ccbt/i18n/scripts/fill_english.py | 25 + .../scripts/generate_african_translations.py | 1129 + .../generate_hi_ur_fa_arc_translations.py | 1357 ++ ccbt/i18n/scripts/generate_translations.py | 698 + ccbt/i18n/scripts/translation_workflow.py | 215 + ccbt/i18n/scripts/validate_po.py | 111 + ccbt/interface/__init__.py | 3 +- ccbt/interface/commands/__init__.py | 7 + ccbt/interface/commands/executor.py | 311 + ccbt/interface/daemon_session_adapter.py | 510 + ccbt/interface/screens/__init__.py | 19 + ccbt/interface/screens/base.py | 434 + ccbt/interface/screens/config/__init__.py | 24 + .../interface/screens/config/global_config.py | 1559 ++ ccbt/interface/screens/config/proxy.py | 423 + ccbt/interface/screens/config/ssl.py | 596 + .../screens/config/torrent_config.py | 1454 ++ ccbt/interface/screens/config/utp.py | 424 + ccbt/interface/screens/config/widgets.py | 174 + ccbt/interface/screens/dialogs.py | 866 + ccbt/interface/screens/monitoring/__init__.py | 39 + ccbt/interface/screens/monitoring/alerts.py | 221 + .../screens/monitoring/disk_analysis.py | 363 + ccbt/interface/screens/monitoring/disk_io.py | 295 + .../screens/monitoring/historical.py | 208 + ccbt/interface/screens/monitoring/ipfs.py | 543 + .../screens/monitoring/metrics_explorer.py | 383 + ccbt/interface/screens/monitoring/nat.py | 533 + ccbt/interface/screens/monitoring/network.py | 290 + .../screens/monitoring/performance.py | 282 + .../monitoring/performance_analysis.py | 333 + ccbt/interface/screens/monitoring/queue.py | 284 + ccbt/interface/screens/monitoring/scrape.py | 248 + .../screens/monitoring/system_resources.py | 155 + ccbt/interface/screens/monitoring/tracker.py | 267 + ccbt/interface/screens/monitoring/xet.py | 440 + ccbt/interface/screens/utility/__init__.py | 8 + .../screens/utility/file_selection.py | 334 + ccbt/interface/screens/utility/help.py | 166 + ccbt/interface/screens/utility/navigation.py | 200 + ccbt/interface/terminal_dashboard.py | 2178 +- ccbt/interface/widgets/__init__.py | 25 + ccbt/interface/widgets/core_widgets.py | 224 + ccbt/interface/widgets/reusable_widgets.py | 145 + ccbt/ml/adaptive_limiter.py | 4 + ccbt/ml/peer_selector.py | 6 +- ccbt/ml/piece_predictor.py | 4 + ccbt/models.py | 1595 +- ccbt/monitoring/__init__.py | 235 + .../__pycache__/__init__.cpython-312.pyc | Bin 1161 -> 0 bytes .../__pycache__/alert_manager.cpython-312.pyc | Bin 31154 -> 0 bytes .../__pycache__/dashboard.cpython-312.pyc | Bin 29573 -> 0 bytes .../metrics_collector.cpython-312.pyc | Bin 30747 -> 0 bytes .../terminal_dashboard.cpython-312.pyc | Bin 57703 -> 0 bytes .../__pycache__/tracing.cpython-312.pyc | Bin 20523 -> 0 bytes ccbt/monitoring/alert_manager.py | 72 +- ccbt/monitoring/dashboard.py | 219 +- ccbt/monitoring/metrics_collector.py | 710 +- ccbt/monitoring/tracing.py | 3 + ccbt/nat/__init__.py | 10 + ccbt/nat/exceptions.py | 13 + ccbt/nat/manager.py | 1120 + ccbt/nat/natpmp.py | 455 + ccbt/nat/port_mapping.py | 324 + ccbt/nat/upnp.py | 1129 + .../__pycache__/__init__.cpython-312.pyc | Bin 497 -> 0 bytes .../__pycache__/profiler.cpython-312.pyc | Bin 18711 -> 0 bytes ccbt/peer/async_peer_connection.py | 4973 +++- ccbt/peer/connection_pool.py | 775 +- ccbt/peer/peer.py | 271 +- ccbt/peer/peer_connection.py | 662 +- ccbt/peer/ssl_peer.py | 453 + ccbt/peer/tcp_server.py | 362 + ccbt/peer/utp_peer.py | 403 + ccbt/peer/webrtc_peer.py | 302 + ccbt/piece/async_metadata_exchange.py | 453 +- ccbt/piece/async_piece_manager.py | 2519 +- ccbt/piece/file_selection.py | 441 + ccbt/piece/hash_v2.py | 755 + ccbt/piece/metadata_exchange.py | 47 +- ccbt/plugins/__init__.py | 4 +- .../__pycache__/__init__.cpython-312.pyc | Bin 502 -> 0 bytes ccbt/plugins/__pycache__/base.cpython-312.pyc | Bin 18121 -> 0 bytes .../logging_plugin.cpython-312.pyc | Bin 5630 -> 0 bytes ccbt/plugins/base.py | 24 + ccbt/protocols/__init__.py | 22 +- .../__pycache__/__init__.cpython-312.pyc | Bin 743 -> 0 bytes .../__pycache__/base.cpython-312.pyc | Bin 30830 -> 0 bytes .../__pycache__/bittorrent.cpython-312.pyc | Bin 11238 -> 0 bytes .../__pycache__/hybrid.cpython-312.pyc | Bin 19765 -> 0 bytes .../__pycache__/ipfs.cpython-312.pyc | Bin 18131 -> 0 bytes .../__pycache__/webtorrent.cpython-312.pyc | Bin 22025 -> 0 bytes ccbt/protocols/base.py | 27 +- ccbt/protocols/bittorrent.py | 275 +- ccbt/protocols/bittorrent_v2.py | 1288 + ccbt/protocols/hybrid.py | 75 +- ccbt/protocols/ipfs.py | 1716 +- ccbt/protocols/webtorrent.py | 1044 +- ccbt/protocols/webtorrent/__init__.py | 48 + ccbt/protocols/webtorrent/webrtc_manager.py | 487 + ccbt/protocols/xet.py | 863 + ccbt/proxy/__init__.py | 23 + ccbt/proxy/auth.py | 270 + ccbt/proxy/client.py | 595 + ccbt/proxy/exceptions.py | 23 + ccbt/queue/__init__.py | 6 + ccbt/queue/bandwidth.py | 204 + ccbt/queue/manager.py | 808 + ccbt/security/__init__.py | 4 + .../__pycache__/__init__.cpython-312.pyc | Bin 878 -> 0 bytes .../anomaly_detector.cpython-312.pyc | Bin 22150 -> 0 bytes .../__pycache__/encryption.cpython-312.pyc | Bin 16583 -> 0 bytes .../peer_validator.cpython-312.pyc | Bin 13677 -> 0 bytes .../__pycache__/rate_limiter.cpython-312.pyc | Bin 19700 -> 0 bytes .../security_manager.cpython-312.pyc | Bin 21164 -> 0 bytes ccbt/security/anomaly_detector.py | 5 +- ccbt/security/ciphers/__init__.py | 19 + ccbt/security/ciphers/aes.py | 102 + ccbt/security/ciphers/base.py | 47 + ccbt/security/ciphers/chacha20.py | 100 + ccbt/security/ciphers/rc4.py | 101 + ccbt/security/dh_exchange.py | 188 + ccbt/security/ed25519_handshake.py | 184 + ccbt/security/encrypted_stream.py | 142 + ccbt/security/encryption.py | 324 +- ccbt/security/ip_filter.py | 711 + ccbt/security/key_manager.py | 436 + ccbt/security/messaging.py | 276 + ccbt/security/mse_handshake.py | 591 + ccbt/security/peer_validator.py | 112 +- ccbt/security/rate_limiter.py | 41 +- ccbt/security/security_manager.py | 107 +- ccbt/security/ssl_context.py | 472 + ccbt/security/tls_certificates.py | 268 + .../__pycache__/__init__.cpython-312.pyc | Bin 772 -> 0 bytes .../services/__pycache__/base.cpython-312.pyc | Bin 17401 -> 0 bytes .../__pycache__/peer_service.cpython-312.pyc | Bin 13214 -> 0 bytes .../storage_service.cpython-312.pyc | Bin 15940 -> 0 bytes .../tracker_service.cpython-312.pyc | Bin 14266 -> 0 bytes ccbt/services/base.py | 13 +- ccbt/services/peer_service.py | 57 +- ccbt/services/storage_service.py | 284 +- ccbt/services/tracker_service.py | 95 +- ccbt/session/__init__.py | 6 +- ccbt/session/adapters.py | 86 + ccbt/session/announce.py | 482 + ccbt/session/async_main.py | 555 +- ccbt/session/checkpoint_operations.py | 264 + ccbt/session/checkpointing.py | 496 + ccbt/session/dht_setup.py | 1272 + ccbt/session/discovery.py | 52 + ccbt/session/download_manager.py | 681 + ccbt/session/download_startup.py | 448 + ccbt/session/factories.py | 122 + ccbt/session/fast_resume.py | 296 + ccbt/session/incoming.py | 170 + ccbt/session/lifecycle.py | 29 + ccbt/session/magnet_handling.py | 75 + ccbt/session/manager_background.py | 73 + ccbt/session/manager_startup.py | 940 + ccbt/session/metrics_status.py | 240 + ccbt/session/models.py | 39 + ccbt/session/peer_events.py | 48 + ccbt/session/peers.py | 641 + ccbt/session/scrape.py | 235 + ccbt/session/session.py | 942 +- ccbt/session/status_aggregation.py | 144 + ccbt/session/tasks.py | 39 + ccbt/session/torrent_addition.py | 552 + ccbt/session/torrent_utils.py | 341 + ccbt/session/types.py | 105 + ccbt/storage/__init__.py | 10 + ccbt/storage/buffers.py | 11 + ccbt/storage/checkpoint.py | 272 +- ccbt/storage/disk_io.py | 1130 +- ccbt/storage/disk_io_init.py | 215 + ccbt/storage/file_assembler.py | 464 +- ccbt/storage/resume_data.py | 280 + ccbt/storage/xet_chunking.py | 540 + ccbt/storage/xet_deduplication.py | 547 + ccbt/storage/xet_hashing.py | 223 + ccbt/storage/xet_shard.py | 408 + ccbt/storage/xet_xorb.py | 455 + ccbt/transport/__init__.py | 7 + ccbt/transport/utp.py | 1874 ++ ccbt/transport/utp_extensions.py | 388 + ccbt/transport/utp_socket.py | 568 + ccbt/utils/backoff.py | 26 + ccbt/utils/bitfield.py | 28 + ccbt/utils/console_utils.py | 230 + ccbt/utils/dht_utils.py | 34 + ccbt/utils/di.py | 63 + ccbt/utils/events.py | 45 +- ccbt/utils/logging_config.py | 227 +- ccbt/utils/metadata_utils.py | 27 + ccbt/utils/metrics.py | 39 +- ccbt/utils/network_optimizer.py | 169 +- ccbt/utils/port_checker.py | 184 + ccbt/utils/resilience.py | 132 +- ccbt/utils/rich_logging.py | 298 + ccbt/utils/tasks.py | 40 + ccbt/utils/time.py | 18 + ccbt/utils/tracker_utils.py | 24 + .codecov.yml => dev/.codecov.yml | 37 + dev/Dockerfile.test | 30 + dev/benchmarks.toml | 36 + dev/docker-compose.test.yml | 107 + dev/mkdocs.yml | 178 + dev/pre-commit-config.yaml | 110 + pytest.ini => dev/pytest.ini | 17 +- ruff.toml => dev/ruff.toml | 80 +- ty.toml => dev/ty.toml | 22 +- docs/API.md | 2380 +- docs/CI_CD.md | 465 + docs/CLI_PROTOCOL_VIOLATIONS.md | 153 + docs/README_PyPI.md | 113 + docs/RELEASE_CHECKLIST.md | 110 + docs/analysis/protocol-patterns-analysis.md | 168 + docs/architecture.md | 508 +- docs/bep52.md | 564 + docs/bep_xet.md | 418 + docs/bitonic.md | 2003 ++ docs/btbt-cli.md | 574 + docs/ccBT-RAIL.md | 175 + docs/checkpoints.md | 26 - docs/cli-reference.md | 37 - docs/configuration.md | 317 +- docs/contributing.md | 228 + docs/daemon-authentication-verification.md | 157 + docs/daemon-cli-authentication-flow.md | 246 + docs/daemon-implementation-plan.md | 545 + docs/dashboard-guide.md | 224 - docs/debugging-daemon-exit.md | 125 + docs/developer/di.md | 26 + docs/examples.md | 77 + docs/examples/bep52/create_hybrid_torrent.py | 183 + docs/examples/bep52/create_v2_torrent.py | 125 + docs/examples/bep52/parse_v2_torrent.py | 218 + docs/examples/bep52/protocol_v2_session.py | 306 + docs/funding.md | 85 + docs/getting-started.md | 163 +- docs/includes/mkdocs.md | 4 + docs/index.md | 512 +- docs/license.md | 563 + docs/monitoring.md | 41 - docs/performance.md | 467 +- .../encryption_benchmark_report.md | 237 + .../runs/disk_io-20251112-191716-a9c4027.json | 81 + .../runs/disk_io-20251112-191742-a9c4027.json | 81 + .../runs/disk_io-20251112-191743-a9c4027.json | 81 + .../encryption-20251112-191730-a9c4027.json | 243 + .../encryption-20251112-191745-a9c4027.json | 243 + .../encryption-20251112-191746-a9c4027.json | 243 + .../encryption-20251112-191747-a9c4027.json | 243 + .../encryption-20251112-191748-a9c4027.json | 243 + .../encryption-20251112-191750-a9c4027.json | 243 + .../encryption-20251112-191759-a9c4027.json | 243 + .../encryption-20251112-191800-a9c4027.json | 243 + .../hash_verify-20251112-191707-a9c4027.json | 42 + .../hash_verify-20251112-191741-a9c4027.json | 42 + .../hash_verify-20251112-191754-a9c4027.json | 42 + .../hash_verify-20251112-191755-a9c4027.json | 42 + .../hash_verify-20251112-191756-a9c4027.json | 42 + .../hash_verify-20251112-191758-a9c4027.json | 42 + .../hash_verify-20251112-191805-a9c4027.json | 42 + .../hash_verify-20251112-191806-a9c4027.json | 42 + ...ck_throughput-20251112-191721-a9c4027.json | 29 + ...ck_throughput-20251112-191742-a9c4027.json | 29 + ...ck_throughput-20251112-191749-a9c4027.json | 29 + ...ck_throughput-20251112-191755-a9c4027.json | 29 + ...ck_throughput-20251112-191756-a9c4027.json | 29 + ...ck_throughput-20251112-191757-a9c4027.json | 29 + ...ck_throughput-20251112-191800-a9c4027.json | 29 + ...ck_throughput-20251112-191807-a9c4027.json | 29 + ...ck_throughput-20251112-191808-a9c4027.json | 29 + ...iece_assembly-20251112-191719-a9c4027.json | 28 + ...iece_assembly-20251112-191745-a9c4027.json | 28 + ...iece_assembly-20251112-191751-a9c4027.json | 28 + ...iece_assembly-20251112-191758-a9c4027.json | 28 + ...iece_assembly-20251112-191759-a9c4027.json | 28 + ...iece_assembly-20251112-191800-a9c4027.json | 28 + ...iece_assembly-20251112-191802-a9c4027.json | 28 + ...iece_assembly-20251112-191808-a9c4027.json | 28 + ...iece_assembly-20251112-191809-a9c4027.json | 28 + docs/reports/coverage.md | 16 + docs/reports/junit.xml | 1 + docs/unimplemented-methods.md | 318 + env.example | 259 +- mkdocs.yml | 123 - pyproject.toml | 134 +- ruff-report.json | 19524 ---------------- scripts/socket_test.py | 22 + tests/__pycache__/__init__.cpython-312.pyc | Bin 151 -> 0 bytes .../conftest.cpython-312-pytest-8.4.2.pyc | Bin 5337 -> 0 bytes ...er_connection.cpython-312-pytest-8.4.2.pyc | Bin 43308 -> 0 bytes ...basic_imports.cpython-312-pytest-8.4.2.pyc | Bin 20201 -> 0 bytes .../test_bencode.cpython-312-pytest-8.4.2.pyc | Bin 39144 -> 0 bytes ...st_checkpoint.cpython-312-pytest-8.4.2.pyc | Bin 45290 -> 0 bytes .../test_disk_io.cpython-312-pytest-8.4.2.pyc | Bin 34738 -> 0 bytes ...embler_blocks.cpython-312-pytest-8.4.2.pyc | Bin 5534 -> 0 bytes .../test_magnet.cpython-312-pytest-8.4.2.pyc | Bin 7936 -> 0 bytes ...llel_metadata.cpython-312-pytest-8.4.2.pyc | Bin 27190 -> 0 bytes .../test_peer.cpython-312-pytest-8.4.2.pyc | Bin 117168 -> 0 bytes ...er_connection.cpython-312-pytest-8.4.2.pyc | Bin 81320 -> 0 bytes ...piece_manager.cpython-312-pytest-8.4.2.pyc | Bin 69829 -> 0 bytes .../test_piece_manager.cpython-312.pyc | Bin 161 -> 0 bytes ..._rarest_first.cpython-312-pytest-8.4.2.pyc | Bin 28085 -> 0 bytes ...functionality.cpython-312-pytest-8.4.2.pyc | Bin 57981 -> 0 bytes .../test_torrent.cpython-312-pytest-8.4.2.pyc | Bin 29838 -> 0 bytes .../test_tracker.cpython-312-pytest-8.4.2.pyc | Bin 30781 -> 0 bytes ...r_server_http.cpython-312-pytest-8.4.2.pyc | Bin 1570 -> 0 bytes .../__pycache__/__init__.cpython-312.pyc | Bin 305 -> 0 bytes ...ult_injection.cpython-312-pytest-8.4.2.pyc | Bin 31079 -> 0 bytes ...njection.cpython-312-pytest-8.4.2.pyc.1820 | Bin 16 -> 0 bytes tests/chaos/test_fault_injection.py | 59 +- ...ed_checkpoint.cpython-312-pytest-8.4.2.pyc | Bin 2889 -> 0 bytes ...nced_commands.cpython-312-pytest-8.4.2.pyc | Bin 46169 -> 0 bytes ...nfig_commands.cpython-312-pytest-8.4.2.pyc | Bin 58011 -> 0 bytes ...anced_options.cpython-312-pytest-8.4.2.pyc | Bin 3489 -> 0 bytes ...tive_enhanced.cpython-312-pytest-8.4.2.pyc | Bin 4785 -> 0 bytes ...sume_commands.cpython-312-pytest-8.4.2.pyc | Bin 17957 -> 0 bytes ...est_advanced_commands_expanded_coverage.py | 335 + tests/cli/test_bep52_cli.py | 447 + tests/cli/test_config_commands_expanded.py | 1194 + .../test_config_commands_expanded_coverage.py | 545 + .../test_config_commands_extended_coverage.py | 237 + tests/cli/test_config_commands_safeguard.py | 342 + tests/cli/test_create_torrent.py | 229 + tests/cli/test_entry_points.py | 11 +- tests/cli/test_file_commands.py | 939 + tests/cli/test_file_commands_coverage.py | 254 + tests/cli/test_filter_commands.py | 806 + tests/cli/test_filter_commands_coverage.py | 124 + ...test_interactive_commands_comprehensive.py | 1643 ++ tests/cli/test_interactive_comprehensive.py | 1298 + tests/cli/test_interactive_coverage.py | 201 + ...est_interactive_download_file_selection.py | 338 + tests/cli/test_interactive_expanded.py | 760 + .../cli/test_interactive_expanded_coverage.py | 363 + tests/cli/test_interactive_file_selection.py | 872 + tests/cli/test_interactive_final_coverage.py | 287 + tests/cli/test_interactive_runloop.py | 166 + tests/cli/test_main_checkpoints_resume.py | 388 + tests/cli/test_main_coverage_gaps.py | 304 + tests/cli/test_main_deep_paths.py | 413 + tests/cli/test_main_entry.py | 1100 +- tests/cli/test_main_error_paths.py | 197 + tests/cli/test_main_focus.py | 298 + tests/cli/test_main_magnet_coverage.py | 35 + tests/cli/test_main_more.py | 155 + tests/cli/test_main_more_topup.py | 97 + tests/cli/test_main_options_matrix.py | 199 + tests/cli/test_main_overrides.py | 914 + tests/cli/test_main_resume_save_verify.py | 401 + tests/cli/test_main_topup.py | 297 + tests/cli/test_monitoring_commands.py | 181 + tests/cli/test_nat_commands.py | 785 + tests/cli/test_proxy_commands.py | 277 + .../cli/test_proxy_commands_comprehensive.py | 255 + tests/cli/test_queue_commands.py | 436 + .../cli/test_queue_commands_comprehensive.py | 704 + tests/cli/test_scrape_commands.py | 391 + tests/cli/test_ssl_commands.py | 614 + tests/cli/test_ssl_commands_coverage.py | 111 + tests/cli/test_status_scrape_display.py | 413 + tests/cli/test_utp_commands.py | 443 + tests/cli/test_utp_config_integration.py | 193 + tests/config/test_config_backup_expanded.py | 572 + tests/config/test_config_capabilities.py | 404 +- tests/config/test_config_conditional.py | 272 + tests/config/test_config_coverage.py | 210 + tests/config/test_config_edge_cases.py | 290 + tests/config/test_config_expanded.py | 483 + tests/config/test_config_migration.py | 288 + tests/config/test_config_schema.py | 285 + tests/config/test_config_validation.py | 150 +- tests/conftest.py | 377 +- tests/core/test_torrent_edge_cases.py | 96 + tests/daemon/__init__.py | 2 + tests/daemon/test_daemon_manager.py | 101 + tests/daemon/test_daemon_metrics.py | 244 + tests/daemon/test_executor_ipc_alignment.py | 450 + tests/daemon/test_ipc_auth.py | 152 + tests/daemon/test_ipc_authentication.py | 210 + tests/daemon/test_ipc_ed25519_auth.py | 96 + tests/daemon/test_ipc_metrics.py | 155 + tests/daemon/test_state_manager.py | 208 + tests/daemon/test_websocket.py | 156 + .../__pycache__/__init__.cpython-312.pyc | Bin 405 -> 0 bytes ...ct_peer_lists.cpython-312-pytest-8.4.2.pyc | Bin 74432 -> 0 bytes ...ast_extension.cpython-312-pytest-8.4.2.pyc | Bin 53455 -> 0 bytes .../test_dht_extension_comprehensive.py | 621 + .../__pycache__/__init__.cpython-312.pyc | Bin 298 -> 0 bytes ...st_end_to_end.cpython-312-pytest-8.4.2.pyc | Bin 39109 -> 0 bytes ..._end_enhanced.cpython-312-pytest-8.4.2.pyc | Bin 12510 -> 0 bytes .../test_resume.cpython-312-pytest-8.4.2.pyc | Bin 23868 -> 0 bytes ...e_integration.cpython-312-pytest-8.4.2.pyc | Bin 20615 -> 0 bytes tests/integration/test_bep47_attributes.py | 417 + tests/integration/test_bittorrent_v2_e2e.py | 715 + .../test_bittorrent_v2_protocol.py | 659 + .../test_connection_pool_integration.py | 147 + .../test_dht_enhancements_integration.py | 823 + .../test_disk_io_phase2_integration.py | 408 + .../integration/test_early_peer_acceptance.py | 272 + tests/integration/test_ed25519_integration.py | 102 + tests/integration/test_encryption_chacha20.py | 190 + .../test_encryption_integration.py | 461 + tests/integration/test_end_to_end.py | 12 + tests/integration/test_end_to_end_enhanced.py | 1 + .../test_fast_resume_integration.py | 480 + tests/integration/test_file_selection_e2e.py | 592 + .../test_ipfs_protocol_integration.py | 504 + tests/integration/test_magnet_bep53.py | 387 + tests/integration/test_nat_integration.py | 204 + .../test_network_optimizations_phase1.py | 295 + tests/integration/test_private_torrents.py | 299 + tests/integration/test_prometheus_endpoint.py | 262 + tests/integration/test_proxy_integration.py | 332 + tests/integration/test_queue_management.py | 456 + tests/integration/test_resume.py | 34 +- tests/integration/test_resume_integration.py | 3 + tests/integration/test_scrape_e2e.py | 308 + tests/integration/test_scrape_integration.py | 490 + tests/integration/test_session_metrics.py | 233 + .../test_session_metrics_edge_cases.py | 179 + tests/integration/test_session_scrape.py | 260 + tests/integration/test_ssl_extension.py | 318 + .../test_status_scrape_integration.py | 254 + tests/integration/test_storage_disk_io.py | 116 + tests/integration/test_webtorrent_e2e.py | 466 + tests/integration/test_xet_integration.py | 719 + .../transport/test_utp_compatibility.py | 170 + .../transport/test_utp_full_handshake.py | 324 + .../transport/test_utp_performance.py | 194 + tests/ml/test_peer_selector.py | 8 +- ...est_dashboard.cpython-312-pytest-8.4.2.pyc | Bin 5553 -> 0 bytes ...onitoring_cli.cpython-312-pytest-8.4.2.pyc | Bin 5265 -> 0 bytes .../test_alert_manager_comprehensive.py | 1949 ++ .../test_dashboard_comprehensive.py | 812 + tests/monitoring/test_dashboard_expanded.py | 760 + .../test_metrics_collector_comprehensive.py | 803 + .../test_metrics_collector_expanded.py | 443 + tests/monitoring/test_tracing_expanded.py | 738 + .../__pycache__/__init__.cpython-312.pyc | Bin 315 -> 0 bytes ...st_benchmarks.cpython-312-pytest-8.4.2.pyc | Bin 42945 -> 0 bytes tests/performance/bench_disk_io.py | 248 + tests/performance/bench_encryption.py | 1444 ++ tests/performance/bench_hash_verify.py | 192 + .../performance/bench_loopback_throughput.py | 171 + tests/performance/bench_piece_assembly.py | 161 + tests/performance/bench_utils.py | 345 + .../test_disk_io_phase2_benchmarks.py | 278 + .../test_encryption_performance.py | 363 + tests/performance/test_webrtc_performance.py | 428 + .../test_async_piece_manager_comprehensive.py | 862 + .../plugins/test_plugin_base_comprehensive.py | 687 + .../__pycache__/__init__.cpython-312.pyc | Bin 324 -> 0 bytes ...de_properties.cpython-312-pytest-8.4.2.pyc | Bin 41515 -> 0 bytes ...on_properties.cpython-312-pytest-8.4.2.pyc | Bin 35764 -> 0 bytes .../__pycache__/__init__.cpython-312.pyc | Bin 338 -> 0 bytes ...brid_protocol.cpython-312-pytest-8.4.2.pyc | Bin 62921 -> 0 bytes ...protocol_base.cpython-312-pytest-8.4.2.pyc | Bin 63201 -> 0 bytes tests/protocols/test_bittorrent_v2.py | 1319 ++ tests/protocols/test_hybrid_protocol.py | 139 +- tests/protocols/test_ipfs_connection.py | 236 + .../test_ipfs_protocol_comprehensive.py | 823 + .../test_protocol_base_comprehensive.py | 759 + tests/scripts/analyze_coverage.py | 383 + tests/scripts/bench_all.py | 68 + tests/scripts/ensure_bandit_dir.py | 24 + tests/scripts/fix_docs_links.py | 133 + tests/scripts/get_benchmark_markers.py | 196 + tests/scripts/get_dependent_modules.py | 264 + tests/scripts/get_test_markers.py | 116 +- tests/scripts/pre_push_validation.sh | 19 + tests/scripts/record_commit_benchmarks.py | 147 + tests/scripts/run_benchmarks_selective.py | 205 + tests/scripts/run_pytest_selective.py | 247 +- tests/scripts/test_aiortc_install.py | 45 + tests/scripts/upload_coverage.py | 145 + .../__pycache__/__init__.cpython-312.pyc | Bin 343 -> 0 bytes ...urity_manager.cpython-312-pytest-8.4.2.pyc | Bin 46908 -> 0 bytes tests/security/test_anomaly_detector.py | 932 + tests/security/test_ciphers.py | 268 + tests/security/test_ciphers_chacha20.py | 219 + tests/security/test_dh_exchange.py | 315 + tests/security/test_encrypted_stream.py | 404 + tests/security/test_encryption.py | 735 + tests/security/test_encryption_coverage.py | 521 + .../security/test_encryption_coverage_gaps.py | 378 + .../security/test_encryption_init_coverage.py | 32 + tests/security/test_ip_filter_coverage.py | 264 + .../security/test_ip_filter_coverage_final.py | 179 + .../security/test_ip_filter_coverage_gaps.py | 113 + tests/security/test_ip_filter_integration.py | 164 + tests/security/test_ip_filter_loading.py | 171 + tests/security/test_ip_filter_matching.py | 119 + tests/security/test_ip_filter_parsing.py | 97 + tests/security/test_ip_filter_rules.py | 145 + tests/security/test_key_manager.py | 120 + tests/security/test_mse_handshake.py | 1270 + tests/security/test_mse_handshake_coverage.py | 770 + tests/security/test_mse_handshake_pe.py | 212 + tests/security/test_rate_limiter.py | 1205 + .../test_rate_limiter_coverage_gaps.py | 399 + .../config/test_proxy_config_encryption.py | 245 + tests/unit/core/test_bencode.py | 22 + tests/unit/core/test_bep47_models.py | 159 + tests/unit/core/test_magnet_bep53.py | 673 + tests/unit/core/test_torrent_attributes.py | 565 + .../core/test_torrent_attributes_coverage.py | 160 + .../test_torrent_attributes_integration.py | 538 + tests/unit/core/test_torrent_coverage.py | 63 + tests/unit/core/test_torrent_v2.py | 2615 +++ tests/unit/discovery/__init__.py | 2 + .../unit/discovery/test_dht_comprehensive.py | 1111 + .../unit/discovery/test_dht_error_handling.py | 397 + tests/unit/discovery/test_dht_indexing.py | 633 + tests/unit/discovery/test_dht_ipv6.py | 394 + tests/unit/discovery/test_dht_ipv6_merging.py | 197 + tests/unit/discovery/test_dht_ipv6_parsing.py | 160 + tests/unit/discovery/test_dht_multiaddr.py | 542 + tests/unit/discovery/test_dht_readonly.py | 277 + tests/unit/discovery/test_dht_storage.py | 823 + tests/unit/discovery/test_dht_xet_chunks.py | 175 + .../unit/discovery/test_pex_comprehensive.py | 395 + tests/unit/discovery/test_pex_refresh.py | 239 + tests/unit/discovery/test_tracker_expanded.py | 1152 + .../discovery/test_tracker_peer_source.py | 125 + .../test_tracker_peer_source_direct.py | 54 + tests/unit/discovery/test_tracker_phase1.py | 265 + .../discovery/test_tracker_phase1_coverage.py | 108 + tests/unit/discovery/test_tracker_proxy.py | 218 + .../discovery/test_tracker_scrape_http.py | 740 + .../unit/discovery/test_tracker_scrape_udp.py | 358 + .../discovery/test_tracker_session_stats.py | 90 + tests/unit/discovery/test_tracker_ssl.py | 470 + .../discovery/test_tracker_udp_routing.py | 301 + tests/unit/discovery/test_xet_cas.py | 432 + tests/unit/disk/test_disk_io.py | 106 +- tests/unit/disk/test_disk_io_edge_cases.py | 746 + tests/unit/disk/test_disk_io_expanded.py | 143 +- .../unit/disk/test_disk_io_final_coverage.py | 236 + .../disk/test_disk_io_phase2_optimizations.py | 484 + .../disk/test_disk_io_remaining_coverage.py | 395 + .../executor/test_adapter_error_handling.py | 248 + tests/unit/extensions/test_fast_coverage.py | 67 + .../unit/extensions/test_webseed_coverage.py | 94 + tests/unit/extensions/test_webseed_proxy.py | 153 + tests/unit/i18n/test_i18n.py | 86 + .../unit/interface/test_monitoring_screens.py | 678 + .../unit/interface/test_terminal_dashboard.py | 125 + .../test_terminal_dashboard_basic.py | 125 + .../test_terminal_dashboard_widgets.py | 296 + .../test_metadata_exchange_complete.py | 361 + .../test_metadata_exchange_expanded.py | 498 + .../test_metrics_collector_coverage.py | 178 + .../monitoring/test_metrics_collector_http.py | 189 + ...st_metrics_collector_http_comprehensive.py | 211 + .../test_metrics_collector_http_coverage.py | 151 + .../test_metrics_collector_http_errors.py | 200 + ...t_metrics_collector_http_final_coverage.py | 172 + tests/unit/monitoring/test_metrics_helpers.py | 708 + .../test_metrics_helpers_edge_cases.py | 223 + tests/unit/nat/test_nat_manager.py | 719 + tests/unit/nat/test_natpmp.py | 411 + tests/unit/nat/test_port_mapping.py | 240 + tests/unit/nat/test_port_mapping_renewal.py | 745 + tests/unit/nat/test_upnp.py | 556 + tests/unit/network/test_connection_pool.py | 3 +- .../test_connection_pool_100_coverage.py | 216 + .../test_connection_pool_edge_cases.py | 290 + .../test_connection_pool_final_coverage.py | 165 + .../unit/network/test_connection_pool_gaps.py | 268 + .../network/test_connection_pool_phase1.py | 477 + .../test_connection_pool_phase1_coverage.py | 261 + tests/unit/network/test_network_optimizer.py | 9 +- .../test_network_optimizer_100_coverage.py | 301 + .../test_network_optimizer_comprehensive.py | 507 + .../network/test_network_optimizer_phase1.py | 220 + ...st_network_optimizer_remaining_coverage.py | 123 + tests/unit/peer/test_async_peer_connection.py | 5 +- ...est_async_peer_connection_coverage_gaps.py | 754 + ...st_async_peer_connection_error_handling.py | 616 + .../test_async_peer_connection_expanded.py | 3 +- ...sync_peer_connection_phase1_integration.py | 164 + .../peer/test_async_peer_pipelining_phase1.py | 257 + .../peer/test_async_peer_timeout_phase1.py | 120 + .../peer/test_connection_pool_creation.py | 469 + tests/unit/peer/test_peer.py | 1 + tests/unit/peer/test_peer_connection.py | 358 +- .../unit/peer/test_peer_connection_cleanup.py | 397 + .../peer/test_peer_connection_coverage.py | 715 + .../peer/test_peer_connection_encryption.py | 277 + .../test_peer_connection_error_handling.py | 269 + tests/unit/peer/test_peer_coverage_gaps.py | 1106 + .../unit/peer/test_peer_source_validation.py | 221 + .../unit/peer/test_ssl_extension_protocol.py | 1160 + tests/unit/peer/test_ssl_peer.py | 635 + tests/unit/peer/test_utp_peer_connection.py | 503 + tests/unit/peer/test_utp_peer_stream.py | 170 + tests/unit/peer/test_webrtc_peer.py | 596 + .../piece/test_async_metadata_expanded.py | 1093 + tests/unit/piece/test_async_piece_manager.py | 3 +- tests/unit/piece/test_file_selection.py | 637 + .../piece/test_file_selection_integration.py | 255 + tests/unit/piece/test_hash_v2.py | 408 + tests/unit/piece/test_hash_v2_coverage.py | 140 + .../piece/test_piece_manager_comprehensive.py | 360 + tests/unit/piece/test_sequential.py | 417 + .../plugins/test_plugin_manager_singleton.py | 84 + .../protocols/test_bittorrent_disconnect.py | 320 + .../unit/protocols/test_bittorrent_scrape.py | 349 + .../protocols/test_bittorrent_v2_upgrade.py | 542 + .../protocols/test_ipfs_content_discovery.py | 220 + .../protocols/test_ipfs_content_operations.py | 260 + .../protocols/test_ipfs_content_retrieval.py | 269 + .../protocols/test_ipfs_message_receiving.py | 210 + .../protocols/test_ipfs_message_sending.py | 241 + .../protocols/test_ipfs_torrent_conversion.py | 229 + tests/unit/protocols/test_protocols_init.py | 57 + tests/unit/protocols/test_webrtc_manager.py | 526 + .../protocols/test_webrtc_manager_complete.py | 332 + .../protocols/test_webrtc_manager_coverage.py | 166 + .../protocols/test_webtorrent_protocol.py | 586 + .../protocols/test_webtorrent_signaling.py | 442 + tests/unit/protocols/test_xet_protocol.py | 795 + tests/unit/proxy/__init__.py | 2 + tests/unit/proxy/conftest.py | 74 + tests/unit/proxy/test_auth_comprehensive.py | 292 + .../proxy/test_auth_coverage_additional.py | 203 + tests/unit/proxy/test_client_comprehensive.py | 351 + .../proxy/test_client_coverage_additional.py | 259 + tests/unit/proxy/test_proxy_auth.py | 390 + tests/unit/proxy/test_proxy_auth_coverage.py | 228 + tests/unit/proxy/test_proxy_bypass.py | 151 + tests/unit/proxy/test_proxy_client.py | 850 + .../unit/proxy/test_proxy_client_coverage.py | 288 + tests/unit/queue_mgmt/__init__.py | 2 + tests/unit/queue_mgmt/test_bandwidth.py | 469 + tests/unit/queue_mgmt/test_queue_manager.py | 945 + .../resilience/test_peer_circuit_breaker.py | 205 + .../test_resilience_additional_coverage.py | 213 + .../test_resilience_comprehensive.py | 557 + .../test_resilience_edge_cases_final.py | 364 + .../security/test_peer_validator_coverage.py | 119 + ...st_security_manager_additional_coverage.py | 80 + .../test_security_manager_coverage.py | 32 + tests/unit/security/test_ssl_context.py | 870 + tests/unit/services/conftest.py | 43 + .../unit/services/test_base_comprehensive.py | 574 + .../test_peer_service_comprehensive.py | 789 + tests/unit/services/test_storage_service.py | 1130 + .../services/test_storage_service_coverage.py | 158 + ...st_storage_service_write_implementation.py | 454 + tests/unit/services/test_tracker_service.py | 909 + .../services/test_tracker_service_coverage.py | 88 + .../unit/session/test_announce_controller.py | 67 + tests/unit/session/test_async_main.py | 1240 +- .../unit/session/test_async_main_coverage.py | 155 + tests/unit/session/test_async_main_metrics.py | 248 + .../test_async_main_metrics_coverage.py | 178 + .../test_async_main_missing_coverage.py | 60 + .../unit/session/test_async_tracker_client.py | 198 + .../session/test_checkpoint_controller.py | 63 + tests/unit/session/test_fast_resume.py | 867 + .../test_magnet_download_continuation.py | 342 + tests/unit/session/test_manager_startup.py | 82 + tests/unit/session/test_peer_initializer.py | 59 + tests/unit/session/test_pex_refresh.py | 99 + tests/unit/session/test_scrape_features.py | 1097 + .../test_session_admin_ops_extended.py | 318 + .../session/test_session_background_loops.py | 207 + .../session/test_session_checkpoint_ops.py | 178 + .../test_session_checkpoint_utilities.py | 467 + .../session/test_session_coverage_boost.py | 691 + tests/unit/session/test_session_edge_cases.py | 398 + .../test_session_error_paths_coverage.py | 816 + .../session/test_session_event_handlers.py | 223 + .../session/test_session_import_export.py | 85 + tests/unit/session/test_session_init.py | 73 + .../session/test_session_manager_coverage.py | 377 + .../test_session_manager_metrics_and_admin.py | 88 + .../session/test_session_missing_coverage.py | 331 + .../test_session_normalize_coverage.py | 114 + .../session/test_session_rehash_and_ops.py | 155 + .../test_session_remaining_coverage.py | 292 + .../session/test_session_resume_checkpoint.py | 319 + .../session/test_session_status_and_utils.py | 260 + .../unit/session/test_session_sync_methods.py | 121 + .../test_session_validate_checkpoint.py | 291 + tests/unit/session/test_task_supervisor.py | 24 + tests/unit/session/test_tracker_announce.py | 260 + .../storage/test_buffers_comprehensive.py | 694 + .../storage/test_checkpoint_edge_cases.py | 668 + .../unit/storage/test_checkpoint_expanded.py | 916 + .../storage/test_checkpoint_final_coverage.py | 215 + .../storage/test_disk_io_cleanup_paths.py | 295 + .../storage/test_disk_io_coverage_gaps.py | 308 + tests/unit/storage/test_disk_io_init.py | 414 + .../storage/test_disk_io_missing_coverage.py | 74 + .../storage/test_file_attributes_assembler.py | 483 + tests/unit/storage/test_resume_data.py | 557 + tests/unit/storage/test_xet_chunking.py | 322 + tests/unit/storage/test_xet_deduplication.py | 709 + tests/unit/storage/test_xet_hashing.py | 288 + tests/unit/storage/test_xet_shard.py | 518 + tests/unit/storage/test_xet_xorb.py | 492 + tests/unit/test_package_init.py | 189 + tests/unit/test_utils_bitfield.py | 20 + tests/unit/test_utils_di.py | 21 + tests/unit/tracker/test_tracker.py | 24 +- .../test_tracker_server_http_comprehensive.py | 337 + tests/unit/tracker/test_tracker_udp_client.py | 70 +- .../test_tracker_udp_client_comprehensive.py | 1013 + tests/unit/transport/__init__.py | 2 + tests/unit/transport/test_utp.py | 1881 ++ tests/unit/transport/test_utp_100_coverage.py | 882 + tests/unit/transport/test_utp_additional.py | 540 + .../transport/test_utp_additional_coverage.py | 1006 + .../unit/transport/test_utp_comprehensive.py | 556 + .../transport/test_utp_congestion_control.py | 287 + .../test_utp_connection_id_collision.py | 155 + tests/unit/transport/test_utp_delayed_ack.py | 250 + tests/unit/transport/test_utp_ecn.py | 254 + tests/unit/transport/test_utp_edge_cases.py | 237 + tests/unit/transport/test_utp_extensions.py | 301 + .../unit/transport/test_utp_final_coverage.py | 1220 + tests/unit/transport/test_utp_packet.py | 213 + .../transport/test_utp_passive_connections.py | 251 + .../unit/transport/test_utp_retransmission.py | 287 + tests/unit/transport/test_utp_sack.py | 348 + .../unit/transport/test_utp_window_scaling.py | 133 + tests/unit/utils/test_events_comprehensive.py | 879 + .../utils/test_exceptions_comprehensive.py | 220 + .../test_logging_config_comprehensive.py | 704 + .../unit/utils/test_metrics_comprehensive.py | 760 + uv | 0 uv.lock | 3198 ++- uv.toml | 5 - 952 files changed, 283357 insertions(+), 30586 deletions(-) create mode 100644 .cursor/plans/network-disk-optimizations-1658c482.plan.md delete mode 100644 .cursor/rules/cli-interface.mdc delete mode 100644 .cursor/rules/testing-patterns.mdc create mode 100644 .env.example create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/compatibility_issue.md create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/user_experience.md create mode 100644 .github/README.md create mode 100644 .github/release.yml create mode 100644 .github/workflows/benchmark.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/compatibility.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/pre-release.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/security.yml create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/version-check.yml delete mode 100644 .pre-commit-config.yaml create mode 100644 .readthedocs.yaml create mode 100644 CI_CD_IMPLEMENTATION_PLAN.md create mode 100644 CI_CD_SETUP_STATUS.md create mode 100644 DAEMON_IMPLEMENTATION_ASSESSMENT.md delete mode 100644 Makefile delete mode 100644 README.md delete mode 100644 __pycache__/test_async_file_writer.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_async_file_writer.cpython-312.pyc delete mode 100644 __pycache__/test_async_file_writer_comprehensive.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_async_file_writer_comprehensive.cpython-312.pyc delete mode 100644 __pycache__/test_debug_file_assembler.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_diagnosis_runner.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_disk_io_fixed.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_disk_io_manager.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_disk_io_simple.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_disk_io_timeout.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_file_assembler_debug.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_file_assembler_simple.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_piece_manager_fast.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_simple_disk_io.cpython-312-pytest-8.4.2.pyc delete mode 100644 __pycache__/test_simple_file_assembler.cpython-312-pytest-8.4.2.pyc delete mode 100644 benchmarks/bench_disk.py delete mode 100644 benchmarks/bench_hash_verification.py delete mode 100644 benchmarks/bench_throughput.py create mode 100644 ccbt.toml copy.example delete mode 100644 ccbt/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/__pycache__/__main__.cpython-312.pyc delete mode 100644 ccbt/__pycache__/async_metadata_exchange.cpython-312.pyc delete mode 100644 ccbt/__pycache__/async_peer_connection.cpython-312.pyc delete mode 100644 ccbt/__pycache__/async_piece_manager.cpython-312.pyc delete mode 100644 ccbt/__pycache__/bencode.cpython-312.pyc delete mode 100644 ccbt/__pycache__/buffers.cpython-312.pyc delete mode 100644 ccbt/__pycache__/checkpoint.cpython-312.pyc delete mode 100644 ccbt/__pycache__/config.cpython-312.pyc delete mode 100644 ccbt/__pycache__/dht.cpython-312.pyc delete mode 100644 ccbt/__pycache__/disk_io.cpython-312.pyc delete mode 100644 ccbt/__pycache__/events.cpython-312.pyc delete mode 100644 ccbt/__pycache__/exceptions.cpython-312.pyc delete mode 100644 ccbt/__pycache__/file_assembler.cpython-312.pyc delete mode 100644 ccbt/__pycache__/logging_config.cpython-312.pyc delete mode 100644 ccbt/__pycache__/magnet.cpython-312.pyc delete mode 100644 ccbt/__pycache__/metrics.cpython-312.pyc delete mode 100644 ccbt/__pycache__/models.cpython-312.pyc delete mode 100644 ccbt/__pycache__/peer.cpython-312.pyc delete mode 100644 ccbt/__pycache__/peer_connection.cpython-312.pyc delete mode 100644 ccbt/__pycache__/pex.cpython-312.pyc delete mode 100644 ccbt/__pycache__/piece_manager.cpython-312.pyc delete mode 100644 ccbt/__pycache__/session.cpython-312.pyc delete mode 100644 ccbt/__pycache__/torrent.cpython-312.pyc delete mode 100644 ccbt/__pycache__/tracker.cpython-312.pyc delete mode 100644 ccbt/__pycache__/tracker_server_http.cpython-312.pyc delete mode 100644 ccbt/__pycache__/tracker_udp_client.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/advanced_commands.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/config_commands.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/interactive.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/main.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/monitoring_commands.cpython-312.pyc delete mode 100644 ccbt/cli/__pycache__/progress.cpython-312.pyc create mode 100644 ccbt/cli/checkpoints.py create mode 100644 ccbt/cli/config_utils.py create mode 100644 ccbt/cli/console.py create mode 100644 ccbt/cli/create_torrent.py create mode 100644 ccbt/cli/daemon_commands.py create mode 100644 ccbt/cli/diagnostics.py create mode 100644 ccbt/cli/downloads.py create mode 100644 ccbt/cli/file_commands.py create mode 100644 ccbt/cli/filter_commands.py create mode 100644 ccbt/cli/ipfs_commands.py create mode 100644 ccbt/cli/monitoring_utils.py create mode 100644 ccbt/cli/nat_commands.py create mode 100644 ccbt/cli/overrides.py create mode 100644 ccbt/cli/proxy_commands.py create mode 100644 ccbt/cli/queue_commands.py create mode 100644 ccbt/cli/resume.py create mode 100644 ccbt/cli/scrape_commands.py create mode 100644 ccbt/cli/ssl_commands.py create mode 100644 ccbt/cli/status.py create mode 100644 ccbt/cli/utp_commands.py create mode 100644 ccbt/cli/xet_commands.py create mode 100644 ccbt/core/torrent_attributes.py create mode 100644 ccbt/core/torrent_v2.py create mode 100644 ccbt/daemon/__init__.py create mode 100644 ccbt/daemon/daemon_manager.py create mode 100644 ccbt/daemon/debug_utils.py create mode 100644 ccbt/daemon/ipc_client.py create mode 100644 ccbt/daemon/ipc_protocol.py create mode 100644 ccbt/daemon/ipc_server.py create mode 100644 ccbt/daemon/main.py create mode 100644 ccbt/daemon/state_manager.py create mode 100644 ccbt/daemon/state_models.py create mode 100644 ccbt/daemon/utils.py create mode 100644 ccbt/discovery/dht_indexing.py create mode 100644 ccbt/discovery/dht_ipv6.py create mode 100644 ccbt/discovery/dht_multiaddr.py create mode 100644 ccbt/discovery/dht_readonly.py create mode 100644 ccbt/discovery/dht_storage.py create mode 100644 ccbt/discovery/xet_cas.py create mode 100644 ccbt/executor/__init__.py create mode 100644 ccbt/executor/base.py create mode 100644 ccbt/executor/config_executor.py create mode 100644 ccbt/executor/executor.py create mode 100644 ccbt/executor/file_executor.py create mode 100644 ccbt/executor/manager.py create mode 100644 ccbt/executor/nat_executor.py create mode 100644 ccbt/executor/protocol_executor.py create mode 100644 ccbt/executor/queue_executor.py create mode 100644 ccbt/executor/registry.py create mode 100644 ccbt/executor/scrape_executor.py create mode 100644 ccbt/executor/security_executor.py create mode 100644 ccbt/executor/session_adapter.py create mode 100644 ccbt/executor/session_executor.py create mode 100644 ccbt/executor/torrent_executor.py delete mode 100644 ccbt/extensions/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/compact.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/dht.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/fast.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/pex.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/protocol.cpython-312.pyc delete mode 100644 ccbt/extensions/__pycache__/webseed.cpython-312.pyc create mode 100644 ccbt/extensions/ssl.py create mode 100644 ccbt/extensions/xet.py create mode 100644 ccbt/i18n/__init__.py create mode 100644 ccbt/i18n/extract.py create mode 100644 ccbt/i18n/fill_english.py create mode 100644 ccbt/i18n/locales/arc/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/en/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/es/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/eu/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/fa/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/fr/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/ha/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/hi/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/ja/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/ko/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/sw/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/th/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/ur/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/yo/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/locales/zh/LC_MESSAGES/ccbt.po create mode 100644 ccbt/i18n/manager.py create mode 100644 ccbt/i18n/scripts/README.md create mode 100644 ccbt/i18n/scripts/add_rich_markup_translations.py create mode 100644 ccbt/i18n/scripts/check_completeness.py create mode 100644 ccbt/i18n/scripts/check_coverage.py create mode 100644 ccbt/i18n/scripts/compile_all.py create mode 100644 ccbt/i18n/scripts/comprehensive_translations.py create mode 100644 ccbt/i18n/scripts/extract.py create mode 100644 ccbt/i18n/scripts/fill_english.py create mode 100644 ccbt/i18n/scripts/generate_african_translations.py create mode 100644 ccbt/i18n/scripts/generate_hi_ur_fa_arc_translations.py create mode 100644 ccbt/i18n/scripts/generate_translations.py create mode 100644 ccbt/i18n/scripts/translation_workflow.py create mode 100644 ccbt/i18n/scripts/validate_po.py create mode 100644 ccbt/interface/commands/__init__.py create mode 100644 ccbt/interface/commands/executor.py create mode 100644 ccbt/interface/daemon_session_adapter.py create mode 100644 ccbt/interface/screens/__init__.py create mode 100644 ccbt/interface/screens/base.py create mode 100644 ccbt/interface/screens/config/__init__.py create mode 100644 ccbt/interface/screens/config/global_config.py create mode 100644 ccbt/interface/screens/config/proxy.py create mode 100644 ccbt/interface/screens/config/ssl.py create mode 100644 ccbt/interface/screens/config/torrent_config.py create mode 100644 ccbt/interface/screens/config/utp.py create mode 100644 ccbt/interface/screens/config/widgets.py create mode 100644 ccbt/interface/screens/dialogs.py create mode 100644 ccbt/interface/screens/monitoring/__init__.py create mode 100644 ccbt/interface/screens/monitoring/alerts.py create mode 100644 ccbt/interface/screens/monitoring/disk_analysis.py create mode 100644 ccbt/interface/screens/monitoring/disk_io.py create mode 100644 ccbt/interface/screens/monitoring/historical.py create mode 100644 ccbt/interface/screens/monitoring/ipfs.py create mode 100644 ccbt/interface/screens/monitoring/metrics_explorer.py create mode 100644 ccbt/interface/screens/monitoring/nat.py create mode 100644 ccbt/interface/screens/monitoring/network.py create mode 100644 ccbt/interface/screens/monitoring/performance.py create mode 100644 ccbt/interface/screens/monitoring/performance_analysis.py create mode 100644 ccbt/interface/screens/monitoring/queue.py create mode 100644 ccbt/interface/screens/monitoring/scrape.py create mode 100644 ccbt/interface/screens/monitoring/system_resources.py create mode 100644 ccbt/interface/screens/monitoring/tracker.py create mode 100644 ccbt/interface/screens/monitoring/xet.py create mode 100644 ccbt/interface/screens/utility/__init__.py create mode 100644 ccbt/interface/screens/utility/file_selection.py create mode 100644 ccbt/interface/screens/utility/help.py create mode 100644 ccbt/interface/screens/utility/navigation.py create mode 100644 ccbt/interface/widgets/__init__.py create mode 100644 ccbt/interface/widgets/core_widgets.py create mode 100644 ccbt/interface/widgets/reusable_widgets.py delete mode 100644 ccbt/monitoring/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/monitoring/__pycache__/alert_manager.cpython-312.pyc delete mode 100644 ccbt/monitoring/__pycache__/dashboard.cpython-312.pyc delete mode 100644 ccbt/monitoring/__pycache__/metrics_collector.cpython-312.pyc delete mode 100644 ccbt/monitoring/__pycache__/terminal_dashboard.cpython-312.pyc delete mode 100644 ccbt/monitoring/__pycache__/tracing.cpython-312.pyc create mode 100644 ccbt/nat/__init__.py create mode 100644 ccbt/nat/exceptions.py create mode 100644 ccbt/nat/manager.py create mode 100644 ccbt/nat/natpmp.py create mode 100644 ccbt/nat/port_mapping.py create mode 100644 ccbt/nat/upnp.py delete mode 100644 ccbt/observability/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/observability/__pycache__/profiler.cpython-312.pyc create mode 100644 ccbt/peer/ssl_peer.py create mode 100644 ccbt/peer/tcp_server.py create mode 100644 ccbt/peer/utp_peer.py create mode 100644 ccbt/peer/webrtc_peer.py create mode 100644 ccbt/piece/file_selection.py create mode 100644 ccbt/piece/hash_v2.py delete mode 100644 ccbt/plugins/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/plugins/__pycache__/base.cpython-312.pyc delete mode 100644 ccbt/plugins/__pycache__/logging_plugin.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/base.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/bittorrent.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/hybrid.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/ipfs.cpython-312.pyc delete mode 100644 ccbt/protocols/__pycache__/webtorrent.cpython-312.pyc create mode 100644 ccbt/protocols/bittorrent_v2.py create mode 100644 ccbt/protocols/webtorrent/__init__.py create mode 100644 ccbt/protocols/webtorrent/webrtc_manager.py create mode 100644 ccbt/protocols/xet.py create mode 100644 ccbt/proxy/__init__.py create mode 100644 ccbt/proxy/auth.py create mode 100644 ccbt/proxy/client.py create mode 100644 ccbt/proxy/exceptions.py create mode 100644 ccbt/queue/__init__.py create mode 100644 ccbt/queue/bandwidth.py create mode 100644 ccbt/queue/manager.py delete mode 100644 ccbt/security/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/security/__pycache__/anomaly_detector.cpython-312.pyc delete mode 100644 ccbt/security/__pycache__/encryption.cpython-312.pyc delete mode 100644 ccbt/security/__pycache__/peer_validator.cpython-312.pyc delete mode 100644 ccbt/security/__pycache__/rate_limiter.cpython-312.pyc delete mode 100644 ccbt/security/__pycache__/security_manager.cpython-312.pyc create mode 100644 ccbt/security/ciphers/__init__.py create mode 100644 ccbt/security/ciphers/aes.py create mode 100644 ccbt/security/ciphers/base.py create mode 100644 ccbt/security/ciphers/chacha20.py create mode 100644 ccbt/security/ciphers/rc4.py create mode 100644 ccbt/security/dh_exchange.py create mode 100644 ccbt/security/ed25519_handshake.py create mode 100644 ccbt/security/encrypted_stream.py create mode 100644 ccbt/security/ip_filter.py create mode 100644 ccbt/security/key_manager.py create mode 100644 ccbt/security/messaging.py create mode 100644 ccbt/security/mse_handshake.py create mode 100644 ccbt/security/ssl_context.py create mode 100644 ccbt/security/tls_certificates.py delete mode 100644 ccbt/services/__pycache__/__init__.cpython-312.pyc delete mode 100644 ccbt/services/__pycache__/base.cpython-312.pyc delete mode 100644 ccbt/services/__pycache__/peer_service.cpython-312.pyc delete mode 100644 ccbt/services/__pycache__/storage_service.cpython-312.pyc delete mode 100644 ccbt/services/__pycache__/tracker_service.cpython-312.pyc create mode 100644 ccbt/session/adapters.py create mode 100644 ccbt/session/announce.py create mode 100644 ccbt/session/checkpoint_operations.py create mode 100644 ccbt/session/checkpointing.py create mode 100644 ccbt/session/dht_setup.py create mode 100644 ccbt/session/discovery.py create mode 100644 ccbt/session/download_manager.py create mode 100644 ccbt/session/download_startup.py create mode 100644 ccbt/session/factories.py create mode 100644 ccbt/session/fast_resume.py create mode 100644 ccbt/session/incoming.py create mode 100644 ccbt/session/lifecycle.py create mode 100644 ccbt/session/magnet_handling.py create mode 100644 ccbt/session/manager_background.py create mode 100644 ccbt/session/manager_startup.py create mode 100644 ccbt/session/metrics_status.py create mode 100644 ccbt/session/models.py create mode 100644 ccbt/session/peer_events.py create mode 100644 ccbt/session/peers.py create mode 100644 ccbt/session/scrape.py create mode 100644 ccbt/session/status_aggregation.py create mode 100644 ccbt/session/tasks.py create mode 100644 ccbt/session/torrent_addition.py create mode 100644 ccbt/session/torrent_utils.py create mode 100644 ccbt/session/types.py create mode 100644 ccbt/storage/disk_io_init.py create mode 100644 ccbt/storage/resume_data.py create mode 100644 ccbt/storage/xet_chunking.py create mode 100644 ccbt/storage/xet_deduplication.py create mode 100644 ccbt/storage/xet_hashing.py create mode 100644 ccbt/storage/xet_shard.py create mode 100644 ccbt/storage/xet_xorb.py create mode 100644 ccbt/transport/__init__.py create mode 100644 ccbt/transport/utp.py create mode 100644 ccbt/transport/utp_extensions.py create mode 100644 ccbt/transport/utp_socket.py create mode 100644 ccbt/utils/backoff.py create mode 100644 ccbt/utils/bitfield.py create mode 100644 ccbt/utils/console_utils.py create mode 100644 ccbt/utils/dht_utils.py create mode 100644 ccbt/utils/di.py create mode 100644 ccbt/utils/metadata_utils.py create mode 100644 ccbt/utils/port_checker.py create mode 100644 ccbt/utils/rich_logging.py create mode 100644 ccbt/utils/tasks.py create mode 100644 ccbt/utils/time.py create mode 100644 ccbt/utils/tracker_utils.py rename .codecov.yml => dev/.codecov.yml (83%) create mode 100644 dev/Dockerfile.test create mode 100644 dev/benchmarks.toml create mode 100644 dev/docker-compose.test.yml create mode 100644 dev/mkdocs.yml create mode 100644 dev/pre-commit-config.yaml rename pytest.ini => dev/pytest.ini (76%) rename ruff.toml => dev/ruff.toml (53%) rename ty.toml => dev/ty.toml (76%) create mode 100644 docs/CI_CD.md create mode 100644 docs/CLI_PROTOCOL_VIOLATIONS.md create mode 100644 docs/README_PyPI.md create mode 100644 docs/RELEASE_CHECKLIST.md create mode 100644 docs/analysis/protocol-patterns-analysis.md create mode 100644 docs/bep52.md create mode 100644 docs/bep_xet.md create mode 100644 docs/bitonic.md create mode 100644 docs/btbt-cli.md create mode 100644 docs/ccBT-RAIL.md delete mode 100644 docs/checkpoints.md delete mode 100644 docs/cli-reference.md create mode 100644 docs/contributing.md create mode 100644 docs/daemon-authentication-verification.md create mode 100644 docs/daemon-cli-authentication-flow.md create mode 100644 docs/daemon-implementation-plan.md delete mode 100644 docs/dashboard-guide.md create mode 100644 docs/debugging-daemon-exit.md create mode 100644 docs/developer/di.md create mode 100644 docs/examples.md create mode 100644 docs/examples/bep52/create_hybrid_torrent.py create mode 100644 docs/examples/bep52/create_v2_torrent.py create mode 100644 docs/examples/bep52/parse_v2_torrent.py create mode 100644 docs/examples/bep52/protocol_v2_session.py create mode 100644 docs/funding.md create mode 100644 docs/includes/mkdocs.md create mode 100644 docs/license.md delete mode 100644 docs/monitoring.md create mode 100644 docs/performance/encryption_benchmark_report.md create mode 100644 docs/reports/benchmarks/runs/disk_io-20251112-191716-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/disk_io-20251112-191742-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/disk_io-20251112-191743-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191730-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191745-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191746-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191747-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191748-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191750-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191759-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/encryption-20251112-191800-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191707-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191741-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191754-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191755-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191756-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191758-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191805-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/hash_verify-20251112-191806-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191721-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191742-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191749-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191755-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191756-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191757-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191800-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191807-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/loopback_throughput-20251112-191808-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191719-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191745-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191751-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191758-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191759-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191800-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191802-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191808-a9c4027.json create mode 100644 docs/reports/benchmarks/runs/piece_assembly-20251112-191809-a9c4027.json create mode 100644 docs/reports/coverage.md create mode 100644 docs/reports/junit.xml create mode 100644 docs/unimplemented-methods.md delete mode 100644 mkdocs.yml delete mode 100644 ruff-report.json create mode 100644 scripts/socket_test.py delete mode 100644 tests/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_async_peer_connection.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_basic_imports.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_bencode.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_checkpoint.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_disk_io.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_file_assembler_blocks.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_magnet.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_parallel_metadata.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_peer.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_peer_connection.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_piece_manager.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_piece_manager.cpython-312.pyc delete mode 100644 tests/__pycache__/test_rarest_first.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_simple_functionality.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_torrent.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_tracker.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/__pycache__/test_tracker_server_http.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/chaos/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/chaos/__pycache__/test_fault_injection.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/chaos/__pycache__/test_fault_injection.cpython-312-pytest-8.4.2.pyc.1820 delete mode 100644 tests/checkpoint/__pycache__/test_advanced_checkpoint.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/cli/__pycache__/test_advanced_commands.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/cli/__pycache__/test_config_commands.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/cli/__pycache__/test_enhanced_options.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/cli/__pycache__/test_interactive_enhanced.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/cli/__pycache__/test_resume_commands.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/cli/test_advanced_commands_expanded_coverage.py create mode 100644 tests/cli/test_bep52_cli.py create mode 100644 tests/cli/test_config_commands_expanded.py create mode 100644 tests/cli/test_config_commands_expanded_coverage.py create mode 100644 tests/cli/test_config_commands_extended_coverage.py create mode 100644 tests/cli/test_config_commands_safeguard.py create mode 100644 tests/cli/test_create_torrent.py create mode 100644 tests/cli/test_file_commands.py create mode 100644 tests/cli/test_file_commands_coverage.py create mode 100644 tests/cli/test_filter_commands.py create mode 100644 tests/cli/test_filter_commands_coverage.py create mode 100644 tests/cli/test_interactive_commands_comprehensive.py create mode 100644 tests/cli/test_interactive_comprehensive.py create mode 100644 tests/cli/test_interactive_coverage.py create mode 100644 tests/cli/test_interactive_download_file_selection.py create mode 100644 tests/cli/test_interactive_expanded.py create mode 100644 tests/cli/test_interactive_expanded_coverage.py create mode 100644 tests/cli/test_interactive_file_selection.py create mode 100644 tests/cli/test_interactive_final_coverage.py create mode 100644 tests/cli/test_interactive_runloop.py create mode 100644 tests/cli/test_main_checkpoints_resume.py create mode 100644 tests/cli/test_main_coverage_gaps.py create mode 100644 tests/cli/test_main_deep_paths.py create mode 100644 tests/cli/test_main_error_paths.py create mode 100644 tests/cli/test_main_focus.py create mode 100644 tests/cli/test_main_magnet_coverage.py create mode 100644 tests/cli/test_main_more.py create mode 100644 tests/cli/test_main_more_topup.py create mode 100644 tests/cli/test_main_options_matrix.py create mode 100644 tests/cli/test_main_overrides.py create mode 100644 tests/cli/test_main_resume_save_verify.py create mode 100644 tests/cli/test_main_topup.py create mode 100644 tests/cli/test_nat_commands.py create mode 100644 tests/cli/test_proxy_commands.py create mode 100644 tests/cli/test_proxy_commands_comprehensive.py create mode 100644 tests/cli/test_queue_commands.py create mode 100644 tests/cli/test_queue_commands_comprehensive.py create mode 100644 tests/cli/test_scrape_commands.py create mode 100644 tests/cli/test_ssl_commands.py create mode 100644 tests/cli/test_ssl_commands_coverage.py create mode 100644 tests/cli/test_status_scrape_display.py create mode 100644 tests/cli/test_utp_commands.py create mode 100644 tests/cli/test_utp_config_integration.py create mode 100644 tests/config/test_config_backup_expanded.py create mode 100644 tests/config/test_config_coverage.py create mode 100644 tests/config/test_config_edge_cases.py create mode 100644 tests/config/test_config_expanded.py create mode 100644 tests/core/test_torrent_edge_cases.py create mode 100644 tests/daemon/__init__.py create mode 100644 tests/daemon/test_daemon_manager.py create mode 100644 tests/daemon/test_daemon_metrics.py create mode 100644 tests/daemon/test_executor_ipc_alignment.py create mode 100644 tests/daemon/test_ipc_auth.py create mode 100644 tests/daemon/test_ipc_authentication.py create mode 100644 tests/daemon/test_ipc_ed25519_auth.py create mode 100644 tests/daemon/test_ipc_metrics.py create mode 100644 tests/daemon/test_state_manager.py create mode 100644 tests/daemon/test_websocket.py delete mode 100644 tests/extensions/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/extensions/__pycache__/test_compact_peer_lists.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/extensions/__pycache__/test_fast_extension.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/extensions/test_dht_extension_comprehensive.py delete mode 100644 tests/integration/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/integration/__pycache__/test_end_to_end.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/integration/__pycache__/test_end_to_end_enhanced.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/integration/__pycache__/test_resume.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/integration/__pycache__/test_resume_integration.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/integration/test_bep47_attributes.py create mode 100644 tests/integration/test_bittorrent_v2_e2e.py create mode 100644 tests/integration/test_bittorrent_v2_protocol.py create mode 100644 tests/integration/test_connection_pool_integration.py create mode 100644 tests/integration/test_dht_enhancements_integration.py create mode 100644 tests/integration/test_disk_io_phase2_integration.py create mode 100644 tests/integration/test_early_peer_acceptance.py create mode 100644 tests/integration/test_ed25519_integration.py create mode 100644 tests/integration/test_encryption_chacha20.py create mode 100644 tests/integration/test_encryption_integration.py create mode 100644 tests/integration/test_fast_resume_integration.py create mode 100644 tests/integration/test_file_selection_e2e.py create mode 100644 tests/integration/test_ipfs_protocol_integration.py create mode 100644 tests/integration/test_magnet_bep53.py create mode 100644 tests/integration/test_nat_integration.py create mode 100644 tests/integration/test_network_optimizations_phase1.py create mode 100644 tests/integration/test_private_torrents.py create mode 100644 tests/integration/test_prometheus_endpoint.py create mode 100644 tests/integration/test_proxy_integration.py create mode 100644 tests/integration/test_queue_management.py create mode 100644 tests/integration/test_scrape_e2e.py create mode 100644 tests/integration/test_scrape_integration.py create mode 100644 tests/integration/test_session_metrics.py create mode 100644 tests/integration/test_session_metrics_edge_cases.py create mode 100644 tests/integration/test_session_scrape.py create mode 100644 tests/integration/test_ssl_extension.py create mode 100644 tests/integration/test_status_scrape_integration.py create mode 100644 tests/integration/test_storage_disk_io.py create mode 100644 tests/integration/test_webtorrent_e2e.py create mode 100644 tests/integration/test_xet_integration.py create mode 100644 tests/integration/transport/test_utp_compatibility.py create mode 100644 tests/integration/transport/test_utp_full_handshake.py create mode 100644 tests/integration/transport/test_utp_performance.py delete mode 100644 tests/monitoring/__pycache__/test_dashboard.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/monitoring/__pycache__/test_monitoring_cli.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/monitoring/test_alert_manager_comprehensive.py create mode 100644 tests/monitoring/test_dashboard_comprehensive.py create mode 100644 tests/monitoring/test_dashboard_expanded.py create mode 100644 tests/monitoring/test_metrics_collector_comprehensive.py create mode 100644 tests/monitoring/test_metrics_collector_expanded.py create mode 100644 tests/monitoring/test_tracing_expanded.py delete mode 100644 tests/performance/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/performance/__pycache__/test_benchmarks.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/performance/bench_disk_io.py create mode 100644 tests/performance/bench_encryption.py create mode 100644 tests/performance/bench_hash_verify.py create mode 100644 tests/performance/bench_loopback_throughput.py create mode 100644 tests/performance/bench_piece_assembly.py create mode 100644 tests/performance/bench_utils.py create mode 100644 tests/performance/test_disk_io_phase2_benchmarks.py create mode 100644 tests/performance/test_encryption_performance.py create mode 100644 tests/performance/test_webrtc_performance.py create mode 100644 tests/piece/test_async_piece_manager_comprehensive.py create mode 100644 tests/plugins/test_plugin_base_comprehensive.py delete mode 100644 tests/property/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/property/__pycache__/test_bencode_properties.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/property/__pycache__/test_piece_selection_properties.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/protocols/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/protocols/__pycache__/test_hybrid_protocol.cpython-312-pytest-8.4.2.pyc delete mode 100644 tests/protocols/__pycache__/test_protocol_base.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/protocols/test_bittorrent_v2.py create mode 100644 tests/protocols/test_ipfs_connection.py create mode 100644 tests/protocols/test_ipfs_protocol_comprehensive.py create mode 100644 tests/protocols/test_protocol_base_comprehensive.py create mode 100644 tests/scripts/analyze_coverage.py create mode 100644 tests/scripts/bench_all.py create mode 100644 tests/scripts/ensure_bandit_dir.py create mode 100644 tests/scripts/fix_docs_links.py create mode 100644 tests/scripts/get_benchmark_markers.py create mode 100644 tests/scripts/get_dependent_modules.py create mode 100644 tests/scripts/pre_push_validation.sh create mode 100644 tests/scripts/record_commit_benchmarks.py create mode 100644 tests/scripts/run_benchmarks_selective.py create mode 100644 tests/scripts/test_aiortc_install.py create mode 100644 tests/scripts/upload_coverage.py delete mode 100644 tests/security/__pycache__/__init__.cpython-312.pyc delete mode 100644 tests/security/__pycache__/test_security_manager.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/security/test_anomaly_detector.py create mode 100644 tests/security/test_ciphers.py create mode 100644 tests/security/test_ciphers_chacha20.py create mode 100644 tests/security/test_dh_exchange.py create mode 100644 tests/security/test_encrypted_stream.py create mode 100644 tests/security/test_encryption.py create mode 100644 tests/security/test_encryption_coverage.py create mode 100644 tests/security/test_encryption_coverage_gaps.py create mode 100644 tests/security/test_encryption_init_coverage.py create mode 100644 tests/security/test_ip_filter_coverage.py create mode 100644 tests/security/test_ip_filter_coverage_final.py create mode 100644 tests/security/test_ip_filter_coverage_gaps.py create mode 100644 tests/security/test_ip_filter_integration.py create mode 100644 tests/security/test_ip_filter_loading.py create mode 100644 tests/security/test_ip_filter_matching.py create mode 100644 tests/security/test_ip_filter_parsing.py create mode 100644 tests/security/test_ip_filter_rules.py create mode 100644 tests/security/test_key_manager.py create mode 100644 tests/security/test_mse_handshake.py create mode 100644 tests/security/test_mse_handshake_coverage.py create mode 100644 tests/security/test_mse_handshake_pe.py create mode 100644 tests/security/test_rate_limiter.py create mode 100644 tests/security/test_rate_limiter_coverage_gaps.py create mode 100644 tests/unit/config/test_proxy_config_encryption.py create mode 100644 tests/unit/core/test_bep47_models.py create mode 100644 tests/unit/core/test_magnet_bep53.py create mode 100644 tests/unit/core/test_torrent_attributes.py create mode 100644 tests/unit/core/test_torrent_attributes_coverage.py create mode 100644 tests/unit/core/test_torrent_attributes_integration.py create mode 100644 tests/unit/core/test_torrent_coverage.py create mode 100644 tests/unit/core/test_torrent_v2.py create mode 100644 tests/unit/discovery/__init__.py create mode 100644 tests/unit/discovery/test_dht_comprehensive.py create mode 100644 tests/unit/discovery/test_dht_error_handling.py create mode 100644 tests/unit/discovery/test_dht_indexing.py create mode 100644 tests/unit/discovery/test_dht_ipv6.py create mode 100644 tests/unit/discovery/test_dht_ipv6_merging.py create mode 100644 tests/unit/discovery/test_dht_ipv6_parsing.py create mode 100644 tests/unit/discovery/test_dht_multiaddr.py create mode 100644 tests/unit/discovery/test_dht_readonly.py create mode 100644 tests/unit/discovery/test_dht_storage.py create mode 100644 tests/unit/discovery/test_dht_xet_chunks.py create mode 100644 tests/unit/discovery/test_pex_comprehensive.py create mode 100644 tests/unit/discovery/test_pex_refresh.py create mode 100644 tests/unit/discovery/test_tracker_expanded.py create mode 100644 tests/unit/discovery/test_tracker_peer_source.py create mode 100644 tests/unit/discovery/test_tracker_peer_source_direct.py create mode 100644 tests/unit/discovery/test_tracker_phase1.py create mode 100644 tests/unit/discovery/test_tracker_phase1_coverage.py create mode 100644 tests/unit/discovery/test_tracker_proxy.py create mode 100644 tests/unit/discovery/test_tracker_scrape_http.py create mode 100644 tests/unit/discovery/test_tracker_scrape_udp.py create mode 100644 tests/unit/discovery/test_tracker_session_stats.py create mode 100644 tests/unit/discovery/test_tracker_ssl.py create mode 100644 tests/unit/discovery/test_tracker_udp_routing.py create mode 100644 tests/unit/discovery/test_xet_cas.py create mode 100644 tests/unit/disk/test_disk_io_edge_cases.py create mode 100644 tests/unit/disk/test_disk_io_final_coverage.py create mode 100644 tests/unit/disk/test_disk_io_phase2_optimizations.py create mode 100644 tests/unit/disk/test_disk_io_remaining_coverage.py create mode 100644 tests/unit/executor/test_adapter_error_handling.py create mode 100644 tests/unit/extensions/test_fast_coverage.py create mode 100644 tests/unit/extensions/test_webseed_coverage.py create mode 100644 tests/unit/extensions/test_webseed_proxy.py create mode 100644 tests/unit/i18n/test_i18n.py create mode 100644 tests/unit/interface/test_monitoring_screens.py create mode 100644 tests/unit/interface/test_terminal_dashboard.py create mode 100644 tests/unit/interface/test_terminal_dashboard_basic.py create mode 100644 tests/unit/interface/test_terminal_dashboard_widgets.py create mode 100644 tests/unit/metadata/test_metadata_exchange_complete.py create mode 100644 tests/unit/metadata/test_metadata_exchange_expanded.py create mode 100644 tests/unit/monitoring/test_metrics_collector_coverage.py create mode 100644 tests/unit/monitoring/test_metrics_collector_http.py create mode 100644 tests/unit/monitoring/test_metrics_collector_http_comprehensive.py create mode 100644 tests/unit/monitoring/test_metrics_collector_http_coverage.py create mode 100644 tests/unit/monitoring/test_metrics_collector_http_errors.py create mode 100644 tests/unit/monitoring/test_metrics_collector_http_final_coverage.py create mode 100644 tests/unit/monitoring/test_metrics_helpers.py create mode 100644 tests/unit/monitoring/test_metrics_helpers_edge_cases.py create mode 100644 tests/unit/nat/test_nat_manager.py create mode 100644 tests/unit/nat/test_natpmp.py create mode 100644 tests/unit/nat/test_port_mapping.py create mode 100644 tests/unit/nat/test_port_mapping_renewal.py create mode 100644 tests/unit/nat/test_upnp.py create mode 100644 tests/unit/network/test_connection_pool_100_coverage.py create mode 100644 tests/unit/network/test_connection_pool_edge_cases.py create mode 100644 tests/unit/network/test_connection_pool_final_coverage.py create mode 100644 tests/unit/network/test_connection_pool_gaps.py create mode 100644 tests/unit/network/test_connection_pool_phase1.py create mode 100644 tests/unit/network/test_connection_pool_phase1_coverage.py create mode 100644 tests/unit/network/test_network_optimizer_100_coverage.py create mode 100644 tests/unit/network/test_network_optimizer_comprehensive.py create mode 100644 tests/unit/network/test_network_optimizer_phase1.py create mode 100644 tests/unit/network/test_network_optimizer_remaining_coverage.py create mode 100644 tests/unit/peer/test_async_peer_connection_coverage_gaps.py create mode 100644 tests/unit/peer/test_async_peer_connection_error_handling.py create mode 100644 tests/unit/peer/test_async_peer_connection_phase1_integration.py create mode 100644 tests/unit/peer/test_async_peer_pipelining_phase1.py create mode 100644 tests/unit/peer/test_async_peer_timeout_phase1.py create mode 100644 tests/unit/peer/test_connection_pool_creation.py create mode 100644 tests/unit/peer/test_peer_connection_cleanup.py create mode 100644 tests/unit/peer/test_peer_connection_coverage.py create mode 100644 tests/unit/peer/test_peer_connection_encryption.py create mode 100644 tests/unit/peer/test_peer_connection_error_handling.py create mode 100644 tests/unit/peer/test_peer_coverage_gaps.py create mode 100644 tests/unit/peer/test_peer_source_validation.py create mode 100644 tests/unit/peer/test_ssl_extension_protocol.py create mode 100644 tests/unit/peer/test_ssl_peer.py create mode 100644 tests/unit/peer/test_utp_peer_connection.py create mode 100644 tests/unit/peer/test_utp_peer_stream.py create mode 100644 tests/unit/peer/test_webrtc_peer.py create mode 100644 tests/unit/piece/test_async_metadata_expanded.py create mode 100644 tests/unit/piece/test_file_selection.py create mode 100644 tests/unit/piece/test_file_selection_integration.py create mode 100644 tests/unit/piece/test_hash_v2.py create mode 100644 tests/unit/piece/test_hash_v2_coverage.py create mode 100644 tests/unit/piece/test_piece_manager_comprehensive.py create mode 100644 tests/unit/piece/test_sequential.py create mode 100644 tests/unit/plugins/test_plugin_manager_singleton.py create mode 100644 tests/unit/protocols/test_bittorrent_disconnect.py create mode 100644 tests/unit/protocols/test_bittorrent_scrape.py create mode 100644 tests/unit/protocols/test_bittorrent_v2_upgrade.py create mode 100644 tests/unit/protocols/test_ipfs_content_discovery.py create mode 100644 tests/unit/protocols/test_ipfs_content_operations.py create mode 100644 tests/unit/protocols/test_ipfs_content_retrieval.py create mode 100644 tests/unit/protocols/test_ipfs_message_receiving.py create mode 100644 tests/unit/protocols/test_ipfs_message_sending.py create mode 100644 tests/unit/protocols/test_ipfs_torrent_conversion.py create mode 100644 tests/unit/protocols/test_protocols_init.py create mode 100644 tests/unit/protocols/test_webrtc_manager.py create mode 100644 tests/unit/protocols/test_webrtc_manager_complete.py create mode 100644 tests/unit/protocols/test_webrtc_manager_coverage.py create mode 100644 tests/unit/protocols/test_webtorrent_protocol.py create mode 100644 tests/unit/protocols/test_webtorrent_signaling.py create mode 100644 tests/unit/protocols/test_xet_protocol.py create mode 100644 tests/unit/proxy/__init__.py create mode 100644 tests/unit/proxy/conftest.py create mode 100644 tests/unit/proxy/test_auth_comprehensive.py create mode 100644 tests/unit/proxy/test_auth_coverage_additional.py create mode 100644 tests/unit/proxy/test_client_comprehensive.py create mode 100644 tests/unit/proxy/test_client_coverage_additional.py create mode 100644 tests/unit/proxy/test_proxy_auth.py create mode 100644 tests/unit/proxy/test_proxy_auth_coverage.py create mode 100644 tests/unit/proxy/test_proxy_bypass.py create mode 100644 tests/unit/proxy/test_proxy_client.py create mode 100644 tests/unit/proxy/test_proxy_client_coverage.py create mode 100644 tests/unit/queue_mgmt/__init__.py create mode 100644 tests/unit/queue_mgmt/test_bandwidth.py create mode 100644 tests/unit/queue_mgmt/test_queue_manager.py create mode 100644 tests/unit/resilience/test_peer_circuit_breaker.py create mode 100644 tests/unit/resilience/test_resilience_additional_coverage.py create mode 100644 tests/unit/resilience/test_resilience_comprehensive.py create mode 100644 tests/unit/resilience/test_resilience_edge_cases_final.py create mode 100644 tests/unit/security/test_peer_validator_coverage.py create mode 100644 tests/unit/security/test_security_manager_additional_coverage.py create mode 100644 tests/unit/security/test_security_manager_coverage.py create mode 100644 tests/unit/security/test_ssl_context.py create mode 100644 tests/unit/services/conftest.py create mode 100644 tests/unit/services/test_base_comprehensive.py create mode 100644 tests/unit/services/test_peer_service_comprehensive.py create mode 100644 tests/unit/services/test_storage_service.py create mode 100644 tests/unit/services/test_storage_service_coverage.py create mode 100644 tests/unit/services/test_storage_service_write_implementation.py create mode 100644 tests/unit/services/test_tracker_service.py create mode 100644 tests/unit/services/test_tracker_service_coverage.py create mode 100644 tests/unit/session/test_announce_controller.py create mode 100644 tests/unit/session/test_async_main_coverage.py create mode 100644 tests/unit/session/test_async_main_metrics.py create mode 100644 tests/unit/session/test_async_main_metrics_coverage.py create mode 100644 tests/unit/session/test_async_main_missing_coverage.py create mode 100644 tests/unit/session/test_async_tracker_client.py create mode 100644 tests/unit/session/test_checkpoint_controller.py create mode 100644 tests/unit/session/test_fast_resume.py create mode 100644 tests/unit/session/test_magnet_download_continuation.py create mode 100644 tests/unit/session/test_manager_startup.py create mode 100644 tests/unit/session/test_peer_initializer.py create mode 100644 tests/unit/session/test_pex_refresh.py create mode 100644 tests/unit/session/test_scrape_features.py create mode 100644 tests/unit/session/test_session_admin_ops_extended.py create mode 100644 tests/unit/session/test_session_background_loops.py create mode 100644 tests/unit/session/test_session_checkpoint_ops.py create mode 100644 tests/unit/session/test_session_checkpoint_utilities.py create mode 100644 tests/unit/session/test_session_coverage_boost.py create mode 100644 tests/unit/session/test_session_edge_cases.py create mode 100644 tests/unit/session/test_session_error_paths_coverage.py create mode 100644 tests/unit/session/test_session_event_handlers.py create mode 100644 tests/unit/session/test_session_import_export.py create mode 100644 tests/unit/session/test_session_init.py create mode 100644 tests/unit/session/test_session_manager_coverage.py create mode 100644 tests/unit/session/test_session_manager_metrics_and_admin.py create mode 100644 tests/unit/session/test_session_missing_coverage.py create mode 100644 tests/unit/session/test_session_normalize_coverage.py create mode 100644 tests/unit/session/test_session_rehash_and_ops.py create mode 100644 tests/unit/session/test_session_remaining_coverage.py create mode 100644 tests/unit/session/test_session_resume_checkpoint.py create mode 100644 tests/unit/session/test_session_status_and_utils.py create mode 100644 tests/unit/session/test_session_sync_methods.py create mode 100644 tests/unit/session/test_session_validate_checkpoint.py create mode 100644 tests/unit/session/test_task_supervisor.py create mode 100644 tests/unit/session/test_tracker_announce.py create mode 100644 tests/unit/storage/test_buffers_comprehensive.py create mode 100644 tests/unit/storage/test_checkpoint_edge_cases.py create mode 100644 tests/unit/storage/test_checkpoint_expanded.py create mode 100644 tests/unit/storage/test_checkpoint_final_coverage.py create mode 100644 tests/unit/storage/test_disk_io_cleanup_paths.py create mode 100644 tests/unit/storage/test_disk_io_coverage_gaps.py create mode 100644 tests/unit/storage/test_disk_io_init.py create mode 100644 tests/unit/storage/test_disk_io_missing_coverage.py create mode 100644 tests/unit/storage/test_file_attributes_assembler.py create mode 100644 tests/unit/storage/test_resume_data.py create mode 100644 tests/unit/storage/test_xet_chunking.py create mode 100644 tests/unit/storage/test_xet_deduplication.py create mode 100644 tests/unit/storage/test_xet_hashing.py create mode 100644 tests/unit/storage/test_xet_shard.py create mode 100644 tests/unit/storage/test_xet_xorb.py create mode 100644 tests/unit/test_package_init.py create mode 100644 tests/unit/test_utils_bitfield.py create mode 100644 tests/unit/test_utils_di.py create mode 100644 tests/unit/tracker/test_tracker_server_http_comprehensive.py create mode 100644 tests/unit/tracker/test_tracker_udp_client_comprehensive.py create mode 100644 tests/unit/transport/__init__.py create mode 100644 tests/unit/transport/test_utp.py create mode 100644 tests/unit/transport/test_utp_100_coverage.py create mode 100644 tests/unit/transport/test_utp_additional.py create mode 100644 tests/unit/transport/test_utp_additional_coverage.py create mode 100644 tests/unit/transport/test_utp_comprehensive.py create mode 100644 tests/unit/transport/test_utp_congestion_control.py create mode 100644 tests/unit/transport/test_utp_connection_id_collision.py create mode 100644 tests/unit/transport/test_utp_delayed_ack.py create mode 100644 tests/unit/transport/test_utp_ecn.py create mode 100644 tests/unit/transport/test_utp_edge_cases.py create mode 100644 tests/unit/transport/test_utp_extensions.py create mode 100644 tests/unit/transport/test_utp_final_coverage.py create mode 100644 tests/unit/transport/test_utp_packet.py create mode 100644 tests/unit/transport/test_utp_passive_connections.py create mode 100644 tests/unit/transport/test_utp_retransmission.py create mode 100644 tests/unit/transport/test_utp_sack.py create mode 100644 tests/unit/transport/test_utp_window_scaling.py create mode 100644 tests/unit/utils/test_events_comprehensive.py create mode 100644 tests/unit/utils/test_exceptions_comprehensive.py create mode 100644 tests/unit/utils/test_logging_config_comprehensive.py create mode 100644 tests/unit/utils/test_metrics_comprehensive.py create mode 100644 uv delete mode 100644 uv.toml diff --git a/.cursor/plans/network-disk-optimizations-1658c482.plan.md b/.cursor/plans/network-disk-optimizations-1658c482.plan.md new file mode 100644 index 0000000..84e5fb5 --- /dev/null +++ b/.cursor/plans/network-disk-optimizations-1658c482.plan.md @@ -0,0 +1,393 @@ + +# Network and Disk I/O Optimization Implementation Plan + +## Analysis Summary + +### Network Bottlenecks Identified + +1. **Connection Management**: No effective reuse of peer connections; frequent connection establishment overhead +2. **HTTP Session Management**: aiohttp session not optimally configured for tracker requests +3. **Request Pipelining**: Limited pipeline depth (16) may not fully utilize high-bandwidth connections +4. **Socket Buffer Sizes**: Fixed sizes (256KB) may be suboptimal for modern high-speed networks +5. **DNS Resolution**: No DNS caching, causing repeated lookups for same trackers +6. **Write Buffer Management**: Ring buffer usage could be optimized +7. **Connection Pooling**: Connection pools exist but not fully utilized in async peer connections + +### Disk I/O Bottlenecks Identified + +1. **Write Batching**: 5ms timeout threshold too short; may flush prematurely on fast storage +2. **MMap Cache**: 128MB default may be too small for large torrents; eviction strategy too aggressive +3. **Checkpoint Frequency**: Saving on every piece completion creates I/O overhead +4. **Read-Ahead**: 64KB read-ahead may be insufficient for sequential reads +5. **I/O Queue Depth**: Default 200 may bottleneck on NVMe drives +6. **Hash Verification**: Parallel hash workers (4) may be insufficient for fast SSDs +7. **Direct I/O**: Not enabled by default; could improve performance on high-speed storage + +## Implementation Tasks + +### Phase 1: Network Optimizations + +#### Task 1.1: Enhance Connection Pooling and Reuse + +**File**: `ccbt/peer/connection_pool.py`, `ccbt/peer/async_peer_connection.py` + +- **Sub-Task 1.1.1**: Improve connection validation and health checks + - **Location**: `ccbt/peer/connection_pool.py:140-146` + - **Change**: Add connection liveness check using socket getsockopt(SO_ERROR) + - **Implementation**: + ```python + def _is_connection_valid(self, connection: Any) -> bool: + # Check socket state via getsockopt(SO_ERROR) + # Check if reader/writer are still valid + # Verify connection hasn't exceeded max idle time + ``` + +- **Sub-Task 1.1.2**: Implement connection warmup strategy + - **Location**: `ccbt/peer/connection_pool.py:234-256` + - **Change**: Pre-establish connections to frequently accessed peers + - **Implementation**: Add `warmup_connections()` method that creates connections for top N peers + +- **Sub-Task 1.1.3**: Add connection reuse metrics + - **Location**: `ccbt/peer/connection_pool.py:207-232` + - **Change**: Track reuse rate, average connection lifetime + - **Implementation**: Extend `get_pool_stats()` with reuse statistics + +- **Sub-Task 1.1.4**: Integrate connection pool with AsyncPeerConnectionManager + - **Location**: `ccbt/peer/async_peer_connection.py:387-451` + - **Change**: Use PeerConnectionPool in `_connect_to_peer()` before creating new connection + - **Implementation**: Check pool first, only create new connection if pool miss + +#### Task 1.2: Optimize HTTP Session Configuration for Trackers + +**File**: `ccbt/discovery/tracker.py:81-98` + +- **Sub-Task 1.2.1**: Configure connection limits and keepalive + - **Location**: `ccbt/discovery/tracker.py:81-98` + - **Change**: Set connector limits and enable connection pooling + - **Implementation**: + ```python + connector = aiohttp.TCPConnector( + limit=self.config.network.tracker_connection_limit, + limit_per_host=self.config.network.tracker_connections_per_host, + ttl_dns_cache=self.config.network.dns_cache_ttl, + keepalive_timeout=300, + enable_cleanup_closed=True + ) + ``` + +- **Sub-Task 1.2.2**: Implement DNS caching with TTL support + - **Location**: `ccbt/discovery/tracker.py:100-123` (new method) + - **Change**: Add DNS cache with TTL-based expiration + - **Implementation**: Create `DNSCache` class with asyncio-based caching + +- **Sub-Task 1.2.3**: Add HTTP session metrics + - **Location**: `ccbt/discovery/tracker.py:499-518` (extend existing method) + - **Change**: Track request/response times, connection reuse + - **Implementation**: Add metrics collection to `_make_request_async()` + +#### Task 1.3: Enhance Socket Buffer Management + +**File**: `ccbt/utils/network_optimizer.py:66-189` + +- **Sub-Task 1.3.1**: Implement adaptive buffer sizing + - **Location**: `ccbt/utils/network_optimizer.py:71-113` + - **Change**: Dynamically adjust buffer sizes based on network conditions + - **Implementation**: Add `_calculate_optimal_buffer_size()` method using BDP (Bandwidth-Delay Product) + +- **Sub-Task 1.3.2**: Add platform-specific buffer optimizations + - **Location**: `ccbt/utils/network_optimizer.py:116-189` + - **Change**: Use platform-specific maximum buffer sizes + - **Implementation**: Query system limits and set buffers accordingly (Linux: /proc/sys/net/core/rmem_max) + +- **Sub-Task 1.3.3**: Enable TCP window scaling + - **Location**: `ccbt/utils/network_optimizer.py:116-189` + - **Change**: Enable TCP window scaling for high-speed connections + - **Implementation**: Check and enable TCP window scaling option + +#### Task 1.4: Optimize Request Pipelining + +**File**: `ccbt/peer/async_peer_connection.py:145-198` + +- **Sub-Task 1.4.1**: Implement adaptive pipeline depth + - **Location**: `ccbt/peer/async_peer_connection.py:149` + - **Change**: Dynamically adjust `max_pipeline_depth` based on connection latency and bandwidth + - **Implementation**: Add `_calculate_pipeline_depth()` method using latency measurements + +- **Sub-Task 1.4.2**: Add request prioritization + - **Location**: `ccbt/peer/async_peer_connection.py:148` (request_queue) + - **Change**: Use priority queue instead of deque for request ordering + - **Implementation**: Replace `deque` with `heapq`-based priority queue, prioritize rarest pieces + +- **Sub-Task 1.4.3**: Implement request coalescing + - **Location**: `ccbt/peer/async_peer_connection.py:1454-1488` + - **Change**: Combine adjacent requests into single larger requests when possible + - **Implementation**: Add `_coalesce_requests()` method before sending + +#### Task 1.5: Improve Timeout and Retry Logic + +**File**: `ccbt/discovery/tracker.py:510-518`, `ccbt/peer/async_peer_connection.py:487-490` + +- **Sub-Task 1.5.1**: Implement exponential backoff with jitter + - **Location**: `ccbt/discovery/tracker.py:510-518` + - **Change**: Replace fixed backoff with exponential backoff + jitter + - **Implementation**: + ```python + backoff_delay = min(base_delay * (2 ** failure_count) + random.uniform(0, base_delay), max_delay) + ``` + +- **Sub-Task 1.5.2**: Add adaptive timeout calculation + - **Location**: `ccbt/peer/async_peer_connection.py:487-490` + - **Change**: Calculate timeout based on measured RTT + - **Implementation**: Use RTT * 3 for timeout calculation, with min/max bounds + +- **Sub-Task 1.5.3**: Implement circuit breaker pattern + - **Location**: `ccbt/utils/resilience.py` (new class) + - **Change**: Add CircuitBreaker for peer connections that repeatedly fail + - **Implementation**: Create `CircuitBreaker` class with open/half-open/closed states + +### Phase 2: Disk I/O Optimizations + +#### Task 2.1: Optimize Write Batching Strategy + +**File**: `ccbt/storage/disk_io.py:628-691` + +- **Sub-Task 2.1.1**: Implement adaptive batching timeout + - **Location**: `ccbt/storage/disk_io.py:654` + - **Change**: Adjust timeout based on storage device performance characteristics + - **Implementation**: Detect storage type (SSD/NVMe/HDD) and set timeout accordingly (NVMe: 0.1ms, SSD: 5ms, HDD: 50ms) + +- **Sub-Task 2.1.2**: Improve contiguous write detection + - **Location**: `ccbt/storage/disk_io.py:785-792` + - **Change**: More aggressive coalescing of near-contiguous writes + - **Implementation**: Extend `_combine_contiguous_writes()` to merge writes within threshold distance (e.g., 4KB) + +- **Sub-Task 2.1.3**: Add write-back caching awareness + - **Location**: `ccbt/storage/disk_io.py:794-898` + - **Change**: Detect if write-back cache is enabled and adjust flush strategy + - **Implementation**: Query OS for cache mode and optimize flush frequency + +- **Sub-Task 2.1.4**: Implement write queue prioritization + - **Location**: `ccbt/storage/disk_io.py:125` + - **Change**: Use priority queue for critical writes (checkpoints, metadata) + - **Implementation**: Replace `asyncio.Queue` with priority queue, prioritize by write type + +#### Task 2.2: Enhance MMap Cache Management + +**File**: `ccbt/storage/disk_io.py:129-131, 900-985` + +- **Sub-Task 2.2.1**: Implement LRU eviction with size awareness + - **Location**: `ccbt/storage/disk_io.py:912-940` + - **Change**: Replace simple LRU with size-aware eviction (evict large files first if needed) + - **Implementation**: Modify `_cache_cleaner()` to prefer evicting large, less-frequently-accessed files + +- **Sub-Task 2.2.2**: Add cache warmup on torrent start + - **Location**: `ccbt/storage/disk_io.py:950-985` (new method) + - **Change**: Pre-load frequently accessed files into mmap cache + - **Implementation**: Add `warmup_cache()` method that loads files in background + +- **Sub-Task 2.2.3**: Implement cache hit rate monitoring + - **Location**: `ccbt/storage/disk_io.py:605-613` + - **Change**: Track detailed cache statistics (hit rate, eviction rate, average access time) + - **Implementation**: Extend `get_cache_stats()` with comprehensive metrics + +- **Sub-Task 2.2.4**: Add adaptive cache size adjustment + - **Location**: `ccbt/storage/disk_io.py:130-132` + - **Change**: Dynamically adjust cache size based on available memory + - **Implementation**: Monitor system memory and adjust cache_size_bytes accordingly + +#### Task 2.3: Optimize Checkpoint I/O Operations + +**File**: `ccbt/storage/checkpoint.py:108-213` + +- **Sub-Task 2.3.1**: Implement incremental checkpoint saves + - **Location**: `ccbt/storage/checkpoint.py:108-152` + - **Change**: Only save changed pieces, not full checkpoint every time + - **Implementation**: Add diff calculation between current and last checkpoint state + +- **Sub-Task 2.3.2**: Optimize checkpoint compression + - **Location**: `ccbt/storage/checkpoint.py:274-310` + - **Change**: Use faster compression algorithm or compress in background thread + - **Implementation**: Use zstd instead of gzip for faster compression, or compress asynchronously + +- **Sub-Task 2.3.3**: Batch checkpoint writes + - **Location**: `ccbt/storage/checkpoint.py:204-213` + - **Change**: Batch multiple checkpoint updates into single write + - **Implementation**: Queue checkpoint saves and flush periodically (e.g., every 10 pieces or 5 seconds) + +- **Sub-Task 2.3.4**: Add checkpoint write deduplication + - **Location**: `ccbt/storage/checkpoint.py:154-213` + - **Change**: Skip checkpoint save if no meaningful changes since last save + - **Implementation**: Compare current state hash with last saved state hash + +#### Task 2.4: Enhance Read Operations + +**File**: `ccbt/storage/disk_io.py:534-604` + +- **Sub-Task 2.4.1**: Implement intelligent read-ahead + - **Location**: `ccbt/storage/disk_io.py:534-565` + - **Change**: Adaptive read-ahead size based on access pattern (sequential vs random) + - **Implementation**: Detect sequential access and increase read-ahead dynamically (up to 1MB for sequential) + +- **Sub-Task 2.4.2**: Add read prefetching for likely-next blocks + - **Location**: `ccbt/storage/disk_io.py:534-565` (new method) + - **Change**: Prefetch blocks that are likely to be requested next + - **Implementation**: Track access patterns and prefetch predicted blocks in background + +- **Sub-Task 2.4.3**: Optimize multi-file torrent reads + - **Location**: `ccbt/storage/file_assembler.py:547-589` + - **Change**: Parallelize reads across multiple file segments + - **Implementation**: Use `asyncio.gather()` to read multiple segments concurrently + +- **Sub-Task 2.4.4**: Add read buffer pooling + - **Location**: `ccbt/storage/disk_io.py:534-565` + - **Change**: Reuse read buffers to reduce allocations + - **Implementation**: Add buffer pool for read operations, similar to write staging buffers + +#### Task 2.5: Optimize I/O Queue and Worker Configuration + +**File**: `ccbt/storage/disk_io.py:99-122, 718-898` + +- **Sub-Task 2.5.1**: Implement adaptive worker count + - **Location**: `ccbt/storage/disk_io.py:119-122` + - **Change**: Dynamically adjust worker count based on I/O queue depth and system load + - **Implementation**: Monitor queue depth and spawn/remove workers as needed + +- **Sub-Task 2.5.2**: Add I/O priority management + - **Location**: `ccbt/storage/disk_io.py:772-898` + - **Change**: Set I/O priority for disk operations (Linux: ioprio_set) + - **Implementation**: Set real-time I/O class for critical operations on Linux + +- **Sub-Task 2.5.3**: Implement I/O scheduling optimization + - **Location**: `ccbt/storage/disk_io.py:728-771` + - **Change**: Sort writes by LBA (Logical Block Address) for optimal disk access + - **Implementation**: Add LBA calculation and sort writes by physical location before flushing + +- **Sub-Task 2.5.4**: Add NVMe-specific optimizations + - **Location**: `ccbt/storage/disk_io.py:213-236` + - **Change**: Detect NVMe and enable optimal settings (larger queue depth, multiple queues) + - **Implementation**: Extend `_detect_platform_capabilities()` to detect NVMe and configure accordingly + +#### Task 2.6: Enhance Hash Verification Performance + +**File**: `ccbt/models.py:736-758` (config), hash verification locations + +- **Sub-Task 2.6.1**: Implement parallel hash verification with work-stealing + - **Location**: Hash verification code (to be located) + - **Change**: Use thread pool with work-stealing for better load balancing + - **Implementation**: Replace fixed worker pool with dynamic work-stealing queue + +- **Sub-Task 2.6.2**: Add hash verification batching + - **Location**: Hash verification code + - **Change**: Batch multiple pieces for verification to reduce overhead + - **Implementation**: Group pieces and verify in batches using vectorized operations where possible + +- **Sub-Task 2.6.3**: Optimize hash chunk size + - **Location**: `ccbt/models.py:748-752` + - **Change**: Use larger chunks (1MB) for hash verification on fast storage + - **Implementation**: Detect storage speed and adjust chunk size dynamically + +### Phase 3: Configuration and Monitoring Enhancements + +#### Task 3.1: Add Performance Monitoring + +**File**: `ccbt/monitoring/metrics_collector.py` (existing), new metrics locations + +- **Sub-Task 3.1.1**: Add network performance metrics + - **Location**: Network components + - **Change**: Track connection establishment time, RTT, throughput per connection + - **Implementation**: Add metrics collection points in `AsyncPeerConnectionManager` + +- **Sub-Task 3.1.2**: Add disk I/O performance metrics + - **Location**: `ccbt/storage/disk_io.py:168-179` + - **Change**: Track I/O latency percentiles, queue depth, cache efficiency + - **Implementation**: Extend stats dictionary with detailed performance metrics + +- **Sub-Task 3.1.3**: Implement performance alerts + - **Location**: `ccbt/monitoring/alert_manager.py` (if exists) + - **Change**: Alert on performance degradation (high latency, low throughput) + - **Implementation**: Add thresholds and alert triggers for performance issues + +#### Task 3.2: Auto-Tuning Configuration + +**File**: `ccbt/config/config.py`, `ccbt/models.py` + +- **Sub-Task 3.2.1**: Add automatic buffer size tuning + - **Location**: Configuration initialization + - **Change**: Detect system capabilities and set optimal buffer sizes + - **Implementation**: Query system limits and set buffers to optimal values + +- **Sub-Task 3.2.2**: Implement storage device detection and tuning + - **Location**: `ccbt/storage/disk_io.py:210-236` + - **Change**: Detect storage type and apply optimal settings automatically + - **Implementation**: Extend detection to identify HDD/SSD/NVMe and configure accordingly + +- **Sub-Task 3.2.3**: Add adaptive configuration based on system resources + - **Location**: Configuration loading + - **Change**: Adjust worker counts, queue sizes based on CPU cores, RAM, storage speed + - **Implementation**: Query system resources and calculate optimal defaults + +### Phase 4: Advanced Optimizations + +#### Task 4.1: Implement Zero-Copy I/O Where Possible + +**File**: `ccbt/storage/disk_io.py:794-898` + +- **Sub-Task 4.1.1**: Use sendfile() for reading pieces to network + - **Location**: Piece serving code + - **Change**: Use OS-level zero-copy when sending data from disk to network + - **Implementation**: Use `os.sendfile()` on Linux/FreeBSD, `TransmitFile()` on Windows + +- **Sub-Task 4.1.2**: Optimize memoryview usage + - **Location**: `ccbt/storage/file_assembler.py:458-493` + - **Change**: Minimize copies by using memoryview consistently + - **Implementation**: Ensure all data operations use memoryview where possible + +#### Task 4.2: Implement io_uring Support (Linux) + +**File**: `ccbt/storage/disk_io.py:814-817` (config), new io_uring module + +- **Sub-Task 4.2.1**: Add io_uring backend + - **Location**: New file `ccbt/storage/io_uring_backend.py` + - **Change**: Implement async I/O using io_uring for Linux + - **Implementation**: Create io_uring-based I/O backend with submission/completion queues + +- **Sub-Task 4.2.2**: Integrate io_uring with DiskIOManager + - **Location**: `ccbt/storage/disk_io.py:794-898` + - **Change**: Use io_uring when available and enabled + - **Implementation**: Add fallback mechanism to thread pool if io_uring unavailable + +#### Task 4.3: Optimize Ring Buffer Usage + +**File**: `ccbt/storage/disk_io.py:133-145, 731-770` + +- **Sub-Task 4.3.1**: Improve ring buffer staging efficiency + - **Location**: `ccbt/storage/disk_io.py:731-770` + - **Change**: Better integration of ring buffer with write batching + - **Implementation**: Ensure ring buffer data is properly staged before flush + +- **Sub-Task 4.3.2**: Add ring buffer size tuning + - **Location**: `ccbt/storage/disk_io.py:134-145` + - **Change**: Dynamically size ring buffer based on write patterns + - **Implementation**: Monitor write sizes and adjust ring buffer accordingly + +## Implementation Order and Dependencies + +1. **Phase 1, Task 1.1-1.2** (Connection pooling, HTTP sessions) - Foundation for network optimizations +2. **Phase 2, Task 2.1-2.2** (Write batching, MMap cache) - High-impact disk optimizations +3. **Phase 1, Task 1.3-1.4** (Socket buffers, pipelining) - Performance improvements +4. **Phase 2, Task 2.3-2.4** (Checkpoints, reads) - Additional disk optimizations +5. **Phase 3** (Monitoring, auto-tuning) - Validation and fine-tuning +6. **Phase 4** (Advanced) - Cutting-edge optimizations + +## Testing Strategy + +- Performance benchmarks for each optimization +- Integration tests with real torrents +- Resource usage monitoring (CPU, memory, I/O) +- Regression testing to ensure no functionality loss + +## Estimated Impact + +- **Network**: 20-40% improvement in connection establishment, 15-30% throughput increase +- **Disk I/O**: 30-50% improvement in write throughput, 20-35% reduction in read latency +- **Overall**: 25-40% improvement in download speeds on fast connections \ No newline at end of file diff --git a/.cursor/rules/bitTorrent-protocols.mdc b/.cursor/rules/bitTorrent-protocols.mdc index 5ab0d65..8f4634c 100644 --- a/.cursor/rules/bitTorrent-protocols.mdc +++ b/.cursor/rules/bitTorrent-protocols.mdc @@ -1,116 +1,83 @@ --- -globs: ccbt/torrent.py,ccbt/peer.py,ccbt/tracker.py,ccbt/dht.py,ccbt/extensions/*.py -description: BitTorrent protocol implementation patterns +globs: ccbt/protocols/**/*.py,ccbt/peer/**/*.py,ccbt/discovery/**/*.py,ccbt/extensions/**/*.py,ccbt/core/torrent*.py +description: BitTorrent protocol implementation patterns and BEP compliance --- # BitTorrent Protocol Implementation -## Core Protocols Implemented - -### BitTorrent Protocol (BEP 5) -- **Handshake**: 68-byte handshake with protocol string, reserved bytes, info hash, peer ID -- **Message Types**: Keep-alive, choke, unchoke, interested, not interested, have, bitfield, request, piece, cancel, port -- **Piece Management**: 16KB blocks, piece verification with SHA-1 -- **Peer Communication**: TCP connections with message framing - -### Fast Extension (BEP 6) -- **Suggest Piece**: Suggest pieces to peers -- **Have All**: Indicate having all pieces -- **Have None**: Indicate having no pieces -- **Reject Request**: Reject specific piece requests -- **Allow Fast**: Allow fast piece requests - -### Extension Protocol (BEP 10) -- **Extension Handshake**: Negotiate supported extensions -- **Custom Extensions**: Support for custom extension messages -- **Extension Messages**: Extended message format with message IDs - -### WebSeed (BEP 19) -- **HTTP Range Requests**: Download pieces via HTTP -- **WebSeed Integration**: Combine BitTorrent and HTTP sources -- **Fallback Support**: Use WebSeed when BitTorrent peers unavailable - -### Compact Peer Lists (BEP 23) -- **IPv4 Format**: 6-byte compact format (4 bytes IP + 2 bytes port) -- **IPv6 Format**: 18-byte compact format (16 bytes IP + 2 bytes port) -- **Efficient Parsing**: Optimized peer list parsing - -### DHT (BEP 5) -- **Kademlia Algorithm**: Distributed hash table implementation -- **Peer Discovery**: Find peers without trackers -- **Bootstrap Nodes**: Connect to DHT network -- **Node Management**: Maintain DHT node table - -### PEX (BEP 11) -- **Peer Exchange**: Exchange peer lists between connected peers -- **Efficient Discovery**: Reduce dependency on trackers -- **Peer Lists**: Compact peer list exchange +## Core Protocols (BEP 3, 5) + +**Base Protocol**: 68-byte handshake (protocol string, reserved bytes, 20-byte info hash, 20-byte peer ID). Message types: keep-alive, choke, unchoke, interested, not interested, have, bitfield, request, piece, cancel, port. SHA-1 hashing for v1 (BEP 3). See [`ccbt/protocols/bittorrent.py`](mdc:ccbt/protocols/bittorrent.py). + +**Protocol v2 (BEP 52)**: SHA-256 hashing, 32-byte info hash, Merkle tree structure, hybrid support. See [`ccbt/protocols/bittorrent_v2.py`](mdc:ccbt/protocols/bittorrent_v2.py), [`ccbt/core/torrent_v2.py`](mdc:ccbt/core/torrent_v2.py). + +## Discovery Protocols + +**DHT (BEP 5)**: Kademlia algorithm in [`ccbt/discovery/dht.py`](mdc:ccbt/discovery/dht.py). IPv6 support (BEP 32), read-only mode (BEP 43), storage (BEP 44), multi-address (BEP 45), indexing (BEP 51). Private torrents (BEP 27) disable DHT. + +**Trackers**: HTTP/UDP trackers in [`ccbt/discovery/tracker.py`](mdc:ccbt/discovery/tracker.py), UDP client (BEP 15) in [`ccbt/discovery/tracker_udp_client.py`](mdc:ccbt/discovery/tracker_udp_client.py). Scrape support (BEP 48). Tiered announce lists (BEP 12). + +**PEX (BEP 11)**: Peer exchange in [`ccbt/extensions/pex.py`](mdc:ccbt/extensions/pex.py), [`ccbt/discovery/pex.py`](mdc:ccbt/discovery/pex.py). Disabled for private torrents (BEP 27). + +**Magnet Links (BEP 9)**: Parsing in [`ccbt/core/magnet.py`](mdc:ccbt/core/magnet.py). File selection (BEP 53) via `so` and `x.pe` parameters. + +## Extension Protocol (BEP 10) + +**Extension Manager**: [`ccbt/extensions/manager.py`](mdc:ccbt/extensions/manager.py) coordinates all extensions. Handshake negotiation in [`ccbt/extensions/protocol.py`](mdc:ccbt/extensions/protocol.py). + +**Fast Extension (BEP 6)**: [`ccbt/extensions/fast.py`](mdc:ccbt/extensions/fast.py) - suggest piece, have all/none, reject request, allow fast. + +**Compact Peer Lists (BEP 23)**: IPv4 (6 bytes), IPv6 (18 bytes) in [`ccbt/extensions/compact.py`](mdc:ccbt/extensions/compact.py). + +**WebSeed (BEP 19)**: HTTP range requests in [`ccbt/extensions/webseed.py`](mdc:ccbt/extensions/webseed.py). + +**SSL/TLS**: Peer/tracker encryption in [`ccbt/extensions/ssl.py`](mdc:ccbt/extensions/ssl.py). + +**XET Extension**: Content-defined chunking, deduplication, P2P CAS. See [`ccbt/extensions/xet.py`](mdc:ccbt/extensions/xet.py), [`docs/bep_xet.md`](mdc:docs/bep_xet.md). + +## File Attributes (BEP 47) + +**Preservation**: Symlinks, executable bits, hidden files. SHA-1 file verification. Padding file skipping. See [`ccbt/piece/async_piece_manager.py`](mdc:ccbt/piece/async_piece_manager.py) checkpoint handling. + +## Private Torrents (BEP 27) + +**Enforcement**: DHT, PEX, LSD disabled. Only tracker-provided peers accepted. Detection in [`ccbt/session/torrent_utils.py`](mdc:ccbt/session/torrent_utils.py), validation in [`ccbt/peer/async_peer_connection.py`](mdc:ccbt/peer/async_peer_connection.py). + +## Transport Protocols + +**uTP (BEP 29)**: uTorrent Transport Protocol for congestion control. See [`ccbt/transport/`](mdc:ccbt/transport/). + +**WebTorrent**: WebRTC data channels, WebSocket trackers in [`ccbt/protocols/webtorrent.py`](mdc:ccbt/protocols/webtorrent.py). ## Implementation Patterns +### Session Delegation + +Session orchestrates via [`ccbt/session/session.py`](mdc:ccbt/session/session.py), delegates to controllers: +- **Announce**: [`ccbt/session/announce.py`](mdc:ccbt/session/announce.py) - tracker announces +- **Checkpointing**: [`ccbt/session/checkpointing.py`](mdc:ccbt/session/checkpointing.py) - state persistence +- **Download Startup**: [`ccbt/session/download_startup.py`](mdc:ccbt/session/download_startup.py) - initialization +- **Torrent Addition**: [`ccbt/session/torrent_addition.py`](mdc:ccbt/session/torrent_addition.py) - torrent/magnet handling + ### Message Handling -```python -class PeerConnection: - async def handle_message(self, message: bytes) -> None: - if message[0] == MessageType.CHOKE: - await self.handle_choke() - elif message[0] == MessageType.UNCHOKE: - await self.handle_unchoke() - # ... other message types -``` - -### Piece Selection -```python -class PieceManager: - def get_next_piece(self) -> Optional[int]: - # Rarest-first algorithm - rarest_pieces = self.get_rarest_pieces() - return rarest_pieces[0] if rarest_pieces else None -``` - -### Tracker Communication -```python -class Tracker: - async def announce(self, torrent: Torrent, peer_id: bytes) -> TrackerResponse: - params = { - 'info_hash': torrent.info_hash, - 'peer_id': peer_id, - 'port': self.port, - 'uploaded': torrent.uploaded_bytes, - 'downloaded': torrent.downloaded_bytes, - 'left': torrent.left_bytes - } - # HTTP GET request to tracker -``` - -### DHT Implementation -```python -class DHT: - async def find_peers(self, info_hash: bytes) -> List[PeerInfo]: - # Kademlia FIND_PEERS query - closest_nodes = self.get_closest_nodes(info_hash) - # Query nodes for peers -``` - -## Protocol Extensions - -### MSE/PE (BEP 3) -- **Message Stream Encryption**: Encrypt peer communication -- **Protocol Encryption**: Encrypt handshake and messages -- **Key Exchange**: Secure key exchange mechanism - -### WebTorrent Support -- **WebRTC Data Channels**: Browser-based peer connections -- **WebSocket Trackers**: WebSocket-based tracker communication -- **Hybrid Mode**: Support both BitTorrent and WebTorrent peers - -### IPFS Integration -- **Content Addressing**: Content-addressed storage -- **IPFS Gateways**: HTTP gateway support -- **Hybrid Protocol**: BitTorrent + IPFS hybrid mode - -## Error Handling -- **Protocol Violations**: Handle invalid protocol messages -- **Connection Errors**: Handle network connection issues -- **Timeout Handling**: Handle peer and tracker timeouts -- **Retry Logic**: Implement exponential backoff for retries \ No newline at end of file + +Peer connections in [`ccbt/peer/async_peer_connection.py`](mdc:ccbt/peer/async_peer_connection.py). Extension messages (BEP 10) handled via `handle_extension_message()`. v2 messages (BEP 52) via `handle_v2_message()`. + +### Piece Management + +Piece manager in [`ccbt/piece/async_piece_manager.py`](mdc:ccbt/piece/async_piece_manager.py). Supports v1/v2/hybrid (BEP 52). Metadata exchange (BEP 10 + ut_metadata) in [`ccbt/piece/async_metadata_exchange.py`](mdc:ccbt/piece/async_metadata_exchange.py). + +### Error Handling + +**Timeouts**: All async operations use `asyncio.wait_for()` with configurable timeouts. See session startup patterns. + +**Protocol Violations**: Invalid messages logged and connection closed gracefully. + +**Retry Logic**: Exponential backoff for tracker announces, DHT queries. See [`ccbt/discovery/tracker.py`](mdc:ccbt/discovery/tracker.py). + +## References + +- Protocol v2: [`docs/bep52.md`](mdc:docs/bep52.md) +- XET Extension: [`docs/bep_xet.md`](mdc:docs/bep_xet.md) +- Session Architecture: [`ccbt/session/session.py`](mdc:ccbt/session/session.py) +- Extension Manager: [`ccbt/extensions/manager.py`](mdc:ccbt/extensions/manager.py) \ No newline at end of file diff --git a/.cursor/rules/cli-interface.mdc b/.cursor/rules/cli-interface.mdc deleted file mode 100644 index 3d1b7e6..0000000 --- a/.cursor/rules/cli-interface.mdc +++ /dev/null @@ -1,105 +0,0 @@ ---- -globs: ccbt/cli/*.py,ccbt/__main__.py -description: CLI and interface implementation patterns ---- - -# CLI & Interface Implementation - -## CLI Architecture -Located in [ccbt/cli/](mdc:ccbt/cli/) directory: - -### Main CLI -- **Entry Point**: [ccbt/__main__.py](mdc:ccbt/__main__.py) - Main CLI entry point -- **Rich Interface**: Beautiful CLI with Rich library integration -- **Command System**: Comprehensive command system with Click -- **Configuration**: CLI-based configuration management - -### Interactive CLI -- **Real-time Display**: Live statistics and progress updates -- **Interactive Commands**: Command-based interface with help system -- **Progress Tracking**: Real-time download progress monitoring -- **Peer Monitoring**: Live peer connection monitoring - -### Progress Management -- **Multiple Progress Types**: Download, upload, piece, speed, peer progress -- **Real-time Updates**: Live progress updates with ETA calculation -- **Speed Monitoring**: Download/upload speed tracking -- **Completion Tracking**: Piece and file completion tracking - -## CLI Commands - -### Basic Commands -```bash -# Download torrent file -ccbt download example.torrent - -# Download from magnet link -ccbt magnet "magnet:?xt=urn:btih:..." - -# Start interactive mode -ccbt interactive - -# Start web interface -ccbt web --port 9090 -``` - -### Advanced Commands -```bash -# Debug mode -ccbt debug - -# Show status -ccbt status - -# Configuration management -ccbt config --create -ccbt config --edit -``` - -## Implementation Patterns - -### CLI Command Structure -```python -import click -from rich.console import Console - -@click.command() -@click.argument('torrent_file', type=click.Path(exists=True)) -@click.option('--interactive', '-i', is_flag=True, help='Start interactive mode') -def download(torrent_file, interactive): - console = Console() - # Implementation -``` - -### Interactive Interface -```python -from ccbt.cli import InteractiveCLI - -interactive_cli = InteractiveCLI(session, console) -await interactive_cli.run() -``` - -### Progress Bars -```python -from ccbt.cli import ProgressManager - -progress_manager = ProgressManager(console) -with progress_manager.create_progress() as progress: - task = progress.add_task("Downloading", total=100) - # Update progress - progress.update(task, completed=50) -``` - -## Rich Interface Features -- **Progress Bars**: Live progress tracking with ETA -- **Tables**: Structured data display -- **Panels**: Information panels with borders -- **Live Updates**: Real-time display updates -- **Color Coding**: Status-based color coding -- **Interactive Elements**: User input and confirmation prompts - -## Configuration Integration -- **Environment Variables**: CCBT_ prefixed environment variables -- **Configuration Files**: TOML-based configuration -- **Hot Reload**: Configuration changes without restart -- **Validation**: Pydantic-based configuration validation \ No newline at end of file diff --git a/.cursor/rules/development-patterns.mdc b/.cursor/rules/development-patterns.mdc index e2300b2..1d85da3 100644 --- a/.cursor/rules/development-patterns.mdc +++ b/.cursor/rules/development-patterns.mdc @@ -1,72 +1,95 @@ --- -globs: *.py +alwaysApply: true description: Development patterns and coding standards for ccBitTorrent --- +# ccBitTorrent Development Patterns (uv + dev) -# ccBitTorrent Development Patterns - -## Type Safety Requirements -- **All functions must have type hints** - Use `typing` module extensively -- **Use Pydantic models** - Replace dataclasses with Pydantic BaseModel for validation -- **Async functions** - Use `async def` for all I/O operations -- **Return type annotations** - Always specify return types, use `-> None` for void functions - -## Async Programming Patterns -```python -# Correct async pattern -async def download_torrent(torrent: Torrent) -> None: - await session.start_download(torrent) - while not torrent.is_complete(): - await asyncio.sleep(1) - -# Use context managers for resource cleanup -async with session: - await session.start_download(torrent) -``` - -## Event-Driven Architecture -- **Emit events** for all significant actions using [ccbt/events.py](mdc:ccbt/events.py) -- **Subscribe to events** for component communication -- **Use typed events** with proper data structures - -```python -from ccbt.events import Event, EventType, emit_event - -# Emit events -await emit_event(Event( - event_type=EventType.PEER_CONNECTED.value, - data={'peer_id': peer_id, 'ip': ip} -)) -``` - -## Error Handling -- **Use custom exceptions** from [ccbt/exceptions.py](mdc:ccbt/exceptions.py) -- **Proper error propagation** in async code -- **Context managers** for resource cleanup - -```python -from ccbt.exceptions import NetworkError, DiskError - -try: - await peer.connect() -except NetworkError as e: - logger.error(f"Network error: {e}") - raise -``` - -## Configuration Management -- **Use Pydantic models** for configuration validation -- **Environment variable overrides** with CCBT_ prefix -- **Hot reload support** for configuration changes - -## Performance Optimization +## Tooling & Configuration +- **All configs in `dev/`**: [`dev/ruff.toml`](mdc:dev/ruff.toml), [`dev/ty.toml`](mdc:dev/ty.toml), [`dev/pytest.ini`](mdc:dev/pytest.ini), [`dev/mkdocs.yml`](mdc:dev/mkdocs.yml), [`dev/pre-commit-config.yaml`](mdc:dev/pre-commit-config.yaml), [`dev/.codecov.yml`](mdc:dev/.codecov.yml) +- **Use `uv` for all commands** - No Makefile. Install pre-commit: `uv run pre-commit install --config dev/pre-commit-config.yaml` (also `--hook-type commit-msg`) + +## Standard Commands +- **Lint**: `uv run ruff --config dev/ruff.toml check ccbt/ --fix --exit-non-zero-on-fix` +- **Format**: `uv run ruff --config dev/ruff.toml format ccbt/` +- **Types**: `uv run ty check --config-file=dev/ty.toml --output-format=concise` +- **Tests**: `uv run pytest -c dev/pytest.ini tests/ -v --tb=short --maxfail=5 --timeout=60` +- **Coverage**: `uv run pytest -c dev/pytest.ini tests/ --cov=ccbt --cov-report=term-missing --cov-report=xml --cov-report=html` +- **Security**: `uv run bandit -r ccbt/ -f json -o docs/reports/bandit/bandit-report.json --severity-level medium -x tests,benchmarks,dev,dist,docs,htmlcov,site,.venv,.pre-commit-cache,.pre-commit-home,.pytest_cache,.ruff_cache,.hypothesis,.github,.ccbt,.cursor,.benchmarks` +- **Docs**: `uv run mkdocs build --strict -f dev/mkdocs.yml` + +## Selective Testing +- Use [`tests/scripts/run_pytest_selective.py`](mdc:tests/scripts/run_pytest_selective.py) with [`tests/scripts/get_test_markers.py`](mdc:tests/scripts/get_test_markers.py) +- Critical files trigger full suite: `dev/pytest.ini`, `dev/pre-commit-config.yaml`, `dev/.codecov.yml`, `tests/conftest.py`, `ccbt/config/config.py` + +## Reports in Docs +- Coverage HTML: `docs/reports/coverage/` (linked in nav) +- Bandit JSON: `docs/reports/bandit/bandit-report.json` (rendered by [`docs/reports/bandit/index.md`](mdc:docs/reports/bandit/index.md)) + +## Architecture & Separation of Concerns + +### Module Boundaries +- **CLI (`ccbt/cli/`)**: Command definitions, orchestration, UI output. Delegates to session. +- **Session (`ccbt/session/`)**: Torrent lifecycle, component coordination. Delegates to specialized controllers. +- **Core (`ccbt/core/`, `ccbt/peer/`, `ccbt/piece/`, `ccbt/storage/`)**: Domain logic, no CLI/session dependencies. +- **Orchestration modules**: [`ccbt/cli/downloads.py`](mdc:ccbt/cli/downloads.py), [`ccbt/cli/status.py`](mdc:ccbt/cli/status.py), [`ccbt/cli/resume.py`](mdc:ccbt/cli/resume.py) bridge CLI→Session. + +### Session Delegation Pattern +- `AsyncSessionManager` orchestrates; delegates to controllers: + - [`ccbt/session/announce.py`](mdc:ccbt/session/announce.py): Tracker announces + - [`ccbt/session/checkpointing.py`](mdc:ccbt/session/checkpointing.py): Checkpoint operations + - [`ccbt/session/download_startup.py`](mdc:ccbt/session/download_startup.py): Download initialization + - [`ccbt/session/torrent_addition.py`](mdc:ccbt/session/torrent_addition.py): Torrent addition flow + - [`ccbt/session/manager_startup.py`](mdc:ccbt/session/manager_startup.py): Component startup sequence + +### Dependency Injection +- Optional DI via [`ccbt/utils/di.py`](mdc:ccbt/utils/di.py): `DIContainer` for factories (security, DHT, NAT, TCP server) +- Falls back to concrete classes when DI not provided +- Use `ComponentFactory` for component creation + +## Type Safety & Code Quality + +### Type Hints +- **All functions require type hints** - Use `typing` module, `from __future__ import annotations` +- **Pydantic models** - Use `BaseModel` for validation, not dataclasses +- **Async functions** - `async def` for all I/O operations +- **Return types** - Always specify, use `-> None` for void functions + +### Async/Await Patterns +- **Always await async functions** - Never call async functions without `await`. Calling without await returns a coroutine object, not the result, causing race conditions and bugs. +- **Correct**: `result = await async_function()` +- **Incorrect**: `result = async_function()` then checking `if asyncio.iscoroutine(result)` +- **Singleton async functions** - If a function returns a singleton (like `get_udp_tracker_client()`), always await it directly. Multiple concurrent calls without await can create multiple instances, causing resource conflicts. +- **Error handling** - Use `try/except` around awaited calls. Use `asyncio.wait_for()` for timeouts. + +### Error Handling +- **Custom exceptions** from [`ccbt/utils/exceptions.py`](mdc:ccbt/utils/exceptions.py) +- **Timeout patterns** - Use `asyncio.wait_for()` with timeouts for blocking operations +- **Graceful degradation** - Log warnings, continue when non-critical components fail + +### Configuration +- **Pydantic models** in [`ccbt/config/config.py`](mdc:ccbt/config/config.py) for validation +- **CLI overrides** via [`ccbt/cli/overrides.py`](mdc:ccbt/cli/overrides.py): `apply_cli_overrides(config_manager, kwargs)` +- **Environment variables** with `CCBT_` prefix + +## Performance & Security + +### Performance - **Zero-copy operations** where possible - **Memory pools** for frequent allocations - **Ring buffers** for high-throughput operations - **SIMD-accelerated** hash verification +- **Async I/O** - All disk/network operations are async -## Security Patterns -- **Validate all inputs** using Pydantic models -- **Rate limiting** for all external interactions +### Security +- **Input validation** via Pydantic models +- **Rate limiting** for external interactions - **Peer validation** before connections -- **Encryption support** for sensitive data \ No newline at end of file +- **Encryption support** for sensitive data +- **IP filtering** via [`ccbt/security/security_manager.py`](mdc:ccbt/security/security_manager.py) + +## Testing Patterns +- **Markers**: Use pytest markers (`@pytest.mark.unit`, `@pytest.mark.integration`, etc.) defined in [`dev/pytest.ini`](mdc:dev/pytest.ini) +- **Coverage target**: 99% project-wide, 90% patch (see [`dev/.codecov.yml`](mdc:dev/.codecov.yml)) +- **Selective runs**: Test only affected modules via selective test runner +- **Mock patterns**: Handle `AttributeError`/`TypeError` gracefully for test mocks +- **Pragma comments**: Use `# pragma: no cover` for UI-only paths, defensive error handlers \ No newline at end of file diff --git a/.cursor/rules/documentation-standards.mdc b/.cursor/rules/documentation-standards.mdc index 0f67f1d..dc1b4eb 100644 --- a/.cursor/rules/documentation-standards.mdc +++ b/.cursor/rules/documentation-standards.mdc @@ -1,3 +1,29 @@ +--- +description: Documentation standards and structure for ccBitTorrent (MkDocs, reports embedding) +globs: "docs/**/*.md" +--- +# Documentation Standards + +## Structure +- Documentation in [`docs/`](mdc:docs/); site built with MkDocs using [`dev/mkdocs.yml`](mdc:dev/mkdocs.yml). +- Add new pages under `docs/`; update navigation in `dev/mkdocs.yml`. + +## Reports in Docs +- Coverage HTML must be placed under `docs/reports/coverage/` so it can be linked as `reports/coverage/index.html` in nav. +- Bandit JSON must be written to `docs/reports/bandit/bandit-report.json`. Render it in [`docs/reports/bandit/index.md`](mdc:docs/reports/bandit/index.md) using a fenced include: + +```json +--8<-- "reports/bandit/bandit-report.json" +``` + +## Build +- Build docs: `uv run mkdocs build --strict -f dev/mkdocs.yml`. + +## Writing +- Use clear headers and short sections. +- Use relative links for internal pages. +- Provide bash/toml/python code blocks with syntax highlighting where appropriate. + --- globs: docs/**/*.md,*.md description: Documentation standards and requirements diff --git a/.cursor/rules/project-structure.mdc b/.cursor/rules/project-structure.mdc index 3f45e23..1451647 100644 --- a/.cursor/rules/project-structure.mdc +++ b/.cursor/rules/project-structure.mdc @@ -1,3 +1,30 @@ +--- +alwaysApply: true +description: Project structure and configuration locations for ccBitTorrent (dev, docs, uv usage) +--- +# Project Structure and Config Locations + +- Config files live in `dev/`: + - `dev/pre-commit-config.yaml` + - `dev/pytest.ini` + - `dev/ruff.toml` + - `dev/ty.toml` + - `dev/mkdocs.yml` + - `dev/.codecov.yml` (if present) +- Project root keeps `pyproject.toml` and `ccbt.toml`. +- Makefile was removed. Prefer `uv` commands: + - Lint: `uv run ruff --config dev/ruff.toml check ccbt/ --fix --exit-non-zero-on-fix` + - Format: `uv run ruff --config dev/ruff.toml format ccbt/` + - Type check: `uv run ty check --config-file=dev/ty.toml --output-format=concise` + - Tests: `uv run pytest -c dev/pytest.ini tests/ ...` + - Pre-commit: `uv run pre-commit run --all-files -c dev/pre-commit-config.yaml` +- Docs build uses MkDocs config at `dev/mkdocs.yml`. +- Reports embedded in docs: + - Coverage HTML copied to `docs/reports/coverage/` (link in nav). + - Bandit JSON written to `docs/reports/bandit/bandit-report.json` and rendered via `docs/reports/bandit/index.md`. + +Key paths referenced across scripts/tests/docs must use the `dev/` versions (not root). + --- description: Project structure and architecture overview alwaysApply: false diff --git a/.cursor/rules/terminal_dashboard.mdc b/.cursor/rules/terminal_dashboard.mdc index 15d9206..a61bbd3 100644 --- a/.cursor/rules/terminal_dashboard.mdc +++ b/.cursor/rules/terminal_dashboard.mdc @@ -1,97 +1,318 @@ --- -globs: ccbt/interface/terminal_dashboard.py -description: Guidance and constraints for Textual-based terminal dashboard implementation +description: Terminal dashboard implementation patterns using Textual framework +globs: ccbt/interface/**/*.py --- -# Terminal Dashboard Rules - -These rules apply to the Textual dashboard in [ccbt/interface/terminal_dashboard.py](mdc:ccbt/interface/terminal_dashboard.py) and align with the roadmap in [textualinterface](mdc:textualinterface). - -## Architecture and Composition -- Prefer compose()/yield over imperative mount during layout construction. - - Build the layout tree in `compose()` using `with` blocks and `yield`. - - Use `on_mount()` only for wiring, background tasks, intervals, and querying refs. -- Query widgets after compose using `query_one` with explicit types. -- Keep I/O async and non-blocking. Use `set_interval()` for periodic UI updates. -- Use `App.BINDINGS` for key actions; implement corresponding `action_*` methods. - -## Rendering with Textual and Rich -- Only pass Rich renderables, text, or Content objects to `Static.update()`. - - Valid: `str`, `rich.table.Table`, `rich.panel.Panel`, etc. - - Invalid: Textual widgets such as `Container`, `Horizontal`, `Vertical`, `DataTable`, `Sparkline`, `Static` instances. -- Never wrap Textual widgets inside Rich renderables (e.g., `Panel(Container(...))`). -- To show multiple renderables in one area, compose a Rich layout (e.g., `Table.grid`) and update the `Static` with that renderable. -- For errors, display a short Rich `Panel` with a message (avoid raising inside the UI loop). - -References: -- Content and rendering: [Content guide](https://textual.textualize.io/guide/content/) -- Widgets overview: [Widgets guide](https://textual.textualize.io/guide/widgets/) -- Styles and layout: [Layout](https://textual.textualize.io/guide/layout/), [Styles reference](https://textual.textualize.io/reference/styles/) - -## Containers and Layout -- Use `Horizontal`/`Container` for structure; manage sizing via CSS only. -- Use fractional sizing and min-heights in CSS for predictable layout: - - `#body { layout: horizontal; } - #left, #right { width: 1fr; } - #overview { height: 1fr; min-height: 8 } - #speeds { height: 1fr; min-height: 5 }` -- Do not attempt to render container widgets; they are not Rich renderables. - -Docs: -- Containers API: [textual.containers](https://textual.textualize.io/api/textual.containers/) -- Grid and size properties: [Grid styles](https://textual.textualize.io/reference/styles/#grid), [Width/Height](https://textual.textualize.io/reference/styles/#width) - -## Widget-Specific Guidance -- Overview (`Static` subclass): generate a `rich.table.Table` and wrap in `rich.panel.Panel`. -- Torrents/Peers (`DataTable`): - - Add columns in `on_mount()`. - - Keep the selection model stable across refresh by reusing row keys. - - Clear and repopulate rows on update; avoid heavy per-row formatting in the UI loop. -- Speeds (`Sparkline` widgets): - - Mount `Sparkline` children directly as Textual widgets; do not place them inside a `Panel`. - - The label/title for the area should be a `Static.update("Speeds")` or a Rich renderable on the parent `Static`. -- Logs (`RichLog`): write short, concise messages; avoid high-frequency spam. -- Input: rely on `Input.Submitted` for command/filter handling; hide input after processing. - -Docs: -- DataTable: https://textual.textualize.io/reference/widgets/#datatable -- Sparkline: https://textual.textualize.io/reference/widgets/#sparkline -- RichLog: https://textual.textualize.io/reference/widgets/#richlog -- Input events: https://textual.textualize.io/reference/widgets/#input - -## Events, Actions, and Key Handling -- Use `BINDINGS` for common actions and implement `action_*` methods. -- For raw key handling, use `on_key` sparingly; prefer actions for discoverability. -- For inputs, handle `on_input_submitted` with id-based routing. - -Docs: -- Actions & bindings: https://textual.textualize.io/guide/actions/ -- Key event: https://textual.textualize.io/reference/events/#key - -## Async and Background Work -- All I/O must be `async` and awaited. -- Use `set_interval()` to schedule periodic updates; gate concurrent polls with a task guard. -- Avoid long operations in UI thread; prefer service calls (`AsyncSessionManager`) and lightweight UI updates. - -## Error Handling and Resilience -- Wrap external/service calls with `contextlib.suppress` where failure is non-critical. -- On exceptions during refresh, update a visible area (`#overview` or status bar) with a red `Panel` containing a concise message; keep the app responsive. -- Never crash the UI due to a non-renderable content; ensure `Static.update()` receives only renderables/text. - -## Metrics and Alerts -- Metrics collection should be optional and failure-tolerant. -- When showing alert rules/active alerts, build Rich tables and combine via `Table.grid`, then `Static.update(Panel(grid, title="Alerts"))`. - -## Theming and Compact Mode -- Toggle theme via `self.dark` boolean; reflect state in status bar. -- For compact mode, adjust `.styles.height` and `.display` of panels; call `refresh(layout=True)` afterward. - -## Testing and Docs -- Add unit tests for composition, bindings, and basic refresh cycle. -- Document user interactions (keys, command palette) and troubleshooting. - -## Prohibited Patterns (lint-level rules) -- Do not pass Textual widgets to Rich containers (e.g., `Panel(Container(...))`). -- Do not block the event loop with synchronous I/O. -- Do not modify layout tree in the refresh loop unless necessary (prefer state updates). +# Terminal Dashboard Implementation Guide +This rule covers patterns and best practices for implementing the Textual-based terminal dashboard in `ccbt/interface/`. + +## Module Structure + +The interface module follows a modular architecture: + +``` +ccbt/interface/ +├── terminal_dashboard.py # Main App class and entry points +├── widgets/ # Reusable UI components +│ ├── core_widgets.py # Overview, TorrentsTable, PeersTable, SpeedSparklines +│ └── reusable_widgets.py # ProgressBarWidget, MetricsTableWidget, SparklineGroup +├── screens/ # Screen components +│ ├── base.py # Base classes (ConfigScreen, MonitoringScreen) +│ ├── dialogs.py # Modal dialogs (AddTorrentScreen) +│ ├── monitoring/ # Monitoring screens (15 screens) +│ ├── config/ # Configuration screens (7 screens) +│ └── utility/ # Utility screens (Help, Navigation, FileSelection) +└── commands/ # Command execution + └── executor.py # CommandExecutor class +``` + +## Import Patterns + +### Textual Import Handling + +Always use TYPE_CHECKING blocks and fallback classes for Textual imports: + +```python +from __future__ import annotations + +from typing import TYPE_CHECKING, Any, ClassVar + +if TYPE_CHECKING: + from textual.app import App, ComposeResult + from textual.screen import Screen + from textual.widgets import Static, DataTable +else: + try: + from textual.app import App, ComposeResult + from textual.screen import Screen + from textual.widgets import Static, DataTable + except ImportError: + # Fallback classes for when textual is not available + class App: # type: ignore[misc] + """Fallback App class when textual is not available.""" + + class Screen: # type: ignore[no-redef] + """Fallback Screen class.""" + + class Static: # type: ignore[no-redef] + """Fallback Static widget.""" + + ComposeResult = None # type: ignore[assignment, misc] +``` + +### Container Imports + +For containers, handle the fallback case: + +```python +try: + from textual.containers import Container, Horizontal, Vertical +except ImportError: + from typing import Any as ComposeResult + Container = None # type: ignore[assignment, misc] + Horizontal = None # type: ignore[assignment, misc] + Vertical = None # type: ignore[assignment, misc] +``` + +## Screen Implementation + +### Base Screen Pattern + +All screens should inherit from base classes in [ccbt/interface/screens/base.py](mdc:ccbt/interface/screens/base.py): + +- **MonitoringScreen**: For monitoring/metrics screens +- **ConfigScreen**: For configuration screens +- **Screen**: For utility screens + +Example monitoring screen: + +```python +from ccbt.interface.screens.base import MonitoringScreen + +class SystemResourcesScreen(MonitoringScreen): # type: ignore[misc] + """Screen to display system resource usage.""" + + CSS = """ + #content { + height: 1fr; + overflow-y: auto; + } + """ + + def compose(self) -> ComposeResult: # pragma: no cover + """Compose the screen.""" + yield Header() + with Vertical(): + yield Static(id="content") + yield Footer() + + async def _refresh_data(self) -> None: # pragma: no cover + """Refresh screen data.""" + content = self.query_one("#content", Static) + # Update content... +``` + +### CSS Patterns + +- Define CSS as class variable `CSS` (string) +- Use `#id` selectors for specific widgets +- Use layout containers: `height: 1fr` for flexible sizing +- Use `overflow-y: auto` for scrollable content +- Reference Textual design tokens: `$primary`, `$surface`, etc. + +### Compose Pattern + +Always use the `compose()` method with `yield`: + +```python +def compose(self) -> ComposeResult: # pragma: no cover + """Compose the screen.""" + yield Header() + with Vertical(): + yield Static(id="content") + yield DataTable(id="table") + yield Footer() +``` + +### Event Handling + +- Use `on_mount()` for initialization +- Use `on_unmount()` for cleanup +- Use `action_*` methods for keyboard bindings +- Use `on_*` methods for widget events (e.g., `on_button_pressed`) + +### Bindings + +Define keyboard bindings as class variable: + +```python +BINDINGS: ClassVar[list[tuple[str, str, str]]] = [ + ("escape", "back", "Back"), + ("q", "quit", "Quit"), + ("r", "refresh", "Refresh"), +] +``` + +## Widget Implementation + +### Widget Base Classes + +Widgets extend Textual widgets (usually `Static`): + +```python +from textual.widgets import Static + +class Overview(Static): # type: ignore[misc] + """Simple widget to render global stats.""" + + def update_from_stats(self, stats: dict[str, Any]) -> None: + """Update widget with statistics.""" + # Use Rich for formatting + from rich.table import Table + from rich.panel import Panel + + table = Table() + # Build table... + self.update(Panel(table, title="Overview")) +``` + +### Widget Patterns + +- Use `update()` method to change widget content +- Use Rich library for formatting (Table, Panel, etc.) +- Keep widgets focused on single responsibility +- Export widgets through `widgets/__init__.py` + +## Configuration Screens + +Configuration screens inherit from `ConfigScreen`: + +```python +from ccbt.interface.screens.base import ConfigScreen + +class SSLConfigScreen(ConfigScreen): # type: ignore[misc] + """Screen to manage SSL/TLS configuration.""" + + CSS = """...""" + BINDINGS: ClassVar[list[tuple[str, str, str]]] = [...] + + def compose(self) -> ComposeResult: + """Compose configuration screen.""" + # Use ConfigValueEditor and ConfigSectionWidget from + # ccbt/interface/screens/config/widgets.py +``` + +## Command Execution + +Use `CommandExecutor` from [ccbt/interface/commands/executor.py](mdc:ccbt/interface/commands/executor.py) to execute CLI commands: + +```python +from ccbt.interface.commands.executor import CommandExecutor + +class MyScreen(Screen): + def __init__(self, session, *args, **kwargs): + super().__init__(*args, **kwargs) + self.session = session + self._command_executor = CommandExecutor(session) + + async def action_some_command(self): + """Execute a CLI command.""" + result = await self._command_executor.execute_command( + "download", ["--torrent", "path/to/file.torrent"] + ) +``` + +## Module Exports + +### Widgets Module + +Export all widgets in [ccbt/interface/widgets/__init__.py](mdc:ccbt/interface/widgets/__init__.py): + +```python +from ccbt.interface.widgets.core_widgets import ( + Overview, + PeersTable, + SpeedSparklines, + TorrentsTable, +) +from ccbt.interface.widgets.reusable_widgets import ( + MetricsTableWidget, + ProgressBarWidget, + SparklineGroup, +) + +__all__ = [ + "MetricsTableWidget", + "Overview", + "PeersTable", + "ProgressBarWidget", + "SparklineGroup", + "SpeedSparklines", + "TorrentsTable", +] +``` + +### Screens Module + +Export base classes in [ccbt/interface/screens/__init__.py](mdc:ccbt/interface/screens/__init__.py). Individual screens are imported directly from their modules. + +## Main Dashboard + +The main dashboard in [ccbt/interface/terminal_dashboard.py](mdc:ccbt/interface/terminal_dashboard.py) contains: + +- `TerminalDashboard` class (extends `App`) +- `run_dashboard()` function +- `main()` function (CLI entry point) + +All screens and widgets are imported from their respective modules. + +## Rich Integration + +Use Rich library for formatting: + +- `Panel`: For bordered content areas +- `Table`: For tabular data +- Rich markup: `[bold]`, `[cyan]`, `[green]`, etc. + +Example: + +```python +from rich.panel import Panel +from rich.table import Table + +table = Table(title="Metrics", expand=True) +table.add_column("Metric", style="cyan", ratio=1) +table.add_column("Value", style="green", ratio=2) +table.add_row("CPU", "45%") + +content.update(Panel(table, title="System Resources")) +``` + +## Type Hints + +- Use `ComposeResult` for `compose()` return type +- Use `TYPE_CHECKING` blocks for type-only imports +- Use `# type: ignore[misc]` for Textual base classes +- Use `# pragma: no cover` for UI code that's hard to test + +## Error Handling + +- Always handle Textual import failures gracefully +- Use try/except blocks for async operations +- Display errors in UI using Rich Panels with `border_style="red"` + +## Testing Considerations + +- Mark UI code with `# pragma: no cover` +- Use integration tests for screen behavior +- Mock Textual widgets in unit tests +- Test fallback behavior when Textual is unavailable + + +## References + +- Main dashboard: [ccbt/interface/terminal_dashboard.py](mdc:ccbt/interface/terminal_dashboard.py) +- Base screens: [ccbt/interface/screens/base.py](mdc:ccbt/interface/screens/base.py) +- Widgets: [ccbt/interface/widgets/](mdc:ccbt/interface/widgets/) +- Textual docs: https://textual.textualize.io/ diff --git a/.cursor/rules/testing-patterns.mdc b/.cursor/rules/testing-patterns.mdc deleted file mode 100644 index 02d21dc..0000000 --- a/.cursor/rules/testing-patterns.mdc +++ /dev/null @@ -1,110 +0,0 @@ ---- -globs: tests/**/*.py -description: Testing patterns and requirements for ccBitTorrent ---- - -# Testing Patterns - -### Testing Requirements -- **Coverage targets**: Project 99% (Codecov), Patch 90% -- **Unit tests** for all functions/methods -- **Integration tests** for component workflows -- **Property-based tests** for algorithms with Hypothesis -- **Performance tests** using pytest-benchmark -- **Chaos tests** for resilience and fault tolerance - -### Suite Layout -Tests live in `tests/` and are organized by domain: -- `tests/unit/` with subpackages: `core/`, `disk/`, `file/`, `metadata/`, `network/`, `peer/`, `piece/`, `resilience/`, `session/`, `tracker/` -- `tests/integration/` -- `tests/property/` -- `tests/performance/` -- `tests/chaos/` -- `tests/extensions/`, `tests/protocols/`, `tests/monitoring/`, `tests/observability/`, `tests/plugins/`, `tests/ml/`, `tests/cli/`, `tests/config/` -- Shared config/fixtures in `tests/conftest.py` - -### Pytest Configuration -- Markers (from `pytest.ini` / `pyproject.toml`): - - `asyncio`, `slow`, `timeout`, `integration`, `unit`, `core`, `peer`, `piece`, `tracker`, `network`, `metadata`, `disk`, `file`, `session`, `resilience`, `connection`, `checkpoint`, `cli` -- Async mode: `asyncio_mode = auto` -- Default addopts (CI/coverage runs, from `pyproject.toml`): - - `--cov=ccbt --cov-report=term-missing --cov-report=html --cov-report=xml` - -### Core Test Fixtures and Hygiene -Defined in `tests/conftest.py`: -- Global logging handler cleanup after each test (prevents closed-file I/O errors) -- Async resource cleanup: cancel and gather pending tasks, yield to loop -- Per-test event loop via `event_loop` fixture -- Deterministic RNG seeding (env `CCBT_TEST_SEED`, defaults to 123456); optional NumPy support -- `tmp_storage` fixture for temp file/disk operations - -### Running Tests -- Full suite: `uv run pytest -v` -- By marker: `uv run pytest -m "unit and not slow"` -- With coverage (local): `uv run pytest --cov=ccbt --cov-report=term-missing --cov-report=xml` -- Timeouts: default 300s per test (`--timeout=300 --timeout-method=thread` in hooks). Coverage hook uses 600s. - -### Selective Test Execution (Pre-commit) -Pre-commit runs selective tests via `tests/scripts/run_pytest_selective.py`: -- Maps changed `ccbt/` files to markers using `tests/scripts/get_test_markers.py` -- Marker mapping derives from `.codecov.yml` flags → paths -- Critical files (`pytest.ini`, `.codecov.yml`, `.pre-commit-config.yaml`, `tests/conftest.py`, `ccbt/config.py`) force running the entire suite -- Regular hook: `-v --tb=short --maxfail=5 --timeout=300 --timeout-method=thread` -- Coverage hook (pre-push): `--cov=ccbt --cov-report=term-missing --cov-report=xml --cov-fail-under=40 --timeout=600 --timeout-method=thread` - -### Coverage and Codecov -- CI targets in `.codecov.yml`: project 99% (±1%), patch 90% (±2%) -- Flags categorize coverage by domain. Ensure paths reflect real modules: - - Example corrections: use `ccbt/peer/`, `ccbt/piece/`, `ccbt/protocols/`, etc., rather than single-file roots -- Local HTML/XML reports are enabled via pytest addopts; artifacts used by Codecov - -### Async Testing Pattern -```python -import pytest - -@pytest.mark.asyncio -async def test_async_operation(): - result = await some_async_fn() - assert result is not None -``` - -### Property-Based Testing -```python -from hypothesis import given, strategies as st - -@given(st.binary()) -def test_bencode_roundtrip(data: bytes) -> None: - encoded = ccbt.core.bencode.encode(data) - decoded = ccbt.core.bencode.decode(encoded) - assert decoded == data -``` - -### Performance Testing -```python -def test_performance(benchmark): - result = benchmark(target_function) - assert result is not None # add domain-specific threshold if applicable -``` - -### Chaos and Resilience Testing -- Fault injection and resilience under timeouts in `tests/chaos/` and `tests/unit/resilience/` -- Use markers `chaos`/`resilience` and thread-based timeouts to avoid event-loop deadlocks - -### CLI and Docs Hooks (Pre-commit) -- Lint: `uv run ruff check ccbt/ --fix` -- Format: `uv run ruff format ccbt/` -- Type check: `uv run ty check --config-file=ty.toml` -- Security: `uv run bandit -r ccbt/ -f json -o bandit-report.json --exclude tests/` -- Tests: `uv run python tests/scripts/run_pytest_selective.py` -- Coverage (pre-push): `uv run python tests/scripts/run_pytest_selective.py --coverage` -- Docs: `uv run mkdocs build --strict` - -### Expectations for New Tests -- Include unit tests for new functions and methods -- Add integration tests when behavior spans multiple services/components -- Add property tests for serialization, selection, or algorithmic logic -- Add performance tests for optimizations or critical paths -- Respect markers and directory conventions to integrate with selective runs -- Keep tests deterministic (use provided fixtures), avoid uncontrolled sleeps - - diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..aa9ae1c --- /dev/null +++ b/.env.example @@ -0,0 +1,334 @@ +# ccBitTorrent Environment Variables Configuration +# Copy this file to .env and modify values as needed +# All variables are prefixed with CCBT_ to avoid conflicts + +# ============================================================================= +# NETWORK CONFIGURATION +# ============================================================================= + +# Connection limits +CCBT_MAX_PEERS=200 # Maximum global peers (1-10000) +CCBT_MAX_PEERS_PER_TORRENT=50 # Maximum peers per torrent (1-1000) +CCBT_MAX_CONNECTIONS_PER_PEER=1 # Max parallel connections per peer (1-8) + +# Request pipeline settings +CCBT_PIPELINE_DEPTH=16 # Request pipeline depth (1-128) +CCBT_BLOCK_SIZE_KIB=16 # Block size in KiB (1-64) +CCBT_MIN_BLOCK_SIZE_KIB=4 # Minimum block size in KiB (1-64) +CCBT_MAX_BLOCK_SIZE_KIB=64 # Maximum block size in KiB (1-1024) + +# Socket tuning +CCBT_SOCKET_RCVBUF_KIB=256 # Socket receive buffer size in KiB (1-65536) +CCBT_SOCKET_SNDBUF_KIB=256 # Socket send buffer size in KiB (1-65536) +CCBT_TCP_NODELAY=true # Enable TCP_NODELAY (true/false) + +# Timeouts (seconds) +CCBT_CONNECTION_TIMEOUT=30.0 # Connection timeout (1.0-300.0) +CCBT_HANDSHAKE_TIMEOUT=10.0 # Handshake timeout (1.0-60.0) +CCBT_KEEP_ALIVE_INTERVAL=120.0 # Keep alive interval (30.0-600.0) +CCBT_PEER_TIMEOUT=60.0 # Peer inactivity timeout (5.0-600.0) +CCBT_DHT_TIMEOUT=2.0 # DHT request timeout (1.0-60.0) + +# Listen settings +CCBT_LISTEN_PORT=6881 # Listen port (1024-65535) +CCBT_LISTEN_INTERFACE=0.0.0.0 # Listen interface +CCBT_ENABLE_IPV6=true # Enable IPv6 support (true/false) + +# Transport protocols +CCBT_ENABLE_TCP=true # Enable TCP transport (true/false) +CCBT_ENABLE_UTP=false # Enable uTP transport (true/false) +CCBT_ENABLE_ENCRYPTION=false # Enable protocol encryption (true/false) + +# uTP (uTorrent Transport Protocol) Configuration (BEP 29) +CCBT_UTP_PREFER_OVER_TCP=true # Prefer uTP over TCP when both are supported (true/false) +CCBT_UTP_CONNECTION_TIMEOUT=30.0 # uTP connection timeout in seconds (5.0-300.0) +CCBT_UTP_MAX_WINDOW_SIZE=65535 # Maximum uTP receive window size in bytes (8192-65535) +CCBT_UTP_MTU=1200 # uTP MTU size (maximum UDP packet size) (576-65507) +CCBT_UTP_INITIAL_RATE=1500 # Initial send rate in bytes/second (1024-100000) +CCBT_UTP_MIN_RATE=512 # Minimum send rate in bytes/second (256-10000) +CCBT_UTP_MAX_RATE=1000000 # Maximum send rate in bytes/second (10000-10000000) +CCBT_UTP_ACK_INTERVAL=0.1 # ACK packet send interval in seconds (0.01-1.0) +CCBT_UTP_RETRANSMIT_TIMEOUT_FACTOR=4.0 # RTT multiplier for retransmit timeout (2.0-10.0) +CCBT_UTP_MAX_RETRANSMITS=10 # Maximum retransmission attempts before connection failure (3-50) + +# Choking strategy +CCBT_MAX_UPLOAD_SLOTS=4 # Maximum upload slots (1-20) +CCBT_OPTIMISTIC_UNCHOKE_INTERVAL=30.0 # Optimistic unchoke interval (1.0-600.0) +CCBT_UNCHOKE_INTERVAL=10.0 # Unchoke interval (1.0-600.0) + +# Rate limiting (KiB/s, 0 = unlimited) +CCBT_GLOBAL_DOWN_KIB=0 # Global download limit (0+) +CCBT_GLOBAL_UP_KIB=0 # Global upload limit (0+) +CCBT_PER_PEER_DOWN_KIB=0 # Per-peer download limit (0+) +CCBT_PER_PEER_UP_KIB=0 # Per-peer upload limit (0+) + +# Tracker settings +CCBT_TRACKER_TIMEOUT=30.0 # Tracker request timeout (5.0-120.0) +CCBT_TRACKER_CONNECT_TIMEOUT=10.0 # Tracker connection timeout (1.0-60.0) +CCBT_TRACKER_CONNECTION_LIMIT=50 # Maximum tracker connections (1-200) +CCBT_TRACKER_CONNECTIONS_PER_HOST=10 # Max connections per tracker host (1-50) +CCBT_DNS_CACHE_TTL=300 # DNS cache TTL in seconds (60-3600) + +# BitTorrent Protocol v2 (BEP 52) settings +CCBT_PROTOCOL_V2_ENABLE=true # Enable BitTorrent Protocol v2 support (BEP 52) (true/false) +CCBT_PROTOCOL_V2_PREFER=false # Prefer v2 protocol when both v1 and v2 are available (true/false) +CCBT_PROTOCOL_V2_SUPPORT_HYBRID=true # Support hybrid torrents (both v1 and v2 metadata) (true/false) +CCBT_PROTOCOL_V2_HANDSHAKE_TIMEOUT=30.0 # v2 handshake timeout in seconds (5.0-300.0) + +# ============================================================================= +# DISK CONFIGURATION +# ============================================================================= + +# Preallocation strategy: none, sparse, full, fallocate +CCBT_PREALLOCATE=full # Preallocation strategy +CCBT_SPARSE_FILES=false # Use sparse files if supported (true/false) + +# Write optimization +CCBT_WRITE_BATCH_KIB=64 # Write batch size in KiB (1-1024) +CCBT_WRITE_BUFFER_KIB=1024 # Write buffer size in KiB (0-65536) +CCBT_USE_MMAP=true # Use memory mapping (true/false) +CCBT_MMAP_CACHE_MB=128 # Memory-mapped cache size in MB (16-2048) +CCBT_MMAP_CACHE_CLEANUP_INTERVAL=30.0 # MMap cache cleanup interval (1.0-300.0) + +# Hash verification +CCBT_HASH_WORKERS=4 # Number of hash verification workers (1-32) +CCBT_HASH_CHUNK_SIZE=65536 # Chunk size for hash verification (1024-1048576) +CCBT_HASH_BATCH_SIZE=4 # Number of pieces to verify in parallel batches (1-64) +CCBT_HASH_QUEUE_SIZE=100 # Hash verification queue size (10-500) + +# I/O threading +CCBT_DISK_WORKERS=2 # Number of disk I/O workers (1-16) +CCBT_DISK_QUEUE_SIZE=200 # Disk I/O queue size (10-1000) +CCBT_CACHE_SIZE_MB=256 # Cache size in MB (16-4096) + +# Advanced settings +CCBT_DIRECT_IO=false # Use direct I/O (true/false) +CCBT_SYNC_WRITES=false # Synchronize writes (true/false) +CCBT_READ_AHEAD_KIB=64 # Read ahead size in KiB (0-1024) +CCBT_ENABLE_IO_URING=false # Enable io_uring on Linux if available (true/false) +CCBT_DOWNLOAD_PATH= # Default download path + +# Checkpoint settings +CCBT_CHECKPOINT_ENABLED=true # Enable download checkpointing (true/false) +CCBT_CHECKPOINT_FORMAT=both # Checkpoint file format (json/binary/both) +CCBT_CHECKPOINT_DIR= # Checkpoint directory (defaults to download_dir/.ccbt/checkpoints) +CCBT_CHECKPOINT_INTERVAL=30.0 # Checkpoint save interval in seconds (1.0-3600.0) +CCBT_CHECKPOINT_ON_PIECE=true # Save checkpoint after each verified piece (true/false) +CCBT_AUTO_RESUME=true # Automatically resume from checkpoint on startup (true/false) +CCBT_CHECKPOINT_COMPRESSION=true # Compress binary checkpoint files (true/false) +CCBT_AUTO_DELETE_CHECKPOINT_ON_COMPLETE=true # Auto-delete checkpoint when download completes (true/false) +CCBT_CHECKPOINT_RETENTION_DAYS=30 # Days to retain checkpoints before cleanup (1-365) + +# Fast Resume settings +CCBT_FAST_RESUME_ENABLED=true # Enable fast resume support (true/false) +CCBT_RESUME_SAVE_INTERVAL=30.0 # Interval to save resume data in seconds (1.0-3600.0) +CCBT_RESUME_VERIFY_ON_LOAD=true # Verify resume data integrity on load (true/false) +CCBT_RESUME_VERIFY_PIECES=10 # Number of pieces to verify on resume (0-100, 0 = disable) +CCBT_RESUME_DATA_FORMAT_VERSION=1 # Resume data format version (1-100) + +# BEP 47: File Attributes Configuration +CCBT_ATTRIBUTES_PRESERVE_ATTRIBUTES=true # Preserve file attributes (executable, hidden, symlinks) (true/false) +CCBT_ATTRIBUTES_SKIP_PADDING_FILES=true # Skip downloading padding files (BEP 47) (true/false) +CCBT_ATTRIBUTES_VERIFY_FILE_SHA1=false # Verify file SHA-1 hashes when provided (BEP 47) (true/false) +CCBT_ATTRIBUTES_APPLY_SYMLINKS=true # Create symlinks for files with attr='l' (true/false) +CCBT_ATTRIBUTES_APPLY_EXECUTABLE_BIT=true # Set executable bit for files with attr='x' (true/false) +CCBT_ATTRIBUTES_APPLY_HIDDEN_ATTR=true # Apply hidden attribute for files with attr='h' (Windows) (true/false) + +# ============================================================================= +# STRATEGY CONFIGURATION +# ============================================================================= + +# Piece selection strategy: round_robin, rarest_first, sequential +CCBT_PIECE_SELECTION=rarest_first # Piece selection strategy +CCBT_ENDGAME_DUPLICATES=2 # Endgame duplicate requests (1-10) +CCBT_ENDGAME_THRESHOLD=0.95 # Endgame mode threshold (0.1-1.0) +CCBT_STREAMING_MODE=false # Enable streaming mode (true/false) + +# Advanced strategy settings +CCBT_RAREST_FIRST_THRESHOLD=0.1 # Rarest first threshold (0.0-1.0) +CCBT_SEQUENTIAL_WINDOW=10 # Sequential window size (1-100) +CCBT_SEQUENTIAL_PRIORITY_FILES= # File paths to prioritize in sequential mode (comma-separated, optional) +CCBT_SEQUENTIAL_FALLBACK_THRESHOLD=0.1 # Fallback to rarest-first if availability < threshold (0.0-1.0) +CCBT_PIPELINE_CAPACITY=4 # Request pipeline capacity (1-32) + +# Piece priorities +CCBT_FIRST_PIECE_PRIORITY=true # Prioritize first piece (true/false) +CCBT_LAST_PIECE_PRIORITY=false # Prioritize last piece (true/false) + +# ============================================================================= +# DISCOVERY CONFIGURATION +# ============================================================================= + +# DHT settings +CCBT_ENABLE_DHT=true # Enable DHT (true/false) +CCBT_DHT_PORT=6882 # DHT port (1024-65535) +# DHT bootstrap nodes (comma-separated) +CCBT_DHT_BOOTSTRAP_NODES=router.bittorrent.com:6881,dht.transmissionbt.com:6881,router.utorrent.com:6881,dht.libtorrent.org:25401 + +# BEP 32: IPv6 Extension for DHT +CCBT_DHT_ENABLE_IPV6=true # Enable IPv6 DHT support (BEP 32) (true/false) +CCBT_DHT_PREFER_IPV6=true # Prefer IPv6 addresses over IPv4 when available (true/false) +# IPv6 DHT bootstrap nodes (comma-separated, format: [hostname:port or [IPv6]:port]) +CCBT_DHT_IPV6_BOOTSTRAP_NODES= + +# BEP 43: Read-only DHT Nodes +CCBT_DHT_READONLY_MODE=false # Enable read-only DHT mode (BEP 43) (true/false) + +# BEP 45: Multiple-Address Operation for DHT +CCBT_DHT_ENABLE_MULTIADDRESS=true # Enable multi-address support (BEP 45) (true/false) +CCBT_DHT_MAX_ADDRESSES_PER_NODE=4 # Maximum addresses to track per node (BEP 45) (1-16) + +# BEP 44: Storing Arbitrary Data in the DHT +CCBT_DHT_ENABLE_STORAGE=false # Enable DHT storage (BEP 44) (true/false) +CCBT_DHT_STORAGE_TTL=3600 # Storage TTL in seconds (BEP 44) (60-86400) +CCBT_DHT_MAX_STORAGE_SIZE=1000 # Maximum storage value size in bytes (BEP 44) (100-10000) + +# BEP 51: DHT Infohash Indexing +CCBT_DHT_ENABLE_INDEXING=true # Enable infohash indexing (BEP 51) (true/false) +CCBT_DHT_INDEX_SAMPLES_PER_KEY=8 # Maximum samples per index key (BEP 51) (1-100) + +# PEX settings +CCBT_ENABLE_PEX=true # Enable Peer Exchange (true/false) +CCBT_PEX_INTERVAL=30.0 # Peer Exchange announce interval in seconds (5.0-3600.0) + +# Tracker settings +CCBT_ENABLE_HTTP_TRACKERS=true # Enable HTTP trackers (true/false) +CCBT_ENABLE_UDP_TRACKERS=true # Enable UDP trackers (true/false) +CCBT_TRACKER_ANNOUNCE_INTERVAL=1800.0 # Tracker announce interval in seconds (60.0-86400.0) +CCBT_TRACKER_SCRAPE_INTERVAL=3600.0 # Tracker scrape interval in seconds (60.0-86400.0) +CCBT_TRACKER_AUTO_SCRAPE=false # Automatically scrape trackers when adding torrents (true/false) + +# Private torrent settings (BEP 27) +CCBT_STRICT_PRIVATE_MODE=true # Enforce strict BEP 27 rules for private torrents (true/false) + +# ============================================================================= +# OBSERVABILITY CONFIGURATION +# ============================================================================= + +# Logging +CCBT_LOG_LEVEL=INFO # Log level (DEBUG/INFO/WARNING/ERROR/CRITICAL) +CCBT_LOG_FILE= # Log file path (empty = stdout) +CCBT_LOG_FORMAT=%(asctime)s - %(name)s - %(levelname)s - %(message)s # Log format string +CCBT_STRUCTURED_LOGGING=true # Use structured logging (true/false) +CCBT_LOG_CORRELATION_ID=true # Include correlation IDs (true/false) + +# Metrics +CCBT_ENABLE_METRICS=true # Enable metrics collection (true/false) +CCBT_METRICS_PORT=9090 # Metrics port (1024-65535) +CCBT_METRICS_INTERVAL=5.0 # Metrics collection interval in seconds (0.5-3600.0) + +# Tracing +CCBT_ENABLE_PEER_TRACING=false # Enable peer tracing (true/false) +CCBT_TRACE_FILE= # Path to write traces (empty = disabled) +CCBT_ALERTS_RULES_PATH=.ccbt/alerts.json # Path to alert rules JSON file + +# ============================================================================= +# LIMITS CONFIGURATION +# ============================================================================= + +# Global rate limits (KiB/s, 0 = unlimited) +CCBT_LIMITS_GLOBAL_DOWN_KIB=0 # Global download limit (0+) +CCBT_LIMITS_GLOBAL_UP_KIB=0 # Global upload limit (0+) + +# Per-torrent rate limits (KiB/s, 0 = unlimited) +CCBT_LIMITS_PER_TORRENT_DOWN_KIB=0 # Per-torrent download limit (0+) +CCBT_LIMITS_PER_TORRENT_UP_KIB=0 # Per-torrent upload limit (0+) + +# Per-peer rate limits (KiB/s, 0 = unlimited) +CCBT_LIMITS_PER_PEER_UP_KIB=0 # Per-peer upload limit (0+) + +# Scheduler settings +CCBT_SCHEDULER_SLICE_MS=100 # Scheduler time slice in ms (1-1000) + +# ============================================================================= +# SECURITY CONFIGURATION +# ============================================================================= + +CCBT_ENABLE_ENCRYPTION=false # Enable protocol encryption (true/false) +CCBT_ENCRYPTION_MODE=preferred # Encryption mode: disabled/preferred/required +CCBT_ENCRYPTION_DH_KEY_SIZE=768 # DH key size in bits: 768 or 1024 +CCBT_ENCRYPTION_PREFER_RC4=true # Prefer RC4 cipher for compatibility (true/false) +CCBT_ENCRYPTION_ALLOWED_CIPHERS=rc4,aes # Allowed ciphers (comma-separated: rc4,aes,chacha20) +CCBT_ENCRYPTION_ALLOW_PLAIN_FALLBACK=true # Allow fallback to plain connection (true/false) +CCBT_VALIDATE_PEERS=true # Validate peers before exchanging data (true/false) +CCBT_RATE_LIMIT_ENABLED=true # Enable security rate limiter (true/false) +CCBT_MAX_CONNECTIONS_PER_PEER=1 # Maximum parallel connections per peer (1-8) + +# IP Filter settings +CCBT_ENABLE_IP_FILTER=false # Enable IP filtering (true/false) +CCBT_FILTER_MODE=block # Filter mode: block or allow +CCBT_FILTER_FILES= # Comma-separated filter file paths +CCBT_FILTER_URLS= # Comma-separated filter list URLs +CCBT_FILTER_UPDATE_INTERVAL=86400.0 # Update interval in seconds (3600.0-604800.0) +CCBT_FILTER_CACHE_DIR=~/.ccbt/filters # Filter cache directory +CCBT_FILTER_LOG_BLOCKED=true # Log blocked connections (true/false) + +# ============================================================================= +# SSL/TLS CONFIGURATION +# ============================================================================= + +# SSL/TLS settings +CCBT_ENABLE_SSL_TRACKERS=true # Enable SSL for tracker connections (true/false) +CCBT_ENABLE_SSL_PEERS=false # Enable SSL for peer connections (true/false) +CCBT_SSL_VERIFY_CERTIFICATES=true # Verify SSL certificates (true/false) +CCBT_SSL_CA_CERTIFICATES= # Path to CA certificates file or directory +CCBT_SSL_CLIENT_CERTIFICATE= # Path to client certificate file (PEM format) +CCBT_SSL_CLIENT_KEY= # Path to client private key file (PEM format) +CCBT_SSL_PROTOCOL_VERSION=TLSv1.2 # TLS protocol version (TLSv1.2, TLSv1.3, PROTOCOL_TLS) +CCBT_SSL_ALLOW_INSECURE_PEERS=true # Allow insecure peers for opportunistic encryption (true/false) + +# ============================================================================= +# PROXY CONFIGURATION +# ============================================================================= + +CCBT_PROXY_ENABLE_PROXY=false # Enable proxy support (true/false) +CCBT_PROXY_TYPE=http # Proxy type: http/socks4/socks5 +CCBT_PROXY_HOST= # Proxy server hostname or IP +CCBT_PROXY_PORT= # Proxy server port (1-65535) +CCBT_PROXY_USERNAME= # Proxy username for authentication +CCBT_PROXY_PASSWORD= # Proxy password (encrypted in storage) +CCBT_PROXY_FOR_TRACKERS=true # Use proxy for tracker requests (true/false) +CCBT_PROXY_FOR_PEERS=false # Use proxy for peer connections (true/false) +CCBT_PROXY_FOR_WEBSEEDS=true # Use proxy for WebSeed requests (true/false) +CCBT_PROXY_BYPASS_LIST= # Comma-separated list of hosts/IPs to bypass proxy + +# ============================================================================= +# MACHINE LEARNING CONFIGURATION +# ============================================================================= + +CCBT_ML_PEER_SELECTION_ENABLED=false # Enable ML-based peer selection (true/false) +CCBT_ML_PIECE_PREDICTION_ENABLED=false # Enable ML piece prediction (true/false) + +# ============================================================================= +# CLI-SPECIFIC OVERRIDES +# ============================================================================= +# These can be used to override any configuration value via environment variables +# Format: CCBT_
_