From: Roland Haeder Date: Wed, 24 Dec 2014 14:07:04 +0000 (+0100) Subject: A lot changes for refacturing protocol handler X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=570dc8ef51eebc922ef551a7ff12a4e072c3702e;p=hub.git A lot changes for refacturing protocol handler Signed-off-by: Roland Haeder --- diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index c20e60d77..a99055086 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -155,7 +155,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // Is no external address set? if ($this->getConfigInstance()->getConfigEntry('external_address') == '') { // Determine external address - $this->getConfigInstance()->setConfigEntry('external_address', ConsoleTools::determineExternalAddress()); + $this->getConfigInstance()->setConfigEntry('external_address', HubTools::determineOwnExternalAddress()); } // END - if // Default response is console diff --git a/application/hub/config.php b/application/hub/config.php index bb5c4e636..855dbfd3d 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -732,6 +732,12 @@ $cfg->setConfigEntry('dht_recipient_discovery_class', 'DhtRecipientDiscovery'); // CFG: UNL-DISCOVERY-CLASS $cfg->setConfigEntry('unl_discovery_class', 'UniversalNodeLocatorDiscovery'); +// CFG: PROTOCOL-DISCOVERY-CLASS +$cfg->setConfigEntry('protocol_discovery_class', 'ProtocolDiscovery'); + +// CFG: TCP-PROTOCOL-HANDLER-CLASS +$cfg->setConfigEntry('tcp_protocol_handler_class', 'TcpProtocolHandler'); + // CFG: UNIVERSAL-NODE-LOCATOR-CLASS $cfg->setConfigEntry('universal_node_locator_class', 'UniversalNodeLocator'); @@ -787,12 +793,12 @@ $cfg->setConfigEntry('private_key', ''); // CFG: PRIVATE-KEY-HASH $cfg->setConfigEntry('private_key_hash', ''); -// CFG: INTERNAL-ADDRESS -$cfg->setConfigEntry('internal_address', ConsoleTools::acquireSelfIPAddress()); - // CFG: EXTERNAL-ADDRESS $cfg->setConfigEntry('external_address', ''); +// CFG: INTERNAL-ADDRESS +$cfg->setConfigEntry('internal_address', ''); + // CFG: ALLOW-PUBLISH-INTERNAL-ADDRESS $cfg->setConfigEntry('allow_publish_internal_address', 'N'); diff --git a/application/hub/init.php b/application/hub/init.php index a3b04697f..42cf82403 100644 --- a/application/hub/init.php +++ b/application/hub/init.php @@ -34,8 +34,8 @@ require($cfg->getConfigEntry('base_path') . 'inc/output.php'); // the inc/database.php script require($cfg->getConfigEntry('base_path') . 'inc/database.php'); -// Get's our IP address -ConsoleTools::acquireSelfIPAddress(); +// Get own internal address +HubTools::determineOwnInternalAddress(); // [EOF] ?> diff --git a/application/hub/interfaces/discovery/class_Discoverable b/application/hub/interfaces/discovery/class_Discoverable new file mode 100644 index 000000000..8c498359d --- /dev/null +++ b/application/hub/interfaces/discovery/class_Discoverable @@ -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 Discoverable!!! extends Discoverable { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/discovery/protocol/.htaccess b/application/hub/interfaces/discovery/protocol/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/discovery/protocol/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/interfaces/discovery/protocol/class_DiscoverableProtocol.php b/application/hub/interfaces/discovery/protocol/class_DiscoverableProtocol.php new file mode 100644 index 000000000..97c894f86 --- /dev/null +++ b/application/hub/interfaces/discovery/protocol/class_DiscoverableProtocol.php @@ -0,0 +1,36 @@ + + * @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 DiscoverableProtocol extends Discoverable { + /** + * "Discovers" the protocol type from given raw package data. This is done + * by looking at the 'recipient' field and extract the first part from it. + * + * @param $packageData Raw package data + * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections + */ + function discoverProtocolByPackageData (array $packageData); +} + +// [EOF] +?> diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index 4074932f8..6bf7b5cd3 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -42,11 +42,11 @@ interface ConnectionHelper extends HubHelper { function doShutdown (); /** - * Getter for port number to satify ProtocolHandler + * Getter for port number to satify HandleableProtocol * * @return $port The port number */ - function getPort (); + function getConnectionPort (); /** * Getter for IP address diff --git a/application/hub/interfaces/helper/hub/class_HubHelper.php b/application/hub/interfaces/helper/hub/class_HubHelper.php index 5ef351e65..853eb0259 100644 --- a/application/hub/interfaces/helper/hub/class_HubHelper.php +++ b/application/hub/interfaces/helper/hub/class_HubHelper.php @@ -22,6 +22,12 @@ * along with this program. If not, see . */ interface HubHelper extends Helper { + /** + * Tries to determine the used protocol for this package (this helper is helping to send out) + * + * @return $protocolType Type of protocol to use, usually TCP + */ + function determineProtocolType (); } // [EOF] diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index ba1875ad0..ec878cc53 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.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 Listenable extends ProtocolHandler { +interface Listenable extends FrameworkInterface { /** * Initializes the listener by setting up the required socket server * @@ -52,6 +52,27 @@ interface Listenable extends ProtocolHandler { * @return void */ function monitorIncomingRawData (Receivable $receiverInstance); + + /** + * Getter for listen address + * + * @return $listenAddress The address this listener should listen on + */ + function getListenAddress (); + + /** + * Getter for listen port + * + * @return $listenPort The port this listener should listen on + */ + function getListenPort (); + + /** + * Getter for peer pool instance + * + * @return $poolInstance The peer pool instance we shall set + */ + function getPoolInstance (); } // [EOF] diff --git a/application/hub/interfaces/tags/class_Tagable.php b/application/hub/interfaces/tags/class_Tagable.php index 4d8b6ec0b..2c6b55754 100644 --- a/application/hub/interfaces/tags/class_Tagable.php +++ b/application/hub/interfaces/tags/class_Tagable.php @@ -26,7 +26,7 @@ interface Tagable extends FrameworkInterface { * Chooses the right protocol from given package data * * @param $packageData Raw package data - * @return $protocolInstance An instance of a ProtocolHandler class + * @return $protocolInstance An instance of a HandleableProtocol class */ function chooseProtocolFromPackageData (array $packageData); diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 58c9dc3ee..d63991945 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -68,11 +68,6 @@ class BaseHubSystem extends BaseFrameworkSystem { */ private $minerInstance = NULL; - /** - * Listener instance - */ - private $listenerInstance = NULL; - /** * A network package handler instance */ @@ -219,25 +214,6 @@ class BaseHubSystem extends BaseFrameworkSystem { $this->minerInstance = $minerInstance; } - /** - * Setter for listener instance - * - * @param $listenerInstance A Listenable instance - * @return void - */ - protected final function setListenerInstance (Listenable $listenerInstance) { - $this->listenerInstance = $listenerInstance; - } - - /** - * Getter for listener instance - * - * @return $listenerInstance A Listenable instance - */ - protected final function getListenerInstance () { - return $this->listenerInstance; - } - /** * Setter for network package handler instance * diff --git a/application/hub/main/discovery/protocol/.htaccess b/application/hub/main/discovery/protocol/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/discovery/protocol/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/discovery/protocol/class_ProtocolDiscovery.php b/application/hub/main/discovery/protocol/class_ProtocolDiscovery.php new file mode 100644 index 000000000..e95a8914e --- /dev/null +++ b/application/hub/main/discovery/protocol/class_ProtocolDiscovery.php @@ -0,0 +1,77 @@ + + * @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 ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtocol, 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 createProtocolDiscovery () { + // Get an instance of this class + $discoveryInstance = new ProtocolDiscovery(); + + // Return the prepared instance + return $discoveryInstance; + } + + /** + * "Discovers" the protocol type from given raw package data. This is done + * by looking at the 'recipient' field and extract the first part from it. + * + * @param $packageData Raw package data + * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections + */ + public function discoverProtocolByPackageData (array $packageData) { + //* DEBUG: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + + /* + * "Explode" the 'recipient' array element into a new one, giving at + * least two entries: protocol://address + */ + $recipient = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); + + // At least 2 entries must be found + assert(count($recipient) >= 2); + + // Now get the first part (protocol type) and make all lower-case + $protocolType = strtolower($recipient[0]); + + // Return it + // @TODO Add some validation here??? + return $protocolType; + } +} + +// [EOF] +?> diff --git a/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php b/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php index a9741d984..56d3db4d3 100644 --- a/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php +++ b/application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.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 BaseRecipientDiscovery extends BaseRecipientDiscovery implements DiscoverableRecipient { +class BaseRecipientDiscovery extends BaseNodeDiscovery implements DiscoverableRecipient { /** * Protected constructor * @@ -44,7 +44,7 @@ class BaseRecipientDiscovery extends BaseRecipientDiscovery implements Discovera * Determines the protoctol name * * @param $packageData Valid package data - * @return $protocolInstance An instance of a ProtocolHandler class + * @return $protocolInstance An instance of a HandleableProtocol class */ protected function determineProtocolByPackageData (array $packageData) { // First we need a tags instance diff --git a/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php index dcb95dbc6..b36aee53a 100644 --- a/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -103,6 +103,8 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * @throws NullPointerException If listenerInstance is NULL */ public function discoverSocket (array $packageData, $connectionType) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: connectionType=' . $connectionType . ' - CALLED!'); + // Assert on type assert($connectionType != BaseConnectionHelper::CONNECTION_TYPE_SERVER); diff --git a/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php b/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php index 6955bd0a4..12ada2e94 100644 --- a/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php +++ b/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php @@ -34,17 +34,12 @@ class ProtocolHandlerFactory extends ObjectFactory { } /** - * Returns a singleton protocol handler instance from given HubHelper - * instance. If an instance is found in registry, it will be returned, else - * a new instance is created and stored in the same registry entry. + * Returns a protocol handler based on given protocol type. This is mostly 'tcp'. * - * @param $helperInstance An instance of a HubHelper class + * @param $protocolType Protocol type to create/return a protocol handler instance for * @return $handlerInstance A protocol handler instance */ - public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) { - // Get the protocol type from given helper instance - die(__METHOD__ . ':' . print_r($helperInstance, TRUE)); - + private static function createProtocolHandlerByType ($protocolType) { // Do we have an instance in the registry? if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) { // Then use this instance @@ -60,6 +55,39 @@ class ProtocolHandlerFactory extends ObjectFactory { // Return the instance return $handlerInstance; } + + /** + * Returns a singleton protocol handler instance from given HubHelper + * instance. If an instance is found in registry, it will be returned, else + * a new instance is created and stored in the same registry entry. + * + * @param $helperInstance An instance of a HubHelper class + * @return $handlerInstance A protocol handler instance + */ + public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) { + // Get the protocol type from given helper instance + $protocolType = $helperInstance->determineProtocolType(); + + // Call super factory method + return self::createProtocolHandlerByType($protocolType); + } + + /** + * Creates an instance of a protocol handler from given (raw) package data + * + * @param $packageData An array with raw package data + * @return $handlerInstance A protocol handler instance + */ + public static final function createProtocolHandlerFromPackageData (array $packageData) { + // Now that there is no direct node instance available, a protocol discovery class is required + $discoveryInstance = ObjectFactory::createObjectByConfiguredName('protocol_discovery_class'); + + // "Discover" the protocol type + $protocolType = $discoveryInstance->discoverProtocolByPackageData($packageData); + + // Call super factory method + return self::createProtocolHandlerByType($protocolType); + } } // [EOF] diff --git a/application/hub/main/factories/socket/class_SocketFactory.php b/application/hub/main/factories/socket/class_SocketFactory.php index 9a1973d08..b642e8246 100644 --- a/application/hub/main/factories/socket/class_SocketFactory.php +++ b/application/hub/main/factories/socket/class_SocketFactory.php @@ -37,10 +37,10 @@ class SocketFactory extends ObjectFactory { * Creates a valid socket resource from given packae data and protocol * * @param $packageData Raw package data - * @param $protocolInstance An instance of a ProtocolHandler class + * @param $protocolInstance An instance of a HandleableProtocol class * @return $socketResource Socket resource */ - public static function createSocketFromPackageData (array $packageData, ProtocolHandler $protocolInstance) { + public static function createSocketFromPackageData (array $packageData, HandleableProtocol $protocolInstance) { // Get an instance $factoryInstance = new SocketFactory(); diff --git a/application/hub/main/handler/protocol/.htaccess b/application/hub/main/handler/protocol/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/handler/protocol/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/handler/protocol/class_ b/application/hub/main/handler/protocol/class_ new file mode 100644 index 000000000..770d44334 --- /dev/null +++ b/application/hub/main/handler/protocol/class_ @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 . + */ +class ???ProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set handler name + $this->setHandlerName('|||_protocol'); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a HandleableMessage class + */ + public final static function create???ProtocolHandler () { + // Get new instance + $handlerInstance = new ???ProtocolHandler(); + + // Return the prepared instance + return $handlerInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/protocol/class_BaseProtocolHandler.php b/application/hub/main/handler/protocol/class_BaseProtocolHandler.php new file mode 100644 index 000000000..c2421c1dd --- /dev/null +++ b/application/hub/main/handler/protocol/class_BaseProtocolHandler.php @@ -0,0 +1,38 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 Hub 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 BaseProtocolHandler extends BaseHandler { + /** + * Protected constructor + * + * @param $className Name of the class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/protocol/tcp/.htaccess b/application/hub/main/handler/protocol/tcp/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/handler/protocol/tcp/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/handler/protocol/tcp/class_TcpProtocolHandler.php b/application/hub/main/handler/protocol/tcp/class_TcpProtocolHandler.php new file mode 100644 index 000000000..bdbdd3ee8 --- /dev/null +++ b/application/hub/main/handler/protocol/tcp/class_TcpProtocolHandler.php @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2014 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 . + */ +class TcpProtocolHandler extends BaseProtocolHandler implements HandleableProtocol, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set handler name + $this->setHandlerName('tcp_protocol'); + } + + /** + * Creates an instance of this class + * + * @return $handlerInstance An instance of a HandleableMessage class + */ + public final static function createTcpProtocolHandler () { + // Get new instance + $handlerInstance = new TcpProtocolHandler(); + + // Return the prepared instance + return $handlerInstance; + } +} + +// [EOF] +?> diff --git a/application/hub/main/helper/class_BaseHubSystemHelper.php b/application/hub/main/helper/class_BaseHubSystemHelper.php index 60d5d7a20..b4f365a81 100644 --- a/application/hub/main/helper/class_BaseHubSystemHelper.php +++ b/application/hub/main/helper/class_BaseHubSystemHelper.php @@ -79,6 +79,17 @@ class BaseHubSystemHelper extends BaseHubSystem implements HubHelper { public final function setPackageTags (array $packageTags) { $this->packageTags = $packageTags; } + + /** + * Tries to determine the used protocol for this package (this helper is helping to send out) + * + * @return $protocolType Type of protocol to use, usually TCP + * @todo 0% done + */ + public function determineProtocolType () { + die(__METHOD__ . ':' . print_r($this, TRUE)); + // Return it + } } // [EOF] diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index 6f2eeb2df..706a3796d 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -40,10 +40,15 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable { */ const CONNECTION_TYPE_SERVER = 'server'; + /** + * Name of used protocol for this connection + */ + private $connectionType = 'invalid'; + /** * Port number used */ - private $port = 0; + private $connectionPort = 0; /** * (IP) Adress used @@ -117,29 +122,48 @@ class BaseConnectionHelper extends BaseHubSystemHelper implements Registerable { */ public final function __toString () { // Class name representation - $class = self::getConnectionClassName($this->getAddress(), $this->getPort(), parent::__toString()); + $class = self::getConnectionClassName($this->getAddress(), $this->getConnectionPort(), parent::__toString()); // Return it return $class; } /** - * Getter for port number to satify ProtocolHandler + * Getter for connection type + * + * @return $connectionType Name of used protocol in this connection + */ + public final function getConnectionType () { + return $this->connectionType; + } + + /** + * Setter for connection type + * + * @param $connectionType Name of used protocol in this connection + * @return void + */ + protected final function setConnectionType ($connectionType) { + $this->connectionType = $connectionType; + } + + /** + * Getter for port number to satify HandleableProtocol * - * @return $port The port number + * @return $connectionPort The port number */ - public final function getPort () { - return $this->port; + public final function getConnectionPort () { + return $this->connectionPort; } /** - * Setter for port number to satify ProtocolHandler + * Setter for port number to satify HandleableProtocol * - * @param $port The port number + * @param $connectionPort The port number * @return void */ - protected final function setPort ($port) { - $this->port = $port; + protected final function setConenctionPort ($connectionPort) { + $this->connectionPort = $connectionPort; } /** diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 0734089b0..de83320a9 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -93,23 +93,28 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Try to solve the recipient try { // Resolve any session ids; 0 = IP, 1 = Port - $recipientData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); + $resolved = HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); + die(__METHOD__ . 'resolved=' . print_r($resolved, TRUE)); + + $recipientData = explode(':', $resolved); } catch (NoValidHostnameException $e) { // Debug message self::createDebugInstance(__CLASS__)->debugOutput('CONNECTION-HELPER[' . __METHOD__ . ':' . __LINE__ . ']: Failed to resolve ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ':' . $e->getMessage()); // Is the recipient equal as configured IP if (substr($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) { - // This connects to shipsimu.org and requests /ip.php which will return our external address - $recipientData[0] = ConsoleTools::determineExternalAddress(); + // This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address + $recipientData[0] = HubTools::determineExternalAddress(); - // Do we have hostname:ip match? + // Do we have ip:port match? + // @TODO Rewrite this test for UNLs if (strpos($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], ':') === FALSE) { - // No hostname:ip! + // No ip:port! $helperInstance->debugInstance($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' does not contain ":". Please fix this.'); } // END - if - // "explode" the hostname:ip, so index 1 will be the port number + // "explode" the ip:port, so index 1 will be the port number + // @TODO Rewrite this test for UNLs $recipientArray = explode(':', $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]); // Add the port @@ -122,7 +127,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp // Set address and maybe port $helperInstance->setAddress($recipientData[0]); - $helperInstance->setPort($recipientData[1]); + $helperInstance->setConnectionPort($recipientData[1]); // Now connect to it if (!$helperInstance->connectToPeerByRecipientData($recipientData)) { diff --git a/application/hub/main/helper/dht/class_DhtBootstrapHelper.php b/application/hub/main/helper/dht/class_DhtBootstrapHelper.php index 41838a244..436cfd16d 100644 --- a/application/hub/main/helper/dht/class_DhtBootstrapHelper.php +++ b/application/hub/main/helper/dht/class_DhtBootstrapHelper.php @@ -83,7 +83,7 @@ class DhtBootstrapHelper extends BaseHubSystemHelper implements HelpableDht { */ public function sendPackage (Distributable $dhtInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); /* * Sanity check: Is the DHT in the approx. state? 'init' for bootstrap @@ -98,10 +98,11 @@ class DhtBootstrapHelper extends BaseHubSystemHelper implements HelpableDht { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. + //* DEBUG: */ die(__METHOD__ . ':dhtInstance=' . print_r($dhtInstance, TRUE)); $packageInstance->enqueueRawDataFromTemplate($this); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('HELPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } } diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index 1007fa88d..2aa6c6a9e 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -126,15 +126,6 @@ class BaseListener extends BaseHubSystem implements Visitable { return $this->listenPort; } - /** - * Getter for port number to satify ProtocolHandler - * - * @return $port The port number - */ - public final function getPort () { - return $this->getListenPort(); - } - /** * "Setter" to set listen address from configuration entry * diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index 87292e4de..e45a78111 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -56,15 +56,6 @@ class BaseListenerDecorator extends BaseDecorator implements Visitable { return $this->getListenerInstance()->getListenPort(); } - /** - * Getter for port - * - * @return $port The port - */ - public final function getPort () { - return $this->getListenerInstance()->getPort(); - } - /** * Accepts the visitor to process the visit "request" * diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index ed7a894f7..de02f5659 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -58,8 +58,14 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { * @todo add some more special bootstrap things for this boot node */ 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($this->detectOwnUniversalNodeLocator())) { + if ($this->ifAddressMatchesBootstrapNodes($unl)) { // Get our port from configuration $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port'); @@ -81,11 +87,11 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { } } else { // IP does match, but no port - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->detectOwnUniversalNodeLocator() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.'); + 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 IP ' . $this->detectOwnUniversalNodeLocator() . ' does not match any known bootstrap-nodes.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.'); } // Enable acceptance of announcements diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index ea4fb11d2..2228b3114 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -122,54 +122,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); } - /** - * Generates an UNL (Universal Node Locator) for the internal address - * - * @return $internalUnl Internal UNL - */ - private function generateInternalUnl () { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); - - // Is there cache? (This shortens a lot calls) - if (!isset($GLOBALS[__METHOD__])) { - // Determine UNL based on this node: - // 1) Get discovery class - $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); - - // 2) "Determine" it - $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal'); - } // END - if - - // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); - return $GLOBALS[__METHOD__]; - } - - /** - * Generates an UNL (Universal Node Locator) for the external address - * - * @return $externalUnl External UNL - */ - private function generateExternalUnl () { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); - - // Is there cache? (This shortens a lot calls) - if (!isset($GLOBALS[__METHOD__])) { - // Determine UNL based on this node: - // 1) Get discovery class - $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); - - // 2) "Determine" it - $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external'); - } // END - if - - // Return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); - return $GLOBALS[__METHOD__]; - } - /** * Generates a random string from various data inluding UUID if PECL * extension uuid is installed. @@ -222,7 +174,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches remote address ' . $unl . '.'); // Stop further searching break; @@ -237,7 +189,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: UNL matches listen address ' . $unl . '.'); // Stop further searching break; @@ -426,8 +378,8 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { } // END - if // Add own external and internal addresses as UNLs - $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, $this->generateInternalUnl()); - $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, $this->generateExternalUnl()); + $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL, HubTools::determineOwnInternalAddress()); + $criteriaInstance->addCriteria(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL, HubTools::determineOwnExternalAddress()); } /** @@ -790,6 +742,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { // Get the Universal Node Locator (UNL) instance $unlInstance = $this->determineUniversalNodeLocator(); + // Make sure the instance is valid + // * DEBUG: */ $this->debugInstance('unlInstance[]=' . gettype($unlInstance)); + assert($unlInstance instanceof LocateableNode); + // ... and the array from it $unlData = $unlInstance->getUnlData(); diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index a7832b99d..dee97c639 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -97,7 +97,6 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R */ const PACKAGE_DATA_SENDER = 'sender'; const PACKAGE_DATA_RECIPIENT = 'recipient'; - const PACKAGE_DATA_PROTOCOL = 'protocol'; const PACKAGE_DATA_CONTENT = 'content'; const PACKAGE_DATA_STATUS = 'status'; const PACKAGE_DATA_SIGNATURE = 'signature'; @@ -451,6 +450,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Now get an iterator $iteratorInstance = $discoveryInstance->getIterator(); + // Make sure the iterator instance is valid + assert($iteratorInstance instanceof Iterator); + // Rewind back to the beginning $iteratorInstance->rewind(); @@ -460,7 +462,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $currentRecipient = $iteratorInstance->current(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Setting recipient to ' . $currentRecipient . ',previous=' . $packageData[self::PACKAGE_DATA_RECIPIENT]); // Set the recipient $packageData[self::PACKAGE_DATA_RECIPIENT] = $currentRecipient; @@ -469,7 +471,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageData); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NETWORK-PACKAGE[' . __METHOD__ . ':' . __LINE__ . ']: Package declared for recipient ' . $currentRecipient); // Skip to next entry $iteratorInstance->next(); @@ -628,8 +630,8 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @return void */ public function enqueueRawDataFromTemplate (HubHelper $helperInstance) { - // Get protocol instance for recipient - $protocolInstance = ProtocolHandlerFactory::createProtocolHandlerFromRecipientHelper($helperInstance); + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!'); // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -656,15 +658,20 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R $this->getHashFromContent($content) ); + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...'); + // Now prepare the temporary array and push it on the 'undeclared' stack $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, array( self::PACKAGE_DATA_SENDER => $this->getSessionId(), self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(), - self::PACKAGE_DATA_PROTOCOL => $protocolInstance->getProtocolName(), self::PACKAGE_DATA_CONTENT => $packageContent, self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW, self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($packageContent, $this->getSessionId()) )); + + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!'); } /** @@ -730,6 +737,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @throws NoTargetException If no target can't be determined */ public function declareEnqueuedPackage () { + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!'); + // Make sure this method isn't working if there is no package enqueued if (!$this->isPackageEnqueued()) { // This is not fatal but should be avoided @@ -745,6 +755,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Declare the raw package data for delivery $this->declareRawPackageData($packageData); + + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!'); } /** @@ -755,6 +768,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @return void */ public function processDeclaredPackage () { + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!'); + // Sanity check if we have packages declared if (!$this->isPackageDeclared()) { // This is not fatal but should be avoided @@ -782,6 +798,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Mark the package with status failed $this->changePackageStatus($packageData, self::STACKER_NAME_DECLARED, self::PACKAGE_STATUS_FAILED); } + + // Debug message + //* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!'); } /** @@ -790,6 +809,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @return void */ public function sendWaitingPackage () { + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!'); + // Sanity check if we have packages waiting for delivery if (!$this->isPackageWaitingForDelivery()) { // This is not fatal but should be avoided @@ -813,6 +835,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Mark package as failed $this->changePackageStatus($packageData, self::STACKER_NAME_OUTGOING, self::PACKAGE_STATUS_FAILED); } + + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!'); } /** @@ -821,6 +846,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @return void */ public function sendEncodedData () { + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': CALLED!'); + // Make sure there is pending encoded data assert($this->isEncodedDataPending()); @@ -880,6 +908,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // Push array back in stack $this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING_STREAM, $encodedDataArray); + + // Debug message + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ': EXIT!'); } /////////////////////////////////////////////////////////////////////////// diff --git a/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php index 02e92bccd..e18cdf4a2 100644 --- a/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php +++ b/application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php @@ -79,7 +79,7 @@ class CruncherKeyProducer extends BaseKeyProducer implements KeyProducer, Regist return; } elseif (!$this->getIteratorInstance()->valid()) { // This producer's iterator has finished its assignment - self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorinstance=' . $this->getIteratorInstance()->__toString() . ''); + self::createDebugInstance(__CLASS__)->debugOutput('PRODUCER: Finished creating keys. iteratorInstance=' . $this->getIteratorInstance()->__toString() . ''); return; } diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php index c93110cbe..8c2423c22 100644 --- a/application/hub/main/recipient/direct/class_DirectRecipient.php +++ b/application/hub/main/recipient/direct/class_DirectRecipient.php @@ -57,7 +57,7 @@ class DirectRecipient extends BaseRecipient implements Recipient { */ public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DIRECT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient); // "Explode" all recipients $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient); diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php index d3262368e..7c2f8f51d 100644 --- a/application/hub/main/recipient/self/class_SelfRecipient.php +++ b/application/hub/main/recipient/self/class_SelfRecipient.php @@ -57,21 +57,17 @@ class SelfRecipient extends BaseRecipient implements Recipient { */ public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) { // Make sure the recipient is valid - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient); - // @TODO Unfinished - die(__METHOD__ . 'recipient=:' . print_r($recipient, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: recipient=' . $recipient); + // @TODO Add more checks on data assert($recipient == NetworkPackage::NETWORK_TARGET_SELF); - // Determine own port - $port = $this->getConfigInstance()->getConfigEntry('node_listen_port'); - // Determine IP or 'external_address' if set - $ip = HubTools::determineOwnExternalAddress(); + $unl = HubTools::determineOwnExternalAddress(); // Is it not empty? - if (!empty($ip)) { + if (!empty($unl)) { // Add it to the list - $listInstance->addEntry('unl', $ip . ':' . $port); + $listInstance->addEntry('unl', $unl); } // END - if } } diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php index d76fc7a25..269005336 100644 --- a/application/hub/main/recipient/upper/class_UpperRecipient.php +++ b/application/hub/main/recipient/upper/class_UpperRecipient.php @@ -65,14 +65,14 @@ class UpperRecipient extends BaseRecipient implements Recipient { // Is maximum reached? if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) { // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); // Then stop adding more break; } // END - if // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER[' . __METHOD__ . ':' . __LINE__ . ']: Adding node ' . print_r($unlData, TRUE) . ' as recipient.'); // Add the entry $listInstance->addEntry('unl', $unlData); diff --git a/application/hub/main/registry/connection/class_ConnectionRegistry.php b/application/hub/main/registry/connection/class_ConnectionRegistry.php index fb7745fc4..2caf8fc76 100644 --- a/application/hub/main/registry/connection/class_ConnectionRegistry.php +++ b/application/hub/main/registry/connection/class_ConnectionRegistry.php @@ -58,17 +58,17 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC /** * "Getter" to get a string respresentation for a key for the sub-registry - * in this format: class:protocol:port + * in this format: class:type:port * * @param $connectionInstance An instance of a ConnectionHelper class * @return $key A string representation of the socket for the registry */ private function getSubRegistryKey (ConnectionHelper $connectionInstance) { - // Get protocol and port number and add both together - $key = sprintf("%s:%s:%s", + // Get connection type and port number and add both together + $key = sprintf('%s:%s:%s', $connectionInstance->__toString(), - $connectionInstance->getProtocolName(), - $connectionInstance->getPort() + $connectionInstance->getConnectionType(), + $connectionInstance->getConnectionPort() ); // Return resulting key @@ -78,10 +78,10 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC /** * "Getter" to get a string respresentation of the protocol * - * @param $connectionInstance An instance of a ConnectionHelper class - * @return $key A string representation of the protocol for the registry + * @param $connectionInstance An instance of a ConnectionHelper class + * @return $key A string representation of the protocol for the registry */ - private function getRegistryKeyFromProtocol (ConnectionHelper $connectionInstance) { + private function getRegistryKeyFromConnection (ConnectionHelper $connectionInstance) { // Get the key $key = $connectionInstance->getProtocolName(); @@ -95,9 +95,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC * @param $connectionInstance An instance of a ConnectionHelper class * @return $isRegistered Whether the protocol is registered */ - private function isProtocolRegistered (ConnectionHelper $connectionInstance) { + private function isConnectionRegistered (ConnectionHelper $connectionInstance) { // Get the key - $key = $this->getRegistryKeyFromProtocol($connectionInstance); + $key = $this->getRegistryKeyFromConnection($connectionInstance); // Determine it $isRegistered = $this->instanceExists($key); @@ -119,9 +119,9 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC $isRegistered = FALSE; // First, check for the instance, there can be only once - if ($this->isProtocolRegistered($connectionInstance)) { + if ($this->isConnectionRegistered($connectionInstance)) { // That one is found so "get" a registry key from it - $key = $this->getRegistryKeyFromProtocol($connectionInstance); + $key = $this->getRegistryKeyFromConnection($connectionInstance); // Get the registry $registryInstance = $this->getInstance($key); @@ -154,15 +154,15 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC } // END - if // Does the instance exist? - if (!$this->isProtocolRegistered($connectionInstance)) { + if (!$this->isConnectionRegistered($connectionInstance)) { // No, not found so we create a sub registry (not needed to configure!) $registryInstance = SubRegistry::createSubRegistry(); // Now we can create the sub-registry for this protocol - $this->addInstance($this->getRegistryKeyFromProtocol($connectionInstance), $registryInstance); + $this->addInstance($this->getRegistryKeyFromConnection($connectionInstance), $registryInstance); } else { // Get the sub-registry back - $registryInstance = $this->getInstance($this->getRegistryKeyFromProtocol($connectionInstance)); + $registryInstance = $this->getInstance($this->getRegistryKeyFromConnection($connectionInstance)); } // Get a key for sub-registries @@ -191,7 +191,7 @@ class ConnectionRegistry extends BaseRegistry implements Register, RegisterableC } // END - if // Now get the key from the protocol - $key = $this->getRegistryKeyFromProtocol($connectionInstance); + $key = $this->getRegistryKeyFromConnection($connectionInstance); // And get the registry $registryInstance = $this->getInstance($key); diff --git a/application/hub/main/registry/socket/class_SocketRegistry.php b/application/hub/main/registry/socket/class_SocketRegistry.php index 4237e482c..e20b0f98a 100644 --- a/application/hub/main/registry/socket/class_SocketRegistry.php +++ b/application/hub/main/registry/socket/class_SocketRegistry.php @@ -58,34 +58,37 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /** * "Getter" to get a string respresentation for a key for the sub-registry - * in this format: class:protocol:port + * in this format: class:type:port * - * @param $protocolInstance An instance of a ProtocolHandler class + * @param $connectionInstance An instance of a Listenable class * @return $key A string representation of the socket for the registry */ - private function getSubRegistryKey (ProtocolHandler $protocolInstance) { + private function getSubRegistryKey (Listenable $connectionInstance) { // Default address is invalid $address = '*invalid*'; + $port = 0; // Which instance is it? // @TODO Tested again base class, rewrite it to a generic interface! - if ($protocolInstance instanceof BaseConnectionHelper) { + if ($connectionInstance instanceof BaseConnectionHelper) { // Get address - $address = $protocolInstance->getAddress(); - } elseif ($protocolInstance instanceof BaseListener) { + $address = $connectionInstance->getAddress(); + $port = $connectionInstance->getConnectionPort(); + } elseif ($connectionInstance instanceof BaseListener) { // Get listen address - $address = $protocolInstance->getListenAddress(); + $address = $connectionInstance->getListenAddress(); + $port = $connectionInstance->getListenPort(); } else { // Not supported! - $this->debugBackTrace('Unsupported protocolInstance=' . $protocolInstance->__toString() . ' detected. Please fix this!'); + $this->debugBackTrace('Unsupported connectionInstance=' . $connectionInstance->__toString() . ' detected. Please fix this!'); } - // Get protocol and port number and add both together + // Get connection type and port number and add both together $key = sprintf('%s:%s:%s:%s', - $protocolInstance->__toString(), - $protocolInstance->getProtocolName(), + $connectionInstance->__toString(), + $connectionInstance->getConnectionType(), $address, - $protocolInstance->getPort() + $port ); // Return resulting key @@ -93,37 +96,37 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } /** - * "Getter" to get a string respresentation of the protocol + * "Getter" to get a string respresentation of the listener * - * @param $protocolInstance An instance of a ProtocolHandler class - * @return $key A string representation of the protocol for the registry + * @param $listenerInstance An instance of a Listenable class + * @return $key A string representation of the listener for the registry */ - private function getRegistryKeyFromProtocol (ProtocolHandler $protocolInstance) { + private function getRegistryKeyFromListener (Listenable $listenerInstance) { // Get the key - $key = $protocolInstance->getProtocolName(); + $key = $listenerInstance->getConnectionType(); // Return resulting key return $key; } /** - * Checks whether the given protocol is registered + * Checks whether the given listener is registered * - * @param $protocolInstance An instance of a ProtocolHandler class - * @return $isRegistered Whether the protocol is registered + * @param $listenerInstance An instance of a Listenable class + * @return $isRegistered Whether the listener is registered */ - private function isProtocolRegistered (ProtocolHandler $protocolInstance) { + private function isListenerRegistered (Listenable $listenerInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!'); // Get the key - $key = $this->getRegistryKeyFromProtocol($protocolInstance); + $key = $this->getRegistryKeyFromListener($listenerInstance); // Determine it $isRegistered = $this->instanceExists($key); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -133,33 +136,33 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * Checks whether given socket resource is registered. If $socketResource is * FALSE only the instance will be checked. * - * @param $protocolInstance An instance of a ProtocolHandler class + * @param $listenerInstance An instance of a Listenable class * @param $socketResource A valid socket resource * @return $isRegistered Whether the given socket resource is registered */ - public function isSocketRegistered (ProtocolHandler $protocolInstance, $socketResource) { + public function isSocketRegistered (Listenable $listenerInstance, $socketResource) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Default is not registered $isRegistered = FALSE; // First, check for the instance, there can be only once - if ($this->isProtocolRegistered($protocolInstance)) { + if ($this->isListenerRegistered($listenerInstance)) { // That one is found so "get" a registry key from it - $key = $this->getRegistryKeyFromProtocol($protocolInstance); + $key = $this->getRegistryKeyFromListener($listenerInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ' - Trying to get instance ...'); // Get the registry $registryInstance = $this->getInstance($key); // "Get" a key for the socket - $socketKey = $this->getSubRegistryKey($protocolInstance); + $socketKey = $this->getSubRegistryKey($listenerInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',key=' . $key . ',socketKey=' . $socketKey . ' - Checking existence ...'); // Is it there? if ($registryInstance->instanceExists($socketKey)) { @@ -178,7 +181,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke } // END - if // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ',isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return the result return $isRegistered; @@ -187,39 +190,39 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /** * Registeres given socket for listener or throws an exception if it is already registered * - * @param $protocolInstance An instance of a ProtocolHandler class + * @param $listenerInstance An instance of a Listenable class * @param $socketResource A valid socket resource * @param $packageData Optional raw package data * @throws SocketAlreadyRegisteredException If the given socket is already registered * @return void */ - public function registerSocket (ProtocolHandler $protocolInstance, $socketResource, array $packageData = array()) { + public function registerSocket (Listenable $listenerInstance, $socketResource, array $packageData = array()) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - ENTERED!'); // Is the socket already registered? - if ($this->isSocketRegistered($protocolInstance, $socketResource)) { + if ($this->isSocketRegistered($listenerInstance, $socketResource)) { // Throw the exception - throw new SocketAlreadyRegisteredException(array($protocolInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED); + throw new SocketAlreadyRegisteredException(array($listenerInstance, $socketResource), BaseListener::EXCEPTION_SOCKET_ALREADY_REGISTERED); } // END - if // Does the instance exist? - if (!$this->isProtocolRegistered($protocolInstance)) { + if (!$this->isListenerRegistered($listenerInstance)) { // No, not found so we create a sub registry (not needed to configure!) $registryInstance = SubRegistry::createSubRegistry(); - // Now we can create the sub-registry for this protocol - $this->addInstance($this->getRegistryKeyFromProtocol($protocolInstance), $registryInstance); + // Now we can create the sub-registry for this listener + $this->addInstance($this->getRegistryKeyFromListener($listenerInstance), $registryInstance); } else { // Get the sub-registry back - $registryInstance = $this->getInstance($this->getRegistryKeyFromProtocol($protocolInstance)); + $registryInstance = $this->getInstance($this->getRegistryKeyFromListener($listenerInstance)); } // Get a key for sub-registries - $socketKey = $this->getSubRegistryKey($protocolInstance); + $socketKey = $this->getSubRegistryKey($listenerInstance); // Get a socket container - $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $protocolInstance, $packageData)); + $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $listenerInstance, $packageData)); // We have a sub-registry, the socket key and the socket, now we need to put all together /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']: socketKey=' . $socketKey . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - adding socket container instance ...'); @@ -229,34 +232,34 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /** * Getter for given listener's socket resource * - * @param $protocolInstance An instance of a ProtocolHandler class + * @param $listenerInstance An instance of a Listenable class * @return $socketResource A valid socket resource * @throws NoSocketRegisteredException If the requested socket is not registered */ - public function getRegisteredSocketResource (ProtocolHandler $protocolInstance) { + public function getRegisteredSocketResource (Listenable $listenerInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ' - ENTERED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ' - ENTERED!'); // The socket must be registered before we can return it - if (!$this->isProtocolRegistered($protocolInstance)) { + if (!$this->isListenerRegistered($listenerInstance)) { // Throw the exception - throw new NoSocketRegisteredException ($protocolInstance, self::SOCKET_NOT_REGISTERED); + throw new NoSocketRegisteredException ($listenerInstance, self::SOCKET_NOT_REGISTERED); } // END - if - // Now get the key from the protocol - $key = $this->getRegistryKeyFromProtocol($protocolInstance); + // Now get the key from the listener + $key = $this->getRegistryKeyFromListener($listenerInstance); // And get the registry $registryInstance = $this->getInstance($key); // Get a socket key - $socketKey = $this->getSubRegistryKey($protocolInstance); + $socketKey = $this->getSubRegistryKey($listenerInstance); // And the final socket resource $socketResource = $registryInstance->getInstance($socketKey)->getSocketResource(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:protocol=' . $protocolInstance->getProtocolName() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SOCKET-REGISTRY[' . __METHOD__ . ':' . __LINE__ . ']:listener=' . $listenerInstance->getConnectionType() . ',socketResource[' . gettype($socketResource) . ']=' . $socketResource . ' - EXIT!'); // Return the resource return $socketResource; @@ -266,7 +269,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * "Getter" for protocol/connection instance from given package data * * @param $packageData Raw package data - * @return $protocolInstance An instance of a ProtocolHandler class + * @return $protocolInstance An instance of a HandleableProtocol class */ public function getHandlerInstanceFromPackageData (array $packageData) { // Init protocol instance diff --git a/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php index 32f86bad3..027f0497f 100644 --- a/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php +++ b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php @@ -92,10 +92,27 @@ class TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolv * @return $unl Universal node locator */ public function resolveUniversalNodeLocatorFromConfigKey ($configKey) { + // Get address + $address = $this->getConfigInstance()->getConfigEntry($configKey . '_address'); + + // Is the address empty? + if (empty($address)) { + // Okay, then find it + switch ($configKey) { + case 'external': // External IP + $address = ConsoleTools::determineExternalAddress(); + break; + + case 'internal': // Internal IP + $address = ConsoleTools::acquireSelfIPAddress(); + break; + } // END - switch + } // END - if + // Put all together $unl = sprintf('%s://%s:%s', $this->getProtocolName(), - $this->getConfigInstance()->getConfigEntry($configKey . '_address'), + $address, $this->getConfigInstance()->getConfigEntry('node_listen_port') ); diff --git a/application/hub/main/tags/package/class_PackageTags.php b/application/hub/main/tags/package/class_PackageTags.php index 71934123d..242511c8f 100644 --- a/application/hub/main/tags/package/class_PackageTags.php +++ b/application/hub/main/tags/package/class_PackageTags.php @@ -97,6 +97,9 @@ class PackageTags extends BaseTags implements Tagable { * @return void */ private function extractTagsFromPackageData (array $packageData) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('TAGS[' . __METHOD__ . ':' . __LINE__ . ']: packageData=' . print_r($packageData, TRUE)); + /* * We take a look at the tags (in most cases only one is needed) so * first we need the content data splitted up into all it's parts. @@ -113,10 +116,11 @@ class PackageTags extends BaseTags implements Tagable { * shared over the whole hub-network. So if the "tag" (let's better say * object type) isn't found in that XML the package won't be distributed. * + * @param $packageData Raw package data * @return void * @throws InvalidTagException If a provided tag from the package data is invalid */ - private function verifyAllTags () { + private function verifyAllTags (array $packageData) { // Get the registry $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance(); @@ -135,7 +139,7 @@ class PackageTags extends BaseTags implements Tagable { } // END - if // Now save the last discovered protocol/recipient type - $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromArray($entry); + $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData); $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]; } // END - foreach } @@ -144,14 +148,14 @@ class PackageTags extends BaseTags implements Tagable { * Chooses the right protocol from given package data * * @param $packageData Raw package data - * @return $lastProtocol An instance of the last used ProtocolHandler class + * @return $lastProtocol An instance of the last used HandleableProtocol class */ public function chooseProtocolFromPackageData (array $packageData) { // Extract the tags $this->extractTagsFromPackageData($packageData); // Now we need to verify every single tag - $this->verifyAllTags(); + $this->verifyAllTags($packageData); // Return the last (and only) found protocol (e.g. 'tcp' is very usual) return $this->lastProtocol; @@ -169,7 +173,7 @@ class PackageTags extends BaseTags implements Tagable { $this->extractTagsFromPackageData($packageData); // Now we need to verify every single tag - $this->verifyAllTags(); + $this->verifyAllTags($packageData); // Now simply check it out $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid')); diff --git a/application/hub/main/template/class_BaseXmlTemplateEngine.php b/application/hub/main/template/class_BaseXmlTemplateEngine.php index 0180385c7..2f60e58e2 100644 --- a/application/hub/main/template/class_BaseXmlTemplateEngine.php +++ b/application/hub/main/template/class_BaseXmlTemplateEngine.php @@ -222,14 +222,14 @@ class BaseXmlTemplateEngine extends BaseTemplateEngine { } /** - * Handles the template dependency for given node + * Handles the template dependency for given XML node * - * @param $node The node we should load a dependency template + * @param $node The XML node we should load a dependency template * @param $templateDependency A template to load to satisfy dependencies * @return void */ protected function handleTemplateDependency ($node, $templateDependency) { - // Check that node is not empty + // Check that the XML node is not empty assert(!empty($node)); // Is the template dependency set? diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 1784578d4..9929662b4 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -94,7 +94,7 @@ class HubTools extends BaseHubSystem { */ protected function resolveUniversalNodeLocatorBySessionId ($sessionId) { // Init variable - die(__METHOD__ . ': Unfinished' . PHP_EOL); + die(__METHOD__ . ': UNFINISHED: sessionId=' . $sessionId . PHP_EOL); $recipientUniversalNodeLocator = 'invalid://invalid:invalid'; // And ask it for Universal Node Locator by given session id @@ -186,44 +186,100 @@ class HubTools extends BaseHubSystem { } /** - * Determine IP or 'external_address' if set + * Determine UNL or 'external_address' if set * - * @return $ip The determined external address of this node + * @return $unl The determined external UNL of this node */ public static function determineOwnExternalAddress () { // Is the external_address config entry set? if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address') != '') { // Use it as external address - $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address'); + $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('external_address'); } else { // Determine own external address by connecting to my (coder) server at 188.138.90.169 - $ip = ConsoleTools::determineExternalAddress(); + $unl = self::determineExternalUniversalNodeLocator(); } // Return it - return $ip; + return $unl; } /** - * Determine IP or 'internal_address' if set + * Determine UNL or 'internal_address' if set * - * @return $ip The determined external address of this node + * @return $unl The determined internal UNL of this node */ public static function determineOwnInternalAddress () { // Is the internal_address config entry set? if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_address') == 'N') { // Not allowed to publish internal address, so use external - $ip = self::determineOwnExternalAddress(); + $unl = self::determineOwnExternalAddress(); } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address') != '') { // Use it as internal address - $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address'); + $unl = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_address'); } else { // Determine own internal address by connecting to my (coder) server at 188.138.90.169 - $ip = ConsoleTools::acquireSelfIPAddress(); + $unl = self::determineInternalUniversalNodeLocator(); } // Return it - return $ip; + return $unl; + } + + /** + * Determines the UNL (Universal Node Locator) for the internal address + * + * @return $internalUnl Internal UNL + */ + public static function determineInternalUniversalNodeLocator () { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + + // Is there cache? (This shortens a lot calls) + if (!isset($GLOBALS[__METHOD__])) { + // Determine UNL based on this node: + // 1) Get discovery class + $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); + + // 2) "Determine" it + $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('internal'); + + // Make sure it is valid + // @TODO Find a better validation than empty() + assert(!empty($GLOBALS[__METHOD__])); + } // END - if + + // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); + return $GLOBALS[__METHOD__]; + } + + /** + * Determines the UNL (Universal Node Locator) for the external address + * + * @return $externalUnl External UNL + */ + public static function determineExternalUniversalNodeLocator () { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + + // Is there cache? (This shortens a lot calls) + if (!isset($GLOBALS[__METHOD__])) { + // Determine UNL based on this node: + // 1) Get discovery class + $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class'); + + // 2) "Determine" it + $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByConfiguredAddress('external'); + + // Make sure it is valid + // @TODO Find a better validation than empty() + assert(!empty($GLOBALS[__METHOD__])); + } // END - if + + // Return it + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('NODE[' . __METHOD__ . ':' . __LINE__ . ']: unl=' . $GLOBALS[__METHOD__] . ' - EXIT!'); + return $GLOBALS[__METHOD__]; } } diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 87d4232ea..9a61f38d8 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -103,6 +103,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $searchInstance An instance of a SearchCriteria class */ private function prepareSearchInstance (array $nodeData) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); @@ -113,6 +116,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]); $searchInstance->setLimit(1); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Return it return $searchInstance; } @@ -134,7 +140,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $dataSetInstance An instance of a StoreableCriteria class */ private function prepareLocalDataSetInstance () { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Get node/request instances $nodeInstance = NodeObjectFactory::createNodeInstance(); @@ -149,8 +156,13 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get Universal Node Locator and "explode" it $unlInstance = $nodeInstance->determineUniversalNodeLocator(); + // Get UNL data from it + $unlData = $unlInstance->getUnlData(); + // Make sure both is valid - assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid')); + // @TODO Bad check on UNL, better use a proper validator + assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL])); + assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] !== 'invalid'); // Get an array of all accepted object types $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); @@ -160,15 +172,17 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Add public node data $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode')); - $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]); + $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]); $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash()); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap())); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); return $dataSetInstance; } @@ -179,7 +193,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $isRegistered Whether *this* node is registered in the DHT */ public function isLocalNodeRegistered () { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Get a search criteria instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -190,14 +205,13 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get Universal Node Locator and "explode" it $unlData = $nodeInstance->getUniversalNodeLocatorArray(); - /* - * Make sure both is not 'invalid' which means that the resolver - * didn't work. - */ - die(__METHOD__ . ':unlData[' . gettype($unlData) . ']=' . print_r($unlData, TRUE) . PHP_EOL); + // Make sure the external address is set and not invalid + // @TODO Bad check on UNL, better use a proper validator + assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL])); + assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] != 'invalid'); // Add Universal Node Locator/node id as criteria - $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unl[0]); + $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]); $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); $searchInstance->setLimit(1); @@ -208,7 +222,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Cache result of if there is an entry, valid() will tell us if an entry is there $isRegistered = $resultInstance->valid(); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return result return $isRegistered; @@ -220,7 +235,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function registerLocalNode () { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Assert to make sure this method is called with no record in DB (the actual backend of the DHT) assert(!$this->isLocalNodeRegistered()); @@ -231,7 +247,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // "Insert" this dataset instance completely into the database $this->queryInsertDataSet($dataSetInstance); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -241,7 +258,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function updateLocalNode () { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Assert to make sure this method is called with one record in DB (the actual backend of the DHT) assert($this->isLocalNodeRegistered()); @@ -265,7 +283,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Update DHT database record $this->queryUpdateDataSet($dataSetInstance); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -275,7 +294,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $nodeData Node data array */ public function findNodeLocalBySessionId ($sessionId) { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: sessionId=' . $sessionId . ' - CALLED!'); // Get search criteria $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -287,8 +307,10 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Query database and get a result instance back $resultInstance = $this->doSelectByCriteria($searchInstance); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!'); + // Return result instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!'); return $resultInstance; } @@ -300,7 +322,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function registerNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance) { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!'); // Get a data set instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT)); @@ -317,7 +340,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Run the "INSERT" query $this->queryInsertDataSet($dataSetInstance); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . '] - EXIT!'); } /** @@ -329,7 +353,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return void */ public function updateNodeByMessageData (array $messageData, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Get a data set instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT)); @@ -349,7 +374,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Run the "UPDATE" query $this->queryUpdateDataSet($dataSetInstance); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -359,12 +385,14 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $isRegistered Whether the given node data is already inserted */ public function isNodeRegistered (array $nodeData) { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]); // Get search criteria $searchInstance = $this->prepareSearchInstance($nodeData); @@ -383,7 +411,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Check if there is an entry $isRegistered = $resultInstance->valid(); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return registration status return $isRegistered; @@ -398,6 +427,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @throws NodeAlreadyRegisteredException If the node is already registered */ public function registerNode (array $nodeData) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); @@ -409,6 +441,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // @TODO Unimplemented part $this->partialStub('nodeData=' . print_r($nodeData, TRUE)); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -421,11 +456,14 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @throws NodeDataMissingException If the node's data is missing */ public function updateNode (array $nodeData) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...'); // Is the node registered? if (!$this->isNodeRegistered($nodeData)) { @@ -449,7 +487,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem $nodeInstance = NodeObjectFactory::createNodeInstance(); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: nodeData=' . print_r($nodeData, TRUE)); // Add all array elements $nodeInstance->addArrayToDataSet($dataSetInstance, $nodeData); @@ -459,6 +497,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Run the "UPDATE" query $this->queryUpdateDataSet($dataSetInstance); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -483,6 +524,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Check pending entries $hasUnpublished = $this->unpublishedEntriesInstance->valid(); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Return it return $hasUnpublished; } @@ -496,6 +540,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @todo Add timestamp to dataset instance */ public function initEntryPublication () { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + /* * Make sure that hasUnpublishedEntries() has been called first by * asserting on the "cached" object instance. This "caching" saves some @@ -524,6 +571,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Run the "UPDATE" query $this->queryUpdateDataSet($dataSetInstance); + + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); } /** @@ -549,7 +599,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $recipients An indexed array with DHT recipients */ public function getResultFromExcludedSender (array $packageData) { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); // Assert on required array field assert(isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])); @@ -569,7 +620,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get a result instance back from DHT database wrapper. $resultInstance = $this->doSelectByCriteria($searchInstance); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); // Return result instance return $resultInstance; @@ -584,6 +636,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem * @return $recipients An indexed array with DHT recipients */ public function getResultFromKeyValue ($key, $value) { + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: CALLED!'); + // Get max recipients $maxRecipients = $this->getConfigInstance()->getConfigEntry('max_dht_recipients'); @@ -596,6 +651,9 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem // Get a result instance back from DHT database wrapper. $resultInstance = $this->doSelectByCriteria($searchInstance); + // Debug message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-WRAPPER[' . __METHOD__ . ':' . __LINE__ . ']: EXIT!'); + // Return result instance return $resultInstance; } diff --git a/application/hub/templates/xml/object_registry/object_registry.xml b/application/hub/templates/xml/object_registry/object_registry.xml index d2765903c..cb8966b5b 100644 --- a/application/hub/templates/xml/object_registry/object_registry.xml +++ b/application/hub/templates/xml/object_registry/object_registry.xml @@ -103,7 +103,7 @@ along with this program. If not, see all 3 unl - all + hub dht_bootstrap_answer diff --git a/core b/core index 7bb55d2b9..0a30519f2 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 7bb55d2b90d5a32710bc0bb220cff5720194a6eb +Subproject commit 0a30519f2e39747163dd4db464c6c0ca98abdb23