relay over ws supossedly working
This commit is contained in:
@@ -350,6 +350,51 @@ def test_relay_rpc_round_trips_http_request_to_peer():
|
||||
assert json.loads(response["body"]) == {"ok": True, "path": "/v1/chat/completions"}
|
||||
|
||||
|
||||
def test_node_relay_bridge_reconnects_after_failed_connection(monkeypatch):
|
||||
"""Node-side relay bridge keeps retrying its outbound WebSocket connection."""
|
||||
import websockets.sync.client as wsc # type: ignore[import]
|
||||
from meshnet_node.relay_bridge import RelayHttpBridge
|
||||
|
||||
attempts = []
|
||||
|
||||
class FakeWebSocket:
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc, tb):
|
||||
return False
|
||||
|
||||
def send(self, _message):
|
||||
pass
|
||||
|
||||
def recv(self, timeout=1):
|
||||
raise TimeoutError
|
||||
|
||||
def fake_connect(url, open_timeout=5):
|
||||
attempts.append((url, open_timeout))
|
||||
if len(attempts) == 1:
|
||||
raise OSError("temporary relay outage")
|
||||
return FakeWebSocket()
|
||||
|
||||
monkeypatch.setattr(wsc, "connect", fake_connect)
|
||||
|
||||
bridge = RelayHttpBridge(
|
||||
relay_url="ws://relay.example/ws",
|
||||
peer_id="peer-reconnect",
|
||||
local_base_url="http://127.0.0.1:8001",
|
||||
advertised_addr="http://127.0.0.1:8001",
|
||||
reconnect_interval=0.01,
|
||||
)
|
||||
try:
|
||||
info = bridge.start()
|
||||
assert info.relay_addr == "ws://relay.example/rpc/peer-reconnect"
|
||||
assert bridge.wait_connected(timeout=1.0)
|
||||
finally:
|
||||
bridge.stop()
|
||||
|
||||
assert len(attempts) >= 2
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tracker gossip fields tests
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -389,6 +434,27 @@ def _start_tracker_and_register(extra_fields: dict) -> dict:
|
||||
return resp
|
||||
|
||||
|
||||
def test_tracker_derives_relay_url_from_public_self_url():
|
||||
from meshnet_tracker.server import TrackerServer, derive_relay_url_from_public_tracker_url
|
||||
|
||||
assert derive_relay_url_from_public_tracker_url("https://ai.neuron.d-popov.com") == (
|
||||
"wss://ai.neuron.d-popov.com/ws"
|
||||
)
|
||||
assert derive_relay_url_from_public_tracker_url("http://127.0.0.1:8081") is None
|
||||
|
||||
tracker = TrackerServer(cluster_self_url="https://ai.neuron.d-popov.com")
|
||||
port = tracker.start()
|
||||
try:
|
||||
import json as _json
|
||||
import urllib.request
|
||||
|
||||
with urllib.request.urlopen(f"http://127.0.0.1:{port}/v1/network/map", timeout=5) as resp:
|
||||
body = _json.loads(resp.read())
|
||||
assert body["relay_url"] == "wss://ai.neuron.d-popov.com/ws"
|
||||
finally:
|
||||
tracker.stop()
|
||||
|
||||
|
||||
def test_tracker_accepts_relay_addr_in_registration():
|
||||
resp = _start_tracker_and_register({
|
||||
"relay_addr": "ws://relay.meshnet.ai:8765/relay/abc123",
|
||||
|
||||
Reference in New Issue
Block a user