(ctx context.Context, agentID uuid.UUID)
| 283 | } |
| 284 | |
| 285 | func (s *ServerTailnet) AgentConn(ctx context.Context, agentID uuid.UUID) (workspacesdk.AgentConn, func(), error) { |
| 286 | var ( |
| 287 | conn workspacesdk.AgentConn |
| 288 | ret func() |
| 289 | ) |
| 290 | |
| 291 | s.logger.Debug(s.ctx, "acquiring agent", slog.F("agent_id", agentID)) |
| 292 | err := s.coordCtrl.ensureAgent(agentID) |
| 293 | if err != nil { |
| 294 | return nil, nil, xerrors.Errorf("ensure agent: %w", err) |
| 295 | } |
| 296 | ret = s.coordCtrl.acquireTicket(agentID) |
| 297 | |
| 298 | conn = workspacesdk.NewAgentConn(s.conn, workspacesdk.AgentConnOptions{ |
| 299 | AgentID: agentID, |
| 300 | CloseFunc: func() error { return workspacesdk.ErrSkipClose }, |
| 301 | Logger: s.logger, |
| 302 | }) |
| 303 | |
| 304 | // Since we now have an open conn, be careful to close it if we error |
| 305 | // without returning it to the user. |
| 306 | |
| 307 | reachable := conn.AwaitReachable(ctx) |
| 308 | if !reachable { |
| 309 | ret() |
| 310 | return nil, nil, xerrors.New("agent is unreachable") |
| 311 | } |
| 312 | |
| 313 | return conn, ret, nil |
| 314 | } |
| 315 | |
| 316 | func (s *ServerTailnet) DialAgentNetConn(ctx context.Context, agentID uuid.UUID, network, addr string) (net.Conn, error) { |
| 317 | conn, release, err := s.AgentConn(ctx, agentID) |
no test coverage detected