Classified ads
Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CaDbRecordModel Class Reference

This is is part of datamodel for storing database records. More...

#include <cadbrecordmodel.h>

Inheritance diagram for CaDbRecordModel:
Inheritance graph
Collaboration diagram for CaDbRecordModel:
Collaboration graph


void error (MController::CAErrorSituation aError, const QString &aExplanation)
void contentReceived (const Hash &aHashOfContent, const Hash &aHashOfCollection, const ProtocolItemType aTypeOfReceivedContent)
- Signals inherited from ModelBase
void error (MController::CAErrorSituation aError, const QString &aExplanation)

Public Member Functions

 CaDbRecordModel (MController *aMController, const MModelProtocolInterface &aModel)
 ~CaDbRecordModel ()
QString publishDbRecord (CaDbRecord &aRecord, const QList< Hash > *aRecordReaders=NULL)
 method for storing and publishing a database record. More...
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)
bool publishedCaDbRecordReceived (CaDbRecord &aRecord, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aFromNode)
bool sentCaDbRecordReceived (CaDbRecord &aRecord, const QByteArray &aSignature, const Hash &aFromNode)
void fillBucket (QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
- Public Member Functions inherited from ModelBase
 ModelBase (QString aDataTableName, unsigned aMaxRowsToKeep)
 ~ModelBase ()
bool setTimeLastReference (const Hash &aObjectFingerPrint, quint32 aTimeWhenLastReferenced)
unsigned getMaxRowsToKeep ()
void setMaxRowsToKeep (unsigned aRows)
void truncateDataTableToMaxRows (void)
void updateDbTableRowCount ()

Private Member Functions

bool doHandlepublishedOrSentRecord (CaDbRecord &aRecord, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aFromNode, bool aWasPublish)
QString persistDbRecordIntoDb (const CaDbRecord &aRecord, bool aIsNew, const QByteArray &aSignature, quint32 aReceivedFrom)
QString isRecordNew (const CaDbRecord &aRecord, bool *aResult, quint32 *aTimestampOfOldRecord=NULL)
bool tryVerifyRecord (CaDbRecord &aRecord, const QByteArray &aSignature, QList< QPair< Hash, Hash > > &aListOfGoodSignatures)
void deleteRecord (const Hash &aRecordId, const Hash &aSenderId)
void updateRecordVerification (const Hash &aRecordId, const Hash &aSenderId, bool aNewVerificationStatus)
void updateFTS (const CaDbRecord &aRecord, bool aIsNewRecord)

Private Attributes

const MModelProtocolInterfaceiModel

Additional Inherited Members

- Protected Attributes inherited from ModelBase
QString iDataTableName
unsigned iMaxRowsToKeep
unsigned iCurrentDbTableRowCount

Detailed Description

This is is part of datamodel for storing database records.

Because classified ads is a distributed database that holds ads, profiles, private messages and profile comments, the same storage implementation can be extended to general-purpose database records. This is the implementation of local storage for those records. See CaDbRecord for records. This same API is available via TCL interface with different syntax but same concepts.

Constructor & Destructor Documentation

◆ CaDbRecordModel()

CaDbRecordModel::CaDbRecordModel ( MController aMController,
const MModelProtocolInterface aModel 

◆ ~CaDbRecordModel()

CaDbRecordModel::~CaDbRecordModel ( )

Member Function Documentation

◆ contentReceived

void CaDbRecordModel::contentReceived ( const Hash aHashOfContent,
const Hash aHashOfCollection,
const ProtocolItemType  aTypeOfReceivedContent 

emitted when new record is received

◆ deleteRecord()

void CaDbRecordModel::deleteRecord ( const Hash aRecordId,
const Hash aSenderId 

◆ doHandlepublishedOrSentRecord()

bool CaDbRecordModel::doHandlepublishedOrSentRecord ( CaDbRecord aRecord,
const QByteArray &  aSignature,
const QList< quint32 > &  aBangPath,
const Hash aFromNode,
bool  aWasPublish 

Workhorse of methods sentDbRecordReceived and publishedDbRecordReceived

true on success

◆ error

void CaDbRecordModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 

◆ fillBucket()

void CaDbRecordModel::fillBucket ( QList< SendQueueItem > &  aSendQueue,
const Hash aStartOfBucket,
const Hash aEndOfBucket,
quint32  aLastMutualConnectTime,
const Hash aForNode 

Method for filling connected peers send queue with items that we have and that belong to said peers bucket.

aSendQueueis send-queue of the connection that serves particular node
aStartOfBucketis hash where bucket of that peer starts. In practice it is the hash of the node itself.
aEndOfBucketis hash where bucket of that peer ends. That in turn depends on network size, or number of active nodes in the network. See method NodeModel::bucketEndHash for details.
aLastMutualConnectTimetime when node was last in contact. In practice we'll fill the bucket items published after this time.

◆ isRecordNew()

QString CaDbRecordModel::isRecordNew ( const CaDbRecord aRecord,
bool *  aResult,
quint32 *  aTimestampOfOldRecord = NULL 

method for checking if db record is in db already.

aRecordis the record to check
aResultgets set to true/false as result
aTimestampOfOldRecordif aResult get set to true, this gets set to timestamp of previously persisted record

◆ persistDbRecordIntoDb()

QString CaDbRecordModel::persistDbRecordIntoDb ( const CaDbRecord aRecord,
bool  aIsNew,
const QByteArray &  aSignature,
quint32  aReceivedFrom 

◆ publishDbRecord()

QString CaDbRecordModel::publishDbRecord ( CaDbRecord aRecord,
const QList< Hash > *  aRecordReaders = NULL 

method for storing and publishing a database record.

Database records are published to the network when persisted. There is separate local storage for data not meant to be shared at the network but database records do get published to all nodes in the network.

aRecordThe db record to be published
aRecordReadersOptional list of profile fingerprints to whom the record will be encrypted to. Only those profiles will be able to read the record. This list is considered only when CaDbRecord::iIsEncrypted is true. If record is set to be encrypted, and this list is empty, the readers of the currently selected profile will be the readers of the record. If profile is public ( there is no list of readers ) and record is set to be encrypted then this list must contain at least one profile.
empty string if success, or error message

◆ publishedCaDbRecordReceived()

bool CaDbRecordModel::publishedCaDbRecordReceived ( CaDbRecord aRecord,
const QByteArray &  aSignature,
const QList< quint32 > &  aBangPath,
const Hash aFromNode 

called by protocol parser when a db record is received

aSignatureis digital signature of the payload of the record
aBangPathis list of last nodes where this content has been, idea is to prevent re-sending content to somewhere where it has already been
aFromNodehash of node sending the record to us
true on success

◆ searchRecords()

QList<CaDbRecord *> CaDbRecordModel::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 

Method for retrieving db records. See CaDbRecord for records being fetched. Limiting criteria can be specified using several optional parameters. Those parameters are considered together using "AND" operation, meaning they all need to be satisfied at the same time for a record to be returned. For example, if both "by sender" and "modified after" parameters are given, result set contains only records from that given profile and whose publish time is after given time.

This may have a side-effect when search terms are broad (like, only collection specified) and it may be suspected that the search is not fully served what it comes to potential resultset, this method may give the query to DbRecordRetrievalEngine that will spam the network with the query. More records from neighboring network nodes fitting the search criteria may then start appearing into database. TCL app that originated the query will receive notifications about new records but it will still need to use this same method here to fetch contents of the new records. In particular, if record is queried using aById parameter and the record is found, then no network-query is started.

aFromCollectionReturns records whose CaDbRecord::iCollectionId match this parameter. Either this or aById argument must be given. Specifying only this will return whole collection that may be huge.
aByIdReturns record whose CaDbRecord::iRecordId matches. Result-set is either empty or contains one record. If user passes KNullHash here then value of this argument is simply ignored and search method will return records fitting criteria stated by other method arguments like aBySearchPhrase. In theory it is possible that 2 users end up publishing a record with same id but that should be fairly rare occasion.
aModifiedAfterReturns records that have last been modified after given time. Time of modification is stored in CaDbRecord::iTimeOfPublish.
aModifiedBeforeReturns records that have last been modified before given time.
aByHavingNumberMoreThanReturns records whose CaDbRecord::iSearchNumber is more or equal than number given here.
aByHavingNumberLessThanReturns records whose CaDbRecord::iSearchNumber is less or equal than number given here.
aBySearchPhraseReturns records whose CaDbRecord::iSearchPhrase matches the string given here, according to rules of sqlite FTS string matching implementation.
aBySenderReturns only records published by profile given in this argument.
aForPublishif set to true, data-parts of the records are returned un-altered from database. Normally records are de-crypted and un-compressed before getting returned but if record is meant to be sent to another node, the bitstream must be exactly the one that got signed.
Pointer array of db records. Caller is responsible for deleting the returned records.

◆ sentCaDbRecordReceived()

bool CaDbRecordModel::sentCaDbRecordReceived ( CaDbRecord aRecord,
const QByteArray &  aSignature,
const Hash aFromNode 

called by protocol parser when a record is received by "send" protocol type

aSignatureis digital signature of the payload of the record
aFromNodehash of node sending the record to us
true on success

◆ tryVerifyRecord()

bool CaDbRecordModel::tryVerifyRecord ( CaDbRecord aRecord,
const QByteArray &  aSignature,
QList< QPair< Hash, Hash > > &  aListOfGoodSignatures 

method tries to verify record. if verification is ok, it sets CaDbRecord::iIsSignatureVerified to true value.

aRecordrecord to verify
aSignaturesignature to verify against. The party assumed to have signed the record is CaDbRecord::iSenderHash.
aListOfGoodSignaturescontains list of records that verify ok. Method adds record to list if it is previously not verified and now verifies ok.
true if signature was good or there was no profile to check against. returns false if profile was there but signature did not verify.

◆ updateFTS()

void CaDbRecordModel::updateFTS ( const CaDbRecord aRecord,
bool  aIsNewRecord 

◆ updateRecordVerification()

void CaDbRecordModel::updateRecordVerification ( const Hash aRecordId,
const Hash aSenderId,
bool  aNewVerificationStatus 

Member Data Documentation

◆ iController

MController* CaDbRecordModel::iController

◆ iModel

const MModelProtocolInterface& CaDbRecordModel::iModel

The documentation for this class was generated from the following file: