Skip to content

Commit

Permalink
feat(enginenetx): add support for filtering tactics
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Apr 15, 2024
1 parent aee17cf commit 7576fc7
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/enginenetx/httpsdialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (hd *httpsDialer) DialTLSContext(ctx context.Context, network string, endpo

// The emitter will emit tactics and then close the channel when done. We spawn 16 workers
// that handle tactics in parallel and post results on the collector channel.
emitter := hd.policy.LookupTactics(ctx, hostname, port)
emitter := httpsFilterTactics(hd.policy.LookupTactics(ctx, hostname, port))
collector := make(chan *httpsDialerErrorOrConn)
joiner := make(chan any)
const parallelism = 16
Expand Down Expand Up @@ -245,6 +245,31 @@ func (hd *httpsDialer) DialTLSContext(ctx context.Context, network string, endpo
return httpsDialerReduceResult(connv, errorv)
}

// httpsFilterTactics filters the tactics and rewrites their InitialDelay.
func httpsFilterTactics(input <-chan *httpsDialerTactic) <-chan *httpsDialerTactic {
output := make(chan *httpsDialerTactic)
go func() {

// make sure we close output chan
defer close(output)

index := 0
for tx := range input {
// rewrite the delays
tx.InitialDelay = happyEyeballsDelay(index)
index++

// TODO(bassosimone): here we should also avoid connecting
// to TCP endpoints that are unreachable

// emit the tactic
output <- tx
}

}()
return output
}

// httpsDialerReduceResult returns either an established conn or an error, using [errDNSNoAnswer] in
// case the list of connections and the list of errors are empty.
func httpsDialerReduceResult(connv []model.TLSConn, errorv []error) (model.TLSConn, error) {
Expand Down

0 comments on commit 7576fc7

Please sign in to comment.