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;
54 const qint64 SYNC_HEADER_SIZE =
sizeof(quint8) +
sizeof(tPayloadSize);
55 const qint64 SYNC_MAX_PAYLOAD_SIZE = (2<<15) - 1;
56 const qint64 SYNC_MAX_MESSAGE_SIZE = SYNC_HEADER_SIZE + SYNC_MAX_PAYLOAD_SIZE;
64 CLIENT_CHALLENGE_RESPONSE,
65 SERVER_CHALLENGERESPONSEVALID,
77 MSGTYPE_SIZE = MSGTYPE_MAX+1
83 case SyncProtocol::ERROR:
86 case SyncProtocol::SERVER_CHALLENGE:
87 deb<<
"SERVER_CHALLENGE";
89 case SyncProtocol::CLIENT_CHALLENGE_RESPONSE:
90 deb<<
"CLIENT_CHALLENGE_RESPONSE";
92 case SyncProtocol::SERVER_CHALLENGERESPONSEVALID:
93 deb<<
"SERVER_CHALLENGERESPONSEVALID";
95 case SyncProtocol::TIME:
98 case SyncProtocol::LOCATION:
101 case SyncProtocol::SELECTION:
104 case SyncProtocol::STELPROPERTY:
107 case SyncProtocol::VIEW:
110 case SyncProtocol::FOV:
113 case SyncProtocol::ALIVE:
117 deb<<
"UNKNOWN("<<int(msg)<<
')';
134 qint64 createFullMessage(QByteArray& target)
const;
138 virtual void serialize(QDataStream& stream)
const;
141 virtual bool deserialize(QDataStream& stream, SyncProtocol::tPayloadSize dataSize);
158 static void writeString(QDataStream& stream,
const QString& str);
159 static QString readString(QDataStream& stream);
171 SyncRemotePeer(QAbstractSocket* socket,
bool isServer,
const QVector<SyncMessageHandler*>& handlerList);
179 void writeData(
const QByteArray& data,
int size=-1);
181 void writeError(
const QString& err);
184 void peerLog(
const QString& msg)
const;
185 QDebug peerLog()
const;
187 bool isAuthenticated()
const {
return authenticated; }
188 QUuid getID()
const {
return id; }
191 void disconnectPeer();
193 QString getError()
const {
return errorString; }
195 void disconnected(
bool cleanDisconnect);
197 void sockDisconnected();
198 void sockError(QAbstractSocket::SocketError err);
199 void sockStateChanged(QAbstractSocket::SocketState state);
203 void receiveMessage();
205 QAbstractSocket* sock;
208 bool expectDisconnect;
212 bool authResponseSent;
215 qint64 lastReceiveTime;
217 QVector<SyncMessageHandler*> handlerList;
218 QByteArray msgWriteBuffer;
235 virtual bool handleMessage(QDataStream& stream, SyncProtocol::tPayloadSize dataSize,
SyncRemotePeer& peer) = 0;
244 stream.skipRawData(dataSize);
245 return !stream.status();
249 Q_DECLARE_INTERFACE(
SyncMessageHandler,
"Stellarium/RemoteSync/SyncMessageHandler/1.0")
Main class of the Field of View plugin.
Base interface for message handlers, i.e. reacting to messages.
Base interface for the messages themselves, allowing to serialize/deserialize them.
Contains sync protocol data definitions shared between client and server.
Server-side auth handler.
Reacts to Server challenge and challenge OK on the client.
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.
virtual SyncProtocol::SyncMessageType getMessageType() const =0
Subclasses must return the message type this message represents.
Skips the message, and does nothing else.
SyncMessageType
Contains the possible message types.
const QByteArray SYNC_MAGIC_VALUE
Magic value for protocol used during connection. Should NEVER change.
virtual QDebug debugOutput(QDebug dbg) const
Subclasses can override this to provide proper debug output.
const quint8 SYNC_PROTOCOL_VERSION
Should be changed with every breaking change.
virtual bool handleMessage(QDataStream &stream, SyncProtocol::tPayloadSize dataSize, SyncRemotePeer &peer)
Read a message directly from the stream.
QDataStream & operator<<(QDataStream &out, const SyncHeader &header)
Write a SyncHeader to a DataStream.