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

Commit

Permalink
Expose the scoreboard (#107)
Browse files Browse the repository at this point in the history
Functional to enable follow-up measurements.

Xref: ooni/probe-engine#87
  • Loading branch information
bassosimone authored Oct 31, 2019
1 parent c29f7ee commit 5197c35
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
42 changes: 33 additions & 9 deletions x/porcelain/porcelain.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/ooni/netx/httpx"
"github.com/ooni/netx/internal/errwrapper"
"github.com/ooni/netx/model"
"github.com/ooni/netx/x/scoreboard"
)

type channelHandler struct {
Expand All @@ -44,6 +45,7 @@ type Results struct {
Connects []*model.ConnectEvent
HTTPRequests []*model.HTTPRoundTripDoneEvent
Queries []*model.ResolveDoneEvent
Scoreboard *scoreboard.Board
TLSHandshakes []*model.TLSHandshakeDoneEvent
}

Expand Down Expand Up @@ -107,9 +109,18 @@ func DNSLookup(
) (*DNSLookupResults, error) {
channel := make(chan model.Measurement)
// TODO(bassosimone): tell DoH to use specific CA bundle?
resolver, err := netx.NewResolver(&channelHandler{
ch: channel,
}, config.ServerNetwork, config.ServerAddress)
root := &model.MeasurementRoot{
Beginning: time.Now(),
Handler: &channelHandler{
ch: channel,
},
}
ctx = model.WithMeasurementRoot(ctx, root)
resolver, err := netx.NewResolver(
handlers.NoHandler,
config.ServerNetwork,
config.ServerAddress,
)
if err != nil {
return nil, err
}
Expand All @@ -123,6 +134,7 @@ func DNSLookup(
defer mu.Unlock()
results.Addresses, results.Error = addrs, err
})
results.TestKeys.Scoreboard = &root.X.Scoreboard
// TODO(bassosimone): tell DoH to close idle connections?
return results, nil
}
Expand Down Expand Up @@ -153,9 +165,14 @@ func HTTPDo(
) (*HTTPDoResults, error) {
channel := make(chan model.Measurement)
// TODO(bassosimone): tell client to use specific CA bundle?
client := httpx.NewClient(&channelHandler{
ch: channel,
})
root := &model.MeasurementRoot{
Beginning: time.Now(),
Handler: &channelHandler{
ch: channel,
},
}
ctx = model.WithMeasurementRoot(ctx, root)
client := httpx.NewClient(handlers.NoHandler)
err := client.ConfigureDNS(
config.DNSServerNetwork, config.DNSServerAddress,
)
Expand Down Expand Up @@ -196,6 +213,7 @@ func HTTPDo(
results.Error = errwrapper.SafeErrWrapperBuilder{
Error: results.Error,
}.MaybeBuild()
results.TestKeys.Scoreboard = &root.X.Scoreboard
return results, nil
}

Expand All @@ -219,9 +237,14 @@ func TLSConnect(
ctx context.Context, config TLSConnectConfig,
) (*TLSConnectResults, error) {
channel := make(chan model.Measurement)
dialer := netx.NewDialer(&channelHandler{
ch: channel,
})
root := &model.MeasurementRoot{
Beginning: time.Now(),
Handler: &channelHandler{
ch: channel,
},
}
ctx = model.WithMeasurementRoot(ctx, root)
dialer := netx.NewDialer(handlers.NoHandler)
// TODO(bassosimone): tell dialer to use specific CA bundle?
err := dialer.ConfigureDNS(
config.DNSServerNetwork, config.DNSServerAddress,
Expand All @@ -244,5 +267,6 @@ func TLSConnect(
defer mu.Unlock()
results.Error = err
})
results.TestKeys.Scoreboard = &root.X.Scoreboard
return results, nil
}
9 changes: 9 additions & 0 deletions x/porcelain/porcelain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func TestIntegrationDNSLookupGood(t *testing.T) {
if len(results.Addresses) < 1 {
t.Fatal("no addresses returned?!")
}
if results.TestKeys.Scoreboard == nil {
t.Fatal("no scoreboard?!")
}
}

func TestIntegrationDNSLookupCancellation(t *testing.T) {
Expand Down Expand Up @@ -98,6 +101,9 @@ func TestIntegrationHTTPDoGood(t *testing.T) {
if len(results.Body) < 1 {
t.Fatal("no body?!")
}
if results.TestKeys.Scoreboard == nil {
t.Fatal("no scoreboard?!")
}
}

func TestIntegrationHTTPDoCancellation(t *testing.T) {
Expand Down Expand Up @@ -170,6 +176,9 @@ func TestIntegrationTLSConnectGood(t *testing.T) {
if results.Error != nil {
t.Fatal(results.Error)
}
if results.TestKeys.Scoreboard == nil {
t.Fatal("no scoreboard?!")
}
}

func TestIntegrationTLSConnectCancellation(t *testing.T) {
Expand Down

0 comments on commit 5197c35

Please sign in to comment.