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

@ -71,7 +71,7 @@ func (qdx *quicDialerTrace) CloseIdleConnections() {
func (tx *Trace) OnQUICHandshakeStart(now time.Time, remoteAddr string, config *quic.Config) {
t := now.Sub(tx.ZeroTime)
select {
case tx.NetworkEvent <- NewAnnotationArchivalNetworkEvent(tx.Index, t, "quic_handshake_start"):
case tx.networkEvent <- NewAnnotationArchivalNetworkEvent(tx.Index, t, "quic_handshake_start"):
default:
}
}
@ -85,7 +85,7 @@ func (tx *Trace) OnQUICHandshakeDone(started time.Time, remoteAddr string, qconn
state = qconn.ConnectionState().TLS.ConnectionState
}
select {
case tx.QUICHandshake <- NewArchivalTLSOrQUICHandshakeResult(
case tx.quicHandshake <- NewArchivalTLSOrQUICHandshakeResult(
tx.Index,
started.Sub(tx.ZeroTime),
"quic",
@ -98,7 +98,7 @@ func (tx *Trace) OnQUICHandshakeDone(started time.Time, remoteAddr string, qconn
default: // buffer is full
}
select {
case tx.NetworkEvent <- NewAnnotationArchivalNetworkEvent(tx.Index, t, "quic_handshake_done"):
case tx.networkEvent <- NewAnnotationArchivalNetworkEvent(tx.Index, t, "quic_handshake_done"):
default: // buffer is full
}
}
@ -107,10 +107,20 @@ func (tx *Trace) OnQUICHandshakeDone(started time.Time, remoteAddr string, qconn
func (tx *Trace) QUICHandshakes() (out []*model.ArchivalTLSOrQUICHandshakeResult) {
for {
select {
case ev := <-tx.QUICHandshake:
case ev := <-tx.quicHandshake:
out = append(out, ev)
default:
return // done
}
}
}
// FirstQUICHandshakeOrNil drains the network events buffered inside the QUICHandshake channel
// and returns the first QUICHandshake, if any. Otherwise, it returns nil.
func (tx *Trace) FirstQUICHandshakeOrNil() *model.ArchivalTLSOrQUICHandshakeResult {
ev := tx.QUICHandshakes()
if len(ev) < 1 {
return nil
}
return ev[0]
}