Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
core: Add support for dtoi usage ping parameter
Browse files Browse the repository at this point in the history
Server side implementation for brave/brave-core#5720
  • Loading branch information
kkuehlz committed Jun 5, 2020
1 parent 8bb2dd1 commit 11aea2d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ exports.countryCodeFrom = (request) => {
return (request.headers['x-brave-country-code'] || 'unknown').toUpperCase()
}

/* Country codes with, on average, less than 100 DAU that we want to exclude
* from certain collections for privacy purposes. Eventually we will want to
* make this a dynamic list. */
const countryCodesLowDAU = new Set([
'AX', 'AS', 'AI', 'AQ', 'AG', 'BQ', 'BV', 'IO', 'BI', 'CV', 'CF', 'TD', 'CX',
'CC', 'KM', 'CG', 'CK', 'DJ', 'DM', 'GQ', 'ER', 'FK', 'FO', 'GF', 'TF', 'GM',
'GL', 'GD', 'GG', 'GN', 'GW', 'HM', 'VA', 'KI', 'KP', 'LS', 'LI', 'MH', 'MR',
'KN', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SC', 'SL', 'SX', 'SB', 'GS', 'SS',
'SJ', 'TJ', 'TL', 'TK', 'TO', 'TC', 'TV', 'UM', 'VU', 'VI', 'WF', 'EH', 'YT',
'FM', 'MC', 'MS', 'NR', 'NE', 'NU', 'NF', 'MP', 'PW', 'PN', 'BL', 'SH',
])

exports.shouldExcludeCountryCode = function(countryCode) {
return countryCodesLowDAU.has(countryCode)
}

// promisified request
exports.prequest = function (url) {
return new Promise((resolve, reject) => {
Expand Down
11 changes: 9 additions & 2 deletions src/controllers/braveCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ let validator = {
monthly: Joi.valid(booleanString).required(),
first: Joi.valid(booleanString).required(),
woi: Joi.string(),
dtoi: Joi.string().optional(),
ref: Joi.string()
}
}

// Build a usage object if query parameters passed in
let buildUsage = (request) => {
if (request.query.daily) {
return {
const country_code = common.countryCodeFrom(request)
const usagePing = {
daily: request.query.daily === 'true',
weekly: request.query.weekly === 'true',
monthly: request.query.monthly === 'true',
Expand All @@ -39,8 +41,13 @@ let buildUsage = (request) => {
channel: request.query.channel || 'unknown',
woi: request.query.woi || '2016-01-04',
ref: request.query.ref || 'none',
country_code: common.countryCodeFrom(request)
country_code: country_code
}
const dtoi = request.query.dtoi
if (!common.shouldExcludeCountryCode(country_code) && dtoi
&& dtoi !== 'null')
usagePing.dtoi = request.query.dtoi
return usagePing
} else {
return null
}
Expand Down
1 change: 1 addition & 0 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const usageSchema = Joi.object().keys({
version: Joi.string(),
channel: Joi.string(),
woi: Joi.string(),
dtoi: Joi.string().optional(),
ref: Joi.string(),
country_code: Joi.string(),
braveDataCenter: Joi.boolean(),
Expand Down

0 comments on commit 11aea2d

Please sign in to comment.