mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-28 15:09:59 +00:00
TUN-3456: New protocol option auto to automatically select between http2 and h2mux
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/ui"
|
||||
"github.com/cloudflare/cloudflared/connection"
|
||||
"github.com/cloudflare/cloudflared/edgediscovery"
|
||||
"github.com/cloudflare/cloudflared/h2mux"
|
||||
"github.com/cloudflare/cloudflared/ingress"
|
||||
"github.com/cloudflare/cloudflared/logger"
|
||||
@@ -231,7 +232,11 @@ func prepareTunnelConfig(
|
||||
}
|
||||
}
|
||||
|
||||
protocol := determineProtocol(namedTunnel)
|
||||
protocol, err := determineProtocol(c, namedTunnel)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger.Infof("Using protocol %s", protocol)
|
||||
toEdgeTLSConfig, err := tlsconfig.CreateTunnelConfig(c, protocol.ServerName())
|
||||
if err != nil {
|
||||
logger.Errorf("unable to create TLS config to connect with edge: %s", err)
|
||||
@@ -293,9 +298,17 @@ func isRunningFromTerminal() bool {
|
||||
return terminal.IsTerminal(int(os.Stdout.Fd()))
|
||||
}
|
||||
|
||||
func determineProtocol(namedTunnel *connection.NamedTunnelConfig) connection.Protocol {
|
||||
if namedTunnel != nil {
|
||||
return namedTunnel.Protocol
|
||||
func determineProtocol(c *cli.Context, namedTunnel *connection.NamedTunnelConfig) (connection.Protocol, error) {
|
||||
if namedTunnel == nil {
|
||||
return connection.H2mux, nil
|
||||
}
|
||||
return connection.H2mux
|
||||
http2Percentage, err := edgediscovery.HTTP2Percentage()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
protocol, ok := connection.SelectProtocol(c.String("protocol"), namedTunnel.Auth.AccountTag, http2Percentage)
|
||||
if !ok {
|
||||
return 0, fmt.Errorf("%s is not valid protocol. %s", c.String("protocol"), availableProtocol)
|
||||
}
|
||||
return protocol, nil
|
||||
}
|
||||
|
@@ -260,16 +260,12 @@ func (sc *subcommandContext) run(tunnelID uuid.UUID) error {
|
||||
return err
|
||||
}
|
||||
|
||||
protocol, ok := connection.ParseProtocol(sc.c.String("protocol"))
|
||||
if !ok {
|
||||
return fmt.Errorf("%s is not valid protocol. %s", sc.c.String("protocol"), availableProtocol)
|
||||
}
|
||||
return StartServer(
|
||||
sc.c,
|
||||
version,
|
||||
shutdownC,
|
||||
graceShutdownC,
|
||||
&connection.NamedTunnelConfig{Auth: *credentials, ID: tunnelID, Protocol: protocol},
|
||||
&connection.NamedTunnelConfig{Auth: *credentials, ID: tunnelID},
|
||||
sc.logger,
|
||||
sc.isUIEnabled,
|
||||
)
|
||||
|
@@ -30,7 +30,7 @@ import (
|
||||
|
||||
const (
|
||||
credFileFlagAlias = "cred-file"
|
||||
availableProtocol = "Available protocols: http2, Go's implementation and h2mux, Cloudflare's implementation of HTTP/2."
|
||||
availableProtocol = "Available protocols: http2 - Go's implementation, h2mux - Cloudflare's implementation of HTTP/2, and auto - automatically select between http2 and h2mux"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -86,14 +86,14 @@ var (
|
||||
Usage: "Allows you to delete a tunnel, even if it has active connections.",
|
||||
EnvVars: []string{"TUNNEL_RUN_FORCE_OVERWRITE"},
|
||||
}
|
||||
selectProtocolFlag = &cli.StringFlag{
|
||||
selectProtocolFlag = altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "protocol",
|
||||
Value: "h2mux",
|
||||
Aliases: []string{"p"},
|
||||
Usage: fmt.Sprintf("Protocol implementation to connect with Cloudflare's edge network. %s", availableProtocol),
|
||||
EnvVars: []string{"TUNNEL_TRANSPORT_PROTOCOL"},
|
||||
Hidden: true,
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
func buildCreateCommand() *cli.Command {
|
||||
|
Reference in New Issue
Block a user