Skip to content

Commit

Permalink
chore(webconnectivitylte): sync {cleartext,secure}flow.go (#1399)
Browse files Browse the repository at this point in the history
Extracted from #1392.

Part of ooni/probe#2634.
  • Loading branch information
bassosimone authored Nov 28, 2023
1 parent 0a49338 commit 0009dd8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/experiment/webconnectivitylte/cleartextflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ func (t *CleartextFlow) Run(parentCtx context.Context, index int64) error {
// create trace
trace := measurexlite.NewTrace(index, t.ZeroTime)

// TODO(bassosimone): the DSL starts measuring for throttling when we start
// fetching the body while here we start immediately. We should come up with
// a consistent policy otherwise data won't be comparable.

// start measuring throttling
sampler := throttling.NewSampler(trace)
defer func() {
Expand All @@ -119,7 +123,7 @@ func (t *CleartextFlow) Run(parentCtx context.Context, index int64) error {
tcpDialer := trace.NewDialerWithoutResolver(t.Logger)
tcpConn, err := tcpDialer.DialContext(tcpCtx, "tcp", t.Address)
t.TestKeys.AppendTCPConnectResults(trace.TCPConnects()...)
defer t.TestKeys.AppendNetworkEvents(trace.NetworkEvents()...) // here to include connect events
defer t.TestKeys.AppendNetworkEvents(trace.NetworkEvents()...) // here to include "connect" events
if err != nil {
ol.Stop(err)
return err
Expand Down Expand Up @@ -241,6 +245,12 @@ func (t *CleartextFlow) httpTransaction(ctx context.Context, network, address, a
txp model.HTTPTransport, req *http.Request, trace *measurexlite.Trace) (*http.Response, []byte, error) {
const maxbody = 1 << 19
started := trace.TimeSince(trace.ZeroTime())
// TODO(bassosimone): I am wondering whether we should have the HTTP transaction
// start at the beginning of the flow rather than here. If we start it at the
// beginning this is nicer, but, at the same time, starting it at the beginning
// of the flow means we're not collecting information about DNS. So, I am a
// bit torn about what is the best approach to follow here. Maybe it does not
// even matter to emit transaction_start/end events given that we have transaction ID.
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index(), started, "http_transaction_start",
))
Expand Down Expand Up @@ -287,6 +297,8 @@ func (t *CleartextFlow) maybeFollowRedirects(ctx context.Context, resp *http.Res
if err != nil {
return // broken response from server
}
// TODO(https://github.com/ooni/probe/issues/2628): we need to handle
// the case where the redirect URL is incomplete
t.Logger.Infof("redirect to: %s", location.String())
resolvers := &DNSResolvers{
CookieJar: t.CookieJar,
Expand Down
12 changes: 12 additions & 0 deletions internal/experiment/webconnectivitylte/secureflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ func (t *SecureFlow) Run(parentCtx context.Context, index int64) error {
// create trace
trace := measurexlite.NewTrace(index, t.ZeroTime)

// TODO(bassosimone): the DSL starts measuring for throttling when we start
// fetching the body while here we start immediately. We should come up with
// a consistent policy otherwise data won't be comparable.

// start measuring throttling
sampler := throttling.NewSampler(trace)
defer func() {
Expand Down Expand Up @@ -296,6 +300,12 @@ func (t *SecureFlow) httpTransaction(ctx context.Context, network, address, alpn
txp model.HTTPTransport, req *http.Request, trace *measurexlite.Trace) (*http.Response, []byte, error) {
const maxbody = 1 << 19
started := trace.TimeSince(trace.ZeroTime())
// TODO(bassosimone): I am wondering whether we should have the HTTP transaction
// start at the beginning of the flow rather than here. If we start it at the
// beginning this is nicer, but, at the same time, starting it at the beginning
// of the flow means we're not collecting information about DNS. So, I am a
// bit torn about what is the best approach to follow here. Maybe it does not
// even matter to emit transaction_start/end events given that we have transaction ID.
t.TestKeys.AppendNetworkEvents(measurexlite.NewAnnotationArchivalNetworkEvent(
trace.Index(), started, "http_transaction_start",
))
Expand Down Expand Up @@ -342,6 +352,8 @@ func (t *SecureFlow) maybeFollowRedirects(ctx context.Context, resp *http.Respon
if err != nil {
return // broken response from server
}
// TODO(https://github.com/ooni/probe/issues/2628): we need to handle
// the case where the redirect URL is incomplete
t.Logger.Infof("redirect to: %s", location.String())
resolvers := &DNSResolvers{
CookieJar: t.CookieJar,
Expand Down

0 comments on commit 0009dd8

Please sign in to comment.