// The endpoint the other machines' checkers dial (novox/hq ADR 0145). // // **This module's own endpoint is the instrument.** It is declared reachable over the private network // like any other service, so it is admitted by exactly the rule that governs every internally-exposed // service and it fails when that rule is wrong. A probe on a port that is never closed — ssh, say — // would have passed throughout the outage this module exists to catch. // // It accepts a connection and closes it. Answering anything would make this a protocol, and then the // question would be whether the protocol worked rather than whether the path did. import { createServer } from "node:net"; const port = Number(process.env.MESH_NETWORK_CHECKER_PORT ?? "9876"); const server = createServer((socket) => { // Written before closing so a person dialling it by hand sees something, and so a half-open // connection is not mistaken for a working path by a client that only checks the handshake. socket.end("mesh network-checker\n"); }); server.on("error", (err: Error) => { // Said and fatal: a probe that cannot listen must not look like a probe that nothing dialled. console.error(`network-checker: cannot serve the probe on ${port}: ${err.message}`); process.exit(1); }); server.listen(port, () => console.log(`network-checker: probe listening on ${port}`)); for (const signal of ["SIGTERM", "SIGINT"] as const) { process.on(signal, () => server.close(() => process.exit(0))); }