tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

profiles.js (3027B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const K = 1024;
      8 const M = 1024 * 1024;
      9 const Bps = 1 / 8;
     10 const KBps = K * Bps;
     11 const MBps = M * Bps;
     12 
     13 const { LocalizationHelper } = require("resource://devtools/shared/l10n.js");
     14 const L10N = new LocalizationHelper(
     15  "devtools/client/locales/network-throttling.properties"
     16 );
     17 
     18 /**
     19 * Predefined network throttling profiles.
     20 * Speeds are in bytes per second.  Latency is in ms.
     21 */
     22 
     23 class ThrottlingProfile {
     24  constructor({ id, download, upload, latency }) {
     25    this.id = id;
     26    this.download = download;
     27    this.upload = upload;
     28    this.latency = latency;
     29  }
     30 
     31  get description() {
     32    const download = this.#toDescriptionData(this.download);
     33    const upload = this.#toDescriptionData(this.upload);
     34    return L10N.getFormatStr(
     35      "throttling.profile.description",
     36      download.value,
     37      download.unit,
     38      upload.value,
     39      upload.unit,
     40      this.latency
     41    );
     42  }
     43 
     44  get menuItemLabel() {
     45    const download = this.#toDescriptionData(this.download);
     46    const upload = this.#toDescriptionData(this.upload);
     47    return L10N.getFormatStr(
     48      "throttling.profile.label",
     49      this.id,
     50      download.value,
     51      download.unit,
     52      upload.value,
     53      upload.unit,
     54      this.latency
     55    );
     56  }
     57 
     58  #toDescriptionData(val) {
     59    if (val % MBps === 0) {
     60      return { value: val / MBps, unit: "Mbps" };
     61    }
     62    return { value: val / KBps, unit: "Kbps" };
     63  }
     64 }
     65 
     66 const PROFILE_CONSTANTS = {
     67  GPRS: "GPRS",
     68  REGULAR_2G: "Regular 2G",
     69  GOOD_2G: "Good 2G",
     70  REGULAR_3G: "Regular 3G",
     71  GOOD_3G: "Good 3G",
     72  REGULAR_4G_LTE: "Regular 4G / LTE",
     73  DSL: "DSL",
     74  WIFI: "Wi-Fi",
     75  OFFLINE: "Offline",
     76 };
     77 
     78 // Should be synced with devtools/docs/user/network_monitor/throttling/index.rst
     79 const profiles = [
     80  {
     81    id: PROFILE_CONSTANTS.OFFLINE,
     82    download: 0,
     83    upload: 0,
     84    latency: 5,
     85  },
     86  {
     87    id: PROFILE_CONSTANTS.GPRS,
     88    download: 50 * KBps,
     89    upload: 20 * KBps,
     90    latency: 500,
     91  },
     92  {
     93    id: PROFILE_CONSTANTS.REGULAR_2G,
     94    download: 250 * KBps,
     95    upload: 50 * KBps,
     96    latency: 300,
     97  },
     98  {
     99    id: PROFILE_CONSTANTS.GOOD_2G,
    100    download: 450 * KBps,
    101    upload: 150 * KBps,
    102    latency: 150,
    103  },
    104  {
    105    id: PROFILE_CONSTANTS.REGULAR_3G,
    106    download: 750 * KBps,
    107    upload: 250 * KBps,
    108    latency: 100,
    109  },
    110  {
    111    id: PROFILE_CONSTANTS.GOOD_3G,
    112    download: 1.5 * MBps,
    113    upload: 750 * KBps,
    114    latency: 40,
    115  },
    116  {
    117    id: PROFILE_CONSTANTS.REGULAR_4G_LTE,
    118    download: 4 * MBps,
    119    upload: 3 * MBps,
    120    latency: 20,
    121  },
    122  {
    123    id: PROFILE_CONSTANTS.DSL,
    124    download: 2 * MBps,
    125    upload: 1 * MBps,
    126    latency: 5,
    127  },
    128  {
    129    id: PROFILE_CONSTANTS.WIFI,
    130    download: 30 * MBps,
    131    upload: 15 * MBps,
    132    latency: 2,
    133  },
    134 ].map(profile => new ThrottlingProfile(profile));
    135 
    136 module.exports = { profiles, PROFILE_CONSTANTS };