src/vs/base/node/id.ts

128 LOC · 66 covered · 62 uncovered · 13 ranges · 2548 concepts · 4 introducers · 1251 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 > /*--------------------------------------------------------------------------------------------- id.ts ×6
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 { networkInterfaces } from 'os';
7 > import { TernarySearchTree } from '../common/ternarySearchTree.js';
8 > import * as uuid from '../common/uuid.js';
9 > import { getMac } from './macAddress.js';
10 > import { isWindows } from '../common/platform.js';
11 > import { stripUTF8BOM } from '../common/strings.js';
12 >
13 > // http://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms/
14 > // VMware ESX 3, Server, Workstation, Player 00-50-56, 00-0C-29, 00-05-69
15 > // Microsoft Hyper-V, Virtual Server, Virtual PC 00-03-FF
16 > // Parallels Desktop, Workstation, Server, Virtuozzo 00-1C-42
17 > // Virtual Iron 4 00-0F-4B
18 > // Red Hat Xen 00-16-3E
19 > // Oracle VM 00-16-3E
20 > // XenSource 00-16-3E
21 > // Novell Xen 00-16-3E
22 > // Sun xVM VirtualBox 08-00-27
23 > export const virtualMachineHint: { value(): number } = new class {
24 >
25 > private _virtualMachineOUIs?: TernarySearchTree<string, boolean>;
26 > private _value?: number;
27 >
28 > private _isVirtualMachineMacAddress(mac: string): boolean {
29 if (!this._virtualMachineOUIs) {
30 this._virtualMachineOUIs = TernarySearchTree.forStrings<boolean>();
31
32 // dash-separated
33 this._virtualMachineOUIs.set('00-50-56', true);
34 this._virtualMachineOUIs.set('00-0C-29', true);
35 this._virtualMachineOUIs.set('00-05-69', true);
36 this._virtualMachineOUIs.set('00-03-FF', true);
37 this._virtualMachineOUIs.set('00-1C-42', true);
38 this._virtualMachineOUIs.set('00-16-3E', true);
39 this._virtualMachineOUIs.set('08-00-27', true);
40
41 // colon-separated
42 this._virtualMachineOUIs.set('00:50:56', true);
43 this._virtualMachineOUIs.set('00:0C:29', true);
44 this._virtualMachineOUIs.set('00:05:69', true);
45 this._virtualMachineOUIs.set('00:03:FF', true);
46 this._virtualMachineOUIs.set('00:1C:42', true);
47 this._virtualMachineOUIs.set('00:16:3E', true);
48 this._virtualMachineOUIs.set('08:00:27', true);
49 }
50 return !!this._virtualMachineOUIs.findSubstr(mac);
51 }
52 > id.ts ×6
53 > value(): number {
54 if (this._value === undefined) {
55 let vmOui = 0;
56 let interfaceCount = 0;
57
58 const interfaces = networkInterfaces();
59 for (const name in interfaces) {
60 const networkInterface = interfaces[name];
61 if (networkInterface) {
62 for (const { mac, internal } of networkInterface) {
63 if (!internal) {
64 interfaceCount += 1;
65 if (this._isVirtualMachineMacAddress(mac.toUpperCase())) {
66 vmOui += 1;
67 }
68 }
69 }
70 }
71 }
72 this._value = interfaceCount > 0
73 ? vmOui / interfaceCount
74 : 0;
75 }
76
77 return this._value;
78 }
79 > }; id.ts ×6
80 >
81 > let machineId: Promise<string>;
82 > export async function getMachineId(errorLogger: (error: Error) => void): Promise<string> { id.ts ×3
83 > if (!machineId) {
84 > machineId = (async () => {
85 > const id = await getMacMachineId(errorLogger);
86 >
87 > return id || uuid.generateUuid(); // fallback, generate a UUID
88 > })();
89 > }
90 >
91 > return machineId;
92 > }
93 > id.ts ×6
94 > async function getMacMachineId(errorLogger: (error: Error) => void): Promise<string | undefined> { id.ts ×3
95 > try {
96 > const crypto = await import('crypto');
97 > const macAddress = getMac();
98 > return crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
99 > } catch (err) {
100 errorLogger(err);
101 return undefined;
102 }
103 > } id.ts ×3
104 > id.ts ×6
105 > const SQM_KEY: string = 'Software\\Microsoft\\SQMClient';
106 > export async function getSqmMachineId(errorLogger: (error: Error) => void): Promise<string> { id.ts ×2
107 > if (isWindows) {
108 const Registry = await import('@vscode/windows-registry');
109 try {
110 return Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', SQM_KEY, 'MachineId') || '';
111 } catch (err) {
112 errorLogger(err);
113 return '';
114 }
115 }
116 > return ''; id.ts ×2
117 > }
118 > id.ts ×6
119 > export async function getDevDeviceId(errorLogger: (error: Error) => void): Promise<string> { id.ts ×2
120 > try {
121 > const deviceIdPackage = await import('@vscode/deviceid');
122 > const id = await deviceIdPackage.getDeviceId();
123 > return stripUTF8BOM(id);
124 > } catch (err) {
125 errorLogger(err);
126 return uuid.generateUuid();
127 }
128 > } id.ts ×2