|
| 1 | +# Migration Notes: Adapting Python Transport Test from Old to New Format |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document outlines the changes needed to adapt the Python transport interop test from the old `transport-interop` format to the new `transport` format. |
| 6 | + |
| 7 | +## Key Differences |
| 8 | + |
| 9 | +### 1. Environment Variables |
| 10 | + |
| 11 | +**Old Format:** |
| 12 | + |
| 13 | +- `LIBP2P_DEBUG` (uppercase) |
| 14 | + |
| 15 | +**New Format:** |
| 16 | + |
| 17 | +- `debug` (lowercase) |
| 18 | + |
| 19 | +**Change Required:** |
| 20 | + |
| 21 | +```python |
| 22 | +# OLD: |
| 23 | +debug_enabled = os.getenv("LIBP2P_DEBUG", "").upper() in ["DEBUG", "1", "TRUE", "YES"] |
| 24 | + |
| 25 | +# NEW: |
| 26 | +debug_enabled = os.getenv("debug", "false").upper() in ["DEBUG", "1", "TRUE", "YES"] |
| 27 | +``` |
| 28 | + |
| 29 | +### 2. Dockerfile Changes |
| 30 | + |
| 31 | +**Old Format (transport-interop):** |
| 32 | + |
| 33 | +- Copies from extracted zip: `COPY py-libp2p-* /app/py-libp2p` |
| 34 | +- Copies pyproject.toml from root: `COPY pyproject.toml .` |
| 35 | +- Has multihash conflict fix |
| 36 | +- Has commented-out yamux patch |
| 37 | + |
| 38 | +**New Format (transport):** |
| 39 | + |
| 40 | +- Copies from current directory: `COPY ./ /app/py-libp2p` |
| 41 | +- Copies pyproject.toml from interop/transport: `COPY interop/transport/pyproject.toml .` |
| 42 | +- Simpler structure (no zip extraction needed) |
| 43 | + |
| 44 | +**Current Dockerfile is already correct for new format!** |
| 45 | + |
| 46 | +### 3. Missing Features in Current py-libp2p Implementation |
| 47 | + |
| 48 | +The old format has several features that should be ported: |
| 49 | + |
| 50 | +#### A. WSS/TLS Support |
| 51 | + |
| 52 | +- TLS client config for WSS dialing |
| 53 | +- TLS server config with self-signed certificates for WSS listening |
| 54 | +- Requires `cryptography` library |
| 55 | + |
| 56 | +#### B. Enhanced Error Handling |
| 57 | + |
| 58 | +- More detailed traceback printing |
| 59 | +- Better error messages with exception types |
| 60 | + |
| 61 | +#### C. WSS Address Conversion |
| 62 | + |
| 63 | +- Converts `/tls/ws` to `/wss` for compatibility with Go implementations |
| 64 | +- Handles WSS dialer workarounds |
| 65 | + |
| 66 | +#### D. Better Logging |
| 67 | + |
| 68 | +- More comprehensive debug output |
| 69 | +- Better error context |
| 70 | + |
| 71 | +## Required Changes |
| 72 | + |
| 73 | +### 1. Update `ping_test.py` |
| 74 | + |
| 75 | +#### Change debug environment variable: |
| 76 | + |
| 77 | +```python |
| 78 | +# Line 48: Change from LIBP2P_DEBUG to debug |
| 79 | +debug_enabled = os.getenv("debug", "false").upper() in ["DEBUG", "1", "TRUE", "YES"] |
| 80 | +``` |
| 81 | + |
| 82 | +#### Add missing imports for WSS/TLS support: |
| 83 | + |
| 84 | +```python |
| 85 | +import ssl |
| 86 | +import tempfile |
| 87 | +import ipaddress |
| 88 | +from typing import Optional |
| 89 | +from cryptography import x509 |
| 90 | +from cryptography.x509.oid import NameOID |
| 91 | +from cryptography.hazmat.primitives import hashes, serialization |
| 92 | +from cryptography.hazmat.primitives.asymmetric import rsa |
| 93 | +from datetime import datetime, timedelta |
| 94 | +``` |
| 95 | + |
| 96 | +#### Add TLS configuration methods (from old format): |
| 97 | + |
| 98 | +- `create_tls_client_config()` - for WSS dialing |
| 99 | +- `create_tls_server_config()` - for WSS listening with self-signed certs |
| 100 | + |
| 101 | +#### Update `run_listener()` to use TLS config: |
| 102 | + |
| 103 | +```python |
| 104 | +# Configure TLS for WSS |
| 105 | +tls_client_config = self.create_tls_client_config() |
| 106 | +tls_server_config = self.create_tls_server_config() |
| 107 | + |
| 108 | +self.host = new_host( |
| 109 | + key_pair=key_pair, |
| 110 | + sec_opt=sec_opt, |
| 111 | + muxer_opt=muxer_opt, |
| 112 | + listen_addrs=listen_addrs, |
| 113 | + enable_quic=(self.transport == "quic-v1"), |
| 114 | + tls_client_config=tls_client_config, # ADD THIS |
| 115 | + tls_server_config=tls_server_config # ADD THIS |
| 116 | +) |
| 117 | +``` |
| 118 | + |
| 119 | +#### Update `run_dialer()` to: |
| 120 | + |
| 121 | +- Handle `/tls/ws` to `/wss` conversion |
| 122 | +- Use TLS client config for WSS |
| 123 | +- Handle WSS dialer workarounds |
| 124 | + |
| 125 | +#### Fix `run_listener()` duplicate code: |
| 126 | + |
| 127 | +The current implementation has duplicate `listen_addrs` assignment - remove the duplicate. |
| 128 | + |
| 129 | +### 2. Update `pyproject.toml` |
| 130 | + |
| 131 | +Add `cryptography` dependency for TLS support: |
| 132 | + |
| 133 | +```toml |
| 134 | +dependencies = [ |
| 135 | + "libp2p @ file:///app/py-libp2p", |
| 136 | + "redis>=4.0.0", |
| 137 | + "typing-extensions>=4.0.0", |
| 138 | + "cryptography>=41.0.0", # ADD THIS for TLS/WSS support |
| 139 | +] |
| 140 | +``` |
| 141 | + |
| 142 | +### 3. Update `Dockerfile` |
| 143 | + |
| 144 | +The current Dockerfile is mostly correct, but ensure: |
| 145 | + |
| 146 | +- It copies from current directory (✓ already correct) |
| 147 | +- It installs all dependencies including cryptography (add if missing) |
| 148 | + |
| 149 | +## Summary of Changes Needed |
| 150 | + |
| 151 | +1. ✅ **Dockerfile**: Already correct for new format |
| 152 | +1. ❌ **ping_test.py**: |
| 153 | + - Change `LIBP2P_DEBUG` → `debug` |
| 154 | + - Add WSS/TLS support methods |
| 155 | + - Add missing imports |
| 156 | + - Fix duplicate `listen_addrs` in `run_listener()` |
| 157 | + - Add WSS address conversion logic |
| 158 | + - Enhance error handling |
| 159 | +1. ❌ **pyproject.toml**: Add `cryptography` dependency |
| 160 | + |
| 161 | +## Testing |
| 162 | + |
| 163 | +After making changes: |
| 164 | + |
| 165 | +1. Commit to py-libp2p repository |
| 166 | +1. Update commit SHA in `transport/impls.yaml` |
| 167 | +1. Test with: `./run_tests.sh --test-select "python" --force-image-rebuild --yes` |
0 commit comments