MCPcopy Index your code
hub / github.com/coder/coder / DialContext

Method DialContext

codersdk/workspacesdk/agentconn.go:353–373  ·  view source on GitHub ↗

DialContext dials the address provided in the workspace agent. The network must be "tcp" or "udp".

(ctx context.Context, network string, addr string)

Source from the content-addressed store, hash-verified

351// DialContext dials the address provided in the workspace agent.
352// The network must be "tcp" or "udp".
353func (c *agentConn) DialContext(ctx context.Context, network string, addr string) (net.Conn, error) {
354 ctx, span := tracing.StartSpan(ctx)
355 defer span.End()
356
357 if !c.AwaitReachable(ctx) {
358 return nil, xerrors.Errorf("workspace agent not reachable in time: %v", ctx.Err())
359 }
360
361 _, rawPort, _ := net.SplitHostPort(addr)
362 port, _ := strconv.ParseUint(rawPort, 10, 16)
363 ipp := netip.AddrPortFrom(c.agentAddress(), uint16(port))
364
365 switch network {
366 case "tcp":
367 return c.Conn.DialContextTCP(ctx, ipp)
368 case "udp":
369 return c.Conn.DialContextUDP(ctx, ipp)
370 default:
371 return nil, xerrors.Errorf("unknown network %q", network)
372 }
373}
374
375// AppHTTPClient returns an HTTP client for reaching HTTP apps served by this
376// workspace agent. Redirects are blocked to prevent misuse.

Callers

nothing calls this directly

Calls 7

AwaitReachableMethod · 0.95
agentAddressMethod · 0.95
StartSpanFunction · 0.92
ErrMethod · 0.80
DialContextTCPMethod · 0.80
DialContextUDPMethod · 0.80
ErrorfMethod · 0.45

Tested by

no test coverage detected