Classified ads
cadbrecordmodel.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Järvinen 2013-2016.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef CLASSIFIED_CADBRECORDMODEL_H
22 #define CLASSIFIED_CADBRECORDMODEL_H
23 #include <QPair>
24 #include "../mcontroller.h" // because enum from there is needed
25 #include "../net/protocol.h" // for SendQueueItem
26 #include "datamodelbase.h"
27 #include <limits>
28 
29 class Hash ;
31 class CaDbRecord ;
32 
44 class CaDbRecordModel : public ModelBase {
45  Q_OBJECT
46 
47 public:
48  CaDbRecordModel(MController *aMController,
49  const MModelProtocolInterface &aModel) ;
51 
72  QString publishDbRecord(CaDbRecord& aRecord,
73  const QList<Hash>* aRecordReaders = NULL ) ;
74 
134  QList<CaDbRecord *> searchRecords(const Hash& aFromCollection,
135  const Hash& aById = KNullHash,
136  const quint32 aModifiedAfter = 0 ,
137  const quint32 aModifiedBefore = std::numeric_limits<quint32>::max(),
138  const qint64 aByHavingNumberMoreThan = std::numeric_limits<qint64>::min(),
139  const qint64 aByHavingNumberLessThan = std::numeric_limits<qint64>::max(),
140  const QString& aBySearchPhrase = QString::null,
141  const Hash& aBySender = KNullHash,
142  const bool aForPublish = false ) ;
143 
144 
157  const QByteArray& aSignature,
158  const QList<quint32>& aBangPath,
159  const Hash& aFromNode) ;
169  bool sentCaDbRecordReceived(CaDbRecord& aRecord,
170  const QByteArray& aSignature,
171  const Hash& aFromNode ) ;
172 
191  void fillBucket(QList<SendQueueItem>& aSendQueue,
192  const Hash& aStartOfBucket,
193  const Hash& aEndOfBucket,
194  quint32 aLastMutualConnectTime,
195  const Hash& aForNode );
196 
197 private: // methods
204  const QByteArray& aSignature,
205  const QList<quint32>& aBangPath,
206  const Hash& aFromNode,
207  bool aWasPublish);
208 
209  QString persistDbRecordIntoDb(const CaDbRecord &aRecord,
210  bool aIsNew,
211  const QByteArray& aSignature,
212  quint32 aReceivedFrom ) ;
213 
221  QString isRecordNew(const CaDbRecord &aRecord,
222  bool* aResult,
223  quint32* aTimestampOfOldRecord = NULL ) ;
224 
241  bool tryVerifyRecord(CaDbRecord& aRecord,
242  const QByteArray& aSignature,
243  QList<QPair<Hash,Hash> >& aListOfGoodSignatures ) ;
244 
245  void deleteRecord(const Hash& aRecordId,
246  const Hash& aSenderId) ;
247  void updateRecordVerification(const Hash& aRecordId,
248  const Hash& aSenderId,
249  bool aNewVerificationStatus) ;
250  void updateFTS(const CaDbRecord& aRecord,
251  bool aIsNewRecord ) ;
252 
253 signals:
255  const QString& aExplanation) ;
257  void contentReceived(const Hash& aHashOfContent,
258  const Hash& aHashOfCollection,
259  const ProtocolItemType aTypeOfReceivedContent) ;
260 private: // member variables:
263 } ;
264 #endif
bool tryVerifyRecord(CaDbRecord &aRecord, const QByteArray &aSignature, QList< QPair< Hash, Hash > > &aListOfGoodSignatures)
void updateRecordVerification(const Hash &aRecordId, const Hash &aSenderId, bool aNewVerificationStatus)
MController * iController
Definition: cadbrecordmodel.h:261
QString isRecordNew(const CaDbRecord &aRecord, bool *aResult, quint32 *aTimestampOfOldRecord=NULL)
QString persistDbRecordIntoDb(const CaDbRecord &aRecord, bool aIsNew, const QByteArray &aSignature, quint32 aReceivedFrom)
void deleteRecord(const Hash &aRecordId, const Hash &aSenderId)
void error(MController::CAErrorSituation aError, const QString &aExplanation)
CaDbRecordModel(MController *aMController, const MModelProtocolInterface &aModel)
bool sentCaDbRecordReceived(CaDbRecord &aRecord, const QByteArray &aSignature, const Hash &aFromNode)
QList< CaDbRecord * > searchRecords(const Hash &aFromCollection, const Hash &aById=KNullHash, const quint32 aModifiedAfter=0, const quint32 aModifiedBefore=std::numeric_limits< quint32 >::max(), const qint64 aByHavingNumberMoreThan=std::numeric_limits< qint64 >::min(), const qint64 aByHavingNumberLessThan=std::numeric_limits< qint64 >::max(), const QString &aBySearchPhrase=QString::null, const Hash &aBySender=KNullHash, const bool aForPublish=false)
Hash is class that carries 160-bit digest.
Definition: hash.h:38
CAErrorSituation
Definition: mcontroller.h:57
const MModelProtocolInterface & iModel
Definition: cadbrecordmodel.h:262
bool publishedCaDbRecordReceived(CaDbRecord &aRecord, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aFromNode)
ProtocolItemType
Definition: protocol.h:157
void contentReceived(const Hash &aHashOfContent, const Hash &aHashOfCollection, const ProtocolItemType aTypeOfReceivedContent)
bool doHandlepublishedOrSentRecord(CaDbRecord &aRecord, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aFromNode, bool aWasPublish)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:46
void fillBucket(QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:48
datamodel-parts common part. this is inherited and contains common funcs
Definition: datamodelbase.h:39
Hash KNullHash
QString publishDbRecord(CaDbRecord &aRecord, const QList< Hash > *aRecordReaders=NULL)
method for storing and publishing a database record.
void updateFTS(const CaDbRecord &aRecord, bool aIsNewRecord)
This is is part of datamodel for storing database records.
Definition: cadbrecordmodel.h:44
Data record in distributed database.
Definition: cadbrecord.h:35