diff --git a/include/ki/protocol/control/ClientHello.h b/include/ki/protocol/control/ClientHello.h index 05b96ec..f126d8c 100644 --- a/include/ki/protocol/control/ClientHello.h +++ b/include/ki/protocol/control/ClientHello.h @@ -15,14 +15,14 @@ namespace control { public: ClientHello(uint16_t session_id = 0, - uint64_t timestamp = 0, uint32_t milliseconds = 0); + uint32_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_timestamp() const; + void set_timestamp(uint32_t timestamp); uint32_t get_milliseconds() const; void set_milliseconds(uint32_t milliseconds); @@ -32,16 +32,10 @@ namespace control size_t get_size() const override 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; - } + uint32_t timestamp = 0, uint32_t milliseconds = 0); private: uint16_t m_session_id; - uint64_t m_timestamp; + uint32_t m_timestamp; uint32_t m_milliseconds; }; } diff --git a/include/ki/protocol/control/Ping.h b/include/ki/protocol/control/Ping.h index 494e38c..5ab0b33 100644 --- a/include/ki/protocol/control/Ping.h +++ b/include/ki/protocol/control/Ping.h @@ -32,14 +32,7 @@ namespace control 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; - } + bool response = false); private: uint16_t m_session_id; uint16_t m_milliseconds; diff --git a/include/ki/protocol/control/ServerHello.h b/include/ki/protocol/control/ServerHello.h index 123a7b6..f94106b 100644 --- a/include/ki/protocol/control/ServerHello.h +++ b/include/ki/protocol/control/ServerHello.h @@ -15,14 +15,14 @@ namespace control { public: ServerHello(uint16_t session_id = 0, - uint64_t timestamp = 0, uint32_t milliseconds = 0); + uint32_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_timestamp() const; + void set_timestamp(uint32_t timestamp); uint32_t get_milliseconds() const; void set_milliseconds(uint32_t milliseconds); @@ -32,16 +32,10 @@ namespace control size_t get_size() const override 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; - } + uint32_t timestamp = 0, uint32_t milliseconds = 0); private: uint16_t m_session_id; - uint64_t m_timestamp; + uint32_t m_timestamp; uint32_t m_milliseconds; }; } diff --git a/src/protocol/control/ClientHello.cpp b/src/protocol/control/ClientHello.cpp index 4edff91..50b7cd9 100644 --- a/src/protocol/control/ClientHello.cpp +++ b/src/protocol/control/ClientHello.cpp @@ -1,4 +1,5 @@ #include "ki/protocol/control/ClientHello.h" +#include "ki/dml/Record.h" namespace ki { @@ -6,7 +7,85 @@ namespace protocol { namespace control { + ClientHello::ClientHello(uint16_t session_id, + uint32_t timestamp, uint32_t milliseconds) + { + m_session_id = session_id; + m_timestamp = timestamp; + m_milliseconds = milliseconds; + } + uint16_t ClientHello::get_session_id() const + { + return m_session_id; + } + + void ClientHello::set_session_id(uint16_t session_id) + { + m_session_id = session_id; + } + + uint32_t ClientHello::get_timestamp() const + { + return m_timestamp; + } + + void ClientHello::set_timestamp(uint32_t timestamp) + { + m_timestamp = timestamp; + } + + uint32_t ClientHello::get_milliseconds() const + { + return m_milliseconds; + } + + void ClientHello::set_milliseconds(uint32_t milliseconds) + { + m_milliseconds = milliseconds; + } + + void ClientHello::write_to(std::ostream& ostream) const + { + dml::Record record; + record.add_field("unknown"); + record.add_field("unknown2"); + record.add_field("m_timestamp")->set_value(m_timestamp); + record.add_field("m_milliseconds")->set_value(m_milliseconds); + record.add_field("m_session_id")->set_value(m_session_id); + record.write_to(ostream); + } + + void ClientHello::read_from(std::istream& istream) + { + dml::Record record; + record.add_field("unknown"); + record.add_field("unknown2"); + auto *timestamp = record.add_field("m_timestamp"); + auto *milliseconds = record.add_field("m_milliseconds"); + auto *session_id = record.add_field("m_session_id"); + record.read_from(istream); + + m_timestamp = timestamp->get_value(); + m_milliseconds = milliseconds->get_value(); + m_session_id = session_id->get_value(); + } + + size_t ClientHello::get_size() const + { + return sizeof(dml::USHRT) + sizeof(dml::UINT) + + sizeof(dml::UINT) + sizeof(dml::UINT) + + sizeof(dml::USHRT); + } + + Packet *ClientHello::create_packet(uint16_t session_id, + uint32_t timestamp, uint32_t milliseconds) + { + const ClientHello data(session_id, timestamp, milliseconds); + auto *packet = new Packet(true, (uint8_t)Opcode::CLIENT_HELLO); + packet->set_payload_data(data); + return packet; + } } } } \ No newline at end of file diff --git a/src/protocol/control/Ping.cpp b/src/protocol/control/Ping.cpp index 7f6a0af..b5a2cd5 100644 --- a/src/protocol/control/Ping.cpp +++ b/src/protocol/control/Ping.cpp @@ -1,4 +1,5 @@ #include "ki/protocol/control/Ping.h" +#include "ki/dml/Record.h" namespace ki { @@ -6,7 +7,80 @@ namespace protocol { namespace control { + Ping::Ping(uint16_t session_id, uint16_t milliseconds, uint8_t minutes) + { + m_session_id = session_id; + m_milliseconds = milliseconds; + m_minutes = minutes; + } + uint16_t Ping::get_session_id() const + { + return m_session_id; + } + + void Ping::set_session_id(uint16_t session_id) + { + m_session_id = session_id; + } + + uint16_t Ping::get_milliseconds() const + { + return m_milliseconds; + } + + void Ping::set_milliseconds(uint16_t milliseconds) + { + m_milliseconds = milliseconds; + } + + uint8_t Ping::get_minutes() const + { + return m_minutes; + } + + void Ping::set_minutes(uint8_t minutes) + { + m_minutes = minutes; + } + + void Ping::write_to(std::ostream &ostream) const + { + dml::Record record; + record.add_field("m_session_id")->set_value(m_session_id); + record.add_field("m_milliseconds")->set_value(m_milliseconds); + record.add_field("m_minutes")->set_value(m_minutes); + record.write_to(ostream); + } + + void Ping::read_from(std::istream &istream) + { + dml::Record record; + auto *session_id = record.add_field("m_session_id"); + auto *milliseconds = record.add_field("m_milliseconds"); + auto *minutes = record.add_field("m_minutes"); + record.read_from(istream); + + m_session_id = session_id->get_value(); + m_milliseconds = milliseconds->get_value(); + m_minutes = minutes->get_value(); + } + + size_t Ping::get_size() const + { + return sizeof(dml::USHRT) + sizeof(dml::USHRT) + + sizeof(dml::UBYT); + } + + Packet* Ping::create_packet(uint16_t session_id, + uint16_t milliseconds, uint8_t minutes, bool response) + { + const 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; + } } } } \ No newline at end of file diff --git a/src/protocol/control/ServerHello.cpp b/src/protocol/control/ServerHello.cpp index 8be2f86..4be2c91 100644 --- a/src/protocol/control/ServerHello.cpp +++ b/src/protocol/control/ServerHello.cpp @@ -1,4 +1,5 @@ #include "ki/protocol/control/ServerHello.h" +#include "ki/dml/Record.h" namespace ki { @@ -6,7 +7,82 @@ namespace protocol { namespace control { + ServerHello::ServerHello(uint16_t session_id, + uint32_t timestamp, uint32_t milliseconds) + { + m_session_id = session_id; + m_timestamp = timestamp; + m_milliseconds = milliseconds; + } + uint16_t ServerHello::get_session_id() const + { + return m_session_id; + } + + void ServerHello::set_session_id(uint16_t session_id) + { + m_session_id = session_id; + } + + uint32_t ServerHello::get_timestamp() const + { + return m_timestamp; + } + + void ServerHello::set_timestamp(uint32_t timestamp) + { + m_timestamp = timestamp; + } + + uint32_t ServerHello::get_milliseconds() const + { + return m_milliseconds; + } + + void ServerHello::set_milliseconds(uint32_t milliseconds) + { + m_milliseconds = milliseconds; + } + + void ServerHello::write_to(std::ostream& ostream) const + { + dml::Record record; + record.add_field("m_session_id")->set_value(m_session_id); + record.add_field("unknown"); + record.add_field("m_timestamp")->set_value(m_timestamp); + record.add_field("m_milliseconds")->set_value(m_milliseconds); + record.write_to(ostream); + } + + void ServerHello::read_from(std::istream& istream) + { + dml::Record record; + auto *session_id = record.add_field("m_session_id"); + record.add_field("unknown"); + auto *timestamp = record.add_field("m_timestamp"); + auto *milliseconds = record.add_field("m_milliseconds"); + record.read_from(istream); + + m_session_id = session_id->get_value(); + m_timestamp = timestamp->get_value(); + m_milliseconds = milliseconds->get_value(); + } + + size_t ServerHello::get_size() const + { + return sizeof(dml::USHRT) + sizeof(dml::GID) + + sizeof(dml::UINT); + } + + Packet *ServerHello::create_packet(uint16_t session_id, + uint32_t timestamp, uint32_t milliseconds) + { + const ServerHello data(session_id, timestamp, milliseconds); + auto *packet = new Packet(true, (uint8_t)Opcode::SERVER_HELLO); + packet->set_payload_data(data); + return packet; + } } } } \ No newline at end of file