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.
/*---------------------------------------------------------------------------------------------
id.ts ×6
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { networkInterfaces } from 'os';
import { TernarySearchTree } from '../common/ternarySearchTree.js';
import * as uuid from '../common/uuid.js';
import { getMac } from './macAddress.js';
import { isWindows } from '../common/platform.js';
import { stripUTF8BOM } from '../common/strings.js';
// http://www.techrepublic.com/blog/data-center/mac-address-scorecard-for-common-virtual-machine-platforms/
// VMware ESX 3, Server, Workstation, Player 00-50-56, 00-0C-29, 00-05-69
// Microsoft Hyper-V, Virtual Server, Virtual PC 00-03-FF
// Parallels Desktop, Workstation, Server, Virtuozzo 00-1C-42
// Virtual Iron 4 00-0F-4B
// Red Hat Xen 00-16-3E
// Oracle VM 00-16-3E
// XenSource 00-16-3E
// Novell Xen 00-16-3E
// Sun xVM VirtualBox 08-00-27
export const virtualMachineHint: { value(): number } = new class {
private _virtualMachineOUIs?: TernarySearchTree<string, boolean>;
private _value?: number;
private _isVirtualMachineMacAddress(mac: string): boolean {
if (!this._virtualMachineOUIs) {
this._virtualMachineOUIs = TernarySearchTree.forStrings<boolean>();
// dash-separated
this._virtualMachineOUIs.set('00-50-56', true);
this._virtualMachineOUIs.set('00-0C-29', true);
this._virtualMachineOUIs.set('00-05-69', true);
this._virtualMachineOUIs.set('00-03-FF', true);
this._virtualMachineOUIs.set('00-1C-42', true);
this._virtualMachineOUIs.set('00-16-3E', true);
this._virtualMachineOUIs.set('08-00-27', true);
// colon-separated
this._virtualMachineOUIs.set('00:50:56', true);
this._virtualMachineOUIs.set('00:0C:29', true);
this._virtualMachineOUIs.set('00:05:69', true);
this._virtualMachineOUIs.set('00:03:FF', true);
this._virtualMachineOUIs.set('00:1C:42', true);
this._virtualMachineOUIs.set('00:16:3E', true);
this._virtualMachineOUIs.set('08:00:27', true);
}
return !!this._virtualMachineOUIs.findSubstr(mac);
}
value(): number {
if (this._value === undefined) {
let vmOui = 0;
let interfaceCount = 0;
const interfaces = networkInterfaces();
for (const name in interfaces) {
const networkInterface = interfaces[name];
if (networkInterface) {
for (const { mac, internal } of networkInterface) {
if (!internal) {
interfaceCount += 1;
if (this._isVirtualMachineMacAddress(mac.toUpperCase())) {
vmOui += 1;
}
}
}
}
}
this._value = interfaceCount > 0
? vmOui / interfaceCount
: 0;
}
return this._value;
}
let machineId: Promise<string>;
export async function getMachineId(errorLogger: (error: Error) => void): Promise<string> {
id.ts ×3
if (!machineId) {
machineId = (async () => {
const id = await getMacMachineId(errorLogger);
return id || uuid.generateUuid(); // fallback, generate a UUID
})();
}
return machineId;
}
async function getMacMachineId(errorLogger: (error: Error) => void): Promise<string | undefined> {
id.ts ×3
try {
const crypto = await import('crypto');
const macAddress = getMac();
return crypto.createHash('sha256').update(macAddress, 'utf8').digest('hex');
} catch (err) {
errorLogger(err);
return undefined;
}
const SQM_KEY: string = 'Software\\Microsoft\\SQMClient';
export async function getSqmMachineId(errorLogger: (error: Error) => void): Promise<string> {
id.ts ×2
if (isWindows) {
const Registry = await import('@vscode/windows-registry');
try {
return Registry.GetStringRegKey('HKEY_LOCAL_MACHINE', SQM_KEY, 'MachineId') || '';
} catch (err) {
errorLogger(err);
return '';
}
}
}
export async function getDevDeviceId(errorLogger: (error: Error) => void): Promise<string> {
id.ts ×2
try {
const deviceIdPackage = await import('@vscode/deviceid');
const id = await deviceIdPackage.getDeviceId();
return stripUTF8BOM(id);
} catch (err) {
errorLogger(err);
return uuid.generateUuid();
}