]> git.mxchange.org Git - hub.git/commitdiff
A lot changes for refacturing protocol handler
authorRoland Haeder <roland@mxchange.org>
Wed, 24 Dec 2014 14:07:04 +0000 (15:07 +0100)
committerRoland Haeder <roland@mxchange.org>
Wed, 24 Dec 2014 14:07:04 +0000 (15:07 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
44 files changed:
application/hub/class_ApplicationHelper.php
application/hub/config.php
application/hub/init.php
application/hub/interfaces/discovery/class_Discoverable [new file with mode: 0644]
application/hub/interfaces/discovery/protocol/.htaccess [new file with mode: 0644]
application/hub/interfaces/discovery/protocol/class_DiscoverableProtocol.php [new file with mode: 0644]
application/hub/interfaces/helper/connections/class_ConnectionHelper.php
application/hub/interfaces/helper/hub/class_HubHelper.php
application/hub/interfaces/listener/class_Listenable.php
application/hub/interfaces/tags/class_Tagable.php
application/hub/main/class_BaseHubSystem.php
application/hub/main/discovery/protocol/.htaccess [new file with mode: 0644]
application/hub/main/discovery/protocol/class_ProtocolDiscovery.php [new file with mode: 0644]
application/hub/main/discovery/recipient/class_BaseRecipientDiscovery.php
application/hub/main/discovery/recipient/socket/class_PackageSocketDiscovery.php
application/hub/main/factories/handler/class_ProtocolHandlerFactory.php
application/hub/main/factories/socket/class_SocketFactory.php
application/hub/main/handler/protocol/.htaccess [new file with mode: 0644]
application/hub/main/handler/protocol/class_ [new file with mode: 0644]
application/hub/main/handler/protocol/class_BaseProtocolHandler.php [new file with mode: 0644]
application/hub/main/handler/protocol/tcp/.htaccess [new file with mode: 0644]
application/hub/main/handler/protocol/tcp/class_TcpProtocolHandler.php [new file with mode: 0644]
application/hub/main/helper/class_BaseHubSystemHelper.php
application/hub/main/helper/connection/class_BaseConnectionHelper.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/helper/dht/class_DhtBootstrapHelper.php
application/hub/main/listener/class_BaseListener.php
application/hub/main/listener/class_BaseListenerDecorator.php
application/hub/main/nodes/boot/class_HubBootNode.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php
application/hub/main/recipient/direct/class_DirectRecipient.php
application/hub/main/recipient/self/class_SelfRecipient.php
application/hub/main/recipient/upper/class_UpperRecipient.php
application/hub/main/registry/connection/class_ConnectionRegistry.php
application/hub/main/registry/socket/class_SocketRegistry.php
application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php
application/hub/main/tags/package/class_PackageTags.php
application/hub/main/template/class_BaseXmlTemplateEngine.php
application/hub/main/tools/class_HubTools.php
application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
application/hub/templates/xml/object_registry/object_registry.xml
core

index c20e60d77bb8f65c05e6a556f3068b8d1394ee5c..a99055086c52c919fecc524c995b678581798f4a 100644 (file)
@@ -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
index bb5c4e6369dfab46c19d3dbbf53a63357aa9e27e..855dbfd3d791414b88c0ea8ab0bd3504d03728ce 100644 (file)
@@ -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');
 
index a3b04697f3728ec246f78e403130ac0446dd70ec..42cf824036aea8ee55f8bed7e1ee14cba14640e1 100644 (file)
@@ -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 (file)
index 0000000..8c49835
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for !!! discovery
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..97c894f
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/**
+ * An interface for protocol discovery
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 4074932f811cbdb0230c6911bd2ad40adddbf794..6bf7b5cd341b777339116626ae8e1cc10446a574 100644 (file)
@@ -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
index 5ef351e65744e7b284ab4daa5d1feaab214d3b48..853eb025961ee0bbc4e64af6baeb0aa952c0af53 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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]
index ba1875ad05c4d9683d8997a87e0cb4a5c7c694b7..ec878cc538ffe69823c904c3b88d092d5e6e49df 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-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]
index 4d8b6ec0bb2a1cbf029932ccc51bdc5d27c2945b..2c6b55754d8b3b1311b5bd52e3378f88874e16e9 100644 (file)
@@ -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);
 
index 58c9dc3eee63847a4802fa42dc9525350c1be535..d6399194594514328ea6aa2332296f3dc8b96c34 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..e95a891
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+/**
+ * A Protocol discovery class
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index a9741d984ad219d66a733e95f1960f8bbbed1066..56d3db4d31554669b0983617b4b8e701ae5ea685 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class 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
index dcb95dbc67f0a957d3d69d6cd4d45ee35615f002..b36aee53aedfb3a88942d11a19d094caea0592d8 100644 (file)
@@ -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);
 
index 6955bd0a4f1ef49d3e684b42825ee5c6e0efe835..12ada2e94afa906ef96fa7759ae95ad5d525d6ee 100644 (file)
@@ -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]
index 9a1973d083cfdb498a82104a06b34b5cf5cee4bf..b642e824600d31c9ba9bf77f586819bac1b1067d 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..770d443
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A ??? protocol handler
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..c2421c1
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general handler for protocols such as TCP, UDP and others.
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..bdbdd3e
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A Tcp protocol handler (IPv4)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 60d5d7a20b6582c638f686c6822e379ebe211f85..b4f365a816ceddddd0581b745606920a39dcbbf6 100644 (file)
@@ -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]
index 6f2eeb2df4800f754c9d28205c88b670293d0d50..706a3796d635566042ee5ed7dbf216e4e83e21f6 100644 (file)
@@ -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;
        }
 
        /**
index 0734089b064f85dca2c9d93d6c4a4e7850be2c07..de83320a9afeac61135b184b3ce36162dc8e6c87 100644 (file)
@@ -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)) {
index 41838a244a7ef27a969ef541856bbca4fff18947..436cfd16d5f9073fa1c673387a3229f4a5d4cc13 100644 (file)
@@ -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!');
        }
 }
 
index 1007fa88d7ed3dc7cab954b33d1220544f762fdb..2aa6c6a9eb10b2eff2ac0f784d99a6b06f7fc7ff 100644 (file)
@@ -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
         *
index 87292e4de815b4a8639c79b3331b7be3ecf7c1c0..e45a78111342945810eacaff0416fe9e8ca9787c 100644 (file)
@@ -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"
         *
index ed7a894f79c41437c2dc0011499a4bbe8d5125e7..de02f5659b3065618e06997075c8b38deb6dbaf1 100644 (file)
@@ -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
index ea4fb11d27c077344c3b447f7198fd0a29413c3b..2228b3114ae06925ebd20d19a5302e337421ec8e 100644 (file)
@@ -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();
 
index a7832b99d29c58279804db7a355ccf7a90ddfd38..dee97c6396165812c480d3bec86482baf6d2853d 100644 (file)
@@ -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!');
        }
 
        ///////////////////////////////////////////////////////////////////////////
index 02e92bccdcf57153c073eb87e0f8c29800708c25..e18cdf4a226ef592563e7ab71c339a74caed184d 100644 (file)
@@ -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;
                }
 
index c93110cbe686c6c5cf9b59950b6a6a8a5ade762f..8c2423c22fdff3a8926b870a807cbfe15455dad7 100644 (file)
@@ -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);
index d3262368e388dfcbdc443b6a5d7410e274a2b565..7c2f8f51dc8679f84bf7720828cf0534eec9a94e 100644 (file)
@@ -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
        }
 }
index d76fc7a258a209621562bf115ba71ae76df068f3..2690053365f5f51ca7ac14e2ffeec991b365322a 100644 (file)
@@ -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);
index fb7745fc41b03b4c0199e4eae803132b382add36..2caf8fc76c882cdc17fab6acd57113bf7841b526 100644 (file)
@@ -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);
index 4237e482c9560d7024128ef57efc59ae399e4c6a..e20b0f98a04fad37b0a341d76bd9595bdd9f6793 100644 (file)
@@ -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
index 32f86bad3e4a230cc44a21d604801b0e2fbea414..027f0497ff4708ecf8f7ded5fd501f7f29c8707e 100644 (file)
@@ -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')
                );
 
index 71934123dcc316a8aab5f0b2bbd6f680c86e05e3..242511c8fd01b86e937795f852e0e2fdadeac9f3 100644 (file)
@@ -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'));
index 0180385c7cab0a45920cdbeab30acf2ce2837599..2f60e58e26da55dc5fe23e4dba287a9f6f2f44ed 100644 (file)
@@ -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?
index 1784578d413bbe0e1cad489eb1126472ef3b7121..9929662b47bf97ee3ce4371728d8e52dbfb5c0c1 100644 (file)
@@ -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__];
        }
 }
 
index 87d4232ea116d7f345fce91bbe3f2a54121b38e8..9a61f38d8b0429490ebb83f82a3dddfbfa7182f6 100644 (file)
@@ -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;
        }
index d2765903c1785db1f50b2d38df8435c675f04f22..cb8966b5ba1503036f530061df604e62befbf759 100644 (file)
@@ -103,7 +103,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        <object-recipient-limitation>all</object-recipient-limitation>
                        <object-max-spread>3</object-max-spread>
                        <object-protocol>unl</object-protocol>
-                       <object-recipient-type>all</object-recipient-type>
+                       <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>dht_bootstrap_answer</object-name>
diff --git a/core b/core
index 7bb55d2b90d5a32710bc0bb220cff5720194a6eb..0a30519f2e39747163dd4db464c6c0ca98abdb23 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 7bb55d2b90d5a32710bc0bb220cff5720194a6eb
+Subproject commit 0a30519f2e39747163dd4db464c6c0ca98abdb23