@@ -19,9 +19,7 @@ const (
1919 edgeH2TLSServerName = "h2.cftunnel.com"
2020 // edgeQUICServerName is the server name to establish quic connection with edge.
2121 edgeQUICServerName = "quic.cftunnel.com"
22- // threshold to switch back to h2mux when the user intentionally pick --protocol http2
23- explicitHTTP2FallbackThreshold = - 1
24- autoSelectFlag = "auto"
22+ autoSelectFlag = "auto"
2523)
2624
2725var (
@@ -237,25 +235,23 @@ func selectNamedTunnelProtocols(
237235 threshold int32 ,
238236 protocol Protocol ,
239237) (ProtocolSelector , error ) {
240- if protocolFlag == H2mux . String () {
241- return & staticProtocolSelector {
242- current : H2mux ,
243- }, nil
244- }
245-
246- if protocolFlag == QUIC .String () {
247- return newAutoProtocolSelector ( QUIC , [] Protocol { QUIC , HTTP2 , H2mux }, explicitHTTP2FallbackThreshold , fetchFunc , ttl , log ) , nil
238+ // If the user picks a protocol, then we stick to it no matter what.
239+ switch protocolFlag {
240+ case H2mux . String ():
241+ return & staticProtocolSelector { current : H2mux }, nil
242+ case QUIC . String ():
243+ return & staticProtocolSelector { current : QUIC }, nil
244+ case HTTP2 .String ():
245+ return & staticProtocolSelector { current : HTTP2 } , nil
248246 }
249247
250- if protocolFlag == HTTP2 .String () {
251- return newAutoProtocolSelector (HTTP2 , []Protocol {HTTP2 , H2mux }, explicitHTTP2FallbackThreshold , fetchFunc , ttl , log ), nil
248+ // If the user does not pick (hopefully the majority) then we use the one derived from the TXT DNS record and
249+ // fallback on failures.
250+ if protocolFlag == autoSelectFlag {
251+ return newAutoProtocolSelector (protocol , []Protocol {QUIC , HTTP2 , H2mux }, threshold , fetchFunc , ttl , log ), nil
252252 }
253253
254- if protocolFlag != autoSelectFlag {
255- return nil , fmt .Errorf ("Unknown protocol %s, %s" , protocolFlag , AvailableProtocolFlagMessage )
256- }
257-
258- return newAutoProtocolSelector (protocol , []Protocol {QUIC , HTTP2 , H2mux }, threshold , fetchFunc , ttl , log ), nil
254+ return nil , fmt .Errorf ("Unknown protocol %s, %s" , protocolFlag , AvailableProtocolFlagMessage )
259255}
260256
261257func selectWarpRoutingProtocols (
@@ -266,19 +262,21 @@ func selectWarpRoutingProtocols(
266262 threshold int32 ,
267263 protocol Protocol ,
268264) (ProtocolSelector , error ) {
269- if protocolFlag == QUIC . String () {
270- return newAutoProtocolSelector ( QUICWarp , [] Protocol { QUICWarp , HTTP2Warp }, explicitHTTP2FallbackThreshold , fetchFunc , ttl , log ), nil
271- }
272-
273- if protocolFlag == HTTP2 .String () {
274- return newAutoProtocolSelector ( HTTP2Warp , [] Protocol { HTTP2Warp }, explicitHTTP2FallbackThreshold , fetchFunc , ttl , log ) , nil
265+ // If the user picks a protocol, then we stick to it no matter what.
266+ switch protocolFlag {
267+ case QUIC . String ():
268+ return & staticProtocolSelector { current : QUICWarp }, nil
269+ case HTTP2 .String ():
270+ return & staticProtocolSelector { current : HTTP2Warp }, nil
275271 }
276272
277- if protocolFlag != autoSelectFlag {
278- return nil , fmt .Errorf ("Unknown protocol %s, %s" , protocolFlag , AvailableProtocolFlagMessage )
273+ // If the user does not pick (hopefully the majority) then we use the one derived from the TXT DNS record and
274+ // fallback on failures.
275+ if protocolFlag == autoSelectFlag {
276+ return newAutoProtocolSelector (protocol , []Protocol {QUICWarp , HTTP2Warp }, threshold , fetchFunc , ttl , log ), nil
279277 }
280278
281- return newAutoProtocolSelector ( protocol , [] Protocol { QUICWarp , HTTP2Warp }, threshold , fetchFunc , ttl , log ), nil
279+ return nil , fmt . Errorf ( "Unknown protocol %s, %s" , protocolFlag , AvailableProtocolFlagMessage )
282280}
283281
284282func switchThreshold (accountTag string ) int32 {
0 commit comments