fix(transport): recover rover feedback and retained WireGuard routes

This commit is contained in:
DCCONSTRUCTIONS
2026-11-04 00:42:24 +03:00
parent f4cdf3744a
commit 1e77b198cb
12 changed files with 833 additions and 30 deletions
+53 -1
View File
@@ -3,7 +3,7 @@ import socket
import time
import pytest
from test_pairing import cert, create, setup # noqa: F401
from test_pairing import cert, create, heartbeat, setup # noqa: F401
from k1link.fleet.rover_datagram import DatagramCipher, RoverDatagramServer
from k1link.fleet.trust import SCHEMA
@@ -177,3 +177,55 @@ def test_wake_hint_does_not_create_board_or_renew_authority():
assert control.intent_changed('node', 'a' * 32, None)
assert control.boards['node']['session']['until'] == deadline
assert control.stream('node', 'a' * 32)['command'] is None
@pytest.mark.parametrize("route", ["100.64.20.5", "10.203.42.2"])
def test_migration_feedback_precedes_full_heartbeat_commit(setup, route): # noqa: F811
"""The feedback needed to send inventory must work before its first commit."""
fleet, _, _, _ = setup
public, _ = create(setup)
fleet.advance(public["id"])
row = fleet.find(public["id"])
row["network_paths"] = {"synthetic-wg": {"core": "10.203.42.2", "node": "10.203.42.3"}}
fleet.save(row)
certificate = cert(row)
migration = {"core_endpoint": f"https://{route}:8782", "endpoint_revision": 1}
body = {"schema": SCHEMA, "node_id": row["node_id"],
"binding_id": row["binding"]["binding_id"], "relay_id": "a" * 32, **migration}
assert fleet.receive(certificate, "/v1/node/rover-link", body, address=route)[0] == 200
fleet.rover_control.view(row["node_id"])
server = RoverDatagramServer("127.0.0.1", fleet, port=0)
# Synthetic listener identity, with actual encrypted packets kept on loopback.
server.address = route
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
client.settimeout(.3)
try:
_, grant = server.open(certificate, body)
channel = bytes.fromhex(grant["channel"])
tx = DatagramCipher(channel, bytes.fromhex(grant["send_key"]))
rx = DatagramCipher(channel, bytes.fromhex(grant["receive_key"]))
client.sendto(tx.seal({}), server.socket.getsockname())
reply = rx.open(client.recv(1201))[1]
assert reply["probe"] == 1 and reply["reply"]["command"] is None
assert fleet.find(public["id"])["binding"] == row["binding"]
assert fleet.receive(certificate, "/v1/node/heartbeat",
{**heartbeat(row), **migration}, address=route)[0] == 200
assert fleet.find(public["id"])["binding"]["endpoint_revision"] == 1
fleet.rover_control.view(row["node_id"])
client.sendto(tx.seal({}), server.socket.getsockname())
assert rx.open(client.recv(1201))[1]["reply"]["command"] is None
# Once a newer endpoint is committed this candidate must still retire.
current = fleet.find(public["id"])
current["binding"]["endpoint_revision"] = 2
fleet.save(current)
deadline = time.monotonic() + .3
while time.monotonic() < deadline:
with server.lock:
if channel not in server.channels:
break
time.sleep(.005)
with server.lock:
assert channel not in server.channels
finally:
client.close()
server.close()