149
150
export function tryFindRootPorts(connections: { socket: number; ip: string; port: number }[], rootProcessesStdout: string, previousPorts: Map<number, CandidatePort & { ppid: number }>): Map<number, CandidatePort & { ppid: number }> {
152
>
const rootProcesses = getRootProcesses(rootProcessesStdout);
153
>
154
>
for (const connection of connections) {
155
>
const previousPort = previousPorts.get(connection.port);
156
>
if (previousPort) {
157
ports.set(connection.port, previousPort);
158
continue;
159
}
160
>
const rootProcessMatch = rootProcesses.find((value) => value.cmd.includes(`${connection.port}`));
extHostTunnelService.ts
161
>
if (rootProcessMatch) {
162
>
let bestMatch = rootProcessMatch;
163
>
// There are often several processes that "look" like they could match the port.
164
>
// The one we want is usually the child of the other. Find the most child process.
165
>
let mostChild: { pid: number; cmd: string; ppid: number } | undefined;
166
>
do {
167
>
mostChild = rootProcesses.find(value => value.ppid === bestMatch.pid);
168
>
if (mostChild) {
169
>
bestMatch = mostChild;
170
>
}
171
>
} while (mostChild);
172
>
ports.set(connection.port, { host: connection.ip, port: connection.port, pid: bestMatch.pid, detail: bestMatch.cmd, ppid: bestMatch.ppid });
173
>
} else {
174
ports.set(connection.port, { host: connection.ip, port: connection.port, ppid: Number.MAX_VALUE });
175
}
177
>
178
>
return ports;
179
>
}
180
181
export class NodeExtHostTunnelService extends ExtHostTunnelService {