Fix candidate filter and auto forwarding wiring (#114290)

This commit is contained in:
Alex Ross
2021-01-13 18:06:31 +01:00
committed by GitHub
parent d66db5cc75
commit b903748b83
4 changed files with 29 additions and 6 deletions

View File

@@ -141,10 +141,13 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
constructor(
@IExtHostRpcService extHostRpc: IExtHostRpcService,
@IExtHostInitDataService private initData: IExtHostInitDataService
@IExtHostInitDataService initData: IExtHostInitDataService
) {
super();
this._proxy = extHostRpc.getProxy(MainContext.MainThreadTunnelService);
if (isLinux && initData.remote.isRemote && initData.remote.authority) {
this._proxy.$setCandidateFinder();
}
}
async openTunnel(extension: IExtensionDescription, forward: TunnelOptions): Promise<vscode.Tunnel | undefined> {
@@ -169,9 +172,6 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
}
async $registerCandidateFinder(): Promise<void> {
if (!isLinux || !this.initData.remote.isRemote || !this.initData.remote.authority) {
return;
}
// Regularly scan to see if the candidate ports have changed.
let movingAverage = new MovingAverage();
let oldPorts: { host: string, port: number, detail: string }[] | undefined = undefined;
@@ -182,7 +182,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
movingAverage.update(timeTaken);
if (!oldPorts || (JSON.stringify(oldPorts) !== JSON.stringify(newPorts))) {
oldPorts = newPorts;
await this._proxy.$onFoundNewCandidates(oldPorts.filter(async (candidate) => await this._showCandidatePort(candidate.host, candidate.port, candidate.detail)));
await this._proxy.$onFoundNewCandidates(oldPorts);
}
await (new Promise<void>(resolve => setTimeout(() => resolve(), this.calculateDelay(movingAverage.value))));
}
@@ -192,6 +192,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
if (provider) {
if (provider.showCandidatePort) {
this._showCandidatePort = provider.showCandidatePort;
await this._proxy.$setCandidateFilter();
}
if (provider.tunnelFactory) {
this._forwardPortProvider = provider.tunnelFactory;
@@ -242,6 +243,10 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
return undefined;
}
async $applyCandidateFilter(candidates: CandidatePort[]): Promise<CandidatePort[]> {
return Promise.all(candidates.filter(candidate => this._showCandidatePort(candidate.host, candidate.port, candidate.detail)));
}
async findCandidatePorts(): Promise<CandidatePort[]> {
let tcp: string = '';
let tcp6: string = '';