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

This is is part of datamodel for storing private messages. More...

#include <privmsgmodel.h>

Inheritance diagram for PrivMessageModel:
Inheritance graph
[legend]
Collaboration diagram for PrivMessageModel:
Collaboration graph
[legend]

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)
 
PrivMessagemessageByFingerPrint (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< HashmessagesForProfile (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

MControlleriController
 
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 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:

Constructor & Destructor Documentation

PrivMessageModel::PrivMessageModel ( MController aMController,
const MModelProtocolInterface aModel 
)
PrivMessageModel::~PrivMessageModel ( )

Member Function Documentation

void PrivMessageModel::contentReceived ( const Hash aHashOfContent,
const Hash aHashOfRecipientProfile,
const ProtocolItemType  aTypeOfReceivdContent 
)
signal

emitted when new message is received

bool PrivMessageModel::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

Workhorse of methods publishedPrivMessageReceived and sentPrivMessageReceived

Returns
true on success
void PrivMessageModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
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.

Parameters
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.
PrivMessage* PrivMessageModel::messageByFingerPrint ( const Hash aFingerPrint)

gets a message. caller is supposed to delete the returned profile.

Parameters
aFingerPrintmessaqe serial number
Returns
message or NULL
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.

Parameters
aFingerPrintmessage serial number
aResultingPrivMessageDatawill contain message data
aResultingSignaturewill contain message signature
aResultingDestinationNodeoutput 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.
aResultingRecipientoutput parameter will get its value set to fingerprint of the profile that is supposed to read the msg
aTimeOfPublishis output variable, if non-NULL, will get its value set to time of publish of the message
Returns
true if message was found
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.

Parameters
aProfileHashoperator profile fingerprint whose messages are requested.
aLastMutualConnectTimemessages that are sent afer aLastMutualConnectTime will be returned.
Returns
list of message fingerprints
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

Parameters
aFingerPrintis the message Hash received from protocol header
aContentis actual message data
aSignatureis digital signature of the aContent
aBangPathis list of last nodes where this content has been, idea is to prevent re-sending content to somewhere where it has already been
aDestinationNodenode where the message should be delivered to ; may be nullhash
aRecipientrecipient profile hash
aTimeStamptimestamp of message (if encrypted, it must be carried outside..)
aFromNodehash of node sending the message to us
Returns
true on success
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.

Parameters
aPrivMessageis 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.
aDestinationNodeif node of the recipient is known, it may be given here.
Returns
true if things went all right
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

Parameters
aFingerPrintis the message Hash received from protocol header
aContentis actual message data
aSignatureis digital signature of the aContent
aDestinationNodenode where the message should be delivered to ; may be nullhash
aRecipientrecipient profile hash
aFlagpossible flags telling about encyption and compression
aTimeStamptimestamp of message (if encrypted, it must be carried outside..)
Returns
true on success
void PrivMessageModel::setAsRead ( const Hash aMessageHash,
bool  aIsRead 
)

method for marking private message as read

Member Data Documentation

MController* PrivMessageModel::iController
private
const MModelProtocolInterface& PrivMessageModel::iModel
private

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