refactor(simplequicping): use step-by-step (#852)

See https://github.com/ooni/probe/issues/2159 and https://github.com/ooni/spec/pull/254
This commit is contained in:
DecFox 2022-08-17 12:49:11 +05:30 committed by GitHub
commit 69602abe8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 922 additions and 26 deletions

View file

@ -58,6 +58,10 @@ type Trace struct {
// calls to the netxlite.NewTLSHandshakerStdlib factory.
NewTLSHandshakerStdlibFn func(dl model.DebugLogger) model.TLSHandshaker
// NewDialerWithoutResolverFn is OPTIONAL and can be used to override
// calls to the netxlite.NewQUICDialerWithoutResolver factory.
NewQUICDialerWithoutResolverFn func(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer
// DNSLookup is MANDATORY and buffers DNS Lookup observations. If you create
// this channel manually, ensure it has some buffer.
DNSLookup chan *model.ArchivalDNSLookupResult
@ -70,6 +74,10 @@ type Trace struct {
// this channel manually, ensure it has some buffer.
TLSHandshake chan *model.ArchivalTLSOrQUICHandshakeResult
// QUICHandshake is MANDATORY and buffers QUIC handshake observations. If you create
// this channel manually, ensure it has some buffer.
QUICHandshake chan *model.ArchivalTLSOrQUICHandshakeResult
// TimeNowFn is OPTIONAL and can be used to override calls to time.Now
// to produce deterministic timing when testing.
TimeNowFn func() time.Time
@ -94,6 +102,10 @@ const (
// TLSHandshakeBufferSize is the buffer for construcing
// the Trace's TLSHandshake buffered channel.
TLSHandshakeBufferSize = 8
// QUICHandshakeBufferSize is the buffer for constructing
// the Trace's QUICHandshake buffered channel.
QUICHandshakeBufferSize = 8
)
// NewTrace creates a new instance of Trace using default settings.
@ -128,6 +140,10 @@ func NewTrace(index int64, zeroTime time.Time) *Trace {
chan *model.ArchivalTLSOrQUICHandshakeResult,
TLSHandshakeBufferSize,
),
QUICHandshake: make(
chan *model.ArchivalTLSOrQUICHandshakeResult,
QUICHandshakeBufferSize,
),
TimeNowFn: nil, // use default
ZeroTime: zeroTime,
}
@ -178,6 +194,15 @@ func (tx *Trace) newTLSHandshakerStdlib(dl model.DebugLogger) model.TLSHandshake
return netxlite.NewTLSHandshakerStdlib(dl)
}
// newWUICDialerWithoutResolver indirectly calls netxlite.NewQUICDialerWithoutResolver
// thus allowing us to mock this func for testing.
func (tx *Trace) newQUICDialerWithoutResolver(listener model.QUICListener, dl model.DebugLogger) model.QUICDialer {
if tx.NewQUICDialerWithoutResolverFn != nil {
return tx.NewQUICDialerWithoutResolverFn(listener, dl)
}
return netxlite.NewQUICDialerWithoutResolver(listener, dl)
}
// TimeNow implements model.Trace.TimeNow.
func (tx *Trace) TimeNow() time.Time {
if tx.TimeNowFn != nil {