protocol: Implement control messages

This commit is contained in:
Joshua Scott 2018-04-03 21:36:24 +01:00
parent 9653475ed9
commit 915b6e7e0a
6 changed files with 240 additions and 30 deletions

View File

@ -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;
};
}

View File

@ -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;

View File

@ -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;
};
}

View File

@ -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<dml::USHRT>("unknown");
record.add_field<dml::UINT>("unknown2");
record.add_field<dml::UINT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::UINT>("m_milliseconds")->set_value(m_milliseconds);
record.add_field<dml::USHRT>("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<dml::USHRT>("unknown");
record.add_field<dml::UINT>("unknown2");
auto *timestamp = record.add_field<dml::UINT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("m_milliseconds");
auto *session_id = record.add_field<dml::USHRT>("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;
}
}
}
}

View File

@ -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<dml::USHRT>("m_session_id")->set_value(m_session_id);
record.add_field<dml::USHRT>("m_milliseconds")->set_value(m_milliseconds);
record.add_field<dml::UBYT>("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<dml::USHRT>("m_session_id");
auto *milliseconds = record.add_field<dml::USHRT>("m_milliseconds");
auto *minutes = record.add_field<dml::UBYT>("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;
}
}
}
}

View File

@ -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<dml::USHRT>("m_session_id")->set_value(m_session_id);
record.add_field<dml::UINT>("unknown");
record.add_field<dml::UINT>("m_timestamp")->set_value(m_timestamp);
record.add_field<dml::UINT>("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<dml::USHRT>("m_session_id");
record.add_field<dml::UINT>("unknown");
auto *timestamp = record.add_field<dml::UINT>("m_timestamp");
auto *milliseconds = record.add_field<dml::UINT>("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;
}
}
}
}