activity_authority_reset_owner.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #pragma once
  2. #include <cstdint>
  3. #include "../../middleware/bap/activity_message/entity_authority.h"
  4. #include "activity_authority_reset.h"
  5. namespace sunrise::server::bap::authority_reset {
  6. /** One connection-local msg-28 exchange can be active at a time. */
  7. enum class Phase : std::uint8_t {
  8. idle,
  9. pending,
  10. awaiting,
  11. complete,
  12. timedOut,
  13. };
  14. /** Result of applying one exact msg-29 body to its pending reset. */
  15. enum class AcknowledgementStatus : std::uint8_t {
  16. complete,
  17. timedOut,
  18. noReset,
  19. staleBinding,
  20. tokenMismatch,
  21. invalidShape,
  22. };
  23. /** State retained by one authenticated ActivityClient link. */
  24. struct Owner final {
  25. ActivityAuthorityResetSnapshot snapshot{};
  26. std::uint64_t bindingGeneration{};
  27. std::uint64_t deadlineTick{};
  28. std::int32_t correlation{-1};
  29. std::int32_t nextCorrelation{};
  30. Phase phase{Phase::idle};
  31. bool staged{};
  32. };
  33. /** Cancels one old binding while preserving the connection's fresh-token sequence. */
  34. void reset(Owner& owner, std::uint64_t bindingGeneration) noexcept;
  35. /** Opens one bounded reset and allocates its non--1 correlation value. */
  36. [[nodiscard]] ActivityAuthorityResetStatus
  37. request(Owner& owner, std::uint64_t bindingGeneration, std::int32_t& correlation) noexcept;
  38. /** @return True when the exact binding has one msg-28 body waiting to be sent. */
  39. [[nodiscard]] bool pending(const Owner& owner, std::uint64_t bindingGeneration) noexcept;
  40. /** Marks the current pending reset as present in a staged transport frame. */
  41. [[nodiscard]] bool
  42. stage(Owner& owner, std::uint64_t bindingGeneration, std::int32_t& correlation) noexcept;
  43. /** Starts the acknowledgement timeout after the complete msg-28 frame reaches the caller. */
  44. void commit_staged(Owner& owner, std::uint64_t bindingGeneration, std::uint64_t now) noexcept;
  45. /** Returns a staged msg-28 to pending when its frame is refused. */
  46. void discard_staged(Owner& owner, std::uint64_t bindingGeneration) noexcept;
  47. /** Applies one correlated acknowledgement before its closed deadline. */
  48. [[nodiscard]] AcknowledgementStatus
  49. submit(Owner& owner,
  50. std::uint64_t bindingGeneration,
  51. std::uint64_t now,
  52. const middleware::bap::activity_message::entity_authority::QueryAnswer& answer) noexcept;
  53. /** Closes an unanswered reset once its bounded wait has elapsed. */
  54. [[nodiscard]] bool
  55. expire(Owner& owner, std::uint64_t bindingGeneration, std::uint64_t now) noexcept;
  56. /** Copies one complete stable result for a later API consumer. */
  57. [[nodiscard]] ActivityAuthorityResetStatus
  58. snapshot(const Owner& owner,
  59. std::uint64_t bindingGeneration,
  60. ActivityAuthorityResetSnapshot& output) noexcept;
  61. } // namespace sunrise::server::bap::authority_reset