refactor(measurexlite): make buffered channels private (#864)
Closes https://github.com/ooni/probe/issues/2215
This commit is contained in:
parent
342a74cad8
commit
e1d014e826
15 changed files with 326 additions and 51 deletions
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue