application/hub/main/tasks/node/decoder/class_NodePackageDecoderTask.php -text
application/hub/main/tasks/node/dht/.htaccess -text svneol=unset#text/plain
application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php svneol=native#text/plain
+application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php svneol=native#text/plain
application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php svneol=native#text/plain
application/hub/main/tasks/node/listener/.htaccess -text svneol=unset#text/plain
application/hub/main/tasks/node/ping/.htaccess -text svneol=unset#text/plain
// CFG: NODE-PACKAGE-DECODER-TASK-CLASS
$cfg->setConfigEntry('node_package_decoder_task_class', 'NodePackageDecoderTask');
+// CFG: NODE-DHT-INIT-TASK-CLASS
+$cfg->setConfigEntry('node_dht_init_task_class', 'NodeDhtInitializationTask');
+
// CFG: NODE-DHT-BOOTSTRAP-TASK-CLASS
$cfg->setConfigEntry('node_dht_bootstrap_task_class', 'NodeDhtBootstrapTask');
// CFG: TASK-CHUNK-ASSEMBLER-MAX-RUNS
$cfg->setConfigEntry('task_chunk_assembler_max_runs', 0);
+// CFG: TASK-DHT-INIT-STATUP-DELAY
+$cfg->setConfigEntry('task_dht_init_startup_delay', 100);
+
+// CFG: TASK-DHT-INIT-INTERVAL-DELAY
+$cfg->setConfigEntry('task_dht_init_interval_delay', 86400000); // = 1 day (won't matter anyway)
+
+// CFG: TASK-DHT-INIT-MAX-RUNS
+$cfg->setConfigEntry('task_dht_init_max_runs', 1);
+
// CFG: TASK-DHT-BOOTSTRAP-STATUP-DELAY
$cfg->setConfigEntry('task_dht_bootstrap_startup_delay', 100);
// CFG: TASK-DHT-BOOTSTRAP-INTERVAL-DELAY
-$cfg->setConfigEntry('task_dht_bootstrap_interval_delay', 3600000); // = 1 hour
+$cfg->setConfigEntry('task_dht_bootstrap_interval_delay', 3600000); // = 1 hour (won't matter anyway)
// CFG: TASK-DHT-BOOTSTRAP-MAX-RUNS
$cfg->setConfigEntry('task_dht_bootstrap_max_runs', 1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface Distributable extends FrameworkInterface {
+ /**
+ * Initializes the distributable hash table (DHT)
+ *
+ * @return void
+ */
+ function initDht();
}
// [EOF]
<?php
-/**
- * An interface for node-list (database) wrapper
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface NodeListWrapper extends FrameworkInterface {
- /**
- * Resolves a session id into an ip:port combination
- *
- * @param $sessionId A valid session id
- * @param $protocol Name of the protocol (TCP/UDP)
- * @return $recipient Recipient as ip:port combination
- */
- function resolveIpPortBySessionId ($sessionId, $protocol);
-
- /**
- * Resolves a ip:port combination into a session id
- *
- * @param $ipPort Ip:port combination
- * @param $protocol Name of the used protocol (TCP/UDP)
- * @return $sessionId A valid session id
- */
- function resolveSessionIdByIpPort ($ipPort, $protocol);
-
- /**
- * Registeres a node by given message data.
- *
- * @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableMessage class
- * @return void
- */
- function registerNodeByMessageData (array $messageData, Handleable $handlerInstance);
-
- /**
- * Updates an existing entry in node list
- *
- * @param $messageData An array of all message data
- * @param $handlerInstance An instance of a HandleableMessage class
- * @param $searchInstance An instance of LocalSearchCriteria class
- * @return void
- */
- function updateNodeByMessageData (array $messageData, Handleable $handlerInstance, LocalSearchCriteria $searchInstance);
-}
-
-// [EOF]
+// @DEPRECATED
?>
$proxyInstance->addExtraAptProxyFilters();
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
$chatInstance->addExtraChatFilters();
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
$cruncherInstance->addExtraCruncherFilters();
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
$nodeInstance->activateNode($requestInstance, $responseInstance);
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Debug message
self::createDebugInstance(__CLASS__)->debugOutput('MAIN: --- Entering main loop. ---');
* 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 NodeDhtFacade extends BaseDht implements Distributable {
+class NodeDhtFacade extends BaseDht implements Distributable, Registerable {
/**
* Protected constructor
*
// Return the prepared instance
return $dhtInstance;
}
+
+ /**
+ * Initializes the distributable hash table (DHT)
+ *
+ * @return void
+ * @todo Please implement this method
+ */
+ public function initDht () {
+ $this->partialStub('Please implement this method.');
+ }
}
// [EOF]
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Prepare a self-test task for the listeners
$taskInstance = ObjectFactory::createObjectByConfiguredName('node_announcement_task_class');
*/
public function execute (Requestable $requestInstance, Responseable $responseInstance) {
// Get task handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task');
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
// Shutdown the task manager and all its registered tasks
$handlerInstance->doShutdown();
$handlerInstance->registerTask('apt_proxy_listener', $taskInstance);
// Put the task handler in registry
- Registry::getRegistry()->addInstance('task', $handlerInstance);
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
}
}
$handlerInstance->registerTask('chat_telnet_listener', $taskInstance);
// Put the task handler in registry
- Registry::getRegistry()->addInstance('task', $handlerInstance);
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
}
}
$handlerInstance->registerTask('cruncher_key_producer', $taskInstance);
// Put the task handler in registry
- Registry::getRegistry()->addInstance('task', $handlerInstance);
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
}
}
$handlerInstance->registerTask('package_decoder', $taskInstance);
// Generate DHT initialization task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_init_task_class');
// Register it as well
- $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
+ $handlerInstance->registerTask('dht_init', $taskInstance);
// Generate DHT query task
$taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_query_task_class');
$handlerInstance->registerTask('ping', $taskInstance);
// Put the task handler in registry
- Registry::getRegistry()->addInstance('task', $handlerInstance);
+ Registry::getRegistry()->addInstance('task_handler', $handlerInstance);
}
}
throw new NodeSessionIdVerficationException(array($this, $messageData), BaseHubSystem::EXCEPTION_NODE_SESSION_ID_NOT_VERIFYING);
} // END - if
+ // Get handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Generate DHT bootstrap task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
+
// Update node data (include status code)
$wrapperInstance->updateNodeByMessageData($messageData, $this, $searchInstance);
* @todo 0% done
*/
public function executeTask () {
- $this->partialStub('Unimplemented task.');
+ // "Cache" the DHT instance
+ $dhtInstance = $this->getDhtInstance();
}
}
--- /dev/null
+<?php
+/**
+ * A DhtInitialization node-task
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * 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 NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $taskInstance An instance of a Visitable class
+ */
+ public final static function createNodeDhtInitializationTask () {
+ // Get new instance
+ $taskInstance = new NodeDhtInitializationTask();
+
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
+
+ // Set the DHT instance here
+ $taskInstance->setDhtInstance($dhtInstance);
+
+ // Return the prepared instance
+ return $taskInstance;
+ }
+
+ /**
+ * Accepts the visitor to process the visitor
+ *
+ * @param $visitorInstance An instance of a Visitor class
+ * @return void
+ */
+ public function accept (Visitor $visitorInstance) {
+ // Visit this task
+ $visitorInstance->visitTask($this);
+ }
+
+ /**
+ * Executes the task
+ *
+ * @return void
+ */
+ public function executeTask () {
+ // Intiailize the DHT
+ $this->getDhtInstance()->initDht();
+ }
+}
+
+// [EOF]
+?>
* @todo 0% done
*/
public function executeTask () {
- $this->partialStub('Unimplemented task.');
+ // "Cache" the DHT instance
+ $dhtInstance = $this->getDhtInstance();
}
}
}
/**
- * Resolves a session id into an ip:port combination
+ * Resolves a session id into an ip:port combination. The opposite method
+ * is resolveSessionIdByIpPort()
*
* @param $sessionId A valid session id
* @param $protocol Name of the used protocol: TCP/UDP
* @return $recipient Recipient as ip:port combination
- * @todo Rewrite this to use DHT
*/
protected function resolveIpPortBySessionId ($sessionId, $protocol) {
- // Get a wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
- // And ask it for the session id
- $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId, $protocol);
+ // And ask it for ip:port by given session id
+ $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol);
+ die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
// Is the recipient invalid?
if ($recipient == 'invalid:invalid') {
}
/**
- * Resolves a ip:port combination into a session id
+ * Resolves a ip:port combination into a session id. The "opposite" method
+ * is resolveIpPortBySessionId().
*
* @param $ipPort Ip:port combination
* @param $protocol Name of used protocol (TCP/UDP)
* @return $sessionId Valid session id
- * @todo Rewrite this to use DHT
*/
public static function resolveSessionIdByIpPort ($ipPort, $protocol) {
- // Get a wrapper instance
- $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+ // Get a DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtObjectInstance();
- // And ask it for the session id
- $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort, $protocol);
+ // And ask it for session id by given ip:port
+ $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol);
+ die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
// Return result
return $sessionId;