application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php -text
application/hub/main/nodes/.htaccess -text
application/hub/main/nodes/boot/.htaccess -text
+application/hub/main/nodes/boot/class_HubBootNode.php -text
application/hub/main/nodes/class_ -text
application/hub/main/nodes/class_BaseHubNode.php -text
application/hub/main/nodes/list/.htaccess -text
+application/hub/main/nodes/list/class_BootListNode.php -text
application/hub/main/nodes/master/.htaccess -text
+application/hub/main/nodes/master/class_HubMasterNode.php -text
application/hub/main/nodes/regular/.htaccess -text
application/hub/main/nodes/regular/class_HubRegularNode.php -text
application/hub/starter.php -text
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
* 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 ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication {
+class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplication, Registerable {
/**
* The version number of this application
*/
$className = 'Hub' . $this->convertToClassName($nodeMode) . 'Node';
// And try to instance it
- $nodeInstance = ObjectFactory::createObjectByName($className);
+ try {
+ // Get an instance
+ $nodeInstance = ObjectFactory::createObjectByName($className, array($requestInstance));
+
+ // Set the app instance
+ $nodeInstance->setApplicationInstance($this);
+ } catch (ClassNotFoundException $e) {
+ // This means, the node mode is invalid!
+ // @TODO Can we rewrite this to app_die() ?
+ die('Node mode ' . $nodeMode . ' is invalid.' . "\n");
+ }
// --------------------- Hub-id aquirement phase ---------------------
// Aquire a hub-id. This step generates on first launch anew one and
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
* @todo We need to find a better name for this interface
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0
- * @copyright Copyright(c) 2007 - 2009 Roland Haeder, this is free software
+ * @copyright Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
*
* This program is free software: you can redistribute it and/or modify
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'Boot' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 HubBootNode extends BaseHubNode implements NodeHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public final static function createHubBootNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubBootNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * 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
+ */
+ public function doBootstrapping (Requestable $requestInstance) {
+ // Call generic (parent) bootstrapping method
+ parent::doGenericBootstrapping();
+ $this->partialStub("Please implement this method.");
+ }
+}
+
+// [EOF]
+?>
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Creates an instance of this hub-node class
*
- * @return $nodeInstance An instance of this hub-node class
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
*/
- public final static function createHub???Node () {
+ public final static function createHub???Node (Requestable $requestInstance) {
// Get a new instance
$nodeInstance = new Hub???Node();
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
// Return the instance
return $nodeInstance;
}
* @return void
*/
public function doBootstrapping (Requestable $requestInstance) {
- $this->partialStub();
- }
-
- /**
- * Method to aquire a hub-id. On first run this generates a new one
- * based on many pseudo-random data. On any later run, unless the id
- * got not removed from database, it will be restored from the database.
- *
- * @param $requestInstance An instance of a Requestable class
- * @return void
- */
- public function aquireHubId (Requestable $requestInstance) {
- $this->partialStub();
+ // Call generic (parent) bootstrapping method
+ parent::doGenericBootstrapping();
+ $this->partialStub("Please implement this method.");
}
}
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Node id
*/
- private $nodeId = "";
+ private $nodeId = '';
+
+ /**
+ * IP/port number of bootstrapping node
+ */
+ private $bootIpPort = '';
/**
* Protected constructor
}
/**
- * Method to aquire a hub-id. On first run this generates a new one
+ * Checks wether the given IP address matches one of the bootstrapping nodes
+ *
+ * @param $remoteAddr IP address to checkout against our bootstrapping list
+ * @return $isFound Wether the IP is found
+ */
+ private function ifAddressMatchesBootstrappingNodes ($remoteAddr) {
+ // By default nothing is found
+ $isFound = false;
+
+ // Run through all configured IPs
+ foreach (explode(',', $this->getConfigInstance()->readConfig('hub_bootstrap_nodes')) as $ipPort) {
+ // Does it match?
+ if (substr($ipPort, 0, strlen($remoteAddr)) == $remoteAddr) {
+ // Found it!
+ $isFound = true;
+
+ // Remember the port number
+ $this->bootIpPort = $ipPort;
+
+ // Output message
+ $this->getDebugInstance()->output(__FUNCTION__.': IP matches remote address ' . $ipPort . '.');
+
+ // Stop further searching
+ break;
+ } elseif (substr($ipPort, 0, strlen($this->getConfigInstance()->readConfig('node_listen_addr'))) == $this->getConfigInstance()->readConfig('node_listen_addr')) {
+ // IP matches listen address. At this point we really don't care
+ // if we can also listen on that address!
+ $isFound = true;
+
+ // Remember the port number
+ $this->bootIpPort = $ipPort;
+
+ // Output message
+ $this->getDebugInstance()->output(__FUNCTION__.': IP matches listen address ' . $ipPort . '.');
+
+ // Stop further searching
+ break;
+ }
+ } // END - foreach
+
+ // Return the result
+ return $isFound;
+ }
+
+ /**
+ * Outputs the console teaser. This should only be executed on startup or
+ * full restarts. This method generates some space around the teaser.
+ *
+ * @return void
+ */
+ private function outputConsoleTeaser () {
+ // Get the app instance (for shortening our code)
+ $app = $this->getApplicationInstance();
+
+ // Output all lines
+ $this->getDebugInstance()->output(' ');
+ $this->getDebugInstance()->output($app->getAppName() . ' v' . $app->getAppVersion() . ' - ' . $this->getRequestInstance()->getRequestElement('mode') . ' mode active');
+ $this->getDebugInstance()->output('Copyright(c) 2007 - 2008 Roland Haeder, 2009 Hub Developer Team');
+ $this->getDebugInstance()->output(' ');
+ $this->getDebugInstance()->output('This program comes with ABSOLUTELY NO WARRANTY; for details see docs/COPYING.');
+ $this->getDebugInstance()->output('This is free software, and you are welcome to redistribute it under certain');
+ $this->getDebugInstance()->output('conditions; see docs/COPYING for details.');
+ $this->getDebugInstance()->output(' ');
+ }
+
+ /**
+ * Do generic things for bootup phase. This can be e.g. checking if the
+ * right node mode is selected for this hub's IP number.
+ *
+ * @todo This method is maybe not yet finished.
+ * @return void
+ */
+ protected function doGenericBootstrapping () {
+ // Now check if the IP address matches one of the bootstrap nodes
+ if ($this->ifAddressMatchesBootstrappingNodes($_SERVER['REMOTE_ADDR'])) {
+ // Get our port
+ $ourPort = $this->getConfigInstance()->readConfig('node_listen_port');
+
+ // Is the port the same?
+ if (substr($this->bootIpPort, -strlen($ourPort), strlen($ourPort)) == $ourPort) {
+ // It is the same!
+ $this->getDebugInstance()->output(__FUNCTION__.': IP/port matches bootstrapping node ' . $this->bootIpPort . '.');
+
+ // Now, does the mode match (should be 'boot'!)
+ if ($this->getRequestInstance()->getRequestElement('mode') == 'boot') {
+ // Output debug message
+ $this->getDebugInstance()->output(__FUNCTION__.': Our node is a valid boot-strapping node.');
+ } else {
+ // Output warning
+ $this->getDebugInstance()->output(__FUNCTION__.': WARNING! Mismatching mode ' . $this->getRequestInstance()->getRequestElement('mode') . '!=boot detected.');
+ }
+ } // END - if
+ } // END - if
+
+ // Finally output our teaser. This should be the last line!
+ $this->outputConsoleTeaser();
+ }
+
+ /**
+ * Generic method to aquire a hub-id. On first run this generates a new one
* based on many pseudo-random data. On any later run, unless the id
* got not removed from database, it will be restored from the database.
*
}
/**
- * Adds registration elements to a given dataset instance
+ * Adds hub data elements to a given dataset instance
*
* @param $criteriaInstance An instance of a storeable criteria
* @param $requestInstance An instance of a Requestable class
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'List' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 HubListNode extends BaseHubNode implements NodeHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public final static function createHubListNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubListNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * 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
+ */
+ public function doBootstrapping (Requestable $requestInstance) {
+ // Call generic (parent) bootstrapping method
+ parent::doGenericBootstrapping();
+ $this->partialStub("Please implement this method.");
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A hub-node class for the 'Master' mode
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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 HubMasterNode extends BaseHubNode implements NodeHelper {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this hub-node class
+ *
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
+ */
+ public final static function createHubMasterNode (Requestable $requestInstance) {
+ // Get a new instance
+ $nodeInstance = new HubMasterNode();
+
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
+ // Return the instance
+ return $nodeInstance;
+ }
+
+ /**
+ * Method to "bootstrap" the node. This step does also apply provided
+ * 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
+ */
+ public function doBootstrapping (Requestable $requestInstance) {
+ // Call generic (parent) bootstrapping method
+ parent::doGenericBootstrapping();
+ $this->partialStub("Please implement this method.");
+ }
+}
+
+// [EOF]
+?>
*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
/**
* Creates an instance of this hub-node class
*
- * @return $nodeInstance An instance of this hub-node class
+ * @param $requestInstance An instance of a Requestable class
+ * @return $nodeInstance An instance of this hub-node class
*/
- public final static function createHubRegularNode () {
+ public final static function createHubRegularNode (Requestable $requestInstance) {
// Get a new instance
$nodeInstance = new HubRegularNode();
+ // Set the request instance
+ $nodeInstance->setRequestInstance($requestInstance);
+
// Return the instance
return $nodeInstance;
}
* @return void
*/
public function doBootstrapping (Requestable $requestInstance) {
- $this->partialStub();
+ // Call generic (parent) bootstrapping method
+ parent::doGenericBootstrapping();
+ $this->partialStub("Please implement this method.");
}
}