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

This is node-specific part of the datamodel. More...

#include <nodemodel.h>

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

Signals

void error (MController::CAErrorSituation aError, const QString &aExplanation)
 
- Signals inherited from ModelBase
void error (MController::CAErrorSituation aError, const QString &aExplanation)
 

Public Member Functions

 NodeModel (MController *aController, const Model &aModel)
 
 ~NodeModel ()
 
virtual HashnodeFingerPrint ()
 
virtual int listenPortOfThisNode ()
 
virtual void setListenPortOfThisNode (int port)
 
virtual const QSslCertificate & nodeCert () const
 
virtual const QSslKey & nodeKey () const
 
virtual QByteArray * getNextItemToSend (Connection &aConnection)
 
virtual NodenodeByHash (const Hash &aHash)
 
virtual QList< HostConnectQueueItemgetHotAddresses ()
 
QList< Node * > * getHotNodes (int aMaxNodes)
 
virtual bool nodeGreetingReceived (Node &aNode, bool aWasInitialGreeting=false)
 
virtual QList< Node * > * getNodesAfterHash (const Hash &aHash, unsigned aMaxNodes, int aMaxInactivityMinutes=-1)
 
bool updateNodeLastConnectTimeInDb (Node &aNode)
 
virtual bool updateNodeLastMutualConnectTimeInDb (const Hash &aNodeFp, quint32 aTime)
 
virtual QList< Node * > * getNodesBeforeHash (const Hash &aHash, unsigned aMaxNodes)
 
virtual void closeOldestInactiveConnection ()
 
QString dataDir ()
 
virtual void addNodeFromBroadcast (const Hash &aNodeFingerPrint, const QHostAddress &aAddr, int aPort)
 
virtual bool addNodeToConnectionWishList (Node *aNode)
 
virtual bool addNodeToConnectionWishList (const Hash &aNode)
 
virtual NodenextConnectionWishListItem ()
 
virtual bool isNodeAlreadyConnected (const Node &aNode) const
 
virtual bool isNodeAlreadyConnected (const Hash &aHash) const
 
virtual Hash bucketEndHash (const Hash &aFingerPrintOfNodeAsking)
 
virtual void setDnsName (QString aName)
 
virtual QString getDnsName ()
 
virtual void offerNodeToRecentlyFailedList (const Hash &aFailedNodeHash)
 
- 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 ()
 

Protected Member Functions

bool insertNodeToDb (Node &aNode)
 
bool updateNodeInDb (Node &aNode)
 
void retrieveListOfHotConnections ()
 
void timerEvent (QTimerEvent *event)
 

Private Member Functions

bool openOrCreateSSLCertificate ()
 
bool saveSslCertToDb (const QByteArray &aCert)
 
bool saveSslKeyToDb (const QByteArray &aKey)
 
bool loadSslCertFromDb ()
 
bool loadSslKeyFromDb ()
 
void deleteOldestConnectedNode ()
 
void countNodes ()
 
Q_IPV6ADDR ipv6AddrFromUints (quint32 aLeastSignificant, quint32 aLessSignificant, quint32 aMoreSignificant, quint32 aMostSignificant) const
 
void removeNodeFromRecentlyFailedList (const Hash &aConnectedHostFingerPrint)
 

Private Attributes

MControlleriController
 
HashiFingerPrintOfThisNode
 
QSslCertificate * iThisNodeCert
 
QSslKey * iThisNodeKey
 
QList< HostConnectQueueItemiHotAddresses
 
const ModeliModel
 
QString iDataDir
 
QList< Node * > iConnectionWishList
 
QList< QPair< Hash, unsigned > > iRecentlyFailedNodes
 
int iTimerId
 

Additional Inherited Members

- Public Types inherited from MNodeModelProtocolInterface
typedef struct MNodeModelProtocolInterface::HostConnectQueueItemStructure HostConnectQueueItem
 
- Protected Attributes inherited from ModelBase
QString iDataTableName
 
unsigned iMaxRowsToKeep
 
unsigned iCurrentDbTableRowCount
 

Detailed Description

This is node-specific part of the datamodel.

This is node-specific part of the datamodel ; this handled storage and handling of data that is directly related to nodes themselves. Node is a peer in network.

Constructor & Destructor Documentation

◆ NodeModel()

NodeModel::NodeModel ( MController aController,
const Model aModel 
)

◆ ~NodeModel()

NodeModel::~NodeModel ( )

Member Function Documentation

◆ addNodeFromBroadcast()

virtual void NodeModel::addNodeFromBroadcast ( const Hash aNodeFingerPrint,
const QHostAddress &  aAddr,
int  aPort 
)
virtual

method for adding node reference from broadcast. this needs difference in handling because in IPv4 network this typically contains private addr space addresses that we don't want to permanently store nor give to others as node-references.

For making connections inside LANs of organisations having NATs and firewalls and whatnot this might still be a handy feature.

Implements MNodeModelProtocolInterface.

◆ addNodeToConnectionWishList() [1/2]

virtual bool NodeModel::addNodeToConnectionWishList ( Node aNode)
virtual

method for adding a node to connection-wishlist. network connector engine will then later pick them up. nodemodel will take ownership of the node and delete the object later.

Returns
true if connection was queued

Implements MNodeModelProtocolInterface.

◆ addNodeToConnectionWishList() [2/2]

virtual bool NodeModel::addNodeToConnectionWishList ( const Hash aNode)
virtual

method for adding a node to connection-wishlist. network connector engine will then later pick them up.

Returns
true if connection was queued

Implements MNodeModelProtocolInterface.

◆ bucketEndHash()

virtual Hash NodeModel::bucketEndHash ( const Hash aFingerPrintOfNodeAsking)
virtual

Important method regarding churn here. This is called from Connection class and this method is used to determine what content belongs to same bucket with the node that is being served by that Connection. Content in the same bucket with the node is then sent over to node ; to keep the content alive in the network.

Intent here is find bucket size where we have approximately 20 live nodes in a bucket. If size of nodes alive in network is less than 20, returned hash is same as the one given in argument, methods using the value must then implement something like "send all data".

This is done so that we order the recently-seen nodes by hash value of the node, then start from the fingerprint of the node that is asking, and from that point we count to 20. The fingerprint of the node at position 20 is the end of the bucket. The fingerprint of the node that asks is the start.

Parameters
aFingerPrintOfNodeAskingfingerprint of node that wants to have its bucket filled
Returns
Ending-address of the nodes bucket.

Implements MNodeModelProtocolInterface.

◆ closeOldestInactiveConnection()

virtual void NodeModel::closeOldestInactiveConnection ( )
virtual

method that picks up a connection that may be closed with smallest amount of hassle..

method also works a bit conditionally, it may be that if there is for instance a lot of connections from same subnet with us, it will not close any connection..

Implements MNodeModelProtocolInterface.

◆ countNodes()

void NodeModel::countNodes ( )
private

internal book-keeping

◆ dataDir()

QString NodeModel::dataDir ( )

Method that returns path of directory where datafiles are kept

◆ deleteOldestConnectedNode()

void NodeModel::deleteOldestConnectedNode ( )
private

prevent db table from overflowing

◆ error

void NodeModel::error ( MController::CAErrorSituation  aError,
const QString &  aExplanation 
)
signal

◆ getDnsName()

virtual QString NodeModel::getDnsName ( )
virtual

called from settings dialog and own node construction

Implements MNodeModelProtocolInterface.

◆ getHotAddresses()

virtual QList<HostConnectQueueItem> NodeModel::getHotAddresses ( )
virtual

method for getting node-connection prospects. lock() must be called by caller. This does not return addresses of nodes that are already connected-to. And this does not return address of this same node. Idea is to use this method internally to fish out some addresses that might be worth connecting.

Implements MNodeModelProtocolInterface.

◆ getHotNodes()

QList<Node *>* NodeModel::getHotNodes ( int  aMaxNodes)
virtual

method for getting node-connection prospects with idea that we make node-greetings out of those and send to neighboring node. This may and will also return address of this node and this may and will also return addresses of nodes currently connected ; it makes sense to give others list of addresses that are known to be online.

Parameters
aMaxNodesmax number of nodes to return
Returns
a qlist that the caller must delete after it is used.

Implements MNodeModelProtocolInterface.

◆ getNextItemToSend()

virtual QByteArray* NodeModel::getNextItemToSend ( Connection aConnection)
virtual

Method that network connections use to request for more stuff to send to peers

Parameters
aConnectionis the connection in question
Returns
octets in QByteArray. Ownership of bytes is transferred, datamodel does not keep a copy and caller is responsible for deleting the returned bytes after they've been sent.

Implements MNodeModelProtocolInterface.

◆ getNodesAfterHash()

virtual QList<Node *>* NodeModel::getNodesAfterHash ( const Hash aHash,
unsigned  aMaxNodes,
int  aMaxInactivityMinutes = -1 
)
virtual

Method for getting node-connection prospects around a given hash. This is used to obtain nodes that might contain content with hash-value near hash-values of nodes.

Parameters
aHashis hash where to start returning
aMaxNodesmax number of nodes to return
aMaxInactivityMinutesleave out nodes that have last activity time older than this many minutes, if negative value specified, just include all.
Returns
a qlist that the caller must delete after it is used.

Implements MNodeModelProtocolInterface.

◆ getNodesBeforeHash()

virtual QList<Node *>* NodeModel::getNodesBeforeHash ( const Hash aHash,
unsigned  aMaxNodes 
)
virtual

We'll try to maintain the connections in hash-space in ring-like structure where each node is connected to the adjacent node, "adjacency" means that nodes whose hash-values are closest to ours, are our adjacent nodes. For this purpose have methods for retrieving list of nodes just before us in the ring and later list of nodes just after us in the ring.

Implements MNodeModelProtocolInterface.

◆ insertNodeToDb()

bool NodeModel::insertNodeToDb ( Node aNode)
protected

◆ ipv6AddrFromUints()

Q_IPV6ADDR NodeModel::ipv6AddrFromUints ( quint32  aLeastSignificant,
quint32  aLessSignificant,
quint32  aMoreSignificant,
quint32  aMostSignificant 
) const
private

◆ isNodeAlreadyConnected() [1/2]

virtual bool NodeModel::isNodeAlreadyConnected ( const Node aNode) const
virtual

method for checking if a node is already connected. This will try matching against hash and network addresses.

Implements MNodeModelProtocolInterface.

◆ isNodeAlreadyConnected() [2/2]

virtual bool NodeModel::isNodeAlreadyConnected ( const Hash aHash) const
virtual

Method for checking if a node is already connected. This version checks only hash, not addresses.

Implements MNodeModelProtocolInterface.

◆ listenPortOfThisNode()

virtual int NodeModel::listenPortOfThisNode ( )
virtual

TCP listen port number method

Implements MNodeModelProtocolInterface.

◆ loadSslCertFromDb()

bool NodeModel::loadSslCertFromDb ( )
private

◆ loadSslKeyFromDb()

bool NodeModel::loadSslKeyFromDb ( )
private

◆ nextConnectionWishListItem()

virtual Node* NodeModel::nextConnectionWishListItem ( )
virtual

method for getting one node from wishlist. caller is obliged to delete the node returned.

Returns
node or null if there is nothing in wishlist

Implements MNodeModelProtocolInterface.

◆ nodeByHash()

virtual Node* NodeModel::nodeByHash ( const Hash aHash)
virtual

Method for getting node details by hash

Parameters
aHashtells which node to retrieve
Returns
node or NULL if not known

Implements MNodeModelProtocolInterface.

◆ nodeCert()

virtual const QSslCertificate& NodeModel::nodeCert ( ) const
virtual

getter for ssl certificate of SSL sock

Implements MNodeModelProtocolInterface.

◆ nodeFingerPrint()

virtual Hash& NodeModel::nodeFingerPrint ( )
virtual

returns fingerprint of this node

Implements MNodeModelProtocolInterface.

◆ nodeGreetingReceived()

virtual bool NodeModel::nodeGreetingReceived ( Node aNode,
bool  aWasInitialGreeting = false 
)
virtual

From MModelProtocolInterface.

Method related to node database handling ; generic node reference update method, that is used also to update reference of this node (self). NodeModel must be locked before this is used.

Practically this is called on 2 occasions: one is a new connection to peer, there peer sends node greeing as the first thing. This may trigger other things inside datamodel.

Second possibility is that we've asked for node references (around some hash) and then we'll receive.

Parameters
aNodeis the node that had its ref sent
aWasInitialGreetingis true if this call was due to initial node greeting sent just as first time after connect
Returns
true if data update was successful

Implements MNodeModelProtocolInterface.

◆ nodeKey()

virtual const QSslKey& NodeModel::nodeKey ( ) const
virtual

getter for ssl certificate of SSL sock

Implements MNodeModelProtocolInterface.

◆ offerNodeToRecentlyFailedList()

virtual void NodeModel::offerNodeToRecentlyFailedList ( const Hash aFailedNodeHash)
virtual

used to offer node to list of recently failed connections. this model maintains a list of such nodes and tries to not immediately re-connect a recently failed node

Implements MNodeModelProtocolInterface.

◆ openOrCreateSSLCertificate()

bool NodeModel::openOrCreateSSLCertificate ( )
private

opens the node cert that is for network traffic

◆ removeNodeFromRecentlyFailedList()

void NodeModel::removeNodeFromRecentlyFailedList ( const Hash aConnectedHostFingerPrint)
private

◆ retrieveListOfHotConnections()

void NodeModel::retrieveListOfHotConnections ( )
protected

◆ saveSslCertToDb()

bool NodeModel::saveSslCertToDb ( const QByteArray &  aCert)
private

◆ saveSslKeyToDb()

bool NodeModel::saveSslKeyToDb ( const QByteArray &  aKey)
private

◆ setDnsName()

virtual void NodeModel::setDnsName ( QString  aName)
virtual

called from settings dialog

Implements MNodeModelProtocolInterface.

◆ setListenPortOfThisNode()

virtual void NodeModel::setListenPortOfThisNode ( int  port)
virtual

Setting of TCP listen port number method

Implements MNodeModelProtocolInterface.

◆ timerEvent()

void NodeModel::timerEvent ( QTimerEvent *  event)
protected

for periodical stuff inside datamodel

◆ updateNodeInDb()

bool NodeModel::updateNodeInDb ( Node aNode)
protected

method for updating existing node in db table

Parameters
aNodeis the node to update
Returns
true if success

◆ updateNodeLastConnectTimeInDb()

bool NodeModel::updateNodeLastConnectTimeInDb ( Node aNode)
virtual

this is like updateNodeInDb but updates only the time of last connect

Implements MNodeModelProtocolInterface.

◆ updateNodeLastMutualConnectTimeInDb()

virtual bool NodeModel::updateNodeLastMutualConnectTimeInDb ( const Hash aNodeFp,
quint32  aTime 
)
virtual

method for updating last mutual connect time of a node

Implements MNodeModelProtocolInterface.

Member Data Documentation

◆ iConnectionWishList

QList<Node *> NodeModel::iConnectionWishList
private

◆ iController

MController* NodeModel::iController
private

◆ iDataDir

QString NodeModel::iDataDir
private

◆ iFingerPrintOfThisNode

Hash* NodeModel::iFingerPrintOfThisNode
private

set by method openOrCreateSSLCertificate

◆ iHotAddresses

QList<HostConnectQueueItem> NodeModel::iHotAddresses
private

◆ iModel

const Model& NodeModel::iModel
private

◆ iRecentlyFailedNodes

QList<QPair<Hash,unsigned> > NodeModel::iRecentlyFailedNodes
private

this variable holds list of nodes that we've tried to connect and failed. purpose of this is that we don't immediately try again

◆ iThisNodeCert

QSslCertificate* NodeModel::iThisNodeCert
private

set by method openOrCreateSSLCertificate

◆ iThisNodeKey

QSslKey* NodeModel::iThisNodeKey
private

set by method openOrCreateSSLCertificate

◆ iTimerId

int NodeModel::iTimerId
private

periodical timer


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