20 #ifndef SYNCPROTOCOL_HPP_ 21 #define SYNCPROTOCOL_HPP_ 24 #include <QDataStream> 25 #include <QAbstractSocket> 36 const QDataStream::Version SYNC_DATASTREAM_VERSION = QDataStream::Qt_5_0;
40 typedef quint16 tPayloadSize;
46 SyncProtocol::tPayloadSize dataSize;
55 const qint64 SYNC_HEADER_SIZE =
sizeof(quint8) +
sizeof(tPayloadSize);
56 const qint64 SYNC_MAX_PAYLOAD_SIZE = (2<<15) - 1;
57 const qint64 SYNC_MAX_MESSAGE_SIZE = SYNC_HEADER_SIZE + SYNC_MAX_PAYLOAD_SIZE;
65 CLIENT_CHALLENGE_RESPONSE,
66 SERVER_CHALLENGERESPONSEVALID,
75 MSGTYPE_SIZE = MSGTYPE_MAX+1
81 case SyncProtocol::ERROR:
84 case SyncProtocol::SERVER_CHALLENGE:
85 deb<<
"SERVER_CHALLENGE";
87 case SyncProtocol::CLIENT_CHALLENGE_RESPONSE:
88 deb<<
"CLIENT_CHALLENGE_RESPONSE";
90 case SyncProtocol::SERVER_CHALLENGERESPONSEVALID:
91 deb<<
"SERVER_CHALLENGERESPONSEVALID";
93 case SyncProtocol::TIME:
96 case SyncProtocol::LOCATION:
99 case SyncProtocol::SELECTION:
102 case SyncProtocol::ALIVE:
106 deb<<
"UNKNOWN("<<int(msg)<<
')';
125 qint64 createFullMessage(QByteArray& target)
const;
129 virtual void serialize(QDataStream& stream)
const;
132 virtual bool deserialize(QDataStream& stream, SyncProtocol::tPayloadSize dataSize);
135 static void writeString(QDataStream& stream,
const QString& str);
136 static QString readString(QDataStream& stream);
146 SyncRemotePeer(QAbstractSocket* socket,
bool isServer,
const QVector<SyncMessageHandler*>& handlerList);
150 void receiveMessage();
155 void writeData(
const QByteArray& data,
int size=-1);
157 void writeError(
const QString& err);
160 void peerLog(
const QString& msg);
163 QAbstractSocket* sock;
166 bool isAuthenticated;
167 bool authResponseSent;
170 qint64 lastReceiveTime;
172 QVector<SyncMessageHandler*> handlerList;
173 QByteArray msgWriteBuffer;
185 virtual bool handleMessage(QDataStream& stream,
SyncRemotePeer& peer) = 0;
188 Q_DECLARE_INTERFACE(
SyncMessageHandler,
"Stellarium/RemoteSync/SyncMessageHandler/1.0")
Base interface for message handlers, i.e. reacting to messages.
Contains sync protocol data definitions shared between client and server.
Handling the connection to a remote peer (i.e. all clients on the server, and the server on the clien...
QDataStream & operator>>(QDataStream &in, SyncHeader &header)
Read a SyncHeader from a DataStream.
SyncMessageType
Contains the possible message types.
const QByteArray SYNC_MAGIC_VALUE
Magic value for protocol used during connection. Should NEVER change.
const quint8 SYNC_PROTOCOL_VERSION
Should be changed with every breaking change.
Base interface for the messages themselves, allowing to serialize/deserialize them.
QDataStream & operator<<(QDataStream &out, const SyncHeader &header)
Write a SyncHeader to a DataStream.