(agentID uuid.UUID)
| 418 | } |
| 419 | |
| 420 | func (m *MultiAgentController) ensureAgent(agentID uuid.UUID) error { |
| 421 | m.mu.Lock() |
| 422 | defer m.mu.Unlock() |
| 423 | |
| 424 | _, ok := m.connectionTimes[agentID] |
| 425 | // If we don't have the agent, subscribe. |
| 426 | if !ok { |
| 427 | m.logger.Debug(context.Background(), |
| 428 | "subscribing to agent", slog.F("agent_id", agentID)) |
| 429 | if m.coordination != nil { |
| 430 | err := m.coordination.SendRequest(&proto.CoordinateRequest{ |
| 431 | AddTunnel: &proto.CoordinateRequest_Tunnel{Id: agentID[:]}, |
| 432 | }) |
| 433 | if err != nil { |
| 434 | err = xerrors.Errorf("subscribe agent: %w", err) |
| 435 | m.coordination.SendErr(err) |
| 436 | _ = m.coordination.CloseClient() |
| 437 | m.coordination = nil |
| 438 | return err |
| 439 | } |
| 440 | } |
| 441 | m.tickets[agentID] = map[uuid.UUID]struct{}{} |
| 442 | } |
| 443 | m.connectionTimes[agentID] = time.Now() |
| 444 | return nil |
| 445 | } |
| 446 | |
| 447 | func (m *MultiAgentController) acquireTicket(agentID uuid.UUID) (release func()) { |
| 448 | id := uuid.New() |
no test coverage detected