extHostTunnelService.ts ×17

Frontier kind: Code frontier

unlabeled · c_d017bb7c9e90

39 tests · 76556 LOC · 262 files · introduces 0 tests · 94 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges94 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
5011 ranges76556 lines · 262 files · Browse complete extent
All tests (intent)
39 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 94 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/workbench/api/common/extHostTunnelService.ts 94 introduced LOC · 17 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- extHostTunnelService.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import { CancellationToken } from '../../../base/common/cancellation.js';
7 > import { Emitter } from '../../../base/common/event.js';
8 > import { Disposable, IDisposable, toDisposable } from '../../../base/common/lifecycle.js';
9 > import * as nls from '../../../nls.js';
10 > import { IExtensionDescription } from '../../../platform/extensions/common/extensions.js';
11 > import { createDecorator } from '../../../platform/instantiation/common/instantiation.js';
12 > import { ILogService } from '../../../platform/log/common/log.js';
13 > import { DisposableTunnel, ProvidedOnAutoForward, ProvidedPortAttributes, RemoteTunnel, TunnelCreationOptions, TunnelOptions, TunnelPrivacyId } from '../../../platform/tunnel/common/tunnel.js';
14 > import { ExtHostTunnelServiceShape, MainContext, MainThreadTunnelServiceShape, PortAttributesSelector, TunnelDto } from './extHost.protocol.js';
15 > import { IExtHostInitDataService } from './extHostInitDataService.js';
16 > import { IExtHostRpcService } from './extHostRpcService.js';
17 > import * as types from './extHostTypes.js';
18 > import { CandidatePort } from '../../services/remote/common/tunnelModel.js';
19 > import * as vscode from 'vscode';
20 >
21 > class ExtensionTunnel extends DisposableTunnel implements vscode.Tunnel { }
22 >
23 > export namespace TunnelDtoConverter {
24 > export function fromApiTunnel(tunnel: vscode.Tunnel): TunnelDto {
25 return {
26 remoteAddress: tunnel.remoteAddress,
31 };
32 }
33 > export function fromServiceTunnel(tunnel: RemoteTunnel): TunnelDto { extHostTunnelService.ts
34 return {
35 remoteAddress: {
43 };
44 }
46 >
47 > export interface Tunnel extends vscode.Disposable {
48 > remote: { port: number; host: string };
49 > localAddress: string;
50 > }
51 >
52 > export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
53 > readonly _serviceBrand: undefined;
54 > openTunnel(extension: IExtensionDescription, forward: TunnelOptions): Promise<vscode.Tunnel | undefined>;
55 > getTunnels(): Promise<vscode.TunnelDescription[]>;
56 > onDidChangeTunnels: vscode.Event<void>;
57 > setTunnelFactory(provider: vscode.RemoteAuthorityResolver | undefined, managedRemoteAuthority: vscode.ManagedResolvedAuthority | undefined): Promise<IDisposable>;
58 > registerPortsAttributesProvider(portSelector: PortAttributesSelector, provider: vscode.PortAttributesProvider): IDisposable;
59 > registerTunnelProvider(provider: vscode.TunnelProvider, information: vscode.TunnelInformation): Promise<IDisposable>;
60 > hasTunnelProvider(): Promise<boolean>;
61 > }
62 >
63 > export const IExtHostTunnelService = createDecorator<IExtHostTunnelService>('IExtHostTunnelService');
64 >
65 > export class ExtHostTunnelService extends Disposable implements IExtHostTunnelService {
66 > readonly _serviceBrand: undefined;
67 > protected readonly _proxy: MainThreadTunnelServiceShape;
68 > private _forwardPortProvider: ((tunnelOptions: TunnelOptions, tunnelCreationOptions: TunnelCreationOptions, token?: vscode.CancellationToken) => Thenable<vscode.Tunnel | undefined> | undefined) | undefined;
69 > private _showCandidatePort: (host: string, port: number, detail: string) => Thenable<boolean> = () => { return Promise.resolve(true); };
70 > private _extensionTunnels: Map<string, Map<number, { tunnel: vscode.Tunnel; disposeListener: IDisposable }>> = new Map();
71 > private _onDidChangeTunnels: Emitter<void> = this._register(new Emitter<void>());
72 > onDidChangeTunnels: vscode.Event<void> = this._onDidChangeTunnels.event;
73 >
74 > private _providerHandleCounter: number = 0;
75 > private _portAttributesProviders: Map<number, { provider: vscode.PortAttributesProvider; selector: PortAttributesSelector }> = new Map();
76 >
77 > constructor(
78 @IExtHostRpcService extHostRpc: IExtHostRpcService,
79 @IExtHostInitDataService initData: IExtHostInitDataService,
83 this._proxy = extHostRpc.getProxy(MainContext.MainThreadTunnelService);
84 }
86 > async openTunnel(extension: IExtensionDescription, forward: TunnelOptions): Promise<vscode.Tunnel | undefined> {
87 this.logService.trace(`ForwardedPorts: (ExtHostTunnelService) ${extension.identifier.value} called openTunnel API for ${forward.remoteAddress.host}:${forward.remoteAddress.port}.`);
88 const tunnel = await this._proxy.$openTunnel(forward, extension.displayName);
96 return undefined;
97 }
99 > async getTunnels(): Promise<vscode.TunnelDescription[]> {
100 return this._proxy.$getTunnels();
101 }
102 > private nextPortAttributesProviderHandle(): number { extHostTunnelService.ts
103 return this._providerHandleCounter++;
104 }
106 > registerPortsAttributesProvider(portSelector: PortAttributesSelector, provider: vscode.PortAttributesProvider): vscode.Disposable {
107 if (portSelector.portRange === undefined && portSelector.commandPattern === undefined) {
108 this.logService.error('PortAttributesProvider must specify either a portRange or a commandPattern');
117 });
118 }
120 > async $providePortAttributes(handles: number[], ports: number[], pid: number | undefined, commandLine: string | undefined, cancellationToken: vscode.CancellationToken): Promise<ProvidedPortAttributes[]> {
121 const providedAttributes: { providedAttributes: vscode.PortAttributes | null | undefined; port: number }[] = [];
122 for (const handle of handles) {
146 }) : [];
147 }
149 > async $registerCandidateFinder(_enable: boolean): Promise<void> { }
150 >
151 > registerTunnelProvider(provider: vscode.TunnelProvider, information: vscode.TunnelInformation): Promise<IDisposable> {
152 if (this._forwardPortProvider) {
153 throw new Error('A tunnel provider has already been registered. Only the first tunnel provider to be registered will be used.');
170 }));
171 }
173 > hasTunnelProvider(): Promise<boolean> {
174 return this._proxy.$hasTunnelProvider();
175 }
177 > /**
178 > * Applies the tunnel metadata and factory found in the remote authority
179 > * resolver to the tunnel system.
180 > *
181 > * `managedRemoteAuthority` should be be passed if the resolver returned on.
182 > * If this is the case, the tunnel cannot be connected to via a websocket from
183 > * the share process, so a synethic tunnel factory is used as a default.
184 > */
185 > async setTunnelFactory(provider: vscode.RemoteAuthorityResolver | undefined, managedRemoteAuthority: vscode.ManagedResolvedAuthority | undefined): Promise<IDisposable> {
186 // Do not wait for any of the proxy promises here.
187 // It will delay startup and there is nothing that needs to be waited for.
229 });
230 }
232 > protected makeManagedTunnelFactory(_authority: vscode.ManagedResolvedAuthority): vscode.RemoteAuthorityResolver['tunnelFactory'] {
233 return undefined; // may be overridden
234 }
236 > async $closeTunnel(remote: { host: string; port: number }, silent?: boolean): Promise<void> {
237 if (this._extensionTunnels.has(remote.host)) {
238 const hostMap = this._extensionTunnels.get(remote.host)!;
246 }
247 }
249 > async $onDidTunnelsChange(): Promise<void> {
250 this._onDidChangeTunnels.fire();
251 }
253 > async $forwardPort(tunnelOptions: TunnelOptions, tunnelCreationOptions: TunnelCreationOptions): Promise<TunnelDto | string | undefined> {
254 if (this._forwardPortProvider) {
255 try {
285 return undefined;
286 }
288 > async $applyCandidateFilter(candidates: CandidatePort[]): Promise<CandidatePort[]> {
289 const filter = await Promise.all(candidates.map(candidate => this._showCandidatePort(candidate.host, candidate.port, candidate.detail ?? '')));
290 const result = candidates.filter((candidate, index) => filter[index]);