(chunk: Buffer | string)
| 827 | resolve(peers); |
| 828 | }; |
| 829 | const onData = (chunk: Buffer | string) => { |
| 830 | const buf = typeof chunk === 'string' ? Buffer.from(chunk, 'utf8') : chunk; |
| 831 | chunks.push(buf); |
| 832 | total += buf.length; |
| 833 | const all = chunks.length === 1 ? buf : Buffer.concat(chunks, total); |
| 834 | const nl = all.indexOf(0x0a); // '\n' |
| 835 | if (nl === -1) { |
| 836 | // No newline yet. If it's already too long to be a hello, it isn't one — |
| 837 | // hand the bytes back as data; otherwise keep accumulating. |
| 838 | if (total > MAX_HELLO_LINE_BYTES) finish({ pid: null, hostPid: null }, all); |
| 839 | else chunks = [all]; |
| 840 | return; |
| 841 | } |
| 842 | const peers = parseClientHelloLine(all.subarray(0, nl).toString('utf8')); |
| 843 | if (peers) { |
| 844 | const tail = all.subarray(nl + 1); |
| 845 | finish(peers, tail.length > 0 ? tail : undefined); |
| 846 | } else { |
| 847 | // First line is not a client-hello (legacy/direct client) — hand the |
| 848 | // whole buffer back so the transport sees the message verbatim. |
| 849 | finish({ pid: null, hostPid: null }, all); |
| 850 | } |
| 851 | }; |
| 852 | const onEnd = () => finish({ pid: null, hostPid: null }); |
| 853 | // On timeout, hand back whatever partial bytes accumulated — discarding |
| 854 | // them would tear the first message the transport parses. |
nothing calls this directly
no test coverage detected