*
* @return void
*/
- function initDht();
+ function initDht ();
+
+ /**
+ * Finds a node by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node data array
+ */
+ function findNodeBySessionId ($sessionId);
}
// [EOF]
* @return void
*/
function updateLocalNode ();
+
+ /**
+ * Finds a node by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node data array
+ */
+ function findNodeBySessionId ($sessionId);
}
// [EOF]
// Update DHT database record
$this->queryUpdateDataSet($dataSetInstance);
}
+
+ /**
+ * Finds a node by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node data array
+ */
+ public function findNodeBySessionId ($sessionId) {
+ // Get search criteria
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Get node instance
+ $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+ // Search for session id and limit it to one entry
+ $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID, $nodeInstance->getSessionId());
+ $searchInstance->setLimit(1);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Return result instance
+ return $resultInstance;
+ }
}
// [EOF]
$this->getWrapperInstance()->registerLocalNode();
}
}
+
+ /**
+ * Finds a node by given session id
+ *
+ * @param $sessionId Session id to lookup
+ * @return $nodeData Node data array
+ */
+ public function findNodeBySessionId ($sessionId) {
+ // Default is empty data array
+ $nodeData = array();
+
+ // Call the wrapper to do the job and get back a result instance
+ $resultInstance = $this->getWrapperInstance()->findNodeBySessionId($sessionId);
+
+ // Is the next entry valid?
+ if ($resultInstance->next()) {
+ // Then load the entry
+ $nodeData = $resultInstance->current();
+ } // END - if
+
+ // Return node data
+ return $nodeData;
+ }
}
// [EOF]
// And ask it for ip:port by given session id
$recipient = $dhtInstance->findNodeBySessionId($sessionId);
- die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
// Is the recipient invalid?
- if ($recipient == 'invalid:invalid') {
+ if ((!isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT])) || ($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT] == 'invalid:invalid')) {
// Get the instance, this might throw a NPE
$nodeInstance = Registry::getRegistry()->getInstance('node');
} // END - if
} // END - if
+ // Is $recipient an array?
+ if ((!is_array($recipient)) || (!isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT]))) {
+ // Fake array with invalid data
+ $recipient = array(
+ NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT => 'invalid:invalid'
+ );
+ } // END - if
+
// Return result
- return $recipient;
+ return $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_IP_PORT];
}
/**