-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/mk 0.8.1 #6
base: master
Are you sure you want to change the base?
Changes from all commits
ce1fb7b
b7e3ce3
3d36737
425d1db
4f18783
a54bdee
a788414
247459b
5968838
05a4293
4889e6b
737539a
569577a
adc3435
2a85d4e
6002d6e
35d78ea
760038e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const cp = require('child_process') | ||
const os = require('os') | ||
const path = require('path') | ||
|
||
const pkg = require('pkg') | ||
|
||
const nodeTargets = { | ||
darwin: "node8-macos-x64", | ||
linux: "node8-linux-x64", | ||
win32: "node8-win-x64", | ||
} | ||
|
||
const nativeModules = { | ||
darwin: [ | ||
'node_modules/measurement-kit/build/Release/measurement-kit.node', | ||
'node_modules/sqlite3/lib/binding/node-v57-darwin-x64/node_sqlite3.node' | ||
], | ||
win32: [], | ||
linux: [] | ||
} | ||
|
||
const platform = os.platform() | ||
|
||
if (!nodeTargets[platform]) { | ||
console.log('this platform is not supported') | ||
process.exit(0) | ||
} | ||
|
||
console.log('- building packed/ooni for ' + nodeTargets[platform]) | ||
pkg.exec([ 'dist/ooni.js', '--target', nodeTargets[platform], '-o', 'packed/ooni' ]) | ||
.then(() => { | ||
nativeModules[platform].forEach(dotNodePath => { | ||
console.log('- copying ' + dotNodePath) | ||
cp.spawnSync('cp', [ | ||
dotNodePath, | ||
'packed/' + path.basename(dotNodePath) | ||
], {shell: true}) | ||
}) | ||
process.exit(0) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import os | ||
import pystache | ||
# pip install https://github.com/okunishinishi/python-stringcase/archive/cc7d5eb58ff4a959a508c3f2296459daf7c3a1f2.zip | ||
import stringcase | ||
|
||
PKG_TMPL = """ | ||
{ | ||
"name": "ooni-{{nettest_dash_case}}", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nice, so |
||
"version": "0.3.0", | ||
"description": "Official OONI test for running {{nettest_name}}", | ||
"dependencies": { | ||
"measurement-kit": "0.1.0" | ||
} | ||
} | ||
""" | ||
|
||
INDEX_TMPL = """ | ||
import { {{nettest_pascal_case}} } from 'measurement-kit' | ||
|
||
export const renderSummary = (measurements, {React, Cli, Components, chalk}) => { | ||
const summary = measurements[0].summary | ||
|
||
// When this function is called from the Cli the Cli will be set, when it's | ||
// called from the Desktop app we have React set instead. | ||
if (Cli) { | ||
Cli.log(Cli.output.labelValue('Label', uploadMbit, {unit: 'Mbit'})) | ||
} else if (React) { | ||
/* | ||
XXX this is broken currently as it depends on react | ||
const { | ||
Container, | ||
Heading | ||
} = Components | ||
return class extends React.Component { | ||
render() { | ||
return <Container> | ||
<Heading h={1}>Results for NDT</Heading> | ||
{uploadMbit} | ||
</Container> | ||
} | ||
} | ||
*/ | ||
} | ||
} | ||
|
||
export const renderHelp = () => { | ||
} | ||
|
||
export const makeSummary = ({test_keys}) => ({ | ||
}) | ||
|
||
export const run = ({ooni, argv}) => { | ||
const {{nettest_camel_case}} = {{nettest_pascal_case}}(ooni.mkOptions) | ||
ooni.init({{nettest_camel_case}}) | ||
|
||
{{nettest_camel_case}}.on('begin', () => ooni.onProgress(0.0, 'starting {{nettest_dash_case}}')) | ||
{{nettest_camel_case}}.on('progress', (percent, message) => { | ||
ooni.onProgress(percent, message, persist) | ||
}) | ||
return ooni.run({{nettest_camel_case}}.run) | ||
} | ||
""" | ||
|
||
nettests = [ | ||
['Web Connectivity', 'web-connectivity'], | ||
['HTTP Invalid Request Line', 'http-invalid-request-line'], | ||
['HTTP Header Field Manipulation', 'http-header-field-manipulation'], | ||
#['NDT', 'ndt'], | ||
['Dash', 'dash'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this might probably be |
||
['Facebook Messenger', 'facebook-messenger'], | ||
['Telegram', 'telegram'], | ||
['WhatsApp', 'whatsapp'] | ||
] | ||
|
||
def gen(): | ||
for nettest_name, nettest_dash_case in nettests: | ||
nettest_camel_case = stringcase.camelcase(nettest_dash_case) | ||
nettest_pascal_case = stringcase.pascalcase(nettest_dash_case) | ||
partials = dict( | ||
nettest_dash_case=nettest_dash_case, | ||
nettest_camel_case=nettest_camel_case, | ||
nettest_pascal_case=nettest_pascal_case, | ||
nettest_name=nettest_name | ||
) | ||
dst_path = os.path.join(os.path.dirname(__file__), '..', 'src', 'nettests', nettest_dash_case) | ||
if not os.path.exists(dst_path): | ||
os.mkdir(dst_path) | ||
|
||
index_path = os.path.join(dst_path, 'index.js') | ||
package_path = os.path.join(dst_path, 'package.json') | ||
with open(index_path, 'w+') as out_file: | ||
out_file.write(pystache.render(INDEX_TMPL, partials)) | ||
print('wrote {}'.format(index_path)) | ||
with open(package_path, 'w+') as out_file: | ||
out_file.write(pystache.render(PKG_TMPL, partials)) | ||
print('wrote {}'.format(package_path)) | ||
|
||
def main(): | ||
gen() | ||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,6 @@ const main = async ctx => { | |
} | ||
await exit(1) | ||
} | ||
|
||
} | ||
|
||
export default main |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,14 @@ import { | |
Result | ||
} from '../config/db' | ||
|
||
import { | ||
notify | ||
} from '../config/ipc' | ||
|
||
import makeCli from '../cli/make-cli' | ||
|
||
import { getGeoipPaths } from '../config/geoip' | ||
|
||
const debug = require('debug')('commands.run') | ||
|
||
const help = () => { | ||
|
@@ -66,30 +72,51 @@ const run = async ({camelName, argv}) => { | |
}) | ||
dbOperations.push(result.save()) | ||
|
||
notify({key: 'ooni.run.nettest.starting', value: camelName}) | ||
console.log(info('Running '+ | ||
chalk.bold(`${nettestType.nettests.length} ${nettestType.name} `) + | ||
`test${sOrNot}`)) | ||
|
||
let dataUsageUp = 0 | ||
let dataUsageDown = 0 | ||
const geoip = await getGeoipPaths() | ||
|
||
for (const nettestLoader of nettestType.nettests) { | ||
const loader = nettestLoader() | ||
const { nettest, meta } = loader | ||
notify({key: 'ooni.run.nettest.running', value: meta}) | ||
console.log(info(`${chalk.bold(meta.name)}`)) | ||
const measurements = await nettest.run({ooni: makeOoni(loader), argv}) | ||
const [measurements, dataUsage] = await nettest.run({ | ||
ooni: makeOoni(loader, geoip), | ||
argv | ||
}) | ||
debug('setting data usage', dataUsage) | ||
dataUsageUp += dataUsage.up || 0 | ||
dataUsageDown += dataUsage.down || 0 | ||
nettest.renderSummary(measurements, { | ||
Cli: makeCli(), | ||
chalk: chalk, | ||
Components: null, | ||
React: null, | ||
}) | ||
dbOperations.push(result.setMeasurements(measurements)) | ||
|
||
for (const measurement of measurements) { | ||
dbOperations.push(result.addMeasurements(measurement)) | ||
} | ||
} | ||
await Promise.all(dbOperations) | ||
|
||
const measurements = await result.getMeasurements() | ||
debug('updating the result table') | ||
debug(measurements) | ||
const summary = nettestType.makeSummary(measurements) | ||
debug('summary: ', summary) | ||
await result.update({ | ||
summary: nettestType.makeSummary(measurements), | ||
endTime: moment.utc().toDate(), | ||
done: true | ||
done: true, | ||
dataUsageUp: dataUsageUp, | ||
dataUsageDown: dataUsageDown, | ||
summary | ||
}) | ||
} | ||
|
||
|
@@ -140,6 +167,7 @@ const main = async ctx => { | |
await exit(0) | ||
} else { | ||
await run({camelName, argv}) | ||
await exit(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? Does |
||
} | ||
} catch(err) { | ||
if (err.usageError) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thing that wonders me: the versioning of Node bindings is not aligned with the version of MK. Do you think that this may be a problem? FTR for Android we use
${mk_version}-${bindings-version}
.