* @return void
* @throws NodeSessionIdVerficationException If the provided session id is not matching
* @todo Do some more here: Handle karma, et cetera?
- * @todo Rewrite this to use DHT
*/
public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
- // Get a database wrapper instance
- $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_list_db_wrapper_class');
+ // Make sure node-list is found in array
+ assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
- // Get also a search criteria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+ // Save node list
+ $nodeList = unserialize(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
- // Lookup external session id/external IP/port
- $searchInstance->addCriteria('session_id' , $messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID]);
+ // Make sure it is completely decoded
+ assert(is_array($nodeList));
- // Only one entry is fine
- $searchInstance->setLimit(1);
+ // ... and remove it as it should not be included now
+ unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
- // Run the query
- $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
+ // Write node list to DHT
+ $this->getDhtInstance()->insertNodeList($nodeList);
- // Is there an try?
- if (!$resultInstance->next()) {
- // This is fatal, caused by "stolen" session id and/or not matching IP number/port combination
- throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
- } // END - if
+ /*
+ * Query DHT and force update (which will throw an exception if the
+ * node is not found).
+ */
+ $this->getDhtInstance()->registerNodeByMessageData($messageData, $this, TRUE);
// Get the node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');