TUN-1619: Add flag to test declarative tunnels.

This commit is contained in:
Chung-Ting Huang 2019-04-04 17:04:55 -05:00
parent c18702f297
commit 102b364cc9
3 changed files with 64 additions and 58 deletions

View File

@ -689,5 +689,11 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
EnvVars: []string{"TUNNEL_TRACE_OUTPUT"}, EnvVars: []string{"TUNNEL_TRACE_OUTPUT"},
Hidden: shouldHide, Hidden: shouldHide,
}), }),
altsrc.NewBoolFlag(&cli.BoolFlag{
Name: "use-declarative-tunnels",
Usage: "Test establishing connections with declarative tunnel methods.",
EnvVars: []string{"TUNNEL_USE_DECLARATIVE"},
Hidden: true,
}),
} }
} }

View File

@ -243,33 +243,34 @@ func prepareTunnelConfig(
} }
return &origin.TunnelConfig{ return &origin.TunnelConfig{
EdgeAddrs: c.StringSlice("edge"), BuildInfo: buildInfo,
OriginUrl: originURL, ClientID: clientID,
Hostname: hostname, ClientTlsConfig: httpTransport.TLSClientConfig,
OriginCert: originCert, CompressionQuality: c.Uint64("compression-quality"),
TlsConfig: toEdgeTLSConfig, EdgeAddrs: c.StringSlice("edge"),
ClientTlsConfig: httpTransport.TLSClientConfig, GracePeriod: c.Duration("grace-period"),
Retries: c.Uint("retries"), HAConnections: c.Int("ha-connections"),
HeartbeatInterval: c.Duration("heartbeat-interval"), HTTPTransport: httpTransport,
MaxHeartbeats: c.Uint64("heartbeat-count"), HeartbeatInterval: c.Duration("heartbeat-interval"),
ClientID: clientID, Hostname: hostname,
BuildInfo: buildInfo, IncidentLookup: origin.NewIncidentLookup(),
ReportedVersion: version, IsAutoupdated: c.Bool("is-autoupdated"),
LBPool: c.String("lb-pool"), IsFreeTunnel: isFreeTunnel,
Tags: tags, LBPool: c.String("lb-pool"),
HAConnections: c.Int("ha-connections"), Logger: logger,
HTTPTransport: httpTransport, MaxHeartbeats: c.Uint64("heartbeat-count"),
Metrics: tunnelMetrics, Metrics: tunnelMetrics,
MetricsUpdateFreq: c.Duration("metrics-update-freq"), MetricsUpdateFreq: c.Duration("metrics-update-freq"),
TransportLogger: transportLogger, NoChunkedEncoding: c.Bool("no-chunked-encoding"),
Logger: logger, OriginCert: originCert,
IsAutoupdated: c.Bool("is-autoupdated"), OriginUrl: originURL,
GracePeriod: c.Duration("grace-period"), ReportedVersion: version,
RunFromTerminal: isRunningFromTerminal(), Retries: c.Uint("retries"),
NoChunkedEncoding: c.Bool("no-chunked-encoding"), RunFromTerminal: isRunningFromTerminal(),
CompressionQuality: c.Uint64("compression-quality"), Tags: tags,
IncidentLookup: origin.NewIncidentLookup(), TlsConfig: toEdgeTLSConfig,
IsFreeTunnel: isFreeTunnel, TransportLogger: transportLogger,
UseDeclarativeTunnel: c.Bool("use-declarative-tunnels"),
}, nil }, nil
} }

View File

@ -37,41 +37,40 @@ const (
lbProbeUserAgentPrefix = "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/;" lbProbeUserAgentPrefix = "Mozilla/5.0 (compatible; Cloudflare-Traffic-Manager/1.0; +https://www.cloudflare.com/traffic-manager/;"
TagHeaderNamePrefix = "Cf-Warp-Tag-" TagHeaderNamePrefix = "Cf-Warp-Tag-"
DuplicateConnectionError = "EDUPCONN" DuplicateConnectionError = "EDUPCONN"
isDeclarativeTunnel = false
) )
type TunnelConfig struct { type TunnelConfig struct {
BuildInfo *BuildInfo
ClientID string
ClientTlsConfig *tls.Config
CloseConnOnce *sync.Once // Used to close connectedSignal no more than once
CompressionQuality uint64
EdgeAddrs []string
GracePeriod time.Duration
HAConnections int
HTTPTransport http.RoundTripper
HeartbeatInterval time.Duration
Hostname string
IncidentLookup IncidentLookup
IsAutoupdated bool
IsFreeTunnel bool
LBPool string
Logger *log.Logger
MaxHeartbeats uint64
Metrics *TunnelMetrics
MetricsUpdateFreq time.Duration
NoChunkedEncoding bool
OriginCert []byte
ReportedVersion string
Retries uint
RunFromTerminal bool
Tags []tunnelpogs.Tag
TlsConfig *tls.Config
TransportLogger *log.Logger
UseDeclarativeTunnel bool
WSGI bool
// OriginUrl may not be used if a user specifies a unix socket. // OriginUrl may not be used if a user specifies a unix socket.
OriginUrl string OriginUrl string
EdgeAddrs []string
Hostname string
OriginCert []byte
TlsConfig *tls.Config
ClientTlsConfig *tls.Config
Retries uint
HeartbeatInterval time.Duration
MaxHeartbeats uint64
ClientID string
BuildInfo *BuildInfo
ReportedVersion string
LBPool string
Tags []tunnelpogs.Tag
HAConnections int
HTTPTransport http.RoundTripper
Metrics *TunnelMetrics
MetricsUpdateFreq time.Duration
TransportLogger *log.Logger
Logger *log.Logger
IsAutoupdated bool
GracePeriod time.Duration
RunFromTerminal bool
NoChunkedEncoding bool
WSGI bool
CompressionQuality uint64
IncidentLookup IncidentLookup
CloseConnOnce *sync.Once // Used to close connectedSignal no more than once
IsFreeTunnel bool
} }
type dialError struct { type dialError struct {
@ -153,7 +152,7 @@ func StartTunnelDaemon(config *TunnelConfig, shutdownC <-chan struct{}, connecte
// If a user specified negative HAConnections, we will treat it as requesting 1 connection // If a user specified negative HAConnections, we will treat it as requesting 1 connection
if config.HAConnections > 1 { if config.HAConnections > 1 {
if isDeclarativeTunnel { if config.UseDeclarativeTunnel {
return connection.NewSupervisor(&connection.CloudflaredConfig{ return connection.NewSupervisor(&connection.CloudflaredConfig{
ConnectionConfig: &connection.ConnectionConfig{ ConnectionConfig: &connection.ConnectionConfig{
TLSConfig: config.TlsConfig, TLSConfig: config.TlsConfig,