refactor(oohelperd): make performing additional measurements easier (#889)

This diff refactors oohelperd to make performing additional measurements easier. We need:

1. to run the DNS task _before_ other tasks such that we can measure both IP addresses returned by the TH and the ones returned by the probe. When we'll introduce TLS measurements, this will allow us to validate probe-provided IP addresses inside the TH call. If probe-provided addresses work with TLS, they are legitimate for the domain.

2. to tie the number of TCP measurements to a list of endpoints collected by the probe _or_ the TH rather than just to the one provided by the probe. Anticipating this change, let us refactor how we read the results of the TCP task to make it independent of the number of addresses provided by the probe.

This work is part of https://github.com/ooni/probe/issues/2237
This commit is contained in:
Simone Basso 2022-08-28 12:17:31 +02:00 committed by GitHub
parent b8cc548d41
commit 867a243fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,22 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp
})
}
// wait for DNS measurements to complete
wg.Wait()
// start assembling the response
cresp := new(ctrlResponse)
select {
case cresp.DNS = <-dnsch:
default:
// we need to emit a non-nil Addrs to match exactly
// the behavior of the legacy TH
cresp.DNS = ctrlDNSResult{
Failure: nil,
Addrs: []string{},
}
}
// tcpconnect: start
tcpconnch := make(chan tcpResultPair, len(creq.TCPConnect))
for _, endpoint := range creq.TCPConnect {
@ -67,26 +83,20 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp
Wg: wg,
})
// wait for measurement steps to complete
// wait for endpoint measurements to complete
wg.Wait()
// assemble response
cresp := new(ctrlResponse)
select {
case cresp.DNS = <-dnsch:
default:
// we need to emit a non-nil Addrs to match exactly
// the behavior of the legacy TH
cresp.DNS = ctrlDNSResult{
Failure: nil,
Addrs: []string{},
}
}
// continue assembling the response
cresp.HTTPRequest = <-httpch
cresp.TCPConnect = make(map[string]ctrlTCPResult)
for len(cresp.TCPConnect) < len(creq.TCPConnect) {
tcpconn := <-tcpconnch
cresp.TCPConnect[tcpconn.Endpoint] = tcpconn.Result
Loop:
for {
select {
case tcpconn := <-tcpconnch:
cresp.TCPConnect[tcpconn.Endpoint] = tcpconn.Result
default:
break Loop
}
}
return cresp, nil