/** * Gets mixed array of MeshingOwnNode and *KnownNode objects to send to */ protected function getLocalAndRemoteReceiverNodes(P2POwnNode $node) { // Rewrite the above from the perspective of the local 'to' node $localNodes = P2POwnNodeQuery::create()->joinMeshingTrustLocalRelatedByToOwnNodeId('TrustLocal')->useQuery('TrustLocal')->joinMeshingTrustType()->endUse()->where('TrustLocal.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->find(); // Get array of node ids in remote database (we can't join between system and node dbs) $remoteNodeIds = MeshingTrustRemoteQuery::create()->joinMeshingTrustType()->where('MeshingTrustRemote.FromOwnNodeId = ?', $node->getId())->where('MeshingTrustType.Name LIKE ?', 'write%')->select('MeshingTrustRemote.KnownNodeId')->find()->getArrayCopy(); // Initialise remote node models $schemaName = $node->getMeshingSchema()->getName(); Meshing_Utils::initialiseNodeDbs($schemaName); $con = Meshing_Node_Utils::getConnectionForNode($node); // Do select in node database for remote node ids $className = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodeQuery'); /* @var $query JobsKnownNodeQuery */ // (This is just an example - can be of any *KnownNodeQuery class) $query = call_user_func(array($className, 'create'), 'KnownNode'); $remoteNodes = $query->where('KnownNode.Id IN ?', $remoteNodeIds)->find($con); /* @var $localNodes PropelObjectCollection */ /* @var $remoteNodes PropelObjectCollection */ return array_merge($localNodes->getArrayCopy(), $remoteNodes->getArrayCopy()); }
public function preRunCheck() { if (!$this->opts->name) { throw new Zend_Console_Getopt_Exception('Which node would you like to start? (use --name)'); } Meshing_Utils::initialiseDb(); $node = P2POwnNodeQuery::create()->findOneByName($this->opts->name); if (!$node) { throw new Zend_Console_Getopt_Exception('A node of that name is not registered'); } // Connect with this node's connection, and ensure there are rows in known_nodes $conn = Propel::getConnection($node->getP2PConnection()->getName()); $schemaName = $node->getMeshingSchema()->getName(); Meshing_Utils::initialiseNodeDbs($schemaName); // Obtain the number of trusted nodes $class = Meshing_Node_Utils::getNodeClassName($schemaName, 'KnownNodePeer'); $knownNodeCount = call_user_func(array($class, 'doCount'), new Criteria(), $distinct = false, $conn); // If there are no trust rows, we cannot start if (!$knownNodeCount) { throw new Zend_Console_Getopt_Exception('A node needs to trust other nodes before it can be started'); } }
/** * If a node identity for the same schema is found, an exception is thrown * * Requires node autoloaders to be set up (Meshing_Utils::initialiseNodeDbs) * * @param PDO $conn */ protected function checkNodeBuildCanProceed(PDO $conn) { // Don't do the checks if force is present if (!$this->opts->force) { // NB: this will only find identities for this schema $peerName = Meshing_Node_Utils::getIdentityPeerClassName($this->opts->schema); try { $identityPeer = call_user_func(array($peerName, 'doSelectOne'), new Criteria(), $conn); } catch (PropelException $e) { // Table doesn't exist - nothing to overwrite! $identityPeer = null; } // If we have an identity row, we must have found a node db of the same schema if ($identityPeer) { throw new Meshing_Console_RunException('A node of the same schema exists in this database already (use --force if you are happy to overwrite).'); } } return true; }