From 38e0547e8413abffbc118c054c983a5b05717dc0 Mon Sep 17 00:00:00 2001 From: Joshua Scott Date: Fri, 13 Apr 2018 03:43:03 +0100 Subject: [PATCH] protocol: Rename control messages to SESSION_OFFER and SESSION_ACCEPT I like these names better --- include/ki/protocol/control/Opcode.h | 4 +- .../{ServerHello.h => SessionAccept.h} | 6 +-- .../control/{ClientHello.h => SessionOffer.h} | 6 +-- src/protocol/CMakeLists.txt | 4 +- .../{ClientHello.cpp => SessionAccept.cpp} | 24 ++++++------ .../{ServerHello.cpp => SessionOffer.cpp} | 26 ++++++------- src/protocol/net/Session.cpp | 38 +++++++++---------- 7 files changed, 54 insertions(+), 54 deletions(-) rename include/ki/protocol/control/{ServerHello.h => SessionAccept.h} (84%) rename include/ki/protocol/control/{ClientHello.h => SessionOffer.h} (84%) rename src/protocol/control/{ClientHello.cpp => SessionAccept.cpp} (70%) rename src/protocol/control/{ServerHello.cpp => SessionOffer.cpp} (66%) diff --git a/include/ki/protocol/control/Opcode.h b/include/ki/protocol/control/Opcode.h index 85ee88e..ab6b489 100644 --- a/include/ki/protocol/control/Opcode.h +++ b/include/ki/protocol/control/Opcode.h @@ -10,11 +10,11 @@ namespace control enum class Opcode : uint8_t { NONE = 0, - SERVER_HELLO = 0, + SESSION_OFFER = 0, UDP_HELLO = 1, PING = 3, PING_RSP = 4, - CLIENT_HELLO = 5 + SESSION_ACCEPT = 5 }; } } diff --git a/include/ki/protocol/control/ServerHello.h b/include/ki/protocol/control/SessionAccept.h similarity index 84% rename from include/ki/protocol/control/ServerHello.h rename to include/ki/protocol/control/SessionAccept.h index dd76843..4350e11 100644 --- a/include/ki/protocol/control/ServerHello.h +++ b/include/ki/protocol/control/SessionAccept.h @@ -9,12 +9,12 @@ namespace protocol { namespace control { - class ServerHello final : public util::Serializable + class SessionAccept final : public util::Serializable { public: - ServerHello(uint16_t session_id = 0, + SessionAccept(uint16_t session_id = 0, int32_t timestamp = 0, uint32_t milliseconds = 0); - virtual ~ServerHello() = default; + virtual ~SessionAccept() = default; uint16_t get_session_id() const; void set_session_id(uint16_t session_id); diff --git a/include/ki/protocol/control/ClientHello.h b/include/ki/protocol/control/SessionOffer.h similarity index 84% rename from include/ki/protocol/control/ClientHello.h rename to include/ki/protocol/control/SessionOffer.h index 98900a6..ab59fb1 100644 --- a/include/ki/protocol/control/ClientHello.h +++ b/include/ki/protocol/control/SessionOffer.h @@ -9,12 +9,12 @@ namespace protocol { namespace control { - class ClientHello final : public util::Serializable + class SessionOffer final : public util::Serializable { public: - ClientHello(uint16_t session_id = 0, + SessionOffer(uint16_t session_id = 0, int32_t timestamp = 0, uint32_t milliseconds = 0); - virtual ~ClientHello() = default; + virtual ~SessionOffer() = default; uint16_t get_session_id() const; void set_session_id(uint16_t session_id); diff --git a/src/protocol/CMakeLists.txt b/src/protocol/CMakeLists.txt index c3e5e38..849f3fe 100644 --- a/src/protocol/CMakeLists.txt +++ b/src/protocol/CMakeLists.txt @@ -1,8 +1,8 @@ target_sources(${PROJECT_NAME} PRIVATE - ${PROJECT_SOURCE_DIR}/src/protocol/control/ClientHello.cpp - ${PROJECT_SOURCE_DIR}/src/protocol/control/ServerHello.cpp ${PROJECT_SOURCE_DIR}/src/protocol/control/Ping.cpp + ${PROJECT_SOURCE_DIR}/src/protocol/control/SessionAccept.cpp + ${PROJECT_SOURCE_DIR}/src/protocol/control/SessionOffer.cpp ${PROJECT_SOURCE_DIR}/src/protocol/dml/Message.cpp ${PROJECT_SOURCE_DIR}/src/protocol/dml/MessageBuilder.cpp ${PROJECT_SOURCE_DIR}/src/protocol/dml/MessageManager.cpp diff --git a/src/protocol/control/ClientHello.cpp b/src/protocol/control/SessionAccept.cpp similarity index 70% rename from src/protocol/control/ClientHello.cpp rename to src/protocol/control/SessionAccept.cpp index 007ec21..26bd526 100644 --- a/src/protocol/control/ClientHello.cpp +++ b/src/protocol/control/SessionAccept.cpp @@ -1,4 +1,4 @@ -#include "ki/protocol/control/ClientHello.h" +#include "ki/protocol/control/SessionAccept.h" #include "ki/dml/Record.h" #include "ki/protocol/exception.h" @@ -8,7 +8,7 @@ namespace protocol { namespace control { - ClientHello::ClientHello(const uint16_t session_id, + SessionAccept::SessionAccept(const uint16_t session_id, const int32_t timestamp, const uint32_t milliseconds) { m_session_id = session_id; @@ -16,37 +16,37 @@ namespace control m_milliseconds = milliseconds; } - uint16_t ClientHello::get_session_id() const + uint16_t SessionAccept::get_session_id() const { return m_session_id; } - void ClientHello::set_session_id(const uint16_t session_id) + void SessionAccept::set_session_id(const uint16_t session_id) { m_session_id = session_id; } - int32_t ClientHello::get_timestamp() const + int32_t SessionAccept::get_timestamp() const { return m_timestamp; } - void ClientHello::set_timestamp(const int32_t timestamp) + void SessionAccept::set_timestamp(const int32_t timestamp) { m_timestamp = timestamp; } - uint32_t ClientHello::get_milliseconds() const + uint32_t SessionAccept::get_milliseconds() const { return m_milliseconds; } - void ClientHello::set_milliseconds(const uint32_t milliseconds) + void SessionAccept::set_milliseconds(const uint32_t milliseconds) { m_milliseconds = milliseconds; } - void ClientHello::write_to(std::ostream& ostream) const + void SessionAccept::write_to(std::ostream& ostream) const { dml::Record record; record.add_field("unknown"); @@ -57,7 +57,7 @@ namespace control record.write_to(ostream); } - void ClientHello::read_from(std::istream& istream) + void SessionAccept::read_from(std::istream& istream) { dml::Record record; record.add_field("unknown"); @@ -72,7 +72,7 @@ namespace control catch (dml::parse_error &e) { std::ostringstream oss; - oss << "Error reading ClientHello payload: " << e.what(); + oss << "Error reading SessionAccept payload: " << e.what(); throw parse_error(oss.str()); } @@ -81,7 +81,7 @@ namespace control m_session_id = session_id->get_value(); } - size_t ClientHello::get_size() const + size_t SessionAccept::get_size() const { return sizeof(dml::USHRT) + sizeof(dml::UINT) + sizeof(dml::INT) + sizeof(dml::UINT) + diff --git a/src/protocol/control/ServerHello.cpp b/src/protocol/control/SessionOffer.cpp similarity index 66% rename from src/protocol/control/ServerHello.cpp rename to src/protocol/control/SessionOffer.cpp index 450a5b5..4ca2635 100644 --- a/src/protocol/control/ServerHello.cpp +++ b/src/protocol/control/SessionOffer.cpp @@ -1,4 +1,4 @@ -#include "ki/protocol/control/ServerHello.h" +#include "ki/protocol/control/SessionOffer.h" #include "ki/dml/Record.h" #include "ki/protocol/exception.h" @@ -8,7 +8,7 @@ namespace protocol { namespace control { - ServerHello::ServerHello(const uint16_t session_id, + SessionOffer::SessionOffer(const uint16_t session_id, const int32_t timestamp, const uint32_t milliseconds) { m_session_id = session_id; @@ -16,37 +16,37 @@ namespace control m_milliseconds = milliseconds; } - uint16_t ServerHello::get_session_id() const + uint16_t SessionOffer::get_session_id() const { return m_session_id; } - void ServerHello::set_session_id(const uint16_t session_id) + void SessionOffer::set_session_id(const uint16_t session_id) { m_session_id = session_id; } - int32_t ServerHello::get_timestamp() const + int32_t SessionOffer::get_timestamp() const { return m_timestamp; } - void ServerHello::set_timestamp(const int32_t timestamp) + void SessionOffer::set_timestamp(const int32_t timestamp) { m_timestamp = timestamp; } - uint32_t ServerHello::get_milliseconds() const + uint32_t SessionOffer::get_milliseconds() const { return m_milliseconds; } - void ServerHello::set_milliseconds(const uint32_t milliseconds) + void SessionOffer::set_milliseconds(const uint32_t milliseconds) { m_milliseconds = milliseconds; } - void ServerHello::write_to(std::ostream& ostream) const + void SessionOffer::write_to(std::ostream& ostream) const { dml::Record record; record.add_field("m_session_id")->set_value(m_session_id); @@ -56,7 +56,7 @@ namespace control record.write_to(ostream); } - void ServerHello::read_from(std::istream& istream) + void SessionOffer::read_from(std::istream& istream) { dml::Record record; auto *session_id = record.add_field("m_session_id"); @@ -70,7 +70,7 @@ namespace control catch (dml::parse_error &e) { std::ostringstream oss; - oss << "Error reading ServerHello payload: " << e.what(); + oss << "Error reading SessionOffer payload: " << e.what(); throw parse_error(oss.str()); } @@ -79,9 +79,9 @@ namespace control m_milliseconds = milliseconds->get_value(); } - size_t ServerHello::get_size() const + size_t SessionOffer::get_size() const { - return sizeof(dml::USHRT) + sizeof(dml::UINT) + + return sizeof(dml::USHRT) + sizeof(dml::UINT) + sizeof(dml::INT) + sizeof(dml::UINT); } } diff --git a/src/protocol/net/Session.cpp b/src/protocol/net/Session.cpp index 1cfa814..30bbdf7 100644 --- a/src/protocol/net/Session.cpp +++ b/src/protocol/net/Session.cpp @@ -1,7 +1,7 @@ #include "ki/protocol/net/Session.h" #include "ki/protocol/exception.h" -#include "ki/protocol/control/ServerHello.h" -#include "ki/protocol/control/ClientHello.h" +#include "ki/protocol/control/SessionOffer.h" +#include "ki/protocol/control/SessionAccept.h" #include "ki/protocol/control/Ping.h" namespace ki @@ -75,7 +75,7 @@ namespace net void Session::on_connected() { // If this is the server-side of a Session - // we need to send SERVER_HELLO first. + // we need to send SESSION_OFFER first. if (get_type() == ParticipantType::SERVER) { // Work out the current timestamp and how many milliseconds @@ -88,9 +88,9 @@ namespace net now.time_since_epoch() ).count() - (timestamp * 1000); - // Send a SERVER_HELLO packet to the client - const control::ServerHello hello(m_id, timestamp, milliseconds); - send_packet(true, control::Opcode::SERVER_HELLO, hello); + // Send a SESSION_OFFER packet to the client + const control::SessionOffer hello(m_id, timestamp, milliseconds); + send_packet(true, control::Opcode::SESSION_OFFER, hello); } } @@ -122,11 +122,11 @@ namespace net { switch ((control::Opcode)header.get_opcode()) { - case (control::Opcode::SERVER_HELLO): + case (control::Opcode::SESSION_OFFER): on_server_hello(); break; - case (control::Opcode::CLIENT_HELLO): + case (control::Opcode::SESSION_ACCEPT): on_client_hello(); break; @@ -146,7 +146,7 @@ namespace net void Session::on_server_hello() { // If this is the server-side of a Session - // we can't handle a SERVER_HELLO + // we can't handle a SESSION_OFFER if (get_type() != ParticipantType::CLIENT) { close(); @@ -157,7 +157,7 @@ namespace net try { // We've been given our id from the server now - const auto server_hello = read_data(); + const auto server_hello = read_data(); m_id = server_hello.get_session_id(); on_hello(m_id, server_hello.get_timestamp(), @@ -173,13 +173,13 @@ namespace net now.time_since_epoch() ).count() - (timestamp * 1000); - // Send a CLIENT_HELLO packet to the server - const control::ClientHello hello(m_id, timestamp, milliseconds); - send_packet(true, control::Opcode::CLIENT_HELLO, hello); + // Send a SESSION_ACCEPT packet to the server + const control::SessionAccept hello(m_id, timestamp, milliseconds); + send_packet(true, control::Opcode::SESSION_ACCEPT, hello); } catch (parse_error &e) { - // The CLIENT_HELLO wasn't valid... + // The SESSION_ACCEPT wasn't valid... // Close the session close(); } @@ -188,7 +188,7 @@ namespace net void Session::on_client_hello() { // If this is the client-side of a Session - // we can't handle a CLIENT_HELLO + // we can't handle a SESSION_ACCEPT if (get_type() != ParticipantType::SERVER) { close(); @@ -199,14 +199,14 @@ namespace net try { // The session is now established! - const auto client_hello = read_data(); + const auto client_hello = read_data(); on_hello(client_hello.get_session_id(), client_hello.get_timestamp(), client_hello.get_milliseconds()); } catch (parse_error &e) { - // The CLIENT_HELLO wasn't valid... + // The SESSION_ACCEPT wasn't valid... // Close the session close(); } @@ -234,7 +234,7 @@ namespace net } catch (parse_error &e) { - // The CLIENT_HELLO wasn't valid... + // The SESSION_ACCEPT wasn't valid... // Close the session close(); } @@ -249,7 +249,7 @@ namespace net } catch (parse_error &e) { - // The CLIENT_HELLO wasn't valid... + // The SESSION_ACCEPT wasn't valid... // Close the session close(); }