From 458c3278a4b9102bcc470d48816fac379492a588 Mon Sep 17 00:00:00 2001 From: Janne Koschinski Date: Wed, 11 Apr 2018 01:58:09 +0200 Subject: [PATCH] protocol: Implement 64-bit message timestamps Add serialization and feature flag for 64-bit message timestamp. Avoids a Y2038 problem and offers higher message time accuracy. Closes GH-340. --- src/common/message.cpp | 30 ++++++++++++++++++++++++------ src/common/quassel.h | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/common/message.cpp b/src/common/message.cpp index 873458f2..34990c64 100644 --- a/src/common/message.cpp +++ b/src/common/message.cpp @@ -52,10 +52,19 @@ Message::Message(const QDateTime &ts, const BufferInfo &bufferInfo, Type type, c QDataStream &operator<<(QDataStream &out, const Message &msg) { + Q_ASSERT(SignalProxy::current()); + Q_ASSERT(SignalProxy::current()->targetPeer()); + // We do not serialize the sender prefixes until we have a new protocol or client-features implemented - out << msg.msgId() - << (quint32) msg.timestamp().toTime_t() - << (quint32) msg.type() + out << msg.msgId(); + + if (SignalProxy::current()->targetPeer()->hasFeature(Quassel::Feature::LongMessageTime)) { + out << (quint64) msg.timestamp().toMSecsSinceEpoch(); + } else { + out << (quint32) msg.timestamp().toTime_t(); + } + + out << (quint32) msg.type() << (quint8) msg.flags() << msg.bufferInfo() << msg.sender().toUtf8(); @@ -70,11 +79,20 @@ QDataStream &operator<<(QDataStream &out, const Message &msg) QDataStream &operator>>(QDataStream &in, Message &msg) { + Q_ASSERT(SignalProxy::current()); + Q_ASSERT(SignalProxy::current()->sourcePeer()); + in >> msg._msgId; - quint32 timeStamp; - in >> timeStamp; - msg._timestamp = QDateTime::fromTime_t(timeStamp); + if (SignalProxy::current()->sourcePeer()->hasFeature(Quassel::Feature::LongMessageTime)) { + quint64 timeStamp; + in >> timeStamp; + msg._timestamp = QDateTime::fromMSecsSinceEpoch(timeStamp); + } else { + quint32 timeStamp; + in >> timeStamp; + msg._timestamp = QDateTime::fromTime_t(timeStamp); + } quint32 type; in >> type; diff --git a/src/common/quassel.h b/src/common/quassel.h index 88b22546..aa155e88 100644 --- a/src/common/quassel.h +++ b/src/common/quassel.h @@ -131,6 +131,7 @@ public: SenderPrefixes, ///< Show prefixes for senders in backlog RemoteDisconnect, ///< Allow this peer to be remotely disconnected ExtendedFeatures, ///< Extended features + LongMessageTime, ///< Serialize message time as 64-bit #if QT_VERSION >= 0x050500 EcdsaCertfpKeys, ///< ECDSA keys for CertFP in identities #endif -- 2.20.1