// Get ip:port combination and "explode" it
$ipPort = $nodeInstance->getAddressPortArray();
- // Make sure both is valid
+ /*
+ * Make sure both is not 'invalid' which means that the resolver
+ * didn't work.
+ */
assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
// Add ip:port/node id as criteria
// Query database and get a result instance back
$resultInstance = $this->doSelectByCriteria($searchInstance);
- // Cache result of if there is an entry, next() will tell us if the next entry is valid
- $GLOBALS[__METHOD__] = $resultInstance->next();
+ // Cache result of if there is an entry, valid() will tell us if an entry is there
+ $GLOBALS[__METHOD__] = $resultInstance->valid();
} // END - if
// Return result
// Run the "UPDATE" query
$this->queryUpdateDataSet($dataSetInstance);
}
+
+ /**
+ * Determines whether the given node data is already inserted in the DHT
+ *
+ * @param $nodeData An array with valid node data
+ * @return $isRegistered Whether the given node data is already inserted
+ */
+ public function isNodeRegistered (array $nodeData) {
+ // Get search criteria
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for node id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]);
+ $searchInstance->setLimit(1);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Check if there is an entry
+ $isRegistered = $resultInstance->valid();
+
+ // Return registration status
+ return $isRegistered;
+ }
}
+ /**
+ * Registers a node with given data in the DHT. If the node is already
+ * registered this method shall throw an exception.
+ *
+ * @param $nodeData An array with valid node data
+ * @return void
+ * @throws NodeAlreadyRegisteredException If the node is already registered
+ */
+ public function registerNode (array $nodeData) {
+ $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
+ }
+
+ /**
+ * Updates a node's entry in the DHT with given data. This will enrich or
+ * just update already exsiting data. If the node is not found this method
+ * shall throw an exception.
+ *
+ * @param $nodeData An array with valid node data
+ * @return void
+ * @throws NodeDataMissingException If the node's data is missing
+ */
+ public function updateNode (array $nodeData) {
+ $this->partialStub('nodeData=' . print_r($nodeData, TRUE));
+ }
+
// [EOF]
?>