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< QPair
< QHostAddress, int > > 
getHotAddresses ()
 
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 void 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 ()
 
- 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 ()
 

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
 

Private Attributes

MControlleriController
 
HashiFingerPrintOfThisNode
 
QSslCertificate * iThisNodeCert
 
QSslKey * iThisNodeKey
 
QList< QPair< QHostAddress, int > > iHotAddresses
 
const ModeliModel
 
QString iDataDir
 
QList< Node * > iConnectionWishList
 

Additional Inherited Members

- 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 ( MController aController,
const Model aModel 
)
NodeModel::~NodeModel ( )

Member Function Documentation

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.

virtual void 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.

Implements MNodeModelProtocolInterface.

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.

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.

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.

void NodeModel::countNodes ( )
private

internal book-keeping

QString NodeModel::dataDir ( )

Method that returns path of directory where datafiles are kept

void NodeModel::deleteOldestConnectedNode ( )
private

prevent db table from overflowing

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

called from settings dialog and own node construction

Implements MNodeModelProtocolInterface.

virtual QList<QPair<QHostAddress,int> > 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.

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.

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.

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.

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.

bool NodeModel::insertNodeToDb ( Node aNode)
protected
Q_IPV6ADDR NodeModel::ipv6AddrFromUints ( quint32  aLeastSignificant,
quint32  aLessSignificant,
quint32  aMoreSignificant,
quint32  aMostSignificant 
) const
private
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.

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.

virtual int NodeModel::listenPortOfThisNode ( )
virtual

TCP listen port number method

Implements MNodeModelProtocolInterface.

bool NodeModel::loadSslCertFromDb ( )
private
bool NodeModel::loadSslKeyFromDb ( )
private
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.

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.

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

getter for ssl certificate of SSL sock

Implements MNodeModelProtocolInterface.

virtual Hash& NodeModel::nodeFingerPrint ( )
virtual

returns fingerprint of this node

Implements MNodeModelProtocolInterface.

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.

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

getter for ssl certificate of SSL sock

Implements MNodeModelProtocolInterface.

bool NodeModel::openOrCreateSSLCertificate ( )
private

opens the node cert that is for network traffic

void NodeModel::retrieveListOfHotConnections ( )
protected
bool NodeModel::saveSslCertToDb ( const QByteArray &  aCert)
private
bool NodeModel::saveSslKeyToDb ( const QByteArray &  aKey)
private
virtual void NodeModel::setDnsName ( QString  aName)
virtual

called from settings dialog

Implements MNodeModelProtocolInterface.

virtual void NodeModel::setListenPortOfThisNode ( int  port)
virtual

Setting of TCP listen port number method

Implements MNodeModelProtocolInterface.

bool NodeModel::updateNodeInDb ( Node aNode)
protected

method for updating existing node in db table

Parameters
aNodeis the node to update
Returns
true if success
bool NodeModel::updateNodeLastConnectTimeInDb ( Node aNode)
virtual

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

Implements MNodeModelProtocolInterface.

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

QList<Node *> NodeModel::iConnectionWishList
private
MController* NodeModel::iController
private
QString NodeModel::iDataDir
private
Hash* NodeModel::iFingerPrintOfThisNode
private

set by method openOrCreateSSLCertificate

QList<QPair<QHostAddress,int> > NodeModel::iHotAddresses
private
const Model& NodeModel::iModel
private
QSslCertificate* NodeModel::iThisNodeCert
private

set by method openOrCreateSSLCertificate

QSslKey* NodeModel::iThisNodeKey
private

set by method openOrCreateSSLCertificate


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