@@ -10,8 +10,11 @@ import (
10
10
11
11
"github.com/google/uuid"
12
12
"golang.org/x/xerrors"
13
+ "tailscale.com/tailcfg"
13
14
14
15
"github.com/coder/coder/v2/codersdk"
16
+ "github.com/coder/coder/v2/codersdk/healthsdk"
17
+ "github.com/coder/coder/v2/codersdk/workspacesdk"
15
18
"github.com/coder/coder/v2/tailnet"
16
19
)
17
20
@@ -346,3 +349,50 @@ func PeerDiagnostics(w io.Writer, d tailnet.PeerDiagnostics) {
346
349
_ , _ = fmt .Fprint (w , "✘ Wireguard is not connected\n " )
347
350
}
348
351
}
352
+
353
+ type ConnDiags struct {
354
+ Info * workspacesdk.AgentConnectionInfo
355
+ PingP2P bool
356
+ LocalNetInfo * tailcfg.NetInfo
357
+ FetchAgentNetInfo func () (healthsdk.AgentNetcheckReport , error )
358
+ // TODO: More diagnostics
359
+ }
360
+
361
+ func ConnDiagnostics (w io.Writer , d ConnDiags ) {
362
+ if d .PingP2P {
363
+ _ , _ = fmt .Fprintln (w , "✔ You are connected directly, peer-to-peer (p2p)." )
364
+ return
365
+ }
366
+ _ , _ = fmt .Fprintln (w , "❗ You are connected via a DERP relay, not directly, peer-to-peer (p2p)." )
367
+
368
+ if d .Info == nil {
369
+ return
370
+ }
371
+
372
+ if d .Info .DisableDirectConnections {
373
+ _ , _ = fmt .Fprintln (w , "❗ Your Coder administrator has blocked direct connections." )
374
+ return
375
+ }
376
+
377
+ if ! d .Info .DERPMap .HasSTUN () {
378
+ _ , _ = fmt .Fprintln (w , "✘ The workspace agent appears to be unable to reach any STUN servers.\n https://coder.com/docs/networking/stun" )
379
+ }
380
+
381
+ if d .LocalNetInfo == nil {
382
+ return
383
+ }
384
+
385
+ if d .LocalNetInfo .MappingVariesByDestIP .EqualBool (true ) {
386
+ _ , _ = fmt .Fprintln (w , "❗ Client is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers." )
387
+ }
388
+
389
+ agentNetcheck , err := d .FetchAgentNetInfo ()
390
+ if err != nil {
391
+ _ , _ = fmt .Fprintf (w , "Failed to retrieve netcheck report from agent: %v\n " , err )
392
+ return
393
+ }
394
+
395
+ if agentNetcheck .NetInfo .MappingVariesByDestIP .EqualBool (true ) {
396
+ _ , _ = fmt .Fprintln (w , "❗ Agent is potentially behind a hard NAT, as multiple endpoints were retrieved from different STUN servers." )
397
+ }
398
+ }
0 commit comments