diff options
author | Kari Oikarinen <kari.oikarinen@qt.io> | 2016-06-27 15:48:11 +0300 |
---|---|---|
committer | Kari Oikarinen <kari.oikarinen@qt.io> | 2016-08-23 08:12:56 +0000 |
commit | 178198621734906e6a5c40274058d6435277fb4f (patch) | |
tree | d7bfa02b8995719ad69b0e501305e83b3d3d92a8 /qdbd | |
parent | 1adcf3d43554d3601e8e998d3993ed36c0fff3b0 (diff) |
Introduce version number to the protocol
Version number is sent as uint32 in the payload of the initial Connect
message. For now Server always responds to the Connect message with the
only protocol version that it knows, but also prints a warning if the
asked for protocol version was not the same.
Connection checks the version in the response and transitions to
Connected state only if the version matches.
Change-Id: I937af5a7e1f6bb5056efc03777178bed86b451d4
Reviewed-by: Kimmo Ollila <kimmo.ollila@theqtcompany.com>
Diffstat (limited to 'qdbd')
-rw-r--r-- | qdbd/server.cpp | 27 | ||||
-rw-r--r-- | qdbd/server.h | 3 |
2 files changed, 27 insertions, 3 deletions
diff --git a/qdbd/server.cpp b/qdbd/server.cpp index b352333..16b0476 100644 --- a/qdbd/server.cpp +++ b/qdbd/server.cpp @@ -23,6 +23,7 @@ #include "../utils/make_unique.h" #include "createexecutor.h" #include "echoexecutor.h" +#include "protocol/protocol.h" #include "protocol/qdbmessage.h" #include "protocol/qdbtransport.h" #include "stream.h" @@ -57,12 +58,14 @@ void Server::handleMessage() resetServer(false); break; } + checkVersion(message); resetServer(true); break; case ServerState::Connected: switch (message.command()) { case QdbMessage::Connect: qWarning() << "Server received QdbMessage::Connect while already connected. Resetting."; + checkVersion(message); resetServer(true); break; case QdbMessage::Open: @@ -182,10 +185,15 @@ void Server::resetServer(bool hostConnected) m_executors.clear(); m_streams.clear(); m_state = hostConnected ? ServerState::Connected : ServerState::Disconnected; - enqueueMessage(QdbMessage{QdbMessage::Connect, 0, 0}); + + QByteArray buffer{}; + QDataStream dataStream{&buffer, QIODevice::WriteOnly}; + dataStream << qdbProtocolVersion; + + enqueueMessage(QdbMessage{QdbMessage::Connect, 0, 0, buffer}); } -void Server::handleWrite(QdbMessage message) +void Server::handleWrite(const QdbMessage &message) { if (m_streams.find(message.deviceStream()) == m_streams.end()) { qWarning() << "Server received message to non-existing stream" << message.deviceStream(); @@ -216,3 +224,18 @@ void Server::closeStream(StreamId id) // Closes are not acknowledged } +void Server::checkVersion(const QdbMessage &message) +{ + Q_ASSERT(message.command() == QdbMessage::Connect); + Q_ASSERT(message.data().size() == sizeof(qdbProtocolVersion)); + + QDataStream dataStream{message.data()}; + uint32_t protocolVersion; + dataStream >> protocolVersion; + + if (protocolVersion != qdbProtocolVersion) { + qWarning() << "Protocol version" << protocolVersion << "requested, but only version" + << qdbProtocolVersion << "is known"; + } +} + diff --git a/qdbd/server.h b/qdbd/server.h index 9c963f9..6f5d36a 100644 --- a/qdbd/server.h +++ b/qdbd/server.h @@ -54,8 +54,9 @@ private: void processQueue(); void handleOpen(StreamId hostId, const QByteArray &tag); void resetServer(bool hostConnected); - void handleWrite(QdbMessage message); + void handleWrite(const QdbMessage &message); void closeStream(StreamId id); + void checkVersion(const QdbMessage &message); ServerState m_state; std::unordered_map<StreamId, std::unique_ptr<Executor>> m_executors; |