mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 19:29:57 +00:00
TUN-6617: Dont fallback to http2 if QUIC conn was successful.
cloudflared falls back aggressively to HTTP/2 protocol if a connection attempt with QUIC failed. This was done to ensure that machines with UDP egress disabled did not stop clients from connecting to the cloudlfare edge. This PR improves on that experience by having cloudflared remember if a QUIC connection was successful which implies UDP egress works. In this case, cloudflared does not fallback to HTTP/2 and keeps trying to connect to the edge with QUIC.
This commit is contained in:
@@ -10,20 +10,26 @@ import (
|
||||
|
||||
type ConnTracker struct {
|
||||
sync.RWMutex
|
||||
isConnected map[int]bool
|
||||
log *zerolog.Logger
|
||||
// int is the connection Index
|
||||
connectionInfo map[uint8]ConnectionInfo
|
||||
log *zerolog.Logger
|
||||
}
|
||||
|
||||
type ConnectionInfo struct {
|
||||
IsConnected bool
|
||||
Protocol connection.Protocol
|
||||
}
|
||||
|
||||
func NewConnTracker(log *zerolog.Logger) *ConnTracker {
|
||||
return &ConnTracker{
|
||||
isConnected: make(map[int]bool, 0),
|
||||
log: log,
|
||||
connectionInfo: make(map[uint8]ConnectionInfo, 0),
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
func MockedConnTracker(mocked map[int]bool) *ConnTracker {
|
||||
func MockedConnTracker(mocked map[uint8]ConnectionInfo) *ConnTracker {
|
||||
return &ConnTracker{
|
||||
isConnected: mocked,
|
||||
connectionInfo: mocked,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +37,17 @@ func (ct *ConnTracker) OnTunnelEvent(c connection.Event) {
|
||||
switch c.EventType {
|
||||
case connection.Connected:
|
||||
ct.Lock()
|
||||
ct.isConnected[int(c.Index)] = true
|
||||
ci := ConnectionInfo{
|
||||
IsConnected: true,
|
||||
Protocol: c.Protocol,
|
||||
}
|
||||
ct.connectionInfo[c.Index] = ci
|
||||
ct.Unlock()
|
||||
case connection.Disconnected, connection.Reconnecting, connection.RegisteringTunnel, connection.Unregistering:
|
||||
ct.Lock()
|
||||
ct.isConnected[int(c.Index)] = false
|
||||
ci := ct.connectionInfo[c.Index]
|
||||
ci.IsConnected = false
|
||||
ct.connectionInfo[c.Index] = ci
|
||||
ct.Unlock()
|
||||
default:
|
||||
ct.log.Error().Msgf("Unknown connection event case %v", c)
|
||||
@@ -46,10 +58,23 @@ func (ct *ConnTracker) CountActiveConns() uint {
|
||||
ct.RLock()
|
||||
defer ct.RUnlock()
|
||||
active := uint(0)
|
||||
for _, connected := range ct.isConnected {
|
||||
if connected {
|
||||
for _, ci := range ct.connectionInfo {
|
||||
if ci.IsConnected {
|
||||
active++
|
||||
}
|
||||
}
|
||||
return active
|
||||
}
|
||||
|
||||
// HasConnectedWith checks if we've ever had a successful connection to the edge
|
||||
// with said protocol.
|
||||
func (ct *ConnTracker) HasConnectedWith(protocol connection.Protocol) bool {
|
||||
ct.RLock()
|
||||
defer ct.RUnlock()
|
||||
for _, ci := range ct.connectionInfo {
|
||||
if ci.Protocol == protocol {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Reference in New Issue
Block a user