Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Fix #5268: Farble concurrency #5269

Merged
merged 1 commit into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class FarblingProtectionHelper {
///
/// It's important to have a value between 0 - 1 in order to be within the array bounds
let randomVoiceIndexScale: Float
/// This value is used to get a random value between 2 and window.navigator.hardwareConcurrency
///
/// Must be a value between 0 and 1
let randomHardwareIndexScale: Float
}

/// Variables representing the prefix of a randomly generated strings used as the plugin name
Expand Down Expand Up @@ -75,7 +79,8 @@ class FarblingProtectionHelper {
fudgeFactor: Float.seededRandom(in: 0.99...1),
fakeVoiceName: fakeVoiceNames.seededRandom() ?? "",
fakePluginData: FarblingProtectionHelper.makeFakePluginData(),
randomVoiceIndexScale: Float(drand48())
randomVoiceIndexScale: Float(drand48()),
randomHardwareIndexScale: Float(drand48())
)

let encoder = JSONEncoder()
Expand Down
21 changes: 21 additions & 0 deletions Client/Frontend/UserContent/UserScripts/FarblingProtection.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ window.braveFarble = (args) => {
}
}

// 4. Farble hardwareConcurrency
// Adds a random value between 2 and the original hardware concurrency
// using the provided `randomHardwareIndexScale` which must be a random value between 0 and 1.
const farbleHardwareConcurrency = (randomHardwareIndexScale) => {
const hardwareConcurrency = window.navigator.hardwareConcurrency
// We only farble amounts greater than 2
if (hardwareConcurrency <= 2) { return }
const remaining = hardwareConcurrency - 2
const newRemaining = Math.round(remaining * randomHardwareIndexScale)

Reflect.defineProperty(window.navigator, 'hardwareConcurrency', {
value: newRemaining + 2
})
}

// A value between 0.99 and 1 to fudge the audio data
// A value between 0.99 to 1 means the values in the destination will
// always be within the expected range of -1 and 1.
Expand All @@ -267,6 +282,12 @@ window.braveFarble = (args) => {
// array bounds
const randomVoiceIndexScale = args['randomVoiceIndexScale']
farbleVoices(fakeVoiceName, randomVoiceIndexScale)

// This value lets us pick a value between 2 and window.navigator.hardwareConcurrency
// It is a value between 0 and 1. For example 0.5 will give us 3 and
// thus return 2 + 3 = 5 for hardware concurrency
const randomHardwareIndexScale = args['randomHardwareIndexScale']
farbleHardwareConcurrency(randomHardwareIndexScale)
}

// Invoke window.braveFarble then delete the function