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

This is part of datamodel for any binary blobs. More...

#include <binaryfilemodel.h>

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

Signals

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

Public Member Functions

 BinaryFileModel (MController *aMController, const MModelProtocolInterface &aModel)
 
 ~BinaryFileModel ()
 
Hash publishBinaryFile (const Profile &aPublishingProfile, const QString &aFileName, const QString &aDescription, const QString &aMimeType, const QByteArray &aContents, bool aIsCompressed, bool aNoEncryption=false, const QList< Hash > *aBinaryRecipientList=NULL)
 
BinaryFilebinaryFileByFingerPrint (const Hash &aFingerPrint)
 
bool binaryFileDataByFingerPrint (const Hash &aFingerPrint, const Hash &aPresumedSender, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, bool *aIsBinaryFilePrivate)
 
bool publishedBinaryFileReceived (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
 
bool sentBinaryFileReceived (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
 
bool binaryFileDataForPublish (const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *iIsBinaryFileCompressed)
 
bool binaryFileDataForSend (const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *aIsBinaryFileCompressed, quint32 *aTimeOfPublish)
 
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 doFindBinaryFileForPublishOrSend (const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *aIsBinaryFileCompressed, quint32 *aTimeOfPublish)
 
bool doHandleReceivedFile (const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const 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 part of datamodel for any binary blobs.

Initially this is for "shared files" profile-functionality but this practically lets you share any octet-stream over DHT.

Constructor & Destructor Documentation

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

Member Function Documentation

BinaryFile* BinaryFileModel::binaryFileByFingerPrint ( const Hash aFingerPrint)

Gets a file. Caller is supposed to delete the returned object. Note that returned data contains metadata only, for actual content use method and because signature is calculated over metadata+content, this method does not yet check for signature -> it is checked when data is retrieved.

Parameters
aFingerPrintfile serial number (hash)
Returns
file or NULL
bool BinaryFileModel::binaryFileDataByFingerPrint ( const Hash aFingerPrint,
const Hash aPresumedSender,
QByteArray &  aResultingBinaryFileData,
QByteArray &  aResultingSignature,
bool *  aIsBinaryFilePrivate 
)

Method for getting file contents. Returned contents are un-encrypted already when returned by this method, and un-compressed. And signature is checked. Need to think a strategy around situation where we have a file but we don't have public key of its publisher ; in this case we just have no clue about origins of the file and this is possible situation too.

Parameters
aFingerPrintprofile serial number
aPresumedSenderis fingerprint of the file sender from file metadata -> file content verification against this key must succeed.
aResultingBinaryFileDatawill contain profile data
aResultingSignaturewill contain profile signature
aIsBinaryFilePrivatewill be set to true if aResultingBinaryFileData is encrypted.
Returns
true if file was found
bool BinaryFileModel::binaryFileDataForPublish ( const Hash aFingerPrint,
QByteArray &  aResultingBinaryFileData,
QByteArray &  aResultingSignature,
QByteArray &  aPublicKeyOfPublisher,
bool *  aIsBinaryFilePrivate,
bool *  iIsBinaryFileCompressed 
)

method that returns unaltered binary file metadata+data in single bytearray for purpose of publishing to other node

Returns
true if content was found
bool BinaryFileModel::binaryFileDataForSend ( const Hash aFingerPrint,
QByteArray &  aResultingBinaryFileData,
QByteArray &  aResultingSignature,
QByteArray &  aPublicKeyOfPublisher,
bool *  aIsBinaryFilePrivate,
bool *  aIsBinaryFileCompressed,
quint32 *  aTimeOfPublish 
)

method that returns unaltered binary file metadata+data in single bytearray for purpose of sending to other node

Returns
true if content was found
void BinaryFileModel::contentReceived ( const Hash aHashOfContent,
const ProtocolItemType  aTypeOfReceivdContent 
)
signal
bool BinaryFileModel::doFindBinaryFileForPublishOrSend ( const Hash aFingerPrint,
QByteArray &  aResultingBinaryFileData,
QByteArray &  aResultingSignature,
QByteArray &  aPublicKeyOfPublisher,
bool *  aIsBinaryFilePrivate,
bool *  aIsBinaryFileCompressed,
quint32 *  aTimeOfPublish 
)
private

workhorse of and

bool BinaryFileModel::doHandleReceivedFile ( const Hash aFingerPrint,
const QByteArray &  aContent,
const QByteArray &  aSignature,
const QList< quint32 > &  aBangPath,
const QByteArray &  aKeyOfPublisher,
const unsigned char  aFlags,
const quint32  aTimeStamp,
const bool  aWasPublish,
const Hash aFromNode 
)
private

workhorse of methods publishedBinaryFileReceived and sentBinaryFileReceived

void BinaryFileModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal
void BinaryFileModel::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.

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.
aForNodefingerprint of the node that asks for the bucket fill ; reason for this is the recvd_from column for preventing immediately re-sending content sent from a peer
Hash BinaryFileModel::publishBinaryFile ( const Profile aPublishingProfile,
const QString &  aFileName,
const QString &  aDescription,
const QString &  aMimeType,
const QByteArray &  aContents,
bool  aIsCompressed,
bool  aNoEncryption = false,
const QList< Hash > *  aBinaryRecipientList = NULL 
)

sends a file to selected nodes in network for others to retrieve.

Don't forget to re-publish the profile after successful completion of file publish as list of files is part of the profile itself.

Parameters
aPublishingProfileis the publishing profile ; it is used to sign the content and its privacy-settings are used decide if file content will be encrypted or not.
aFileNameis string telling original file-system file name
aDescriptionis free text describing the content
aMimeTypeis mime type, like application/octet-stream or image/gif
aContentsis the meat being thrown
aIsCompressedindicates if aContent should be uncompressed before use.
aNoEncryptionIf false then privateness of aPublishingProfile is used to decide if content gets encrypted during publish. If true then content will always go out without encryption. Use-case for this is attachment of public posting where everybody needs to be able to read, also when poster has private profile.
aBinaryRecipientListIs list of fingerprints of profiles whose keys will be used to encrypt the content. If these keys are given, then normal "readers of publishing profile" recipient-key-list method is not used. Use-case for this parameter is attachment of a private message; there is dual recipient (sender and receiver) and that's it.
Returns
Fingerprint of the published file or KNullHash if things went bad.
bool BinaryFileModel::publishedBinaryFileReceived ( const Hash aFingerPrint,
const QByteArray &  aContent,
const QByteArray &  aSignature,
const QList< quint32 > &  aBangPath,
const QByteArray &  aKeyOfPublisher,
const unsigned char  aFlags,
const quint32  aTimeStamp,
const Hash aFromNode 
)

called by protocol parser when a file is received due to publish

Parameters
aFingerPrintis the profile Hash received from protocol header
aContentis actual file data
aSignatureis digital signature of the aContent
aBangPathis list of low-order bits of hashes of nodes where this content has been. This is for preventing sending content back to nodes where it has already been.
aKeyOfPublisheris the key that was used to sign the file. that is transferred outside file just because the recipient might not have the key beforehand ; if she does, the existing key will be used in verifying process.
aFlagspossible flags telling about encyption and compression
aTimeStamptimestamp of file (if encrypted, it must be carried outside..)
aFromNodehash of the node that sent the file. low-order bits of the hash will be stored along with the content, serving as bang-path of length 1.
Returns
true on success
bool BinaryFileModel::sentBinaryFileReceived ( const Hash aFingerPrint,
const QByteArray &  aContent,
const QByteArray &  aSignature,
const QByteArray &  aKeyOfPublisher,
const unsigned char  aFlags,
const quint32  aTimeStamp,
const Hash aFromNode 
)

called by protocol parser when a file is received due to send

Parameters
aFingerPrintis the profile Hash received from protocol header
aContentis actual file data
aSignatureis digital signature of the aContent
aKeyOfPublisheris the key that was used to sign the file. that is transferred outside file just because the recipient might not have the key beforehand ; if she does, the existing key will be used in verifying process.
aFlagspossible flags telling about encyption and compression
aTimeStamptimestamp of file (if encrypted, it must be carried outside..)
aFromNodefingerprint of the node that sent the content
Returns
true on success

Member Data Documentation

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

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