diff --git a/include/ki/protocol/control/ClientHello.h b/include/ki/protocol/control/ClientHello.h new file mode 100644 index 0000000..ee00b66 --- /dev/null +++ b/include/ki/protocol/control/ClientHello.h @@ -0,0 +1,49 @@ +#pragma once +#include "../../util/Serializable.h" +#include "../Packet.h" +#include "Opcode.h" +#include +#include + +namespace ki +{ +namespace protocol +{ +namespace control +{ + class ClientHello : public util::Serializable + { + public: + ClientHello(uint16_t session_id = 0, + uint64_t timestamp = 0, uint32_t milliseconds = 0); + virtual ~ClientHello() = default; + + uint16_t get_session_id() const; + void set_session_id(uint16_t session_id); + + uint64_t get_timestamp() const; + void set_timestamp(uint64_t timestamp); + + uint32_t get_milliseconds() const; + void set_milliseconds(uint32_t milliseconds); + + void write_to(std::ostream &ostream) const final; + void read_from(std::istream &istream) final; + size_t get_size() const final; + + static Packet *create_packet(uint16_t session_id = 0, + uint64_t timestamp = 0, uint32_t milliseconds = 0) + { + ClientHello data(session_id, timestamp, milliseconds); + auto *packet = new Packet(true, (uint8_t)Opcode::CLIENT_HELLO); + packet->set_payload_data(data); + return packet; + } + private: + uint16_t m_session_id; + uint64_t m_timestamp; + uint32_t m_milliseconds; + }; +} +} +} diff --git a/include/ki/protocol/control/Opcode.h b/include/ki/protocol/control/Opcode.h new file mode 100644 index 0000000..8442a56 --- /dev/null +++ b/include/ki/protocol/control/Opcode.h @@ -0,0 +1,20 @@ +#pragma once +#include + +namespace ki +{ +namespace protocol +{ +namespace control +{ + enum class Opcode : uint8_t + { + SERVER_HELLO = 0, + UDP_HELLO = 1, + PING = 3, + PING_RSP = 4, + CLIENT_HELLO = 5 + }; +} +} +} \ No newline at end of file diff --git a/include/ki/protocol/control/Ping.h b/include/ki/protocol/control/Ping.h new file mode 100644 index 0000000..dff0ed9 --- /dev/null +++ b/include/ki/protocol/control/Ping.h @@ -0,0 +1,50 @@ +#pragma once +#include "../../util/Serializable.h" +#include "../Packet.h" +#include "Opcode.h" +#include + +namespace ki +{ + namespace protocol + { + namespace control + { + class Ping : public util::Serializable + { + public: + Ping(uint16_t session_id = 0, + uint16_t milliseconds = 0, uint8_t minutes = 0); + virtual ~Ping() = default; + + uint16_t get_session_id() const; + void set_session_id(uint16_t session_id); + + uint16_t get_milliseconds() const; + void set_milliseconds(uint16_t milliseconds); + + uint8_t get_minutes() const; + void set_minutes(uint8_t minutes); + + void write_to(std::ostream &ostream) const final; + void read_from(std::istream &istream) final; + size_t get_size() const final; + + static Packet *create_packet(uint16_t session_id = 0, + uint16_t milliseconds = 0, uint8_t minutes = 0, + bool response = false) + { + Ping data(session_id, milliseconds, minutes); + auto *packet = new Packet(true, + (uint8_t)(response ? Opcode::PING_RSP : Opcode::PING)); + packet->set_payload_data(data); + return packet; + } + private: + uint16_t m_session_id; + uint16_t m_milliseconds; + uint8_t m_minutes; + }; + } + } +} diff --git a/include/ki/protocol/control/ServerHello.h b/include/ki/protocol/control/ServerHello.h new file mode 100644 index 0000000..2c0d50e --- /dev/null +++ b/include/ki/protocol/control/ServerHello.h @@ -0,0 +1,49 @@ +#pragma once +#include "../../util/Serializable.h" +#include "../Packet.h" +#include "Opcode.h" +#include +#include + +namespace ki +{ +namespace protocol +{ +namespace control +{ + class ServerHello : public util::Serializable + { + public: + ServerHello(uint16_t session_id = 0, + uint64_t timestamp = 0, uint32_t milliseconds = 0); + virtual ~ServerHello() = default; + + uint16_t get_session_id() const; + void set_session_id(uint16_t session_id); + + uint64_t get_timestamp() const; + void set_timestamp(uint64_t timestamp); + + uint32_t get_milliseconds() const; + void set_milliseconds(uint32_t milliseconds); + + void write_to(std::ostream &ostream) const final; + void read_from(std::istream &istream) final; + size_t get_size() const final; + + static Packet *create_packet(uint16_t session_id = 0, + uint64_t timestamp = 0, uint32_t milliseconds = 0) + { + ServerHello data(session_id, timestamp, milliseconds); + auto *packet = new Packet(true, (uint8_t)Opcode::SERVER_HELLO); + packet->set_payload_data(data); + return packet; + } + private: + uint16_t m_session_id; + uint64_t m_timestamp; + uint32_t m_milliseconds; + }; +} +} +}