Allow extensions to provide a port forwarding implementation.

Part of #81388
This commit is contained in:
Alex Ross
2019-12-16 16:20:05 +01:00
parent c11a0c1300
commit 92a83fb895
9 changed files with 182 additions and 33 deletions

View File

@@ -7,6 +7,7 @@ import { MainThreadTunnelServiceShape, IExtHostContext, MainContext, ExtHostCont
import { TunnelOptions, TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { IRemoteExplorerService } from 'vs/workbench/services/remote/common/remoteExplorerService';
import { ITunnelProvider, ITunnelService } from 'vs/platform/remote/common/tunnel';
@extHostNamedCustomer(MainContext.MainThreadTunnelService)
export class MainThreadTunnelService implements MainThreadTunnelServiceShape {
@@ -14,7 +15,8 @@ export class MainThreadTunnelService implements MainThreadTunnelServiceShape {
constructor(
extHostContext: IExtHostContext,
@IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService
@IRemoteExplorerService private readonly remoteExplorerService: IRemoteExplorerService,
@ITunnelService private readonly tunnelService: ITunnelService
) {
this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostTunnelService);
}
@@ -22,7 +24,7 @@ export class MainThreadTunnelService implements MainThreadTunnelServiceShape {
async $openTunnel(tunnelOptions: TunnelOptions): Promise<TunnelDto | undefined> {
const tunnel = await this.remoteExplorerService.forward(tunnelOptions.remote.port, tunnelOptions.localPort, tunnelOptions.name);
if (tunnel) {
return { remote: { host: tunnel.tunnelRemoteHost, port: tunnel.tunnelRemotePort }, localAddress: tunnel.localAddress };
return TunnelDto.fromServiceTunnel(tunnel);
}
return undefined;
}
@@ -35,6 +37,28 @@ export class MainThreadTunnelService implements MainThreadTunnelServiceShape {
this.remoteExplorerService.registerCandidateFinder(() => this._proxy.$findCandidatePorts());
}
async $setTunnelProvider(): Promise<void> {
const tunnelProvider: ITunnelProvider = {
forwardPort: (tunnelOptions: TunnelOptions) => {
const forward = this._proxy.$forwardPort(tunnelOptions);
if (forward) {
return forward.then(tunnel => {
return {
tunnelRemotePort: tunnel.remote.port,
tunnelRemoteHost: tunnel.remote.host,
localAddress: tunnel.localAddress,
dispose: () => {
this._proxy.$closeTunnel({ host: tunnel.remote.host, port: tunnel.remote.port });
}
};
});
}
return undefined;
}
};
this.tunnelService.setTunnelProvider(tunnelProvider);
}
dispose(): void {
//
}