* - listen-port (TCP/UDP listen port for inbound connections)
*
* @param $messageArray An array with all minimum message data
- * @param $handlerInstance An instance of a HandleableMessage class
+ * @param $handlerInstance An instance of a Handleable class
+ * @param $forceUpdate Optionally force update, don't register (default: register if not found)
* @return void
*/
- function registerNodeByMessageData (array $messageData, HandleableMessage $handlerInstance);
+ function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE);
}
// [EOF]
* - listen-port (TCP/UDP listen port for inbound connections)
*
* @param $messageArray An array with all minimum message data
- * @param $handlerInstance An instance of a HandleableMessage class
+ * @param $handlerInstance An instance of a Handleable class
+ * @param $forceUpdate Optionally force update, don't register (default: register if not found)
* @return void
+ * @throws NodeSessionIdVerficationException If the node was not found and update is forced
*/
- public function registerNodeByMessageData (array $messageData, HandleableMessage $handlerInstance) {
+ public function registerNodeByMessageData (array $messageData, Handleable $handlerInstance, $forceUpdate = FALSE) {
// Get a search criteria class
$searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
if ($resultInstance->next()) {
// Entry found, so update it
$this->getWrapperInstance()->updateNodeByMessageData($messageData, $handlerInstance, $searchInstance);
- } else {
+ } elseif ($forceUpdate === FALSE) {
// Nothing found, so register it
$this->getWrapperInstance()->registerNodeByMessageData($messageData, $handlerInstance);
+ } else {
+ /*
+ * Do not register non-existent nodes here. This is maybe 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);
}
// Save last exception
// Call parent constructor
parent::__construct(__CLASS__);
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT
+ );
+
// Set handler name
$this->setHandlerName('announcement_answer_okay');
}
* @param $messageData An array of message data
* @param $packageInstance An instance of a Receivable class
* @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');
-
- // Get also a search criteria instance
- $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
- // Lookup external session id/external IP/port
- $searchInstance->addCriteria('node_session_id' , $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
- $searchInstance->addCriteria('node_external_ip', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_IP]);
- $searchInstance->addCriteria('node_listen_port', $messageData[XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_LISTEN_PORT]);
-
- // Only one entry is fine
- $searchInstance->setLimit(1);
-
- // Run the query
- $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
-
- // 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 handler instance
$handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Register it as well
$handlerInstance->registerTask('dht_bootstrap', $taskInstance);
- // Update node data (include status code)
- $wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
-
// Get the node instance
$nodeInstance = Registry::getRegistry()->getInstance('node');
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
+
+ // Set it here
+ $this->setDhtInstance($dhtInstance);
}
/**
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseHandler extends BaseHubSystem {
+class BaseHandler extends BaseHubSystem implements Handleable {
/**
* Handler name
*/
protected function __construct ($className) {
// Call parent constructor
parent::__construct($className);
-
- // Get a DHT instance
- $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
-
- // Set it here
- $this->setDhtInstance($dhtInstance);
}
/**