src/vs/platform/remote/common/remoteHosts.ts

109 LOC · 94 covered · 15 uncovered · 22 ranges · 5749 concepts · 14 introducers · 3094 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- remoteHosts.ts ×7
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 { Schemas } from '../../../base/common/network.js';
7 > import { URI } from '../../../base/common/uri.js';
8 >
9 > export function getRemoteAuthority(uri: URI): string | undefined {
10 return uri.scheme === Schemas.vscodeRemote ? uri.authority : undefined;
11 }
13 > export function getRemoteName(authority: string): string;
14 > export function getRemoteName(authority: undefined): undefined;
15 > export function getRemoteName(authority: string | undefined): string | undefined;
16 > export function getRemoteName(authority: string | undefined): string | undefined {
17 > if (!authority) { remoteHosts.ts ×2
18 return undefined;
19 }
20 > const pos = authority.indexOf('+'); remoteHosts.ts ×2
21 > if (pos < 0) {
22 > // e.g. localhost:8000 remoteHosts.ts ×1
23 > return authority;
24 > }
25 > return authority.substr(0, pos); remoteHosts.ts ×1
26 > }
28 > /**
29 > * Returns the suffix part of the authority after the '+' character.
30 > * For remote connections, this is typically the server/tunnel identifier.
31 > * Examples:
32 > * - For tunnels: `tunnel+myTunnel` returns `myTunnel`
33 > * - For SSH: `ssh+myserver` returns `myserver`
34 > * - For localhost: `localhost:8000` returns `undefined`
35 > * @param authority The remote authority string.
36 > * @returns The suffix after the '+' character, or undefined if there is no '+' character.
37 > */
38 > export function getRemoteServerRootPath(authority: string): string | undefined;
39 > export function getRemoteServerRootPath(authority: undefined): undefined;
40 > export function getRemoteServerRootPath(authority: string | undefined): string | undefined;
41 > export function getRemoteServerRootPath(authority: string | undefined): string | undefined {
42 if (!authority) {
43 return undefined;
44 }
45 const pos = authority.indexOf('+');
46 if (pos < 0) {
47 return undefined;
48 }
49 return authority.substring(pos + 1);
50 }
52 > export function parseAuthorityWithPort(authority: string): { host: string; port: number } {
53 > const { host, port } = parseAuthority(authority); remoteHosts.ts ×2
54 > if (typeof port === 'undefined') {
55 throw new Error(`Invalid remote authority: ${authority}. It must either be a remote of form <remoteName>+<arg> or a remote host of form <host>:<port>.`);
56 }
57 > return { host, port }; remoteHosts.ts ×2
58 > }
60 > export function parseAuthorityWithOptionalPort(authority: string, defaultPort: number): { host: string; port: number } {
61 > let { host, port } = parseAuthority(authority); remoteHosts.ts ×1
62 > if (typeof port === 'undefined') {
63 > port = defaultPort;
64 > }
65 > return { host, port };
66 > }
68 > function parseAuthority(authority: string): { host: string; port: number | undefined } { remoteHosts.ts ×1
69 > // check for ipv6 with port
70 > const m1 = authority.match(/^(\[[0-9a-z:]+\]):(\d+)$/);
71 > if (m1) {
72 > return { host: m1[1], port: parseInt(m1[2], 10) }; remoteHosts.ts ×1
73 > }
75 > // check for ipv6 without port
76 > const m2 = authority.match(/^(\[[0-9a-z:]+\])$/);
77 > if (m2) {
78 > return { host: m2[1], port: undefined }; remoteHosts.ts ×1
79 > }
81 > // anything with a trailing port
82 > const m3 = authority.match(/(.*):(\d+)$/);
83 > if (m3) {
84 > return { host: m3[1], port: parseInt(m3[2], 10) }; remoteHosts.ts ×1
85 > }
87 > // doesn't contain a port
88 > return { host: authority, port: undefined };
89 > }
91 > const loopbackHosts = new Set([
92 > 'localhost',
93 > '127.0.0.1',
94 > '::1',
95 > '[::1]',
96 > '0000:0000:0000:0000:0000:0000:0000:0001',
97 > '[0000:0000:0000:0000:0000:0000:0000:0001]'
98 > ]);
99 >
100 > /**
101 > * Returns whether the given host (as found in a direct `<host>:<port>` remote
102 > * authority) refers to the local loopback interface. The check is intentionally
103 > * strict: only `localhost` and the IPv4/IPv6 loopback literals are considered
104 > * local. Any other host (a routable IP address or a hostname) is treated as a
105 > * connection that leaves the local machine.
106 > */
107 > export function isLoopbackHost(host: string): boolean {
108 > return loopbackHosts.has(host.toLowerCase()); remoteHosts.ts ×1
109 > }