Skip to content

Commit

Permalink
feat: start to prepare for filtering endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
bassosimone committed Apr 16, 2024
1 parent 5618b72 commit 2153e36
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
6 changes: 6 additions & 0 deletions internal/enginenetx/statsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,9 @@ func (mt *statsManager) LookupTactics(domain string, port string) ([]*statsTacti
}
return out, len(out) > 0
}

// IsTCPEndpointAccessible returns whether a given TCP endpoint has recently been accessible.
func (mt *statsManager) IsTCPEndpointAccessible(address, port string) bool {
// TODO(bassosimone): implement
return true
}
47 changes: 32 additions & 15 deletions internal/enginenetx/statspolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ func (p *statsPolicy) LookupTactics(ctx context.Context, domain string, port str
maybeEmitTactic := func(t *httpsDialerTactic) {
// as a safety mechanism let's gracefully handle the
// case in which the tactic is nil
if t == nil {
return
if t != nil {
// handle the case in which we already emitted a policy
key := t.tacticSummaryKey()
if uniq[key] > 0 {
return
}
uniq[key]++

// 🚀!!!
t.InitialDelay = happyEyeballsDelay(index)
index += 1
out <- t
}

// handle the case in which we already emitted a policy
key := t.tacticSummaryKey()
if uniq[key] > 0 {
return
}
uniq[key]++

// 🚀!!!
t.InitialDelay = happyEyeballsDelay(index)
index += 1
out <- t
}

// TODO(bassosimone): as an optimization, here we could mix cached tactics
Expand All @@ -70,7 +68,7 @@ func (p *statsPolicy) LookupTactics(ctx context.Context, domain string, port str
}

// fallback to the secondary policy
for t := range p.Fallback.LookupTactics(ctx, domain, port) {
for t := range p.onlyAccessibleEndpoints(p.Fallback.LookupTactics(ctx, domain, port)) {
maybeEmitTactic(t)
}
}()
Expand Down Expand Up @@ -99,3 +97,22 @@ func statsPolicyFilterStatsTactics(tactics []*statsTactic, good bool) (out []*ht
}
return
}

// onlyAccessibleEndpoints uses stats-based knowledge to exclude using endpoints that
// have recently been observed as being failing during TCP connect.
func (p *statsPolicy) onlyAccessibleEndpoints(input <-chan *httpsDialerTactic) <-chan *httpsDialerTactic {
output := make(chan *httpsDialerTactic)
go func() {
// make sure we close the output channel
defer close(output)

// avoid including tactics using endpoints that are consistently failing
for tx := range input {
if tx == nil || !p.Stats.IsTCPEndpointAccessible(tx.Address, tx.Port) {
continue
}
output <- tx
}
}()
return output
}

0 comments on commit 2153e36

Please sign in to comment.