Skip to content

Commit 9c0577c

Browse files
committed
Forward ports with any host to localhost
and fix related bugs Fixes microsoft#88060
1 parent 29759db commit 9c0577c

3 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/vs/workbench/api/node/extHostTunnelService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export class ExtHostTunnelService extends Disposable implements IExtHostTunnelSe
183183
ip: this.parseIpAddress(address[0]),
184184
port: parseInt(address[1], 16)
185185
};
186-
}).map(port => [port.port, port])
186+
}).map(port => [port.ip + ':' + port.port, port])
187187
).values()
188188
];
189189
}

src/vs/workbench/services/remote/common/remoteExplorerService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export interface Tunnel {
4646
}
4747

4848
export function MakeAddress(host: string, port: number): string {
49-
if (host = '127.0.0.1') {
49+
if (host === '127.0.0.1') {
5050
host = 'localhost';
5151
}
5252
return host + ':' + port;

src/vs/workbench/services/remote/node/tunnelService.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import { ILogService } from 'vs/platform/log/common/log';
1919
import { findFreePort } from 'vs/base/node/ports';
2020
import { Event, Emitter } from 'vs/base/common/event';
2121

22-
export async function createRemoteTunnel(options: IConnectionOptions, tunnelRemotePort: number, tunnelLocalPort?: number): Promise<RemoteTunnel> {
23-
const tunnel = new NodeRemoteTunnel(options, tunnelRemotePort, tunnelLocalPort);
22+
export async function createRemoteTunnel(options: IConnectionOptions, tunnelRemoteHost: string, tunnelRemotePort: number, tunnelLocalPort?: number): Promise<RemoteTunnel> {
23+
const tunnel = new NodeRemoteTunnel(options, tunnelRemoteHost, tunnelRemotePort, tunnelLocalPort);
2424
return tunnel.waitForReady();
2525
}
2626

2727
class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
2828

2929
public readonly tunnelRemotePort: number;
3030
public tunnelLocalPort!: number;
31-
public tunnelRemoteHost: string = 'localhost';
31+
public tunnelRemoteHost: string;
3232
public localAddress!: string;
3333

3434
private readonly _options: IConnectionOptions;
@@ -38,7 +38,7 @@ class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
3838
private readonly _listeningListener: () => void;
3939
private readonly _connectionListener: (socket: net.Socket) => void;
4040

41-
constructor(options: IConnectionOptions, tunnelRemotePort: number, private readonly suggestedLocalPort?: number) {
41+
constructor(options: IConnectionOptions, tunnelRemoteHost: string, tunnelRemotePort: number, private readonly suggestedLocalPort?: number) {
4242
super();
4343
this._options = options;
4444
this._server = net.createServer();
@@ -51,7 +51,7 @@ class NodeRemoteTunnel extends Disposable implements RemoteTunnel {
5151
this._server.on('connection', this._connectionListener);
5252

5353
this.tunnelRemotePort = tunnelRemotePort;
54-
54+
this.tunnelRemoteHost = tunnelRemoteHost;
5555
}
5656

5757
public dispose(): void {
@@ -229,7 +229,7 @@ export class TunnelService implements ITunnelService {
229229
this.addTunnelToMap(remoteHost, remotePort, tunnel);
230230
}
231231
return tunnel;
232-
} else if (remoteHost === 'localhost') {
232+
} else {
233233
const options: IConnectionOptions = {
234234
commit: product.commit,
235235
socketFactory: nodeSocketFactory,
@@ -243,11 +243,10 @@ export class TunnelService implements ITunnelService {
243243
logService: this.logService
244244
};
245245

246-
const tunnel = createRemoteTunnel(options, remotePort, localPort);
246+
const tunnel = createRemoteTunnel(options, remoteHost, remotePort, localPort);
247247
this.addTunnelToMap(remoteHost, remotePort, tunnel);
248248
return tunnel;
249249
}
250-
return undefined;
251250
}
252251
}
253252

0 commit comments

Comments
 (0)