( line: string, )
| 1096 | * which case the caller treats the bytes as ordinary JSON-RPC. |
| 1097 | */ |
| 1098 | export function parseClientHelloLine( |
| 1099 | line: string, |
| 1100 | ): { pid: number; hostPid: number | null; challenge?: string } | null { |
| 1101 | let parsed: unknown; |
| 1102 | try { parsed = JSON.parse(line); } catch { return null; } |
| 1103 | if (!parsed || typeof parsed !== 'object') return null; |
| 1104 | const o = parsed as Record<string, unknown>; |
| 1105 | if (o.codegraph_client !== 1 || typeof o.pid !== 'number') return null; |
| 1106 | const peers: { pid: number; hostPid: number | null; challenge?: string } = { |
| 1107 | pid: o.pid, |
| 1108 | hostPid: typeof o.hostPid === 'number' ? o.hostPid : null, |
| 1109 | }; |
| 1110 | if (typeof o.challenge === 'string' && o.challenge.length > 0 && o.challenge.length <= MAX_CHALLENGE_LENGTH) { |
| 1111 | peers.challenge = o.challenge; |
| 1112 | } |
| 1113 | return peers; |
| 1114 | } |
| 1115 | |
| 1116 | /** |
| 1117 | * A client's peer is dead when its proxy process is gone, or when its known |
no test coverage detected