From d9442666cf3dee440aeca9ac1377880d3d01f3a3 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 31 Oct 2014 23:43:41 +0100 Subject: [PATCH] Continued on rewrite: - Added new interface + first (completely unfinished) implementation for UNL discovery - - Made UNL upper-case Signed-off-by: Roland Haeder --- application/hub/config.php | 3 + .../discovery/class_Discoverable.php | 20 ---- .../discovery/{dht => recipient}/.htaccess | 0 .../recipient/class_DiscoverableRecipient.php | 48 ++++++++ .../{node => recipient/dht}/.htaccess | 0 .../dht/class_DiscoverableDhtRecipient.php | 4 +- .../{socket => recipient/node}/.htaccess | 0 .../node/class_DiscoverableNodeRecipient.php | 18 +-- .../discovery/recipient/socket}/.htaccess | 0 .../socket/class_DiscoverableSocket.php | 2 +- .../discovery/unl}/.htaccess | 0 ...class_DiscoverableUniversalNodeLocator.php | 28 +++++ .../helper/nodes/class_NodeHelper.php | 8 +- .../interfaces/recipient/class_Recipient.php | 2 +- application/hub/main/discovery/class_ | 50 +++++++++ .../discovery/class_BaseNodeDiscovery.php | 69 +----------- .../main/discovery/{socket => node}/.htaccess | 0 .../class_UniversalNodeLocatorDiscovery.php | 50 +++++++++ .../hub/main/discovery/recipient/.htaccess | 1 + .../hub/main/discovery/recipient/class_ | 50 +++++++++ .../class_BaseRecipientDiscovery.php | 105 ++++++++++++++++++ .../main/discovery/recipient/dht/.htaccess | 1 + .../dht/class_DhtRecipientDiscovery.php | 2 +- .../discovery/recipient/package/.htaccess | 1 + .../class_PackageRecipientDiscovery.php | 4 +- .../main/discovery/recipient/socket/.htaccess | 1 + .../socket/class_PackageSocketDiscovery.php | 2 +- .../lists/recipient/class_RecipientList.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 25 +++-- .../main/pools/peer/class_DefaultPeerPool.php | 2 +- application/hub/main/recipient/class_ | 2 +- .../main/recipient/dht/class_DhtRecipient.php | 2 +- .../direct/class_DirectRecipient.php | 2 +- .../recipient/self/class_SelfRecipient.php | 2 +- .../recipient/upper/class_UpperRecipient.php | 2 +- application/hub/main/tools/class_HubTools.php | 32 +++--- ...odeDistributedHashTableDatabaseWrapper.php | 6 +- core | 2 +- 38 files changed, 395 insertions(+), 153 deletions(-) rename application/hub/interfaces/discovery/{dht => recipient}/.htaccess (100%) create mode 100644 application/hub/interfaces/discovery/recipient/class_DiscoverableRecipient.php rename application/hub/interfaces/discovery/{node => recipient/dht}/.htaccess (100%) rename application/hub/interfaces/discovery/{ => recipient}/dht/class_DiscoverableDhtRecipient.php (91%) rename application/hub/interfaces/discovery/{socket => recipient/node}/.htaccess (100%) rename application/hub/interfaces/discovery/{ => recipient}/node/class_DiscoverableNodeRecipient.php (77%) rename application/hub/{main/discovery/dht => interfaces/discovery/recipient/socket}/.htaccess (100%) rename application/hub/interfaces/discovery/{ => recipient}/socket/class_DiscoverableSocket.php (96%) rename application/hub/{main/discovery/package => interfaces/discovery/unl}/.htaccess (100%) create mode 100644 application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php create mode 100644 application/hub/main/discovery/class_ rename application/hub/main/discovery/{socket => node}/.htaccess (100%) create mode 100644 application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php create mode 100644 application/hub/main/discovery/recipient/.htaccess create mode 100644 application/hub/main/discovery/recipient/class_ create mode 100644 application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php create mode 100644 application/hub/main/discovery/recipient/dht/.htaccess rename application/hub/main/discovery/{ => recipient}/dht/class_DhtRecipientDiscovery.php (94%) create mode 100644 application/hub/main/discovery/recipient/package/.htaccess rename application/hub/main/discovery/{ => recipient}/package/class_PackageRecipientDiscovery.php (95%) create mode 100644 application/hub/main/discovery/recipient/socket/.htaccess rename application/hub/main/discovery/{ => recipient}/socket/class_PackageSocketDiscovery.php (98%) diff --git a/application/hub/config.php b/application/hub/config.php index 1e0180534..d66d1badf 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -729,6 +729,9 @@ $cfg->setConfigEntry('socket_discovery_class', 'PackageSocketDiscovery'); // CFG: DHT-RECIPIENT-DISCOVERY-CLASS $cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery'); +// CFG: UNIVERSAL-NODE-LOCATOR-DISCOVERY-CLASS +$cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery'); + // CFG: RECIPIENT-LIST-CLASS $cfg->setConfigEntry('recipient_list_class', 'RecipientList'); diff --git a/application/hub/interfaces/discovery/class_Discoverable.php b/application/hub/interfaces/discovery/class_Discoverable.php index edeba3578..8bb0dc9f0 100644 --- a/application/hub/interfaces/discovery/class_Discoverable.php +++ b/application/hub/interfaces/discovery/class_Discoverable.php @@ -22,26 +22,6 @@ * along with this program. If not, see . */ interface Discoverable extends FrameworkInterface { - /** - * "Getter" for recipient iterator - * - * @return $iteratorInstance An instance of a Iterateable object - */ - function getIterator (); - - /** - * Clears all recipients for e.g. another package to deliver - * - * @return void - */ - function clearRecipients (); - - /** - * Checks whether the recipient list is empty - * - * @return $isEmpty Whether the recipient list is empty - */ - function isRecipientListEmpty (); } // [EOF] diff --git a/application/hub/interfaces/discovery/dht/.htaccess b/application/hub/interfaces/discovery/recipient/.htaccess similarity index 100% rename from application/hub/interfaces/discovery/dht/.htaccess rename to application/hub/interfaces/discovery/recipient/.htaccess diff --git a/application/hub/interfaces/discovery/recipient/class_DiscoverableRecipient.php b/application/hub/interfaces/discovery/recipient/class_DiscoverableRecipient.php new file mode 100644 index 000000000..28f7db1e2 --- /dev/null +++ b/application/hub/interfaces/discovery/recipient/class_DiscoverableRecipient.php @@ -0,0 +1,48 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 DiscoverableRecipient extends Discoverable { + /** + * "Getter" for recipient iterator + * + * @return $iteratorInstance An instance of a Iterateable object + */ + function getIterator (); + + /** + * Clears all recipients for e.g. another package to deliver + * + * @return void + */ + function clearRecipients (); + + /** + * Checks whether the recipient list is empty + * + * @return $isEmpty Whether the recipient list is empty + */ + function isRecipientListEmpty (); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/discovery/node/.htaccess b/application/hub/interfaces/discovery/recipient/dht/.htaccess similarity index 100% rename from application/hub/interfaces/discovery/node/.htaccess rename to application/hub/interfaces/discovery/recipient/dht/.htaccess diff --git a/application/hub/interfaces/discovery/dht/class_DiscoverableDhtRecipient.php b/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php similarity index 91% rename from application/hub/interfaces/discovery/dht/class_DiscoverableDhtRecipient.php rename to application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php index 0dd47fbfd..79e721c82 100644 --- a/application/hub/interfaces/discovery/dht/class_DiscoverableDhtRecipient.php +++ b/application/hub/interfaces/discovery/recipient/dht/class_DiscoverableDhtRecipient.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface DiscoverableDhtRecipient extends Discoverable { +interface DiscoverableDhtRecipient extends DiscoverableRecipient { /** * Resolves one or more recipients for a DHT transfer by given package data. * diff --git a/application/hub/interfaces/discovery/socket/.htaccess b/application/hub/interfaces/discovery/recipient/node/.htaccess similarity index 100% rename from application/hub/interfaces/discovery/socket/.htaccess rename to application/hub/interfaces/discovery/recipient/node/.htaccess diff --git a/application/hub/interfaces/discovery/node/class_DiscoverableNodeRecipient.php b/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php similarity index 77% rename from application/hub/interfaces/discovery/node/class_DiscoverableNodeRecipient.php rename to application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php index 5c6a48924..a36d11948 100644 --- a/application/hub/interfaces/discovery/node/class_DiscoverableNodeRecipient.php +++ b/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface DiscoverableNodeRecipient extends Discoverable, IteratorAggregate { +interface DiscoverableNodeRecipient extends DiscoverableRecipient { /** * Tries to discover all recipients for given package data * @@ -37,20 +37,6 @@ interface DiscoverableNodeRecipient extends Discoverable, IteratorAggregate { * @return void */ function discoverRawRecipients (array $decodedData); - - /** - * "Getter" for recipient iterator - * - * @return $iteratorInstance An instance of a Iterateable object - */ - function getIterator (); - - /** - * Clears all recipients for e.g. another package to deliver - * - * @return void - */ - function clearRecipients (); } // [EOF] diff --git a/application/hub/main/discovery/dht/.htaccess b/application/hub/interfaces/discovery/recipient/socket/.htaccess similarity index 100% rename from application/hub/main/discovery/dht/.htaccess rename to application/hub/interfaces/discovery/recipient/socket/.htaccess diff --git a/application/hub/interfaces/discovery/socket/class_DiscoverableSocket.php b/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php similarity index 96% rename from application/hub/interfaces/discovery/socket/class_DiscoverableSocket.php rename to application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php index d147d0a2f..a94352633 100644 --- a/application/hub/interfaces/discovery/socket/class_DiscoverableSocket.php +++ b/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -interface DiscoverableSocket extends Discoverable { +interface DiscoverableSocket extends DiscoverableRecipient { /** * Tries to discover the right socket for given package data and returns a * matching socket resource. diff --git a/application/hub/main/discovery/package/.htaccess b/application/hub/interfaces/discovery/unl/.htaccess similarity index 100% rename from application/hub/main/discovery/package/.htaccess rename to application/hub/interfaces/discovery/unl/.htaccess diff --git a/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php new file mode 100644 index 000000000..203ce429b --- /dev/null +++ b/application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php @@ -0,0 +1,28 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 DiscoverableUniversalNodeLocator extends Discoverable { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php index 83d4fca5a..81d4a4000 100644 --- a/application/hub/interfaces/helper/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -109,16 +109,16 @@ interface NodeHelper extends Helper, AddableCriteria { function doSelfConnection (Taskable $taskInstance); /** - * Determines the universal node locator + * Determines the Universal Node Locator * - * @return $unl A an universal node locator for this node + * @return $unl A an Universal Node Locator for this node */ function determineUniversalNodeLocator (); /** - * "Getter for an universal node locator array + * "Getter for an Universal Node Locator array * - * @return $unlArray An array an universal node locator for this node + * @return $unlArray An array an Universal Node Locator for this node */ function getUniversalNodeLocatorArray (); diff --git a/application/hub/interfaces/recipient/class_Recipient.php b/application/hub/interfaces/recipient/class_Recipient.php index bf01e643f..eab4a6a69 100644 --- a/application/hub/interfaces/recipient/class_Recipient.php +++ b/application/hub/interfaces/recipient/class_Recipient.php @@ -23,7 +23,7 @@ */ interface Recipient extends FrameworkInterface { /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) diff --git a/application/hub/main/discovery/class_ b/application/hub/main/discovery/class_ new file mode 100644 index 000000000..95ee1f011 --- /dev/null +++ b/application/hub/main/discovery/class_ @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 . + */ +class !!!Discovery extends BaseNodeDiscovery implements Discoverable,,,, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create an instance of this class + * + * @return $discoveryInstance An instance of this discovery class + */ + public static final function create!!!Discovery () { + // Get an instance of this class + $discoveryInstance = new !!!Discovery(); + + // Return the prepared instance + return $discoveryInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/class_BaseNodeDiscovery.php b/application/hub/main/discovery/class_BaseNodeDiscovery.php index 2e5ff6a52..9a8db0a27 100644 --- a/application/hub/main/discovery/class_BaseNodeDiscovery.php +++ b/application/hub/main/discovery/class_BaseNodeDiscovery.php @@ -1,6 +1,6 @@ * @version 0.0.0 @@ -31,73 +31,6 @@ class BaseNodeDiscovery extends BaseDiscovery implements Discoverable { protected function __construct ($className) { // Call parent constructor parent::__construct($className); - - /* - * Get recipients list instance and set it here for all discovery - * implementations. - */ - $listInstance = RecipientListFactory::createRecipientListInstance(); - $this->setListInstance($listInstance); - } - - /** - * Determines the protoctol name - * - * @param $packageData Valid package data - * @return $protocolInstance An instance of a ProtocolHandler class - */ - protected function determineProtocolByPackageData (array $packageData) { - // First we need a tags instance - $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); - - /* - * We need to decide here which socket (TCP or UDP) should be used for - * the actual data transmission. In this process we will find out if - * the recipient of this package has already a known (registered) socket - * and if so we can re-use it. If there is no socket registered, we try - * to make a new connection to the given universal node locator. - */ - $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData); - - // Return it - return $protocolInstance; - } - - /** - * "Getter" for recipient iterator - * - * @return$iteratorInstance An instance of a Iterateable object - */ - public final function getIterator () { - // Get iterator from it - $iteratorInstance = $this->getListInstance()->getIterator(); - - // Return it - return $iteratorInstance; - } - - /** - * Clears all recipients for e.g. another package to deliver. This method - * simply clears the inner list instance. - * - * @return void - */ - public final function clearRecipients () { - // Clear the list - $this->getListInstance()->clearList(); - } - - /** - * Checks whether the recipient list is empty - * - * @return $isEmpty Whether the recipient list is empty - */ - public final function isRecipientListEmpty () { - // Check it ... - $isEmpty = ($this->getListInstance()->count() == 0); - - // Return it - return $isEmpty; } } diff --git a/application/hub/main/discovery/socket/.htaccess b/application/hub/main/discovery/node/.htaccess similarity index 100% rename from application/hub/main/discovery/socket/.htaccess rename to application/hub/main/discovery/node/.htaccess diff --git a/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php new file mode 100644 index 000000000..b5c3126b4 --- /dev/null +++ b/application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 . + */ +class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements DiscoverableUniversalNodeLocator, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create an instance of this class + * + * @return $discoveryInstance An instance of this discovery class + */ + public static final function createUniversalNodeLocatorDiscovery () { + // Get an instance of this class + $discoveryInstance = new UniversalNodeLocatorDiscovery(); + + // Return the prepared instance + return $discoveryInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/recipient/.htaccess b/application/hub/main/discovery/recipient/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/discovery/recipient/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/discovery/recipient/class_ b/application/hub/main/discovery/recipient/class_ new file mode 100644 index 000000000..bd903423f --- /dev/null +++ b/application/hub/main/discovery/recipient/class_ @@ -0,0 +1,50 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 . + */ +class !!!RecipientDiscovery extends BaseRecipientDiscovery implements Discoverable,,,Recipient, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Create an instance of this class + * + * @return $discoveryInstance An instance of this discovery class + */ + public static final function create!!!Discovery () { + // Get an instance of this class + $discoveryInstance = new !!!Discovery(); + + // Return the prepared instance + return $discoveryInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php b/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php new file mode 100644 index 000000000..a9741d984 --- /dev/null +++ b/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php @@ -0,0 +1,105 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Core Developer Team + * @license GNU GPL 3.0 or any newer version + * @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 + * 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 . + */ +class BaseRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableRecipient { + /** + * Protected constructor + * + * @param $className Real class name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + /* + * Get recipients list instance and set it here for all discovery + * implementations. + */ + $listInstance = RecipientListFactory::createRecipientListInstance(); + $this->setListInstance($listInstance); + } + + /** + * Determines the protoctol name + * + * @param $packageData Valid package data + * @return $protocolInstance An instance of a ProtocolHandler class + */ + protected function determineProtocolByPackageData (array $packageData) { + // First we need a tags instance + $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); + + /* + * We need to decide here which socket (TCP or UDP) should be used for + * the actual data transmission. In this process we will find out if + * the recipient of this package has already a known (registered) socket + * and if so we can re-use it. If there is no socket registered, we try + * to make a new connection to the given Universal Node Locator. + */ + $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData); + + // Return it + return $protocolInstance; + } + + /** + * "Getter" for recipient iterator + * + * @return$iteratorInstance An instance of a Iterateable object + */ + public final function getIterator () { + // Get iterator from it + $iteratorInstance = $this->getListInstance()->getIterator(); + + // Return it + return $iteratorInstance; + } + + /** + * Clears all recipients for e.g. another package to deliver. This method + * simply clears the inner list instance. + * + * @return void + */ + public final function clearRecipients () { + // Clear the list + $this->getListInstance()->clearList(); + } + + /** + * Checks whether the recipient list is empty + * + * @return $isEmpty Whether the recipient list is empty + */ + public final function isRecipientListEmpty () { + // Check it ... + $isEmpty = ($this->getListInstance()->count() == 0); + + // Return it + return $isEmpty; + } +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/recipient/dht/.htaccess b/application/hub/main/discovery/recipient/dht/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/discovery/recipient/dht/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/discovery/dht/class_DhtRecipientDiscovery.php b/application/hub/main/discovery/recipient/dht/class_DhtRecipientDiscovery.php similarity index 94% rename from application/hub/main/discovery/dht/class_DhtRecipientDiscovery.php rename to application/hub/main/discovery/recipient/dht/class_DhtRecipientDiscovery.php index 7a82c1c50..5fe1bee35 100644 --- a/application/hub/main/discovery/dht/class_DhtRecipientDiscovery.php +++ b/application/hub/main/discovery/recipient/dht/class_DhtRecipientDiscovery.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DhtRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableDhtRecipient, Registerable { +class DhtRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableDhtRecipient, Registerable { /** * Protected constructor * diff --git a/application/hub/main/discovery/recipient/package/.htaccess b/application/hub/main/discovery/recipient/package/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/discovery/recipient/package/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php similarity index 95% rename from application/hub/main/discovery/package/class_PackageRecipientDiscovery.php rename to application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php index ee4c3b1ae..46325e9b4 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class PackageRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableNodeRecipient, Registerable { +class PackageRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableNodeRecipient, Registerable { /** * Protected constructor * @@ -83,7 +83,7 @@ class PackageRecipientDiscovery extends BaseNodeDiscovery implements Discoverabl * * @param $decodedData Raw raw package data array * @return void - * @todo Add some validation of recipient field, e.g. an universal node locator is found + * @todo Add some validation of recipient field, e.g. an Universal Node Locator is found * @todo The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here */ public function discoverRawRecipients (array $decodedData) { diff --git a/application/hub/main/discovery/recipient/socket/.htaccess b/application/hub/main/discovery/recipient/socket/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/discovery/recipient/socket/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php similarity index 98% rename from application/hub/main/discovery/socket/class_PackageSocketDiscovery.php rename to application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php index 156397a42..dcb95dbc6 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -21,7 +21,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class PackageSocketDiscovery extends BaseNodeDiscovery implements DiscoverableSocket, Registerable { +class PackageSocketDiscovery extends BaseRecipientDiscovery implements DiscoverableSocket, Registerable { /** * Protected constructor * diff --git a/application/hub/main/lists/recipient/class_RecipientList.php b/application/hub/main/lists/recipient/class_RecipientList.php index 3debbe0bd..c3b1805a6 100644 --- a/application/hub/main/lists/recipient/class_RecipientList.php +++ b/application/hub/main/lists/recipient/class_RecipientList.php @@ -42,7 +42,7 @@ class RecipientList extends BaseList implements Listable, Registerable { $listInstance = new RecipientList(); // Add groups: - // 1.) universal node locators + // 1.) Universal Node Locators $listInstance->addGroup('unl'); // 2.) Session ids diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 08746675e..3e0538d17 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -686,28 +686,33 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { } /** - * Determines the universal node locator + * Determines the Universal Node Locator * - * @return $unl A an universal node locator for this node + * @return $unl A an Universal Node Locator for this node */ - public final function determineUniversalNodeLocator () { - // Get IP and port - $unl = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port'); + public function determineUniversalNodeLocator () { + // Determine UNL based on this node: + // 1) Get discovery class + $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); + + // 1) "Determine it + $unl = $discoveryInstance->discoverUniversalNodeLocatorByNode($this); // Return it return $unl; } /** - * "Getter" for universal node locator array + * "Getter" for Universal Node Locator array * - * @return $unlArray An array of the universal node locator for this node + * @return $unlArray An array of the Universal Node Locator for this node */ public final function getUniversalNodeLocatorArray () { - // Get IP and port + // Get Universal Node Locator (UNL) + $unl = $this->determineUniversalNodeLocator(); + // @TODO Unfinished - die(__METHOD__ . ':' . print_r($this, TRUE)); - $unlArray = explode(':', $this->determineUniversalNodeLocator()); + die(__METHOD__ . ':' . print_r($unl, TRUE)); // Return it return $unlArray; diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 8f3e2a1f5..39ffea7c4 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -223,7 +223,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { // Temporary resolve recipient field $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); - // Make sure it is a valid universal node locator array (3 elements) + // Make sure it is a valid Universal Node Locator array (3 elements) assert(count($recipientIpArray) == 3); // Debug message diff --git a/application/hub/main/recipient/class_ b/application/hub/main/recipient/class_ index c5a6f2e4e..3d9449c35 100644 --- a/application/hub/main/recipient/class_ +++ b/application/hub/main/recipient/class_ @@ -46,7 +46,7 @@ class ???Recipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php index 40daab4a4..e4a7d7f42 100644 --- a/application/hub/main/recipient/dht/class_DhtRecipient.php +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -46,7 +46,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern). This * implementation will add more than one recipient to the list as a DHT is * distributed and the package might go to more than one recipient. diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php index 71e61d392..014809cfe 100644 --- a/application/hub/main/recipient/direct/class_DirectRecipient.php +++ b/application/hub/main/recipient/direct/class_DirectRecipient.php @@ -46,7 +46,7 @@ class DirectRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php index f0a0c89e5..6693e6b65 100644 --- a/application/hub/main/recipient/self/class_SelfRecipient.php +++ b/application/hub/main/recipient/self/class_SelfRecipient.php @@ -46,7 +46,7 @@ class SelfRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php index f391d8fae..d6532029a 100644 --- a/application/hub/main/recipient/upper/class_UpperRecipient.php +++ b/application/hub/main/recipient/upper/class_UpperRecipient.php @@ -46,7 +46,7 @@ class UpperRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or universal node locator + * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index c41aa047e..c154b5532 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -86,17 +86,17 @@ class HubTools extends BaseHubSystem { } /** - * Resolves a session id into an universal node locator. The opposite method + * Resolves a session id into an Universal Node Locator. The opposite method * is resolveSessionIdByUniversalNodeLocator() * * @param $sessionId A valid session id - * @return $recipientUniversalNodeLocator Recipient as universal node locator + * @return $recipientUniversalNodeLocator Recipient as Universal Node Locator */ protected function resolveUniversalNodeLocatorBySessionId ($sessionId) { // Init variable $recipientUniversalNodeLocator = 'invalid:invalid'; - // And ask it for universal node locator by given session id + // And ask it for Universal Node Locator by given session id $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId); // Is the recipient valid? @@ -109,7 +109,7 @@ class HubTools extends BaseHubSystem { // Is the session id the same? if ($nodeInstance->getSessionId() == $sessionId) { - // Then get the universal node locator from it, assume TCP by default + // Then get the Universal Node Locator from it, assume TCP by default $recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port'); } // END - if } @@ -119,17 +119,17 @@ class HubTools extends BaseHubSystem { } /** - * Resolves a universal node locator into a session id. The "opposite" method + * Resolves a Universal Node Locator into a session id. The "opposite" method * is resolveUniversalNodeLocatorBySessionId(). * - * @param $unl Universal node locator + * @param $unl Universal Node Locator * @return $sessionId Valid session id */ public static function resolveSessionIdByUniversalNodeLocator ($unl) { // Get an own instance $selfInstance = self::getSelfInstance(); - // And ask it for session id by given universal node locator + // And ask it for session id by given Universal Node Locator $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unl); die(__METHOD__.':recipient=
'.print_r($recipient, TRUE).'
' . PHP_EOL); @@ -138,25 +138,25 @@ class HubTools extends BaseHubSystem { } /** - * Resolves given session id into an universal node locator, if universal node locator is set, it won't be translated + * Resolves given session id into an Universal Node Locator, if Universal Node Locator is set, it won't be translated * - * @param $address Session id or universal node locator - * @return $recipient Recipient as universal node locator - * @throws InvalidSessionIdException If the provided session id is invalid (and no universal node locator) + * @param $address Session id or Universal Node Locator + * @return $recipient Recipient as Universal Node Locator + * @throws InvalidSessionIdException If the provided session id is invalid (and no Universal Node Locator) * @throws NoValidHostnameException If the provided hostname cannot be resolved into an IP address */ public static function resolveSessionId ($address) { // Get an own instance $selfInstance = self::getSelfInstance(); - // Default is direct universal node locator + // Default is direct Universal Node Locator $recipient = $address; - // Does it match a direct universal node locator? (hint: see www.regexlib.com for the regular expression) + // Does it match a direct Universal Node Locator? (hint: see www.regexlib.com for the regular expression) if (preg_match('/([a-z0-9]{3,10})\/\/:([a-z0-9\.]{5,})/', $address)) { // @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5}) - // Direct universal node locator found - self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct universal node locator ' . $address . ' detected.'); + // Direct Universal Node Locator found + self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct Universal Node Locator ' . $address . ' detected.'); } elseif (isset($selfInstance->sessionIdCache[$address])) { // Debug message self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.'); @@ -170,7 +170,7 @@ class HubTools extends BaseHubSystem { // Debug message self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.'); - // Resolve session id into an universal node locator + // Resolve session id into an Universal Node Locator $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address); // Debug message diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 34b0b63fa..9dafd9f35 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -146,7 +146,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Set the primary key $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID); - // Get universal node locator and "explode" it + // Get Universal Node Locator and "explode" it $unl = $nodeInstance->getUniversalNodeLocatorArray(); // Make sure both is valid @@ -187,7 +187,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get node instance $nodeInstance = NodeObjectFactory::createNodeInstance(); - // Get universal node locator and "explode" it + // Get Universal Node Locator and "explode" it $unl = $nodeInstance->getUniversalNodeLocatorArray(); /* @@ -196,7 +196,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem */ assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid')); - // Add universal node locator/node id as criteria + // Add Universal Node Locator/node id as criteria $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $unl[0]); $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $unl[1]); $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); diff --git a/core b/core index 584f44fab..1613679bb 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 584f44fab69cbffea39a99f0b169e3bdbb98b385 +Subproject commit 1613679bba663e7d92c2194fd14a047770befe2c -- 2.39.2