From c5f2f6d2f83cd429e493afb816e61bc0503a8b88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 22 Aug 2012 19:25:28 +0000 Subject: [PATCH] Move NodeHelper interface, implement missing method 'isAcceptingNodeListRequests' in generic code --- .gitattributes | 2 + .../hub/interfaces/helper/nodes/.htaccess | 1 + .../helper/nodes/class_NodeHelper.php | 188 ++++++++++++++++++ .../hub/interfaces/nodes/class_NodeHelper.php | 180 +---------------- .../hub/main/nodes/boot/class_HubBootNode.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 20 +- 6 files changed, 211 insertions(+), 182 deletions(-) create mode 100644 application/hub/interfaces/helper/nodes/.htaccess create mode 100644 application/hub/interfaces/helper/nodes/class_NodeHelper.php diff --git a/.gitattributes b/.gitattributes index 0a6b23555..1063fc781 100644 --- a/.gitattributes +++ b/.gitattributes @@ -78,6 +78,8 @@ application/hub/interfaces/helper/hub/.htaccess -text svneol=unset#text/plain application/hub/interfaces/helper/hub/class_HelpableHub.php svneol=native#text/plain application/hub/interfaces/helper/messages/.htaccess svneol=native#text/plain application/hub/interfaces/helper/messages/class_MessageHelper.php svneol=native#text/plain +application/hub/interfaces/helper/nodes/.htaccess -text svneol=unset#text/plain +application/hub/interfaces/helper/nodes/class_NodeHelper.php svneol=native#text/plain application/hub/interfaces/listener/.htaccess -text svneol=unset#text/plain application/hub/interfaces/listener/class_Listenable.php svneol=native#text/plain application/hub/interfaces/lists/.htaccess -text svneol=unset#text/plain diff --git a/application/hub/interfaces/helper/nodes/.htaccess b/application/hub/interfaces/helper/nodes/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/helper/nodes/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php new file mode 100644 index 000000000..d0c2aba6a --- /dev/null +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -0,0 +1,188 @@ + + * @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 + * @todo We need to find a better name for this interface + * + * 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 . + */ +interface NodeHelper extends Helper { + /** + * Method to "bootstrap" the node. This step does also apply provided + * command-line arguments stored in the request instance. You should now + * get it from calling $this->getRequestInstance(). + * + * @return void + */ + function doBootstrapping (); + + /** + * Initializes hub-specific queues + * + * @return void + */ + function initQueues (); + + /** + * Outputs the console teaser. This should only be executed on startup or + * full restarts. This method generates some space around the teaser. + * + * @return void + */ + function outputConsoleTeaser (); + + /** + * Add some node-specific filters + * + * @return void + */ + function addExtraNodeFilters (); + + /** + * Generic method to acquire 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 A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance); + + /** + * Activates the hub by doing some final preparation and setting + * $hubIsActive to true + * + * @param $requestInstance A Requestable class + * @param $responseInstance A Responseable class + * @return void + */ + function activateNode (Requestable $requestInstance, Responseable $responseInstance); + + /** + * Generates a session id which will be sent to the other hubs and peers + * + * @return void + */ + function bootstrapGenerateSessionId (); + + /** + * Generates a private key for en-/decryption + * + * @return void + */ + function bootstrapGeneratePrivateKey (); + + /** + * Initializes the listener pool (class) + * + * @return void + */ + function initializeListenerPool (); + + /** + * Restores a previously stored node list from database + * + * @return void + */ + function bootstrapRestoreNodeList (); + + /** + * Announces this hub to the upper (bootstrap or list) hubs. After this is + * successfully done the given task is unregistered from the handler. + * + * @param $taskInstance The task instance running this announcement + * @return void + * @throws NodeAlreadyAnnouncedException If this hub is already announced + */ + function announceSelfToUpperNodes (Taskable $taskInstance); + + /** + * Does a self-connect attempt on the public IP address. This should make + * it sure, we are reachable from outside world. + * + * @param $taskInstance The task instance running this announcement + * @return void + */ + function doSelfConnection (Taskable $taskInstance); + + /** + * "Getter for address:port combination + * + * @param $handlerInstance An instance of a Networkable class + * @return $addressPort A address:port combination for this node + */ + function getAddressPort (Networkable $handlerInstance); + + /** + * 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 + * @return void + */ + function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance); + + /** + * Updates/refreshes node data (e.g. state). + * + * @return void + */ + function updateNodeData (); + + /** + * Checks whether this node accepts announcements + * + * @return $acceptAnnouncements Whether this node accepts announcements + */ + function isAcceptingAnnouncements (); + + /** + * Checks whether this node has attempted to announce itself + * + * @return $hasAnnounced Whether this node has attempted to announce itself + */ + function ifNodeHasAnnounced (); + + /** + * Checks wether this node is accepting node-list requests + * + * @return $acceptsRequest Wether this node accepts node-list requests + */ + function isAcceptingNodeListRequests (); + + /** + * Handles message answer by given data array + * + * @param $messageData A valid answer message data array + * @param $packageInstance An instance of a Receivable class + * @return void + */ + function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance); + + /** + * "Getter" for an array of all accepted object types + * + * @return $objectList Array of all accepted object types + */ + function getListFromAcceptedObjectTypes (); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/nodes/class_NodeHelper.php b/application/hub/interfaces/nodes/class_NodeHelper.php index 8bc85b802..f551ef47b 100644 --- a/application/hub/interfaces/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/nodes/class_NodeHelper.php @@ -1,181 +1,3 @@ - * @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 - * @todo We need to find a better name for this interface - * - * 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 . - */ -interface NodeHelper extends FrameworkInterface { - /** - * Method to "bootstrap" the node. This step does also apply provided - * command-line arguments stored in the request instance. You should now - * get it from calling $this->getRequestInstance(). - * - * @return void - */ - function doBootstrapping (); - - /** - * Initializes hub-specific queues - * - * @return void - */ - function initQueues (); - - /** - * Outputs the console teaser. This should only be executed on startup or - * full restarts. This method generates some space around the teaser. - * - * @return void - */ - function outputConsoleTeaser (); - - /** - * Add some node-specific filters - * - * @return void - */ - function addExtraNodeFilters (); - - /** - * Generic method to acquire 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 A Requestable class - * @param $responseInstance A Responseable class - * @return void - */ - function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance); - - /** - * Activates the hub by doing some final preparation and setting - * $hubIsActive to true - * - * @param $requestInstance A Requestable class - * @param $responseInstance A Responseable class - * @return void - */ - function activateNode (Requestable $requestInstance, Responseable $responseInstance); - - /** - * Generates a session id which will be sent to the other hubs and peers - * - * @return void - */ - function bootstrapGenerateSessionId (); - - /** - * Generates a private key for en-/decryption - * - * @return void - */ - function bootstrapGeneratePrivateKey (); - - /** - * Initializes the listener pool (class) - * - * @return void - */ - function initializeListenerPool (); - - /** - * Restores a previously stored node list from database - * - * @return void - */ - function bootstrapRestoreNodeList (); - - /** - * Announces this hub to the upper (bootstrap or list) hubs. After this is - * successfully done the given task is unregistered from the handler. - * - * @param $taskInstance The task instance running this announcement - * @return void - * @throws NodeAlreadyAnnouncedException If this hub is already announced - */ - function announceSelfToUpperNodes (Taskable $taskInstance); - - /** - * Does a self-connect attempt on the public IP address. This should make - * it sure, we are reachable from outside world. - * - * @param $taskInstance The task instance running this announcement - * @return void - */ - function doSelfConnection (Taskable $taskInstance); - - /** - * "Getter for address:port combination - * - * @param $handlerInstance An instance of a Networkable class - * @return $addressPort A address:port combination for this node - */ - function getAddressPort (Networkable $handlerInstance); - - /** - * 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 - * @return void - */ - function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance); - - /** - * Updates/refreshes node data (e.g. state). - * - * @return void - */ - function updateNodeData (); - - /** - * Checks whether this node accepts announcements - * - * @return $acceptAnnouncements Whether this node accepts announcements - */ - function isAcceptingAnnouncements (); - - /** - * Checks whether this node has attempted to announce itself - * - * @return $hasAnnounced Whether this node has attempted to announce itself - */ - function ifNodeHasAnnounced (); - - /** - * Handles message answer by given data array - * - * @param $messageData A valid answer message data array - * @param $packageInstance An instance of a Receivable class - * @return void - */ - function handleAnswerStatusByMessageData (array $messageData, Receivable $packageInstance); - - /** - * "Getter" for an array of all accepted object types - * - * @return $objectList Array of all accepted object types - */ - function getListFromAcceptedObjectTypes (); -} - -// [EOF] +// @DEPRECATED ?> diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index d79259f7a..bc62fcb1c 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -72,7 +72,7 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrapping node ' . $this->getBootIpPort() . '.'); // Now, does the mode match - if ($this->getRequestInstance()->getRequestElement('mode') == BaseHubNode::NODE_TYPE_BOOT) { + if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) { // Output debug message self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrapping node.'); } else { diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 39190abd2..b596da7f0 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -735,8 +735,24 @@ class BaseHubNode extends BaseHubSystem implements Updateable { protected final function enableAcceptingAnnouncements ($acceptAnnouncements = true) { $this->acceptAnnouncements = $acceptAnnouncements; } - - + + /** + * Checks wether this node is accepting node-list requests + * + * @return $acceptsRequest Wether this node accepts node-list requests + */ + public function isAcceptingNodeListRequests () { + /* + * Only 'regular' nodes does not accept such requests, checking + * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be + * added then the next check will be true. + */ + $acceptsRequest = ((!$this instanceof HubRegularNode) && ($this->getRequestInstance()->getRequestElement('mode') != self::NODE_TYPE_REGULAR)); + + // Return it + return $acceptsRequest; + } + /** * "Getter" for address:port combination * -- 2.39.2