peer_external_ack.h 1.4 KB

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include "../../../middleware/gameplay/peer/established_packet.h"
  3. namespace sunrise::server::gameplay::peer {
  4. struct CompletedExternal {
  5. std::uint64_t groupSessionId{};
  6. std::uint64_t transmissionId{};
  7. middleware::gameplay::peer::AckOutcome outcome{
  8. middleware::gameplay::peer::AckOutcome::unresolved};
  9. };
  10. using DisplacedExternals =
  11. std::array<CompletedExternal, state::gameplay::external::kExternalContributionCapacity>;
  12. // Called after transport ownership/guard validation, independently of lane decoding.
  13. [[nodiscard]] inline std::size_t acknowledge_external(
  14. state::gameplay::PeerLink& peer,
  15. const middleware::gameplay::peer::AckState& ack,
  16. DisplacedExternals& completed) noexcept {
  17. namespace wire = middleware::gameplay::peer;
  18. std::size_t count = 0;
  19. for (auto& contribution : peer.externalContributions) {
  20. if (!contribution.occupied) continue;
  21. const auto outcome = wire::acknowledgement_outcome(ack, contribution.packetSequence);
  22. if (outcome == wire::AckOutcome::unresolved) continue;
  23. completed[count++] = {contribution.groupSessionId, contribution.transmissionId, outcome};
  24. if (outcome == wire::AckOutcome::received && contribution.commonPresent
  25. && contribution.viewGeneration == peer.viewGeneration) peer.commonCommitted = true;
  26. contribution = {};
  27. }
  28. return count;
  29. }
  30. }