42 lines
1 KiB
C++
42 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
|
|
#include "Context.hpp"
|
|
#include "PacketContent.hpp"
|
|
#include "SecurityMode.hpp"
|
|
|
|
|
|
namespace drp::packet::base {
|
|
|
|
|
|
/**
|
|
* A generic packet that can be transmitted through the network.
|
|
* @param channel the channel of the packet. Two system can be created inside a same network by using different
|
|
* channels value. "0" is used for "broadcast" message across networks.
|
|
* @param securityMode the type of security used in the packet.
|
|
* @param content the content of the packet. It is encrypted accordingly to the securityMode.
|
|
*/
|
|
class Packet {
|
|
public:
|
|
explicit Packet(
|
|
const Context& context,
|
|
std::uint8_t channel,
|
|
SecurityMode securityMode,
|
|
const PacketContent& content
|
|
);
|
|
[[nodiscard]] PacketContent getContent(
|
|
const Context& context,
|
|
const sockaddr_storage& address,
|
|
socklen_t addressLength
|
|
) const;
|
|
|
|
private:
|
|
std::uint8_t channel;
|
|
std::uint8_t securityMode;
|
|
std::array<std::uint8_t, sizeof(PacketContent)> content;
|
|
};
|
|
|
|
|
|
}
|