chore: continue merging probe-engine into probe-cli (#211)

* chore: remove duplicate code of conduct

* chore: remove AUTHORS file

I doubt this actually has any value in the era of GitHub.

* chore: move CODEOWNERS to toplevel

* chore: move CONTRIBUTING.md to toplevel and adapt it

* chore: remove duplicated LICENSE file

* chore(engine): remove now-obsolete design document

* chore: remove the testusing test

We're not going to make this code importable from third parties
like we did for probe-engine. It seems this feature was only used
for the experiment in Spain so it makes sense to drop it.

* chore: enable code generation tests

See https://github.com/ooni/probe/issues/1335

* chore: enable code-ql checks

* cleanup: remove libooniffi code and tests

It seems this code is not used. We are not aware of anyone using it. And we
don't want to expose it publicly as an API. So, what to do?

I guess it's fine to delete it. If there is anyone that needs it, we have
in the history a reference to it and we can always reinstate it.

* chore: move issue templates to ooni/probe
This commit is contained in:
Simone Basso 2021-02-03 14:42:51 +01:00 committed by GitHub
parent d5b3e90605
commit ef8fa97e13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 9 additions and 1024 deletions

View File

@ -7,7 +7,7 @@ name: "CodeQL"
on:
push:
branches: [ master, mobile-staging ]
branches: [ master, mobile-staging, 'release/**' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]

View File

@ -1,4 +1,4 @@
# Contributing to ooni/probe-engine
# Contributing to ooni/probe-cli
This is an open source project, and contributions are welcome! You are welcome
to open pull requests. An open pull request will be reviewed by a core
@ -10,6 +10,11 @@ reviewer is satisfied, they will merge the pull request.
Please, before opening a new issue, check whether the issue or feature request
you want us to consider has not already been reported by someone else.
For new issues, please use: https://github.com/ooni/probe.
Please, also check https://github.com/ooni/probe-engine for legacy issues. This is
the repository where the measurement engine previously was located.
## PR requirements
Every pull request that introduces new functionality should feature
@ -67,8 +72,8 @@ to write better unit tests for our code.
To get a sense of what we expect from an experiment, see:
- the experiment/example experiment
- the internal/engine/experiment/example experiment
- the experiment/webconnectivity experiment
- the internal/engine/experiment/webconnectivity experiment
Thank you!

View File

@ -1,28 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug, triage
assignees: bassosimone
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior.
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**System information (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View File

@ -1,29 +0,0 @@
---
name: Routine sprint releases
about: Bi-weekly releases of probe-engine, etc.
title: ''
labels: effort/M, priority/medium
assignees: bassosimone
---
- [ ] psiphon: run ./update.bash
- [ ] engine: update dependencies
- [ ] engine: update internal/httpheader/useragent.go
- [ ] engine: update version/version.go
- [ ] engine: update resources/assets.go
- [ ] engine: update bundled certs (using `go generate ./...`)
- [ ] engine: make sure all workflows are green
- [ ] engine: tag a new version
- [ ] engine: update again version.go to be alpha
- [ ] engine: create release at GitHub
- [ ] engine: update mobile-staging branch to create oonimkall
- [ ] cli: pin to latest engine
- [ ] cli: update internal/version/version.go
- [ ] cli: tag a new version
- [ ] cli: update internal/version/version.go again to be alpha
- [ ] android: pin to latest oonimkall
- [ ] ios: pin to latest oonimkall
- [ ] desktop: pin to latest cli
- [ ] engine: create issue for next routine release
- [ ] e2etesting: see whether we can remove legacy checks

View File

@ -1,29 +0,0 @@
name: libooniffi
on:
schedule:
- cron: "0 5 * * 3"
jobs:
darwin:
runs-on: macos-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.14"
- uses: actions/checkout@v2
- run: ./libooniffi/buildtest.bash darwin
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.14"
- uses: actions/checkout@v2
- run: ./libooniffi/buildtest.bash linux
windows:
runs-on: windows-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.14"
- uses: actions/checkout@v2
- run: bash.exe ./libooniffi/buildtest.bash windows

View File

@ -1,13 +0,0 @@
name: using
on:
schedule:
- cron: "0 5 * * 3"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: "1.14"
- uses: actions/checkout@v2
- run: ./testusing.bash

View File

@ -1,2 +0,0 @@
Simone Basso
Arturo Filastò

View File

@ -1,255 +0,0 @@
# OONI Code of Conduct
Statement of Intent:
OONI is committed to fostering an inclusive environment and
community. OONI is a place where people should feel safe to engage, share their
point of view, and participate.
This code of conduct applies to OONI as a whole. It is intended to
provide guidelines for contributors. Employees and contractors of OONI
are also subject to company policies and procedures. Those
people should feel free to contact HR with questions or concerns.
This code of conduct is not exhaustive or complete. It is an ongoing effort to
summarize our shared understanding. We want to provide a welcoming, safe
environment, so we can work together to pursue powerful solutions. We reserve
the right to deviate from strictly enforcing this code. Any deviations must
produce an outcome which is fairer, and aligned with our values. We understand
that keeping a living document relevant and “patched” involves sustained
effort.
0. Summary: Don't be a jerk. Be awesome instead.
The OONI community should be a good place where people are glad to be.
DO: Be kind, thoughtful, and considerate.
DO: Make OONI a place where people are happy and comfortable.
DO: Remember: We are all contributing; we are all learning. Nobody was born
an expert.
DO: Yield the floor. Listen. Make sure everyone gets heard.
DON'T: Insult, harass, intimidate, or be a jerk.
DON'T: Treat honest mistakes as an excuse to hassle people. Mistakes are for
learning.
DON'T: Hunt for ways to uphold the letter of this code while violating its
spirit.
AND DO: Eagerly email: team@openobservatory.org with
questions or concerns.
1. Purpose
A primary goal of the OONI community is to be inclusive of many different
contributors. We want to include contributors from the most varied and diverse
backgrounds possible. As such, we are committed to providing a friendly, safe
and welcoming environment for all, regardless of their experience, gender
identity or expression, sexual orientation, family, relationships, ability
(whether bodily or mental), personal appearance, socioeconomic status, body
size, race, ethnicity, age, religion, nationality, or membership in a
disadvantaged and/or underrepresented group.
A safe environment means one free from abuse, whether isolated or systemic. We
explicitly acknowledge that tolerating abuse is a security problem. Allowing
abusers and malicious people to disrupt our community puts our software,
developers, and users at risk.
This code of conduct outlines our expectations for all those who participate in
our community, as well as the consequences for unacceptable behavior.
We invite all those who participate in OONI to help us create safe
and positive experiences for everyone.
2. Be your best self
The following behaviors are expected and requested of all community members:
* Participate in an honest and active way. In doing so, you contribute to
the health and longevity of this community.
* Exercise consideration and respect in your speech and actions.
* Attempt collaboration and dialog before engaging in conflict.
* Refrain from demeaning, discriminatory, or harassing behavior and speech.
* Be mindful of your surroundings and of your fellow participants. Alert
community leaders if you notice:
- a dangerous situation
- someone in distress
- violations of this code of conduct, even if they seem minor
* Remember that community event venues may be shared with members of the
public. Please be respectful to everyone using these locations.
* Respect the privacy of your fellow community members.
3. Unacceptable behaviors
The following behaviors are unacceptable within our community:
* Violence, sexual assault, threats of violence, or violent language
directed against another person, especially violence against a person or
group based on a protected characteristic. (Display of weapons may
constitute intimidation or a threat of violence.)
* Sexist, racist, homophobic, transphobic, ableist or otherwise
discriminatory jokes and language.
* Spontaneously posting or displaying sexually explicit or violent
material. (If it is necessary to share such material when working on
OONI's mission, do so with sensitivity. Be aware that many people don't
want to see it.)
* Posting or threatening to post other peoples personally identifying
information ("doxing") without their consent.
* Personal insults or attacks, particularly those related to:
- experience
- gender identity or expression
- sexual orientation
- family
- relationships
- ability (whether bodily or mental)
- personal appearance
- socioeconomic status
- body size
- race
- ethnicity
- age
- religion
- nationality
- membership in a disadvantaged and/or underrepresented group
* Inappropriate photography, audio recording, or recording of personal
information. You should have someone's consent before recording these
things, and before posting them publicly.
* Inappropriate physical contact. You should have someones consent before
touching them.
* Unwelcome sexual attention: this includes sexualized comments or jokes,
inappropriate touching, groping, and unwelcome sexual advances.
* Deliberate intimidation, stalking or following (online or in person).
* Deliberately undermining the spirit of this code while following the
letter.
* Sustained disruption of any community events, including talks,
presentations, and online conversations.
* Deliberately pushing against someone's stated boundaries.
* Advocating for, or encouraging, any of the above behavior.
4. Unacceptable behavior has consequences
We will not tolerate unacceptable behavior from any community member. We will
not make exceptions for sponsors and those with decision-making authority.
People in formal or informal leadership roles must model the highest standards
of behavior.
Anyone asked by another community member to stop unacceptable behavior is
expected to comply immediately. Please don't step in on someone else's behalf
without their consent.
5. Where to go for help
The OONI team can assist with intra-community conflict resolution. You can contact
the whole OONI team:
- if you have questions or concerns about the code of conduct, or
- if you feel that you have witnessed a code of conduct violation
However, if you feel that there is a conflict of interest with any team
member, you may contact members individually. See: https://ooni.org/about/.
6. What to do if you witness unacceptable behavior
If you are subject to or witness unacceptable behavior, or have any other
concerns, please notify the OONI team as soon as possible. You can
contact the OONI team in person, or at
team@openobservatory.org. Current team members are listed
on the [about page](https://ooni.org/about/). The OONI team's incident response will vary on a
case-by-case basis. We will make every effort to respond to the
incident immediately. We will prioritize the safety of the person who
has been harmed, or is at risk of harm. Person(s) who have been harmed or are
at risk of harm can withdraw the incident report at any time. We will never do
anything without the consent of the person who has been harmed or is at risk of
harm, except in situations where there is a threat of imminent danger or harm
to anyone.
7. What the person reporting a violation can expect
The OONI team prioritizes the safety and well-being of any person who
feels that they have been harmed or may be in danger of being harmed. Anyone
reporting an issue to the OONI team can expect that their report will
be taken seriously. Initial reports can be taken in written or verbal form.
The next steps in an incident response will vary on a case-by-case basis.
8. How the OONI team responds to incidents
If a community member engages in unacceptable behavior, the OONI team
may take any action they deem appropriate, including but not limited to a
warning, informal mediation, temporary ban or permanent expulsion from the
community.
9. Scope of this document
This code of conduct covers all community participants:
- paid and unpaid contributors
- sponsors
- other guests
when interacting:
- in all online and in-person community venues
- in one-on-one communications that relate to community work
This code of conduct and its related procedures also applies to unacceptable
behavior occurring outside the scope of community activities when such behavior
has the potential to adversely affect the safety and well-being of community
members. As members of the OONI community, we support and follow this Code while
we are working on OONI, and take care not to undermine it in the rest of our
time.
10. License and attribution
This code of conduct is shared under a Creative Commons CC-BY-SA 4.0
International license.
This code of conduct is adapted from The Tor Project code of conduct and uses
some language and framing from the [Citizen Code of Conduct](https://citizencodeofconduct.org),
which is shared under a CC-BY-SA license.

View File

@ -1,139 +0,0 @@
# Replacing Measurement Kit
| Author | Simone Basso |
|--------------|--------------|
| Last-Updated | 2020-07-09 |
| Status | historical |
*Abstract* We describe our plan of replacing Measurement Kit for OONI
Probe Android and iOS (in particular) and (also) the CLI.
## Introduction
We want to write experiments in Go. This reduces our burden
compared to writing them using C/C++ code.
Go consumers of probe-engine shall directly use its Go API. We
will discuss the Go API in a future revision of this spec.
For mobile apps, we want to replace these MK APIs:
- [measurement-kit/android-libs](https://github.com/measurement-kit/android-libs)
- [measurement-kit/mkall-ios](https://github.com/measurement-kit/mkall-ios)
We also want consumers of [measurement-kit's FFI API](https://git.io/Jv4Rv)
to be able to replace measurement-kit with probe-engine.
## APIs to replace
### Mobile APIs
We define a Go API that `gomobile` binds to a Java/ObjectiveC
API that is close enough to the MK's mobile APIs.
### FFI API
We define a CGO API such that `go build -buildmode=c-shared`
yields an API reasonably close to MK's FFI API.
## Running experiments
It seems the generic API for enabling running experiments both on
mobile devices and for FFI consumers is like:
```Go
type Task struct{ ... }
func StartTask(input string) (*Task, error)
func (t *Task) Interrupt()
func (t *Task) IsDone() bool
func (t *Task) WaitForNextEvent() string
```
This should be enough to generate a suitable mobile API when
using the `gomobile` Go subcommand.
We can likewise generate a FFI API as follows:
```Go
package main
import (
"C"
"sync"
"github.com/ooni/probe-engine/oonimkall"
)
var (
idx int64 = 1
m = make(map[int64]*oonimkall.Task)
mu sync.Mutex
)
//export ooni_task_start
func ooni_task_start(settings string) int64 {
tp, err := oonimkall.StartTask(settings)
if err != nil {
return 0
}
mu.Lock()
handle := idx
idx++
m[handle] = tp
mu.Unlock()
return handle
}
//export ooni_task_interrupt
func ooni_task_interrupt(handle int64) {
mu.Lock()
if tp := m[handle]; tp != nil {
tp.Interrupt()
}
mu.Unlock()
}
//export ooni_task_is_done
func ooni_task_is_done(handle int64) bool {
isdone := true
mu.Lock()
if tp := m[handle]; tp != nil {
isdone = tp.IsDone()
}
mu.Unlock()
return isdone
}
//export ooni_task_wait_for_next_event
func ooni_task_wait_for_next_event(handle int64) (event string) {
mu.Lock()
tp := m[handle]
mu.Unlock()
if tp != nil {
event = tp.WaitForNextEvent()
}
return
}
func main() {}
```
This is close enough to [measurement-kit's FFI API](https://git.io/Jv4Rv) that
a few lines of C allow to implement an ABI compatible replacement.
## Other APIs of interest
We currently don't have plans for replacing other MK APIs. We will introduce
new APIs specifically tailored for our OONI needs, but they will be out of
scope with respect to the main goal of this design document.
## History
[The initial version of this design document](
https://github.com/measurement-kit/engine/blob/master/DESIGN.md)
lived in the measurement-kit namespace at GitHub. It discussed
a bunch of broad, extra topics, e.g., code bloat that are not
discussed in this document. More details regarding the migration
from MK to probe-engine are at [measurement-kit/measurement-kit#1913](
https://github.com/measurement-kit/measurement-kit/issues/1913).

View File

@ -1,26 +0,0 @@
Copyright 2019 Open Observatory of Network Interference (OONI), The Tor Project
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -1,23 +0,0 @@
#!/bin/bash
#
# This script simulates a user creating a new project that depends
# on github.com/ooni/probe-engine@GITHUB_SHA.
#
set -ex
mkdir -p /tmp/example.org/x
cd /tmp/example.org/x
go mod init example.org/x
cat > main.go << EOF
package main
import "github.com/ooni/probe-engine/libminiooni"
func main() {
libminiooni.Main()
}
EOF
go get -v github.com/ooni/probe-engine@$GITHUB_SHA
go build -v .
./x --yes -OTunnel=psiphon -ni https://www.example.com urlgetter

View File

@ -1,8 +0,0 @@
/asn.mmdb
/ca-bundle.pem
/country.mmdb
/ffirun
/ffirun.exe
/libooniffi.dll
/libooniffi.h
/libooniffi.so

View File

@ -1,16 +0,0 @@
# Directory github.com/ooni/probe-engine/libooniffi
This directory contains code to generate shared/static libraries with
a Measurement Kit compatible ABI. To this end, we wrap the [oonimkall](
../oonimkall) API with a simple C API.
The generated libraries have a Measurement Kit compatible ABI. You can
also instruct your compiler so that [ooniffi.h](ooniffi.h) defines macros
that make code written for Measurement Kit compile and work. To this
end, please see comments insider [ooniffi.h](ooniffi.h).
To see how we compile this library for several systems, please take a
look at [libooniffi.yml](../.github/workflows/libooniffi.yml).
This is not used in any OONI product. We may break something
in ooniffi without noticing it. Please, be aware of that.

View File

@ -1,26 +0,0 @@
#!/bin/bash
set -e
cd $(dirname $0)
case $1 in
darwin)
set -x
go build -ldflags '-s -w' -buildmode=c-shared -o libooniffi.so .
clang++ -std=c++11 -Wall -Wextra -I. -L. -o ffirun -looniffi ./testdata/ffirun.cpp
./ffirun testdata/webconnectivity.json
;;
linux)
set -x
go build -ldflags '-s -w' -buildmode=c-shared -o libooniffi.so .
g++ -std=c++11 -Wall -Wextra -I. -L. -o ffirun ./testdata/ffirun.cpp -looniffi
LD_LIBRARY_PATH=. ./ffirun testdata/webconnectivity.json
;;
windows)
set -x
go build -ldflags '-s -w' -buildmode=c-shared -o libooniffi.dll .
x86_64-w64-mingw32-g++ -std=c++11 -Wall -Wextra -I. -L. -o ffirun.exe -looniffi ./testdata/ffirun.cpp
./ffirun.exe testdata/webconnectivity.json
;;
*)
echo "usage: $0 darwin|linux|windows" 1>&2
exit 1
esac

View File

@ -1,17 +0,0 @@
#include "ooniffi.h"
#include "_cgo_export.h"
ooniffi_task_t *ooniffi_task_start(const char *settings) {
/* Implementation note: Go does not have the concept of const but
we know that the code is just making a copy of settings. */
return ooniffi_task_start_((char *)settings);
}
const char *ooniffi_event_serialization(ooniffi_event_t *event) {
/* Implementation note: Go does not have the concept of const but
we want to return const to very clearly communicate that the
returned string is owned by the event. This is what tools like
python's ctypes and SWIG expect from us. */
return (const char *)ooniffi_event_serialization_(event);
}

View File

@ -1,7 +0,0 @@
EXPORTS
ooniffi_task_start
ooniffi_task_is_done
ooniffi_task_wait_for_next_event
ooniffi_event_serialization
ooniffi_event_destroy
ooniffi_task_destroy

View File

@ -1,152 +0,0 @@
package main
import (
//#include "ooniffi.h"
//
//#include <stdint.h>
//#include <stdlib.h>
//
//struct ooniffi_task_ {
// int64_t Handle;
//};
//
// struct ooniffi_event_ {
// char *String;
//};
"C"
"sync"
"unsafe"
"github.com/ooni/probe-cli/v3/pkg/oonimkall"
)
var (
idx C.int64_t
m = make(map[C.int64_t]*oonimkall.Task)
mu sync.Mutex
)
func cstring(s string) *C.char {
return C.CString(s)
}
func freestring(s *C.char) {
C.free(unsafe.Pointer(s))
}
func gostring(s *C.char) string {
return C.GoString(s)
}
const maxIdx = C.INT64_MAX
//export ooniffi_task_start_
func ooniffi_task_start_(settings *C.char) *C.ooniffi_task_t {
if settings == nil {
return nil
}
tp, err := oonimkall.StartTask(gostring(settings))
if err != nil {
return nil
}
mu.Lock()
defer mu.Unlock()
// TODO(bassosimone): the following if is basic protection against
// undefined behaviour, i.e., the counter wrapping around. A much
// better strategy would probably be to restart from 0. However it's
// also unclear if any device could run that many tests, so...
if idx >= maxIdx {
return nil
}
handle := idx
idx++
m[handle] = tp
task := (*C.ooniffi_task_t)(C.malloc(C.sizeof_ooniffi_task_t))
task.Handle = handle
return task
}
func setmaxidx() C.int64_t {
o := idx
idx = maxIdx
return o
}
func restoreidx(v C.int64_t) {
idx = v
}
//export ooniffi_task_wait_for_next_event
func ooniffi_task_wait_for_next_event(task *C.ooniffi_task_t) (event *C.ooniffi_event_t) {
if task != nil {
mu.Lock()
tp := m[task.Handle]
mu.Unlock()
if tp != nil {
event = (*C.ooniffi_event_t)(C.malloc(C.sizeof_ooniffi_event_t))
event.String = cstring(tp.WaitForNextEvent())
}
}
return
}
//export ooniffi_task_is_done
func ooniffi_task_is_done(task *C.ooniffi_task_t) C.int {
var isdone C.int = 1
if task != nil {
mu.Lock()
if tp := m[task.Handle]; tp != nil && !tp.IsDone() {
isdone = 0
}
mu.Unlock()
}
return isdone
}
//export ooniffi_task_interrupt
func ooniffi_task_interrupt(task *C.ooniffi_task_t) {
if task != nil {
mu.Lock()
if tp := m[task.Handle]; tp != nil {
tp.Interrupt()
}
mu.Unlock()
}
}
//export ooniffi_event_serialization_
func ooniffi_event_serialization_(event *C.ooniffi_event_t) (s *C.char) {
if event != nil {
s = event.String
}
return
}
//export ooniffi_event_destroy
func ooniffi_event_destroy(event *C.ooniffi_event_t) {
if event != nil {
C.free(unsafe.Pointer(event.String))
C.free(unsafe.Pointer(event))
}
}
//export ooniffi_task_destroy
func ooniffi_task_destroy(task *C.ooniffi_task_t) {
if task != nil {
mu.Lock()
tp := m[task.Handle]
delete(m, task.Handle)
mu.Unlock()
C.free(unsafe.Pointer(task))
if tp != nil { // drain task if needed
tp.Interrupt()
go func() {
for !tp.IsDone() {
tp.WaitForNextEvent()
}
}()
}
}
}
func main() {}

View File

@ -1,51 +0,0 @@
#ifndef INCLUDE_OONIFFI_H_
#define INCLUDE_OONIFFI_H_
#include <stdint.h>
#include <stdlib.h>
/*
* ABI compatible with Measurement Kit v0.10.11 [1].
*
* Just replace `mk_` with `ooniffi_` and recompile.
*
* .. [1] https://github.com/measurement-kit/measurement-kit/tree/v0.10.11/
*
* This is not used in any OONI product. We may break something
* in ooniffi without noticing it. Please, be aware of that.
*/
typedef struct ooniffi_task_ ooniffi_task_t;
typedef struct ooniffi_event_ ooniffi_event_t;
#ifdef __cplusplus
extern "C" {
#endif
extern ooniffi_task_t *ooniffi_task_start(const char *settings);
extern ooniffi_event_t *ooniffi_task_wait_for_next_event(ooniffi_task_t *task);
extern int ooniffi_task_is_done(ooniffi_task_t *task);
extern void ooniffi_task_interrupt(ooniffi_task_t *task);
extern const char *ooniffi_event_serialization(ooniffi_event_t *str);
extern void ooniffi_event_destroy(ooniffi_event_t *str);
extern void ooniffi_task_destroy(ooniffi_task_t *task);
#ifdef __cplusplus
}
#endif
/*
* Define OONIFFI_EMULATE_MK_API to provide a MK-compatible API at
* compile time that will map to ooniffi's own API.
*/
#ifdef OONIFFI_EMULATE_MK_API
#define mk_task_start ooniffi_task_start
#define mk_task_wait_for_next_event ooniffi_task_wait_for_next_event
#define mk_task_is_done ooniffi_task_is_done
#define mk_task_interrupt ooniffi_task_interrupt
#define mk_event_serialization ooniffi_event_serialization
#define mk_event_destroy ooniffi_event_destroy
#define mk_task_destroy ooniffi_task_destroy
#endif
#endif /* INCLUDE_OONIFFI_H_ */

View File

@ -1,139 +0,0 @@
package main
import (
"testing"
)
func TestTaskStartNullPointer(t *testing.T) {
if ooniffi_task_start_(nil) != nil {
t.Fatal("expected nil result here")
}
}
func TestTaskStartInvalidJSON(t *testing.T) {
settings := cstring("{")
defer freestring(settings)
if ooniffi_task_start_(settings) != nil {
t.Fatal("expected nil result here")
}
}
func TestTaskStartIdxWrapping(t *testing.T) {
settings := cstring(`{
"assets_dir": "../testdata/oonimkall/assets",
"log_level": "DEBUG",
"name": "Example",
"options": {
"software_name": "oonimkall-test",
"software_version": "0.1.0"
},
"state_dir": "../testdata/oonimkall/state",
"temp_dir": "../testdata/oonimkall/tmp"
}`)
defer freestring(settings)
o := setmaxidx()
// do twice and see if it's idempotent
if task := ooniffi_task_start_(settings); task != nil {
t.Fatal("expected nil task here")
}
if task := ooniffi_task_start_(settings); task != nil {
t.Fatal("expected nil task here")
}
restoreidx(o)
}
func TestTaskWaitForNextEventNullPointer(t *testing.T) {
if ooniffi_task_wait_for_next_event(nil) != nil {
t.Fatal("expected nil result here")
}
}
func TestTaskIsDoneNullPointer(t *testing.T) {
if ooniffi_task_is_done(nil) == 0 {
t.Fatal("expected true-ish result here")
}
}
func TestTaskInterruptNullPointer(t *testing.T) {
ooniffi_task_interrupt(nil) // mainly: we don't crash :^)
}
func TestEventSerializationNullPointer(t *testing.T) {
if ooniffi_event_serialization_(nil) != nil {
t.Fatal("expected nil result here")
}
}
func TestEventDestroyNullPointer(t *testing.T) {
ooniffi_event_destroy(nil) // mainly: we don't crash
}
func TestTaskDestroyNullPointer(t *testing.T) {
ooniffi_task_destroy(nil) // mainly: we don't crash
}
func TestExampleNormalUsage(t *testing.T) {
settings := cstring(`{
"assets_dir": "../testdata/oonimkall/assets",
"log_level": "DEBUG",
"name": "Example",
"options": {
"software_name": "oonimkall-test",
"software_version": "0.1.0"
},
"state_dir": "../testdata/oonimkall/state",
"temp_dir": "../testdata/oonimkall/tmp"
}`)
defer freestring(settings)
task := ooniffi_task_start_(settings)
if task == nil {
t.Fatal("expected non-nil task here")
}
for ooniffi_task_is_done(task) == 0 {
event := ooniffi_task_wait_for_next_event(task)
t.Logf("%s", gostring(ooniffi_event_serialization_(event)))
ooniffi_event_destroy(event)
}
ooniffi_task_destroy(task)
}
func TestExampleInterruptAndDestroy(t *testing.T) {
settings := cstring(`{
"assets_dir": "../testdata/oonimkall/assets",
"log_level": "DEBUG",
"name": "Example",
"options": {
"software_name": "oonimkall-test",
"software_version": "0.1.0"
},
"state_dir": "../testdata/oonimkall/state",
"temp_dir": "../testdata/oonimkall/tmp"
}`)
defer freestring(settings)
task := ooniffi_task_start_(settings)
if task == nil {
t.Fatal("expected non-nil task here")
}
ooniffi_task_interrupt(task)
ooniffi_task_destroy(task)
}
func TestExampleDestroyImmediately(t *testing.T) {
settings := cstring(`{
"assets_dir": "../testdata/oonimkall/assets",
"log_level": "DEBUG",
"name": "Example",
"options": {
"software_name": "oonimkall-test",
"software_version": "0.1.0"
},
"state_dir": "../testdata/oonimkall/state",
"temp_dir": "../testdata/oonimkall/tmp"
}`)
defer freestring(settings)
task := ooniffi_task_start_(settings)
if task == nil {
t.Fatal("expected non-nil task here")
}
ooniffi_task_destroy(task)
}

View File

@ -1,43 +0,0 @@
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#define OONIFFI_EMULATE_MK_API
#include "ooniffi.h"
int main(int argc, char **argv) {
if (argc != 2) {
std::clog << "usage: ffirun /path/to/json/settings" << std::endl;
exit(1);
}
std::ifstream filep(argv[1]);
if (!filep.good()) {
std::clog << "fatal: cannot open settings file" << std::endl;
exit(1);
}
std::string settings((std::istreambuf_iterator<char>(filep)),
std::istreambuf_iterator<char>());
auto taskp = mk_task_start(settings.c_str());
if (taskp == nullptr) {
std::clog << "fatal: cannot start task" << std::endl;
exit(1);
}
while (!mk_task_is_done(taskp)) {
auto evp = mk_task_wait_for_next_event(taskp);
if (evp == nullptr) {
std::clog << "warning: cannot wait for next event" << std::endl;
break;
}
auto evstr = mk_event_serialization(evp);
if (evstr != nullptr) {
std::cout << evstr << std::endl;
} else {
std::clog << "warning: cannot get event serialization" << std::endl;
}
mk_event_destroy(evp);
}
mk_task_destroy(taskp);
}

View File

@ -1,17 +0,0 @@
{
"assets_dir": ".",
"inputs": [
"https://www.example.com",
"https://www.example.org"
],
"name": "WebConnectivity",
"log_level": "INFO",
"options": {
"no_collector": true,
"software_name": "ooniffi",
"software_version": "0.1.0-dev"
},
"state_dir": ".",
"temp_dir": ".",
"version": 1
}