introduction.cpp 819 B

12345678910111213141516171819202122232425
  1. #include "introduction.h"
  2. namespace sunrise::middleware::gameplay::nat {
  3. namespace {
  4. /** The message type opens the introduction. */
  5. constexpr std::size_t kTypeOffset = 0;
  6. /** Type 13 is a direct introduction request, sent to every address a peer advertises. */
  7. constexpr std::byte kRequestType{13};
  8. /** Type 12 is the reply the requester waits for. It resolves the address it arrived from. */
  9. constexpr std::byte kReplyType{12};
  10. } // namespace
  11. /** Turns one direct introduction request into its reply, in place. */
  12. bool make_introduction_reply(std::span<std::byte> datagram) noexcept {
  13. if (datagram.size() != kIntroductionSize || datagram[kTypeOffset] != kRequestType) {
  14. return false;
  15. }
  16. datagram[kTypeOffset] = kReplyType;
  17. return true;
  18. }
  19. } // namespace sunrise::middleware::gameplay::nat