Skip to content

Commit 8772013

Browse files
committed
chore: include if direction is over private network in ping diagnostics
1 parent b1298a3 commit 8772013

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cli/cliui/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (d ConnDiags) splitDiagnostics() (general, client, agent []string) {
411411
}
412412

413413
if d.DisableDirect {
414-
general = append(general, "❗ Direct connections are disabled locally, by `--disable-direct` or `CODER_DISABLE_DIRECT`")
414+
general = append(general, "❗ Direct connections are disabled locally, by `--disable-direct-connections` or `CODER_DISABLE_DIRECT_CONNECTIONS`")
415415
if !d.Verbose {
416416
return general, client, agent
417417
}

cli/ping.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func (r *RootCmd) ping() *serpent.Command {
128128
}
129129

130130
if r.disableDirect {
131-
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
132131
opts.BlockEndpoints = true
133132
}
134133
if !r.disableNetworkTelemetry {
@@ -197,6 +196,7 @@ func (r *RootCmd) ping() *serpent.Command {
197196
results := &pingSummary{
198197
Workspace: workspaceName,
199198
}
199+
var overPrivateNetwork bool
200200
n := 0
201201
start := time.Now()
202202
pingLoop:
@@ -240,6 +240,7 @@ func (r *RootCmd) ping() *serpent.Command {
240240
_, _ = fmt.Fprintln(inv.Stdout, "p2p connection established in",
241241
pretty.Sprint(cliui.DefaultStyles.DateTimeStamp, time.Since(start).Round(time.Millisecond).String()),
242242
)
243+
overPrivateNetwork = isPrivateEndpoint(pong.Endpoint)
243244
}
244245
didP2p = true
245246

@@ -276,7 +277,11 @@ func (r *RootCmd) ping() *serpent.Command {
276277
}
277278

278279
if didP2p {
279-
_, _ = fmt.Fprintf(inv.Stderr, "✔ You are connected directly (p2p)\n")
280+
msg := "✔ You are connected directly (p2p)"
281+
if overPrivateNetwork {
282+
msg += ", over a private network"
283+
}
284+
_, _ = fmt.Fprintln(inv.Stderr, msg)
280285
} else {
281286
_, _ = fmt.Fprintf(inv.Stderr, "❗ You are connected via a DERP relay, not directly (p2p)\n%s#common-problems-with-direct-connections\n", connDiags.TroubleshootingURL)
282287
}
@@ -329,3 +334,11 @@ func isAWSIP(awsRanges *cliutil.AWSIPRanges, ni *tailcfg.NetInfo) bool {
329334
}
330335
return false
331336
}
337+
338+
func isPrivateEndpoint(endpoint string) bool {
339+
ip, err := netip.ParseAddrPort(endpoint)
340+
if err != nil {
341+
return false
342+
}
343+
return ip.Addr().IsPrivate()
344+
}

0 commit comments

Comments
 (0)