23 lines
1.0 KiB
Python
23 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Test de connectivité d'un relay Nostr — ws:// local ou wss:// via tunnel.
|
|
Usage: python3 test_nostr_relay.py [url1 url2 ...] (defaut: ws://127.0.0.1:3001)
|
|
Exige: python3 -c "import websockets" (dispo sur openclaw-1, sinon: pip install websockets)
|
|
Attendu sur relay fermé (auth_required): réponse ["AUTH", "<challenge>"] = connexion OK.
|
|
Piège: le handshake curl ne renvoie PAS 101 (il renvoie 200) — utiliser ce script à la place."""
|
|
import asyncio, json, sys, websockets
|
|
|
|
async def test(url):
|
|
try:
|
|
async with websockets.connect(url, open_timeout=15) as ws:
|
|
await ws.send(json.dumps(["REQ", "test-conn", {"kinds": [0], "limit": 1}]))
|
|
msg = await asyncio.wait_for(ws.recv(), timeout=10)
|
|
return f"OK — réponse: {msg[:120]}"
|
|
except Exception as e:
|
|
return f"FAIL — {type(e).__name__}: {str(e)[:150]}"
|
|
|
|
async def main():
|
|
urls = sys.argv[1:] or ["ws://127.0.0.1:3001"]
|
|
for u in urls:
|
|
print(f"{u} → {await test(u)}")
|
|
|
|
asyncio.run(main()) |