Classified ads
|
This is is part of datamodel for storing private messages. More...
#include <privmsgmodel.h>
Signals | |
void | error (MController::CAErrorSituation aError, const QString &aExplanation) |
void | contentReceived (const Hash &aHashOfContent, const Hash &aHashOfRecipientProfile, const ProtocolItemType aTypeOfReceivdContent) |
Signals inherited from ModelBase | |
void | error (MController::CAErrorSituation aError, const QString &aExplanation) |
Public Member Functions | |
PrivMessageModel (MController *aMController, const MModelProtocolInterface &aModel) | |
~PrivMessageModel () | |
bool | publishPrivMessage (PrivMessage &aPrivMessage, const Hash &aDestinationNode=KNullHash) |
PrivMessage * | messageByFingerPrint (const Hash &aFingerPrint) |
bool | messageDataByFingerPrint (const Hash &aFingerPrint, QByteArray &aResultingPrivMessageData, QByteArray &aResultingSignature, Hash *aResultingDestinationNode, Hash *aResultingRecipient, quint32 *aTimeOfPublish=NULL) |
bool | publishedPrivMessageReceived (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aDestinationNode, const Hash &aRecipient, const quint32 aTimeStamp, const Hash &aFromNode) |
bool | sentPrivMessageReceived (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const Hash &aDestinationNode, const Hash &aRecipient, const quint32 aTimeStamp, const Hash &fromNode) |
void | fillBucket (QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode) |
QList< Hash > | messagesForProfile (const Hash &aProfileHash, const quint32 aLastMutualConnectTime) |
void | setAsRead (const Hash &aMessageHash, bool aIsRead) |
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 | doHandlepublishedOrSentPrivMessage (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const Hash &aDestinationNode, const Hash &aRecipient, const quint32 aTimeStamp, bool aWasPublish, const Hash &aFromNode) |
Private Attributes | |
MController * | iController |
const MModelProtocolInterface & | iModel |
Additional Inherited Members | |
Protected Attributes inherited from ModelBase | |
QString | iDataTableName |
unsigned | iMaxRowsToKeep |
unsigned | iCurrentDbTableRowCount |
This is is part of datamodel for storing private messages.
Encryption keys related to messages need to be done using ContentEncryptionModel but after it has done its job, this part of datamodel handles that actual message-content.
Private messages are handled differently in (at least) one way worth mentioning: when other published content is sent over network, the content is accompanied by public key used to sign the content. Private messages have the public key of the content inside the content and the content is encrypted. This means 2 things:
PrivMessageModel::PrivMessageModel | ( | MController * | aMController, |
const MModelProtocolInterface & | aModel | ||
) |
PrivMessageModel::~PrivMessageModel | ( | ) |
|
signal |
emitted when new message is received
|
private |
Workhorse of methods publishedPrivMessageReceived and sentPrivMessageReceived
|
signal |
void PrivMessageModel::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.
Note that for private messages the bucket is kind of 2-way process. This method checks for private messages that are destined for this particular (connecting) node. In addition this method checks for messages where the destination profile belongs to bucket defined by aStartOfBucket/aEndOfBucket. In addition to these mechanisms this is also exploited by 3rd logick (possibly to be implemented in networkconnectorengine) that every-now-and-then creates connections to nodes that (according to hash) are supposed to contain private messages destined to profiles whose private keys we have in storage.
aSendQueue | is send-queue of the connection that serves particular node |
aStartOfBucket | is hash where bucket of that peer starts. In practice it is the hash of the node itself. |
aEndOfBucket | is 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. |
aLastMutualConnectTime | time when node was last in contact. In practice we'll fill the bucket items published after this time. |
PrivMessage* PrivMessageModel::messageByFingerPrint | ( | const Hash & | aFingerPrint | ) |
gets a message. caller is supposed to delete the returned profile.
aFingerPrint | messaqe serial number |
bool PrivMessageModel::messageDataByFingerPrint | ( | const Hash & | aFingerPrint, |
QByteArray & | aResultingPrivMessageData, | ||
QByteArray & | aResultingSignature, | ||
Hash * | aResultingDestinationNode, | ||
Hash * | aResultingRecipient, | ||
quint32 * | aTimeOfPublish = NULL |
||
) |
Gets a message. Because message is signed .. and that means that a particular byte-stream (containing actually a serialized json object) gets signed those bytes can't be altered or signature will not verify. This methods gets the actual signed bytestream that has been checked against a public key.
Note that this method does not check the signature any more, idea is that we don't store into db messages that fail the signature check so this method only gets the message, does not set it.
aFingerPrint | message serial number |
aResultingPrivMessageData | will contain message data |
aResultingSignature | will contain message signature |
aResultingDestinationNode | output parameter will get its value set to fingerprint of the node where the message is supposed to go. May come out as KNullHash if the node is not known. |
aResultingRecipient | output parameter will get its value set to fingerprint of the profile that is supposed to read the msg |
aTimeOfPublish | is output variable, if non-NULL, will get its value set to time of publish of the message |
QList<Hash> PrivMessageModel::messagesForProfile | ( | const Hash & | aProfileHash, |
const quint32 | aLastMutualConnectTime | ||
) |
method for getting list of messages destined for given operator that has been posted after the given date. This is called upon network protocol message KPrivMessagesForProfile.
aProfileHash | operator profile fingerprint whose messages are requested. |
aLastMutualConnectTime | messages that are sent afer aLastMutualConnectTime will be returned. |
bool PrivMessageModel::publishedPrivMessageReceived | ( | const Hash & | aFingerPrint, |
const QByteArray & | aContent, | ||
const QByteArray & | aSignature, | ||
const QList< quint32 > & | aBangPath, | ||
const Hash & | aDestinationNode, | ||
const Hash & | aRecipient, | ||
const quint32 | aTimeStamp, | ||
const Hash & | aFromNode | ||
) |
called by protocol parser when a message is received
aFingerPrint | is the message Hash received from protocol header |
aContent | is actual message data |
aSignature | is digital signature of the aContent |
aBangPath | is list of last nodes where this content has been, idea is to prevent re-sending content to somewhere where it has already been |
aDestinationNode | node where the message should be delivered to ; may be nullhash |
aRecipient | recipient profile hash |
aTimeStamp | timestamp of message (if encrypted, it must be carried outside..) |
aFromNode | hash of node sending the message to us |
bool PrivMessageModel::publishPrivMessage | ( | PrivMessage & | aPrivMessage, |
const Hash & | aDestinationNode = KNullHash |
||
) |
sends private message to selected nodes in network for others to retrieve. as a side-effect will update aPrivMessage.iFingerPrint, supposing the publish is successful.
aPrivMessage | is the message to publish. Messages are "sent" so that they're published into network. Recipient then may poll them. Networking logick will try to short-cut this if correct node seems to be already connected but in principle messages are sent by process of publish. |
aDestinationNode | if node of the recipient is known, it may be given here. |
bool PrivMessageModel::sentPrivMessageReceived | ( | const Hash & | aFingerPrint, |
const QByteArray & | aContent, | ||
const QByteArray & | aSignature, | ||
const Hash & | aDestinationNode, | ||
const Hash & | aRecipient, | ||
const quint32 | aTimeStamp, | ||
const Hash & | fromNode | ||
) |
called by protocol parser when a private message is received by "send" protocol type
aFingerPrint | is the message Hash received from protocol header |
aContent | is actual message data |
aSignature | is digital signature of the aContent |
aDestinationNode | node where the message should be delivered to ; may be nullhash |
aRecipient | recipient profile hash |
aFlag | possible flags telling about encyption and compression |
aTimeStamp | timestamp of message (if encrypted, it must be carried outside..) |
void PrivMessageModel::setAsRead | ( | const Hash & | aMessageHash, |
bool | aIsRead | ||
) |
method for marking private message as read
|
private |
|
private |