2018-02-13 10:48:46 +01:00
|
|
|
package groups
|
|
|
|
|
|
|
|
import (
|
2018-03-20 14:19:19 +01:00
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
2018-05-03 14:59:55 +02:00
|
|
|
"github.com/ooni/probe-cli/internal/database"
|
|
|
|
"github.com/ooni/probe-cli/nettests"
|
|
|
|
"github.com/ooni/probe-cli/nettests/im"
|
|
|
|
"github.com/ooni/probe-cli/nettests/middlebox"
|
|
|
|
"github.com/ooni/probe-cli/nettests/performance"
|
|
|
|
"github.com/ooni/probe-cli/nettests/websites"
|
2018-02-13 10:48:46 +01:00
|
|
|
)
|
|
|
|
|
2018-03-20 12:38:33 +01:00
|
|
|
// NettestGroup base structure
|
|
|
|
type NettestGroup struct {
|
|
|
|
Label string
|
|
|
|
Nettests []nettests.Nettest
|
2018-03-20 14:19:19 +01:00
|
|
|
Summary database.ResultSummaryFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// PerformanceSummary is the result summary for a performance test
|
|
|
|
type PerformanceSummary struct {
|
|
|
|
Upload int64
|
|
|
|
Download int64
|
|
|
|
Ping float64
|
|
|
|
Bitrate int64
|
2018-03-20 12:38:33 +01:00
|
|
|
}
|
|
|
|
|
2018-03-21 12:18:45 +01:00
|
|
|
// MiddleboxSummary is the summary for the middlebox tests
|
|
|
|
type MiddleboxSummary struct {
|
|
|
|
Detected bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// IMSummary is the summary for the im tests
|
|
|
|
type IMSummary struct {
|
2018-03-23 15:22:58 +01:00
|
|
|
Tested uint
|
|
|
|
Blocked uint
|
2018-03-21 12:18:45 +01:00
|
|
|
}
|
|
|
|
|
2018-03-23 13:17:39 +01:00
|
|
|
// WebsitesSummary is the summary for the websites test
|
|
|
|
type WebsitesSummary struct {
|
|
|
|
Tested uint
|
|
|
|
Blocked uint
|
|
|
|
}
|
|
|
|
|
2018-02-13 10:48:46 +01:00
|
|
|
// NettestGroups that can be run by the user
|
2018-03-20 12:38:33 +01:00
|
|
|
var NettestGroups = map[string]NettestGroup{
|
|
|
|
"websites": NettestGroup{
|
2018-02-13 10:48:46 +01:00
|
|
|
Label: "Websites",
|
|
|
|
Nettests: []nettests.Nettest{
|
|
|
|
websites.WebConnectivity{},
|
|
|
|
},
|
2018-03-20 14:19:19 +01:00
|
|
|
Summary: func(m database.SummaryMap) (string, error) {
|
2018-03-23 13:17:39 +01:00
|
|
|
// XXX to generate this I need to create the summary map as a list
|
2018-03-23 14:58:33 +01:00
|
|
|
var summary WebsitesSummary
|
|
|
|
summary.Tested = 0
|
|
|
|
summary.Blocked = 0
|
|
|
|
for _, msmtSummaryStr := range m["WebConnectivity"] {
|
|
|
|
var wcSummary websites.WebConnectivitySummary
|
|
|
|
|
|
|
|
err := json.Unmarshal([]byte(msmtSummaryStr), &wcSummary)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal WebConnectivity summary")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if wcSummary.Blocked {
|
|
|
|
summary.Blocked++
|
|
|
|
}
|
|
|
|
summary.Tested++
|
|
|
|
}
|
|
|
|
summaryBytes, err := json.Marshal(summary)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(summaryBytes), nil
|
2018-03-20 12:38:33 +01:00
|
|
|
},
|
2018-02-13 10:48:46 +01:00
|
|
|
},
|
2018-03-20 12:38:33 +01:00
|
|
|
"performance": NettestGroup{
|
2018-02-13 16:16:23 +01:00
|
|
|
Label: "Performance",
|
|
|
|
Nettests: []nettests.Nettest{
|
2018-03-14 14:44:37 +01:00
|
|
|
performance.Dash{},
|
2018-02-13 16:16:23 +01:00
|
|
|
performance.NDT{},
|
|
|
|
},
|
2018-03-20 14:19:19 +01:00
|
|
|
Summary: func(m database.SummaryMap) (string, error) {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
ndtSummary performance.NDTSummary
|
|
|
|
dashSummary performance.DashSummary
|
|
|
|
summary PerformanceSummary
|
|
|
|
)
|
2018-03-23 14:58:33 +01:00
|
|
|
err = json.Unmarshal([]byte(m["Dash"][0]), &dashSummary)
|
2018-03-20 14:19:19 +01:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal Dash summary")
|
|
|
|
return "", err
|
|
|
|
}
|
2018-03-23 14:58:33 +01:00
|
|
|
err = json.Unmarshal([]byte(m["Ndt"][0]), &ndtSummary)
|
2018-03-20 14:19:19 +01:00
|
|
|
if err != nil {
|
2018-03-20 14:31:05 +01:00
|
|
|
log.WithError(err).Error("failed to unmarshal NDT summary")
|
2018-03-20 14:19:19 +01:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
summary.Bitrate = dashSummary.Bitrate
|
|
|
|
summary.Download = ndtSummary.Download
|
|
|
|
summary.Upload = ndtSummary.Upload
|
|
|
|
summary.Ping = ndtSummary.AvgRTT
|
|
|
|
summaryBytes, err := json.Marshal(summary)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(summaryBytes), nil
|
2018-03-20 12:38:33 +01:00
|
|
|
},
|
2018-02-13 10:48:46 +01:00
|
|
|
},
|
2018-03-22 15:22:29 +01:00
|
|
|
"middlebox": NettestGroup{
|
2018-03-21 12:18:45 +01:00
|
|
|
Label: "Middleboxes",
|
|
|
|
Nettests: []nettests.Nettest{
|
|
|
|
middlebox.HTTPInvalidRequestLine{},
|
|
|
|
middlebox.HTTPHeaderFieldManipulation{},
|
|
|
|
},
|
2018-03-20 14:19:19 +01:00
|
|
|
Summary: func(m database.SummaryMap) (string, error) {
|
2018-03-21 12:18:45 +01:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
hhfmSummary middlebox.HTTPHeaderFieldManipulationSummary
|
|
|
|
hirlSummary middlebox.HTTPInvalidRequestLineSummary
|
|
|
|
summary MiddleboxSummary
|
|
|
|
)
|
2018-03-23 14:58:33 +01:00
|
|
|
err = json.Unmarshal([]byte(m["HttpHeaderFieldManipulation"][0]), &hhfmSummary)
|
2018-03-21 12:18:45 +01:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal hhfm summary")
|
|
|
|
return "", err
|
|
|
|
}
|
2018-03-23 14:58:33 +01:00
|
|
|
err = json.Unmarshal([]byte(m["HttpInvalidRequestLine"][0]), &hirlSummary)
|
2018-03-21 12:18:45 +01:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal hirl summary")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
summary.Detected = hirlSummary.Tampering == true || hhfmSummary.Tampering == true
|
|
|
|
summaryBytes, err := json.Marshal(summary)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(summaryBytes), nil
|
2018-03-20 12:38:33 +01:00
|
|
|
},
|
2018-02-13 10:48:46 +01:00
|
|
|
},
|
2018-03-20 12:38:33 +01:00
|
|
|
"im": NettestGroup{
|
2018-03-21 12:18:45 +01:00
|
|
|
Label: "Instant Messaging",
|
|
|
|
Nettests: []nettests.Nettest{
|
|
|
|
im.FacebookMessenger{},
|
|
|
|
im.Telegram{},
|
|
|
|
im.WhatsApp{},
|
|
|
|
},
|
2018-03-20 14:19:19 +01:00
|
|
|
Summary: func(m database.SummaryMap) (string, error) {
|
2018-03-23 15:22:58 +01:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
waSummary im.WhatsAppSummary
|
|
|
|
tgSummary im.TelegramSummary
|
|
|
|
fbSummary im.FacebookMessengerSummary
|
|
|
|
summary IMSummary
|
|
|
|
)
|
|
|
|
err = json.Unmarshal([]byte(m["Whatsapp"][0]), &waSummary)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal whatsapp summary")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
err = json.Unmarshal([]byte(m["Telegram"][0]), &tgSummary)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal telegram summary")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
err = json.Unmarshal([]byte(m["FacebookMessenger"][0]), &fbSummary)
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Error("failed to unmarshal facebook summary")
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
// XXX it could actually be that some are not tested when the
|
|
|
|
// configuration is changed.
|
|
|
|
summary.Tested = 3
|
|
|
|
summary.Blocked = 0
|
|
|
|
if fbSummary.Blocked == true {
|
|
|
|
summary.Blocked++
|
|
|
|
}
|
|
|
|
if tgSummary.Blocked == true {
|
|
|
|
summary.Blocked++
|
|
|
|
}
|
|
|
|
if waSummary.Blocked == true {
|
|
|
|
summary.Blocked++
|
|
|
|
}
|
|
|
|
|
|
|
|
summaryBytes, err := json.Marshal(summary)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(summaryBytes), nil
|
2018-03-20 12:38:33 +01:00
|
|
|
},
|
2018-02-13 10:48:46 +01:00
|
|
|
},
|
|
|
|
}
|