/**
* A hub-node class for the 'Boot' mode
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.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
* 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 HubBootNode extends BaseHubNode implements NodeHelper {
+class HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
/**
* Protected constructor
*
* @param $requestInstance An instance of a Requestable class
* @return $nodeInstance An instance of this hub-node class
*/
- public final static function createHubBootNode (Requestable $requestInstance) {
+ public static final function createHubBootNode (Requestable $requestInstance) {
// Get a new instance
$nodeInstance = new HubBootNode();
* command-line arguments stored in the request instance. The regular node
* should communicate with the bootstrap-nodes at this point.
*
- * @param $requestInstance An instance of a Requestable class
* @return void
+ * @todo add some more special bootstrap things for this boot node
*/
- public function doBootstrapping (Requestable $requestInstance) {
- // Call generic (parent) bootstrapping method
- parent::doGenericBootstrapping();
- $this->partialStub("Please implement this method.");
+ public function doBootstrapping () {
+ // Get UNL
+ $unl = $this->detectOwnUniversalNodeLocator();
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $unl);
+
+ // Now check if the IP address matches one of the bootstrap nodes
+ if ($this->ifAddressMatchesBootstrapNodes($unl)) {
+ // Get our port from configuration
+ $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
+
+ // Extract port
+ $bootPort = substr($this->getBootUniversalNodeLocator(), -strlen($ourPort), strlen($ourPort));
+
+ // Is the port the same?
+ if ($bootPort == $ourPort) {
+ // It is the same!
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: UNL matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
+
+ // Now, does the mode match
+ if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
+ // Output debug message
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrap node.');
+ } else {
+ // Output warning
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.');
+ }
+ } else {
+ // IP does match, but no port
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
+ }
+ } else {
+ // Node does not match any know bootstrap-node
+ self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.');
+ }
+
+ // Enable acceptance of announcements
+ $this->enableAcceptingAnnouncements();
+
+ // This might not be all...
+ $this->partialStub('Please implement more bootsrapping steps.');
+ }
+
+ /**
+ * Add some node-specific filters
+ *
+ * @return void
+ */
+ public function addExtraNodeFilters () {
+ // Get the application instance from registry
+ $applicationInstance = Registry::getRegistry()->getInstance('app');
+
+ // Get the controller from the application
+ $controllerInstance = $applicationInstance->getControllerInstance();
+
+ // @TODO Add some filters here
+ $this->partialStub('Add some filters here.');
+ }
+
+ /**
+ * Adds extra tasks to the given handler for this node
+ *
+ * @param $handlerInstance An instance of a HandleableTask class
+ * @return void
+ */
+ public function addExtraTasks (HandleableTask $handlerInstance) {
+ // Prepare a task for booting the DHT
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_bootstrap_task_class');
+
+ // Register it
+ $handlerInstance->registerTask('dht_bootstrap', $taskInstance);
}
}