"""Re-probe every final host whose QUIC handshake failed: 8 at a time, 15 s timeout.
Usage: python -I recheck.py SCAN_JSONL OUT_JSON"""
import asyncio, json, sys
sys.path.insert(0, __file__.rsplit("/", 1)[0])
from probe import quic

async def main(src, out):
    hosts = sorted({r["final"] for r in map(json.loads, open(src)) if r["ok"] and r.get("final") and r.get("quic") != "h3"})
    sem = asyncio.Semaphore(8)
    async def one(h):
        async with sem: return h, await quic(h, 15.0)
    res = dict(await asyncio.gather(*(one(h) for h in hosts)))
    json.dump(res, open(out, "w"), indent=0)
    print(len(hosts), "rechecked;", sum(v == "h3" for v in res.values()), "now h3")

asyncio.run(main(sys.argv[1], sys.argv[2]))
