protocol: Rename control messages to SESSION_OFFER and SESSION_ACCEPT

I like these names better
This commit is contained in:
Joshua Scott 2018-04-13 03:43:03 +01:00
parent 00b404f132
commit 38e0547e84
7 changed files with 54 additions and 54 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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<dml::USHRT>("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<dml::USHRT>("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) +

View File

@ -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<dml::USHRT>("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<dml::USHRT>("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);
}
}

View File

@ -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<control::ServerHello>();
const auto server_hello = read_data<control::SessionOffer>();
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<control::ClientHello>();
const auto client_hello = read_data<control::SessionAccept>();
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();
}