( line: string, )
| 1083 | * which case the caller treats the bytes as ordinary JSON-RPC. |
| 1084 | */ |
| 1085 | export function parseClientHelloLine( |
| 1086 | line: string, |
| 1087 | ): { pid: number; hostPid: number | null; challenge?: string } | null { |
| 1088 | let parsed: unknown; |
| 1089 | try { parsed = JSON.parse(line); } catch { return null; } |
| 1090 | if (!parsed || typeof parsed !== 'object') return null; |
| 1091 | const o = parsed as Record<string, unknown>; |
| 1092 | if (o.codegraph_client !== 1 || typeof o.pid !== 'number') return null; |
| 1093 | const peers: { pid: number; hostPid: number | null; challenge?: string } = { |
| 1094 | pid: o.pid, |
| 1095 | hostPid: typeof o.hostPid === 'number' ? o.hostPid : null, |
| 1096 | }; |
| 1097 | if (typeof o.challenge === 'string' && o.challenge.length > 0 && o.challenge.length <= MAX_CHALLENGE_LENGTH) { |
| 1098 | peers.challenge = o.challenge; |
| 1099 | } |
| 1100 | return peers; |
| 1101 | } |
| 1102 | |
| 1103 | /** |
| 1104 | * A client's peer is dead when its proxy process is gone, or when its known |
no test coverage detected