refactor(measurexlite): make buffered channels private (#864)

Closes https://github.com/ooni/probe/issues/2215
This commit is contained in:
DecFox 2022-08-17 23:40:48 +05:30 committed by GitHub
commit e1d014e826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 326 additions and 51 deletions

View file

@ -83,7 +83,7 @@ func (tx *Trace) OnDNSRoundTripForLookupHost(started time.Time, reso model.Resol
response model.DNSResponse, addrs []string, err error, finished time.Time) {
t := finished.Sub(tx.ZeroTime)
select {
case tx.DNSLookup <- NewArchivalDNSLookupResultFromRoundTrip(
case tx.dnsLookup <- NewArchivalDNSLookupResultFromRoundTrip(
tx.Index,
started.Sub(tx.ZeroTime),
reso,
@ -150,10 +150,20 @@ func archivalAnswersFromAddrs(addrs []string) (out []model.ArchivalDNSAnswer) {
func (tx *Trace) DNSLookupsFromRoundTrip() (out []*model.ArchivalDNSLookupResult) {
for {
select {
case ev := <-tx.DNSLookup:
case ev := <-tx.dnsLookup:
out = append(out, ev)
default:
return
}
}
}
// FirstDNSLookupOrNil drains the network events buffered inside the DNSLookup channel
// and returns the first DNSLookup, if any. Otherwise, it returns nil.
func (tx *Trace) FirstDNSLookup() *model.ArchivalDNSLookupResult {
ev := tx.DNSLookupsFromRoundTrip()
if len(ev) < 1 {
return nil
}
return ev[0]
}