提交 483e81f3 编写于 作者: A Alex Ross

Fix duplicate port forwards for ipv4 vs ipv6

Fixes https://github.com/microsoft/vscode/issues/111400
上级 995983da
......@@ -60,8 +60,14 @@ export function extractLocalHostUriMetaDataForPortMapping(uri: URI): { address:
};
}
export const LOCALHOST_ADDRESSES = ['localhost', '127.0.0.1', '0:0:0:0:0:0:0:1', '::1'];
export function isLocalhost(host: string): boolean {
return host === 'localhost' || host === '127.0.0.1';
return LOCALHOST_ADDRESSES.indexOf(host) >= 0;
}
export const ALL_INTERFACES_ADDRESSES = ['0.0.0.0', '0:0:0:0:0:0:0:0', '::'];
export function isAllInterfaces(host: string): boolean {
return ALL_INTERFACES_ADDRESSES.indexOf(host) >= 0;
}
function getOtherLocalhost(host: string): string | undefined {
......
......@@ -7,7 +7,7 @@ import { Event, Emitter } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
import { isLocalhost, ITunnelService, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
import { ALL_INTERFACES_ADDRESSES, isAllInterfaces, isLocalhost, ITunnelService, LOCALHOST_ADDRESSES, RemoteTunnel } from 'vs/platform/remote/common/tunnel';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IEditableData } from 'vs/workbench/common/views';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
......@@ -65,18 +65,29 @@ export function parseAddress(address: string): { host: string, port: number } |
}
export function mapHasAddress<T>(map: Map<string, T>, host: string, port: number): T | undefined {
if (!isLocalhost(host)) {
return map.get(makeAddress(host, port));
const initialAddress = map.get(makeAddress(host, port));
if (initialAddress) {
return initialAddress;
}
const stringAddress = makeAddress('localhost', port);
if (map.has(stringAddress)) {
return map.get(stringAddress);
}
const numberAddress = makeAddress('127.0.0.1', port);
if (map.has(numberAddress)) {
return map.get(numberAddress);
if (isLocalhost(host)) {
// Do localhost checks
for (const testHost of LOCALHOST_ADDRESSES) {
const testAddress = makeAddress(testHost, port);
if (map.has(testAddress)) {
return map.get(testAddress);
}
}
} else if (isAllInterfaces(host)) {
// Do all interfaces checks
for (const testHost of ALL_INTERFACES_ADDRESSES) {
const testAddress = makeAddress(testHost, port);
if (map.has(testAddress)) {
return map.get(testAddress);
}
}
}
return undefined;
}
......@@ -85,7 +96,7 @@ export function mapHasAddressLocalhostOrAllInterfaces<T>(map: Map<string, T>, ho
if (originalAddress) {
return originalAddress;
}
const otherHost = host === '0.0.0.0' ? 'localhost' : (host === 'localhost' ? '0.0.0.0' : undefined);
const otherHost = isAllInterfaces(host) ? 'localhost' : (host === 'localhost' ? '0.0.0.0' : undefined);
if (otherHost) {
return mapHasAddress(map, otherHost, port);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册