Skip to content

Commit ed1389e

Browse files
TUN-4814: Revert "TUN-4699: Make quick tunnels the default in cloudflared"
This reverts commit 18992ef.
1 parent 8fb6508 commit ed1389e

File tree

11 files changed

+85
-47
lines changed

11 files changed

+85
-47
lines changed

cmd/cloudflared/tunnel/cmd.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func runAdhocNamedTunnel(sc *subcommandContext, name, credentialsOutputPath stri
206206

207207
// runClassicTunnel creates a "classic" non-named tunnel
208208
func runClassicTunnel(sc *subcommandContext) error {
209-
return StartServer(sc.c, version, nil, sc.log, sc.isUIEnabled)
209+
return StartServer(sc.c, version, nil, sc.log, sc.isUIEnabled, "")
210210
}
211211

212212
func routeFromFlag(c *cli.Context) (route tunnelstore.Route, ok bool) {
@@ -225,6 +225,7 @@ func StartServer(
225225
namedTunnel *connection.NamedTunnelConfig,
226226
log *zerolog.Logger,
227227
isUIEnabled bool,
228+
quickTunnelHostname string,
228229
) error {
229230
_ = raven.SetDSN(sentryDSN)
230231
var wg sync.WaitGroup
@@ -324,15 +325,6 @@ func StartServer(
324325

325326
observer := connection.NewObserver(log, logTransport, isUIEnabled)
326327

327-
// Send Quick Tunnel URL to UI if applicable
328-
var quickTunnelURL string
329-
if namedTunnel != nil {
330-
quickTunnelURL = namedTunnel.QuickTunnelUrl
331-
}
332-
if quickTunnelURL != "" {
333-
observer.SendURL(quickTunnelURL)
334-
}
335-
336328
tunnelConfig, ingressRules, err := prepareTunnelConfig(c, buildInfo, version, log, logTransport, observer, namedTunnel)
337329
if err != nil {
338330
log.Err(err).Msg("Couldn't start tunnel")
@@ -350,7 +342,7 @@ func StartServer(
350342
defer wg.Done()
351343
readinessServer := metrics.NewReadyServer(log)
352344
observer.RegisterSink(readinessServer)
353-
errC <- metrics.ServeMetrics(metricsListener, ctx.Done(), readinessServer, quickTunnelURL, log)
345+
errC <- metrics.ServeMetrics(metricsListener, ctx.Done(), readinessServer, quickTunnelHostname, log)
354346
}()
355347

356348
if err := ingressRules.StartOrigins(&wg, log, ctx.Done(), errC); err != nil {
@@ -634,7 +626,6 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
634626
altsrc.NewStringFlag(&cli.StringFlag{
635627
Name: "quick-service",
636628
Usage: "URL for a service which manages unauthenticated 'quick' tunnels.",
637-
Value: "https://api.trycloudflare.com",
638629
Hidden: true,
639630
}),
640631
selectProtocolFlag,

cmd/cloudflared/tunnel/configuration.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func prepareTunnelConfig(
161161
log.Err(err).Str(LogFieldHostname, configHostname).Msg("Invalid hostname")
162162
return nil, ingress.Ingress{}, errors.Wrap(err, "Invalid hostname")
163163
}
164-
isQuickTunnel := hostname == ""
164+
isFreeTunnel := hostname == ""
165165
clientID := c.String("id")
166166
if !c.IsSet("id") {
167167
clientID, err = generateRandomClientID(log)
@@ -179,7 +179,7 @@ func prepareTunnelConfig(
179179
tags = append(tags, tunnelpogs.Tag{Name: "ID", Value: clientID})
180180

181181
var originCert []byte
182-
if !isQuickTunnel {
182+
if !isFreeTunnel {
183183
originCertPath := c.String("origincert")
184184
originCertLog := log.With().
185185
Str(LogFieldOriginCertPath, originCertPath).
@@ -278,6 +278,7 @@ func prepareTunnelConfig(
278278
HAConnections: c.Int("ha-connections"),
279279
IncidentLookup: origin.NewIncidentLookup(),
280280
IsAutoupdated: c.Bool("is-autoupdated"),
281+
IsFreeTunnel: isFreeTunnel,
281282
LBPool: c.String("lb-pool"),
282283
Tags: tags,
283284
Log: log,

cmd/cloudflared/tunnel/quick_tunnel.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7-
"strings"
87
"time"
98

109
"github.com/google/uuid"
@@ -52,7 +51,7 @@ func RunQuickTunnel(sc *subcommandContext) error {
5251
TunnelName: data.Result.Name,
5352
}
5453

55-
for _, line := range AsciiBox([]string{
54+
for _, line := range connection.AsciiBox([]string{
5655
"Your Quick Tunnel has been created! Visit it at:",
5756
data.Result.Hostname,
5857
}, 2) {
@@ -62,9 +61,10 @@ func RunQuickTunnel(sc *subcommandContext) error {
6261
return StartServer(
6362
sc.c,
6463
version,
65-
&connection.NamedTunnelConfig{Credentials: credentials, QuickTunnelUrl: data.Result.Hostname},
64+
&connection.NamedTunnelConfig{Credentials: credentials},
6665
sc.log,
6766
sc.isUIEnabled,
67+
data.Result.Hostname,
6868
)
6969
}
7070

@@ -86,26 +86,3 @@ type QuickTunnel struct {
8686
AccountTag string `json:"account_tag"`
8787
Secret []byte `json:"secret"`
8888
}
89-
90-
// Print out the given lines in a nice ASCII box.
91-
func AsciiBox(lines []string, padding int) (box []string) {
92-
maxLen := maxLen(lines)
93-
spacer := strings.Repeat(" ", padding)
94-
border := "+" + strings.Repeat("-", maxLen+(padding*2)) + "+"
95-
box = append(box, border)
96-
for _, line := range lines {
97-
box = append(box, "|"+spacer+line+strings.Repeat(" ", maxLen-len(line))+spacer+"|")
98-
}
99-
box = append(box, border)
100-
return
101-
}
102-
103-
func maxLen(lines []string) int {
104-
max := 0
105-
for _, line := range lines {
106-
if len(line) > max {
107-
max = len(line)
108-
}
109-
}
110-
return max
111-
}

cmd/cloudflared/tunnel/subcommand_context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func (sc *subcommandContext) run(tunnelID uuid.UUID) error {
286286
&connection.NamedTunnelConfig{Credentials: credentials},
287287
sc.log,
288288
sc.isUIEnabled,
289+
"",
289290
)
290291
}
291292

component-tests/test_reconnect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ def test_named_reconnect(self, tmp_path, component_tests_config):
2424
# Repeat the test multiple times because some issues only occur after multiple reconnects
2525
self.assert_reconnect(config, cloudflared, 5)
2626

27-
@pytest.mark.skipif(platform.system() == "Windows", reason=f"Currently buggy on Windows TUN-4699")
2827
def test_classic_reconnect(self, tmp_path, component_tests_config):
2928
extra_config = copy.copy(self.extra_config)
3029
extra_config["hello-world"] = True
3130
config = component_tests_config(
3231
additional_config=extra_config, named_tunnel=False)
33-
with start_cloudflared(tmp_path, config, cfd_args=[], new_process=True, allow_input=True, capture_output=True) as cloudflared:
32+
with start_cloudflared(tmp_path, config, cfd_args=[], new_process=True, allow_input=True, capture_output=False) as cloudflared:
3433
self.assert_reconnect(config, cloudflared, 1)
3534

3635
def send_reconnect(self, cloudflared, secs):

connection/connection.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ type Config struct {
2929
}
3030

3131
type NamedTunnelConfig struct {
32-
Credentials Credentials
33-
Client pogs.ClientInfo
34-
QuickTunnelUrl string
32+
Credentials Credentials
33+
Client pogs.ClientInfo
3534
}
3635

3736
// Credentials are stored in the credentials file and contain all info needed to run a tunnel.
@@ -56,6 +55,10 @@ type ClassicTunnelConfig struct {
5655
UseReconnectToken bool
5756
}
5857

58+
func (c *ClassicTunnelConfig) IsTrialZone() bool {
59+
return c.Hostname == ""
60+
}
61+
5962
// Type indicates the connection type of the connection.
6063
type Type int
6164

connection/event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
Connected
1919
// Reconnecting means the connection to the edge is being re-established.
2020
Reconnecting
21-
// SetURL means this connection's tunnel was given a URL by the edge. Used for quick tunnels.
21+
// SetURL means this connection's tunnel was given a URL by the edge. Used for free tunnels.
2222
SetURL
2323
// RegisteringTunnel means the non-named tunnel is registering its connection.
2424
RegisteringTunnel

connection/observer.go

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package connection
22

33
import (
4+
"fmt"
5+
"net/url"
6+
"strings"
7+
48
"github.com/rs/zerolog"
9+
10+
tunnelpogs "github.com/cloudflare/cloudflared/tunnelrpc/pogs"
511
)
612

713
const (
@@ -48,6 +54,53 @@ func (o *Observer) logServerInfo(connIndex uint8, location, msg string) {
4854
o.metrics.registerServerLocation(uint8ToString(connIndex), location)
4955
}
5056

57+
func (o *Observer) logTrialHostname(registration *tunnelpogs.TunnelRegistration) error {
58+
// Print out the user's trial zone URL in a nice box (if they requested and got one and UI flag is not set)
59+
if !o.uiEnabled {
60+
if registrationURL, err := url.Parse(registration.Url); err == nil {
61+
for _, line := range AsciiBox(TrialZoneMsg(registrationURL.String()), 2) {
62+
o.log.Info().Msg(line)
63+
}
64+
} else {
65+
o.log.Error().Msg("Failed to connect tunnel, please try again.")
66+
return fmt.Errorf("empty URL in response from Cloudflare edge")
67+
}
68+
}
69+
return nil
70+
}
71+
72+
// Print out the given lines in a nice ASCII box.
73+
func AsciiBox(lines []string, padding int) (box []string) {
74+
maxLen := maxLen(lines)
75+
spacer := strings.Repeat(" ", padding)
76+
77+
border := "+" + strings.Repeat("-", maxLen+(padding*2)) + "+"
78+
79+
box = append(box, border)
80+
for _, line := range lines {
81+
box = append(box, "|"+spacer+line+strings.Repeat(" ", maxLen-len(line))+spacer+"|")
82+
}
83+
box = append(box, border)
84+
return
85+
}
86+
87+
func maxLen(lines []string) int {
88+
max := 0
89+
for _, line := range lines {
90+
if len(line) > max {
91+
max = len(line)
92+
}
93+
}
94+
return max
95+
}
96+
97+
func TrialZoneMsg(url string) []string {
98+
return []string{
99+
"Your free tunnel has started! Visit it:",
100+
" " + url,
101+
}
102+
}
103+
51104
func (o *Observer) sendRegisteringEvent(connIndex uint8) {
52105
o.sendEvent(Event{Index: connIndex, EventType: RegisteringTunnel})
53106
}
@@ -56,7 +109,7 @@ func (o *Observer) sendConnectedEvent(connIndex uint8, location string) {
56109
o.sendEvent(Event{Index: connIndex, EventType: Connected, Location: location})
57110
}
58111

59-
func (o *Observer) SendURL(url string) {
112+
func (o *Observer) sendURL(url string) {
60113
o.sendEvent(Event{EventType: SetURL, URL: url})
61114
}
62115

connection/rpc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ func (h *h2muxConnection) registerTunnel(ctx context.Context, credentialSetter C
159159
return h.processRegisterTunnelError(registrationErr, register)
160160
}
161161

162+
// Send free tunnel URL to UI
163+
h.observer.sendURL(registration.Url)
162164
credentialSetter.SetEventDigest(h.connIndex, registration.EventDigest)
163165
return h.processRegistrationSuccess(registration, register, credentialSetter, classicTunnel)
164166
}
@@ -185,6 +187,14 @@ func (h *h2muxConnection) processRegistrationSuccess(
185187
h.observer.log.Info().Msgf("Each HA connection's tunnel IDs: %v", h.observer.metrics.tunnelsHA.String())
186188
}
187189

190+
// Print out the user's trial zone URL in a nice box (if they requested and got one and UI flag is not set)
191+
if classicTunnel.IsTrialZone() {
192+
err := h.observer.logTrialHostname(registration)
193+
if err != nil {
194+
return err
195+
}
196+
}
197+
188198
credentialManager.SetConnDigest(h.connIndex, registration.ConnDigest)
189199
h.observer.metrics.userHostnamesCounts.WithLabelValues(registration.Url).Inc()
190200

metrics/readiness.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func (rs *ReadyServer) OnTunnelEvent(c conn.Event) {
3636
rs.Lock()
3737
rs.isConnected[int(c.Index)] = false
3838
rs.Unlock()
39+
case conn.SetURL:
40+
break
3941
default:
4042
rs.log.Error().Msgf("Unknown connection event case %v", c)
4143
}

0 commit comments

Comments
 (0)