Implement makeTunnel for localhost

Part of #81388
This commit is contained in:
Alex Ross
2019-12-11 09:53:48 +01:00
parent c4198fac1f
commit 15c35f5566
8 changed files with 101 additions and 16 deletions

View File

@@ -3,19 +3,54 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtHostTunnelServiceShape } from 'vs/workbench/api/common/extHost.protocol';
import * as vscode from 'vscode';
import { ExtHostTunnelServiceShape, MainThreadTunnelServiceShape, MainContext } from 'vs/workbench/api/common/extHost.protocol';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IExtHostRpcService } from 'vs/workbench/api/common/extHostRpcService';
import * as vscode from 'vscode';
import { Disposable } from 'vs/base/common/lifecycle';
export interface TunnelOptions {
remote: { port: number, host: string };
localPort?: number;
name?: string;
closeable?: boolean;
}
export interface TunnelDto {
remote: { port: number, host: string };
localAddress: string;
}
export interface IExtHostTunnelService extends ExtHostTunnelServiceShape {
makeTunnel(forward: vscode.TunnelOptions): Promise<vscode.Tunnel>;
makeTunnel(forward: TunnelOptions): Promise<vscode.Tunnel | undefined>;
}
export const IExtHostTunnelService = createDecorator<IExtHostTunnelService>('IExtHostTunnelService');
export class ExtHostTunnelService implements IExtHostTunnelService {
makeTunnel(forward: vscode.TunnelOptions): Promise<vscode.Tunnel> {
throw new Error('Method not implemented.');
export class ExtHostTunnelService extends Disposable implements IExtHostTunnelService {
private readonly _proxy: MainThreadTunnelServiceShape;
constructor(
@IExtHostRpcService extHostRpc: IExtHostRpcService
) {
super();
this._proxy = extHostRpc.getProxy(MainContext.MainThreadTunnelService);
}
async makeTunnel(forward: TunnelOptions): Promise<vscode.Tunnel | undefined> {
const tunnel = await this._proxy.$openTunnel(forward);
if (tunnel) {
const disposableTunnel: vscode.Tunnel = {
remote: tunnel.remote,
localAddress: tunnel.localAddress,
dispose: () => {
return this._proxy.$closeTunnel(tunnel.remote.port);
}
};
this._register(disposableTunnel);
return disposableTunnel;
}
return undefined;
}
}