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

@ -54,7 +54,7 @@ func (tx *Trace) OnConnectDone(
switch network {
case "tcp", "tcp4", "tcp6":
select {
case tx.TCPConnect <- NewArchivalTCPConnectResult(
case tx.tcpConnect <- NewArchivalTCPConnectResult(
tx.Index,
started.Sub(tx.ZeroTime),
remoteAddr,
@ -112,10 +112,20 @@ func archivalPortToString(sport string) int {
func (tx *Trace) TCPConnects() (out []*model.ArchivalTCPConnectResult) {
for {
select {
case ev := <-tx.TCPConnect:
case ev := <-tx.tcpConnect:
out = append(out, ev)
default:
return // done
}
}
}
// FirstTCPConnectOrNil drains the network events buffered inside the TCPConnect channel
// and returns the first TCPConnect, if any. Otherwise, it returns nil.
func (tx *Trace) FirstTCPConnectOrNil() *model.ArchivalTCPConnectResult {
ev := tx.TCPConnects()
if len(ev) < 1 {
return nil
}
return ev[0]
}