1
>
/*---------------------------------------------------------------------------------------------
tunnelModel.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import * as nls from '../../../../nls.js';
7
>
import { debounce } from '../../../../base/common/decorators.js';
8
>
import { Emitter, Event } from '../../../../base/common/event.js';
9
>
import { hash } from '../../../../base/common/hash.js';
10
>
import { Disposable, DisposableStore } from '../../../../base/common/lifecycle.js';
11
>
import { URI } from '../../../../base/common/uri.js';
12
>
import { ConfigurationTarget, IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
13
>
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
14
>
import { ILogService } from '../../../../platform/log/common/log.js';
15
>
import { IAddressProvider } from '../../../../platform/remote/common/remoteAgentConnection.js';
16
>
import { IRemoteAuthorityResolverService, TunnelDescription } from '../../../../platform/remote/common/remoteAuthorityResolver.js';
17
>
import { IStorageService, StorageScope, StorageTarget } from '../../../../platform/storage/common/storage.js';
18
>
import { RemoteTunnel, ITunnelService, TunnelProtocol, TunnelPrivacyId, LOCALHOST_ADDRESSES, ProvidedPortAttributes, PortAttributesProvider, isLocalhost, isAllInterfaces, ProvidedOnAutoForward, ALL_INTERFACES_ADDRESSES } from '../../../../platform/tunnel/common/tunnel.js';
19
>
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
20
>
import { IWorkbenchEnvironmentService } from '../../environment/common/environmentService.js';
21
>
import { IExtensionService } from '../../extensions/common/extensions.js';
22
>
import { CancellationToken } from '../../../../base/common/cancellation.js';
23
>
import { isNumber, isObject, isString } from '../../../../base/common/types.js';
24
>
import { deepClone } from '../../../../base/common/objects.js';
25
>
import { IContextKeyService, RawContextKey } from '../../../../platform/contextkey/common/contextkey.js';
26
>
27
>
const MISMATCH_LOCAL_PORT_COOLDOWN = 10 * 1000; // 10 seconds
28
>
const TUNNELS_TO_RESTORE = 'remote.tunnels.toRestore';
29
>
const TUNNELS_TO_RESTORE_EXPIRATION = 'remote.tunnels.toRestoreExpiration';
30
>
const RESTORE_EXPIRATION_TIME = 1000 * 60 * 60 * 24 * 14; // 2 weeks
31
>
export const ACTIVATION_EVENT = 'onTunnel';
32
>
export const forwardedPortsFeaturesEnabled = new RawContextKey<boolean>('forwardedPortsViewEnabled', false, nls.localize('tunnel.forwardedPortsViewEnabled', "Whether the Ports view is enabled."));
33
>
export const forwardedPortsViewEnabled = new RawContextKey<boolean>('forwardedPortsViewOnlyEnabled', false, nls.localize('tunnel.forwardedPortsViewEnabled', "Whether the Ports view is enabled."));
34
>
35
>
export interface RestorableTunnel {
36
>
remoteHost: string;
37
>
remotePort: number;
38
>
localAddress: string;
39
>
localUri: URI;
40
>
protocol: TunnelProtocol;
41
>
localPort?: number;
42
>
name?: string;
43
>
source: {
44
>
source: TunnelSource;
45
>
description: string;
46
>
};
47
>
}
48
>
49
>
export interface Tunnel {
50
>
remoteHost: string;
51
>
remotePort: number;
52
>
localAddress: string;
53
>
localUri: URI;
54
>
protocol: TunnelProtocol;
55
>
localPort?: number;
56
>
name?: string;
57
>
closeable?: boolean;
58
>
privacy: TunnelPrivacyId | string;
59
>
runningProcess: string | undefined;
60
>
hasRunningProcess?: boolean;
61
>
pid: number | undefined;
62
>
source: {
63
>
source: TunnelSource;
64
>
description: string;
65
>
};
66
>
}
67
>
68
>
export function parseAddress(address: string): { host: string; port: number } | undefined {
69
const matches = address.match(/^([a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*:)?([0-9]+)$/);
70
if (!matches) {