]> git.mxchange.org Git - hub.git/commitdiff
Added more UNL (Universal Node Locator) stuff:
authorRoland Haeder <roland@mxchange.org>
Tue, 11 Nov 2014 21:40:18 +0000 (22:40 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 11 Nov 2014 21:43:28 +0000 (22:43 +0100)
- Added interface for protocol resolvers
- Added factory for same class
- Added (lifeless) TCP resolver (NodeHelper -> LocateableNode resolver)
- The UNL is now a class implementation (see interface LocateableNode)

Signed-off-by: Roland Haeder <roland@mxchange.org>
31 files changed:
application/hub/config.php
application/hub/interfaces/discovery/unl/class_DiscoverableUniversalNodeLocator.php
application/hub/interfaces/helper/nodes/class_NodeHelper.php
application/hub/interfaces/locator/.htaccess [new file with mode: 0644]
application/hub/interfaces/locator/class_LocateableNode.php [new file with mode: 0644]
application/hub/interfaces/resolver/.htaccess [new file with mode: 0644]
application/hub/interfaces/resolver/class_ProtocolResolver.php [new file with mode: 0644]
application/hub/main/discovery/node/class_UniversalNodeLocatorDiscovery.php
application/hub/main/discovery/recipient/package/class_PackageRecipientDiscovery.php
application/hub/main/factories/resolver/.htaccess [new file with mode: 0644]
application/hub/main/factories/resolver/class_ProtocolResolverFactory.php [new file with mode: 0644]
application/hub/main/listener/tcp/decorators/class_ClientTcpListenerDecorator.php
application/hub/main/listener/tcp/decorators/class_HubTcpListenerDecorator.php
application/hub/main/listener/udp/decorators/class_ClientUdpListenerDecorator.php
application/hub/main/listener/udp/decorators/class_HubUdpListenerDecorator.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/pools/class_BasePool.php
application/hub/main/pools/peer/class_DefaultPeerPool.php
application/hub/main/recipient/dht/class_DhtRecipient.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/resolver/protocol/.htaccess [new file with mode: 0644]
application/hub/main/resolver/protocol/class_ [new file with mode: 0644]
application/hub/main/resolver/protocol/class_BaseProtocolResolver.php [new file with mode: 0644]
application/hub/main/resolver/protocol/tcp/.htaccess [new file with mode: 0644]
application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php [new file with mode: 0644]
application/hub/main/tags/package/class_PackageTags.php
application/hub/main/tools/class_HubTools.php
application/hub/main/wrapper/states/class_PeerStateLookupDatabaseWrapper.php
core

index d66d1badfa1cd90a65fb74e104276f2db2e443ae..a1ec1a2ecdb592eaa63d37579cde67ad29393516 100644 (file)
@@ -744,6 +744,12 @@ $cfg->setConfigEntry('tcp_connection_helper_class', 'TcpConnectionHelper');
 // CFG: UDP-CONNECTION-HELPER-CLASS
 $cfg->setConfigEntry('udp_connection_helper_class', 'UdpConnectionHelper');
 
+// CFG: HUB-COMMUNICATION-PROTOCOL-TYPE
+$cfg->setConfigEntry('hub_communication_protocol_type', 'tcp');
+
+// CFG: TCP-PROTOCOL-RESOLVER-CLASS
+$cfg->setConfigEntry('tcp_protocol_resolver_class', 'TcpProtocolResolver');
+
 // CFG: TCP-BUFFER-LENGTH
 $cfg->setConfigEntry('tcp_buffer_length', 1024);
 
index 203ce429b26a0b463beae09a7dc3472cdd1c4293..9885b370e25889fa37ce13fdd476e08e446fbbe3 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 interface DiscoverableUniversalNodeLocator extends Discoverable {
+       /**
+        * "Discovers" an instance of a LocateableNode class for given NodeHelper class
+        *
+        * @param       $nodeInstance   An instance of a NodeHelper class
+        * @return      $unlInstance    An instance of a LocateableNode class
+        */
+       function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance);
 }
 
 // [EOF]
index 81d4a4000266981af02a9eb999266e74fe18b85d..59e0760cfb71a1a85559d1c3f9e5f931d99693c0 100644 (file)
@@ -109,16 +109,16 @@ interface NodeHelper extends Helper, AddableCriteria {
        function doSelfConnection (Taskable $taskInstance);
 
        /**
-        * Determines the Universal Node Locator
+        * Determines an instance of a LocateableNode class
         *
-        * @return      $unl    A an Universal Node Locator for this node
+        * @return      $unlInstance    An instance of a LocateableNode class for this node
         */
        function determineUniversalNodeLocator ();
 
        /**
-        * "Getter for an Universal Node Locator array
+        * "Getter for an array of an instance of a LocateableNode class
         *
-        * @return      $unlArray       An array an Universal Node Locator for this node
+        * @return      $unlArray       An array of an instance of a LocateableNode class
         */
        function getUniversalNodeLocatorArray ();
 
diff --git a/application/hub/interfaces/locator/.htaccess b/application/hub/interfaces/locator/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/locator/class_LocateableNode.php b/application/hub/interfaces/locator/class_LocateableNode.php
new file mode 100644 (file)
index 0000000..8be0226
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for node locators (UNL mostly)
+ *
+ * @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/>.
+ */
+interface LocateableNode extends FrameworkInterface {
+}
+
+// [EOF]
+?>
diff --git a/application/hub/interfaces/resolver/.htaccess b/application/hub/interfaces/resolver/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/resolver/class_ProtocolResolver.php b/application/hub/interfaces/resolver/class_ProtocolResolver.php
new file mode 100644 (file)
index 0000000..21dbeca
--- /dev/null
@@ -0,0 +1,28 @@
+OS<?php
+/**
+ * An interface for ProtocolResolvers
+ *
+ * @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/>.
+ */
+interface ProtocolResolver extends FrameworkInterface {
+}
+
+// [EOF]
+?>
index b5c3126b4a2146fceee7d23b29ada9745295db86..8011b3aa60d8653464b62843822dc947f68dee14 100644 (file)
@@ -44,6 +44,24 @@ class UniversalNodeLocatorDiscovery extends BaseNodeDiscovery implements Discove
                // Return the prepared instance
                return $discoveryInstance;
        }
+
+       /**
+        * "Discovers" an instance of a LocateableNode class for given NodeHelper class
+        *
+        * @param       $nodeInstance   An instance of a NodeHelper class
+        * @return      $unlInstance    An instance of a LocateableNode class
+        */
+       public function discoverUniversalNodeLocatorByNode (NodeHelper $nodeInstance) {
+               /*
+                * First get an instance from the configured hub communication protocol
+                * type (which is mostly TCP, so you get a TcpProtocolResolver here).
+                */
+               $resolverInstance = ProtocolResolverFactory::createResolverFromConfiguredProtocol();
+
+               // Then resolve the node instance into an UNL instance
+               $unlInstance = $resolverInstance->resolveUniversalResourceLocatorFromNodeHelper($nodeInstance);
+               die(__METHOD__ . ':unlInstance=' . print_r($unlInstance, TRUE));
+       }
 }
 
 // [EOF]
index 46325e9b4b4dee12cf53c2795d49f72b6534950a..9fa8fe942381eeac1227c4bed36cfc590bf7d7da 100644 (file)
@@ -88,6 +88,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov
         */
        public function discoverRawRecipients (array $decodedData) {
                // This must be available
+               die(__METHOD__ . ': Unfinished' . PHP_EOL);
                assert(isset($decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
                // First clear all recipients
diff --git a/application/hub/main/factories/resolver/.htaccess b/application/hub/main/factories/resolver/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/resolver/class_ProtocolResolverFactory.php b/application/hub/main/factories/resolver/class_ProtocolResolverFactory.php
new file mode 100644 (file)
index 0000000..92d9ea1
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A factory class for ProtocolResolver
+ *
+ * @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 ProtocolResolverFactory extends ObjectFactory {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Returns a singleton (registry-based) ProtocolResolver instance
+        *
+        * @return      $resolverInstance       An instance of a ProtocolResolver class
+        */
+       public static final function createResolverFromConfiguredProtocol () {
+               // Get the configured protocol
+               $protocolName = FrameworkConfiguration::getSelfInstance()->getConfigEntry('hub_communication_protocol_type');
+
+               // If there is no handler?
+               if (Registry::getRegistry()->instanceExists($protocolName . '_protocol_resolver')) {
+                       // Get handler from registry
+                       $resolverInstance = Registry::getRegistry()->getInstance($protocolName . '_protocol_resolver');
+               } else {
+                       // Get the handler instance
+                       $resolverInstance = self::createObjectByConfiguredName($protocolName . '_protocol_resolver_class');
+
+                       // Add it to the registry
+                       Registry::getRegistry()->addInstance($protocolName . '_protocol_resolver', $resolverInstance);
+               }
+
+               // Return the instance
+               return $resolverInstance;
+       }
+}
+
+// [EOF]
+?>
index 6d41c9f52b8acd7da09a34954a7e1a82d522f6d1..87f19300f6506e3ba803fbb1958d337f18b5a916 100644 (file)
@@ -31,8 +31,9 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set listener type
+               // Set listener type and protocol name
                $this->setListenerType('peer');
+               $this->setProtocolName('tcp');
        }
 
        /**
index 5d23f7b8526688aa52ec110d4f34b3c984d40abc..71022812292d6a39a307afe139924ad1346c6f4a 100644 (file)
@@ -31,8 +31,9 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set listener type
+               // Set listener type and protocol name
                $this->setListenerType('hub');
+               $this->setProtocolName('tcp');
        }
 
        /**
index 81548a6ba6316cb04bb531ac24b1ed1b1b5df480..a3c6fb12faa60da8d34e1cd267f392401dc3aa84 100644 (file)
@@ -31,8 +31,9 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set listener type
+               // Set listener type and protocol name
                $this->setListenerType('peer');
+               $this->setProtocolName('udp');
        }
 
        /**
index 2e1760405be91e5f475e5f1e8571c34b848cbddb..45ee6e2b76982ee2f57fa1f59b4b0a571cc6bc4b 100644 (file)
@@ -31,8 +31,9 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set listener type
+               // Set listener type and protocol name
                $this->setListenerType('hub');
+               $this->setProtocolName('udp');
        }
 
        /**
index 3e0538d177a37a75bc84ec80c7ad0370238c0d3b..e71a63026f12c43db3fd7cd585e1643f65fe1648 100644 (file)
@@ -39,7 +39,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        /**
         * Universal node locator of bootstrap node
         */
-       private $bootUniversalNodeLocator = '';
+       private $bootUnlInstance = '';
 
        /**
         * Whether this node is anncounced (keep on FALSE!)
@@ -147,10 +147,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        /**
         * Getter for boot IP/port combination
         *
-        * @return      $bootUniversalNodeLocator               The IP/port combination of the boot node
+        * @return      $bootUnlInstance                The IP/port combination of the boot node
         */
        protected final function getBootUniversalNodeLocator () {
-               return $this->bootUniversalNodeLocator;
+               return $this->bootUnlInstance;
        }
 
        /**
@@ -164,9 +164,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
                $isFound = FALSE;
 
                // Run through all configured IPs
-               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
-                       // Get back an array from the UNL
-                       $unlArray = HubTools::getArrayFromUniversalNodeLocator($unl);
+               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) {
                        // @TODO Unfinished
                        die(__METHOD__ . ':' . print_r($unlArray, TRUE));
 
@@ -175,11 +173,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
                                // Found it!
                                $isFound = TRUE;
 
-                               // Remember the port number
-                               $this->bootUniversalNodeLocator = $unl;
+                               // Remember the UNL array
+                               $this->bootUnlInstance = $unlArray;
 
                                // Output message
-                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
+                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unlArray->__toString() . '.');
 
                                // Stop further searching
                                break;
@@ -191,10 +189,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
                                $isFound = TRUE;
 
                                // Remember the port number
-                               $this->bootUniversalNodeLocator = $unl;
+                               $this->bootUnlInstance = $unlArray;
 
                                // Output message
-                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.');
+                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unlArray->__toString() . '.');
 
                                // Stop further searching
                                break;
@@ -686,33 +684,33 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        }
 
        /**
-        * Determines the Universal Node Locator
+        * Determines an instance of a LocateableNode class
         *
-        * @return      $unl    A an Universal Node Locator for this node
+        * @return      $unlInstance    An instance of a LocateableNode class for this node
         */
        public function determineUniversalNodeLocator () {
                // Determine UNL based on this node:
                // 1) Get discovery class
                $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
 
-               // 1) "Determine it
-               $unl = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
+               // 2) "Determine it
+               $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
 
-               // Return it
-               return $unl;
+               // 3) Return it
+               return $unlInstance;
        }
 
        /**
-        * "Getter" for Universal Node Locator array
+        * "Getter" for an array of an instance of a LocateableNode class
         *
-        * @return      $unlArray       An array of the Universal Node Locator for this node
+        * @return      $unlArray       An array from an instance of a LocateableNode class for this node
         */
        public final function getUniversalNodeLocatorArray () {
-               // Get Universal Node Locator (UNL)
-               $unl = $this->determineUniversalNodeLocator();
+               // Get the Universal Node Locator (UNL) instance
+               $unlInstance = $this->determineUniversalNodeLocator();
 
                // @TODO Unfinished
-               die(__METHOD__ . ':' . print_r($unl, TRUE));
+               die(__METHOD__ . ':unlInstance[' . gettype($unlInstance) . ']=' . print_r($unlInstance, TRUE));
 
                // Return it
                return $unlArray;
index 280f6392017aeb3b7dd68cb4a0516ea0633cb7e6..9090a8be640f65461b3e7e5fe1ba99c8d47781c3 100644 (file)
@@ -77,6 +77,11 @@ class BasePool extends BaseHubSystem implements Visitable {
         * @return      void
         */
        protected final function addInstance ($group, $poolName, Visitable $visitableInstance) {
+               /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: group=' . $group . ',poolName=' . $poolName . ',visitableInstance=' . $visitableInstance->__toString() . ' - CALLED!');
+
+               // Make sure the group is not 'invalid'
+               assert($group != 'invalid');
+
                // Is the pool group there?
                if (!$this->getPoolEntriesInstance()->isGroupSet($group)) {
                        // Create the missing pool group
index 39ffea7c4a0cd7e10fc0d1aecdf0786c2dcdf19c..5c5fdbcbcd839e32176e6466036942f9647d3b38 100644 (file)
@@ -221,13 +221,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                $socketResource = FALSE;
 
                // Temporary resolve recipient field
-               $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
+               $unlArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
                // Make sure it is a valid Universal Node Locator array (3 elements)
-               assert(count($recipientIpArray) == 3);
+               assert(count($unlArray) == 3);
 
                // Debug message
-               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),recipientIpArray[0]=' . $recipientIpArray[0] . ',recipientIpArray[1]=' . $recipientIpArray[1] . ' ...');
+               //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('POOL[' . __METHOD__ . ':' . __LINE__ . ']: Checking ' . count($this->getAllSockets()) . ' socket(s),unlArray[0]=' . $unlArray[0] . ',unlArray[1]=' . $unlArray[1] . ' ...');
 
                // Default is all sockets
                $sockets = $this->getAllSockets();
@@ -258,7 +258,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
 
                        // Get
                        // If the "peer" IP and recipient is same, use it
-                       if ($peerIp == $recipientIpArray[0]) {
+                       if ($peerIp == $unlArray[0]) {
                                // IPs match, so take the socket and quit this loop
                                $socketResource = $socketArray[self::SOCKET_ARRAY_RESOURCE];
 
index e4a7d7f422c328cc856e8ed0a7fd089aab44c990..40a4efd283f7e747c3866393450f8906772c4172 100644 (file)
@@ -74,7 +74,7 @@ class DhtRecipient extends BaseRecipient implements Recipient {
                foreach ($recipients as $recipient) {
                        // These array elements must exist for this loop:
                        // @TODO Unfinished
-                       die(__METHOD__ . ':' . print_r($recipient, TRUE));
+                       die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE));
                        assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP]));
                        assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]));
 
index 014809cfeadc604a39ca16ff387f4822ecad10a1..0ed776e902bd700c4c44c076e2f2bb2344211cb9 100644 (file)
@@ -68,10 +68,10 @@ class DirectRecipient extends BaseRecipient implements Recipient {
                // Try it on all
                foreach ($recipients as $recipient) {
                        // Try to sole a single recipient
-                       $unl = HubTools::resolveSessionId($recipient);
+                       $unlArray = HubTools::resolveSessionId($recipient);
 
                        // Add it as recipient
-                       $listInstance->addEntry('unl', $unl);
+                       $listInstance->addEntry('unl', $unlArray);
                } // END - foreach
        }
 }
index 6693e6b656a4e30524b6330c486c3bba227e5ca4..85d29eab85b3a1e13598497075d278db4a7d0361 100644 (file)
@@ -59,7 +59,7 @@ class SelfRecipient extends BaseRecipient implements Recipient {
                // Make sure the recipient is valid
                //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient);
                // @TODO Unfinished
-               die(__METHOD__ . ':' . print_r($this, TRUE));
+               die(__METHOD__ . 'recipient=:' . print_r($recipient, TRUE));
                assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
 
                // Determine own port
index d6532029a2247dc9dcc84ac22481ffd9c2f1ea22..33d45ffeab06fa4d066d00bbcf374f795159e9c1 100644 (file)
@@ -61,7 +61,7 @@ class UpperRecipient extends BaseRecipient implements Recipient {
                assert($recipient == NetworkPackage::NETWORK_TARGET_UPPER);
 
                // Get all bootstrap nodes
-               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
+               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) {
                        // Is maximum reached?
                        if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
                                // Debug message
@@ -72,10 +72,10 @@ class UpperRecipient extends BaseRecipient implements Recipient {
                        } // END - if
 
                        // Debug message
-                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $unl . ' as recipient.');
+                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlArray, TRUE) . ' as recipient.');
 
                        // Add the entry
-                       $listInstance->addEntry('unl', $unl);
+                       $listInstance->addEntry('unl', $unlArray);
                } // END - foreach
        }
 }
diff --git a/application/hub/main/resolver/protocol/.htaccess b/application/hub/main/resolver/protocol/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/resolver/protocol/class_ b/application/hub/main/resolver/protocol/class_
new file mode 100644 (file)
index 0000000..8246fbc
--- /dev/null
@@ -0,0 +1,62 @@
+<?php
+/**
+ * A !!! protocol resolver class
+ *
+ * @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 !!!ProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of a !!! command resolver with a given default command
+        *
+        * @return      $resolverInstance       The prepared command resolver instance
+        */
+       public static final function create!!!ProtocolResolver () {
+               // Create the new instance
+               $resolverInstance = new !!!ProtocolResolver();
+
+               // Return the prepared instance
+               return $resolverInstance;
+       }
+
+       /**
+        * Returns an command instance for a given request class or null if
+        * it was not found
+        *
+        * @param       $nodeInstance   An instance of a NodeHelper class
+        * @return      $unlInstance    An instance of a LocateableNode class
+        * @todo        0% done
+        */
+       public function resolveUniversalResourceLocatorFromNodeHelper (NodeHelper $nodeInstance) {
+               $this->partialStub('Please implement this method.');
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/resolver/protocol/class_BaseProtocolResolver.php b/application/hub/main/resolver/protocol/class_BaseProtocolResolver.php
new file mode 100644 (file)
index 0000000..1a8e825
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A generic protocol resolver class
+ *
+ * @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 BaseProtocolResolver extends BaseResolver {
+       /**
+        * 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/resolver/protocol/tcp/.htaccess b/application/hub/main/resolver/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/resolver/protocol/tcp/class_TcpProtocolResolver.php b/application/hub/main/resolver/protocol/tcp/class_TcpProtocolResolver.php
new file mode 100644 (file)
index 0000000..bc23f32
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+/**
+ * A TCP protocol resolver class
+ *
+ * @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 TcpProtocolResolver extends BaseProtocolResolver implements ProtocolResolver, Registerable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set protocol type
+               $this->setProtocolName('tcp');
+       }
+
+       /**
+        * Creates an instance of a Tcp command resolver with a given default command
+        *
+        * @return      $resolverInstance       The prepared command resolver instance
+        */
+       public static final function createTcpProtocolResolver () {
+               // Create the new instance
+               $resolverInstance = new TcpProtocolResolver();
+
+               // Return the prepared instance
+               return $resolverInstance;
+       }
+
+       /**
+        * Returns an command instance for a given request class or null if
+        * it was not found
+        *
+        * @param       $nodeInstance   An instance of a NodeHelper class
+        * @return      $unlInstance    An instance of a LocateableNode class
+        * @todo        0% done
+        */
+       public function resolveUniversalResourceLocatorFromNodeHelper (NodeHelper $nodeInstance) {
+               $this->partialStub('Please implement this method.');
+       }
+}
+
+// [EOF]
+?>
index 7cfbed0abaad075fad71669f05bb984d5bf22502..71934123dcc316a8aab5f0b2bbd6f680c86e05e3 100644 (file)
@@ -153,7 +153,7 @@ class PackageTags extends BaseTags implements Tagable {
                // Now we need to verify every single tag
                $this->verifyAllTags();
 
-               // Return it
+               // Return the last (and only) found protocol (e.g. 'tcp' is very usual)
                return $this->lastProtocol;
        }
 
index c154b553282a07d482310ff1d85b8608214245d0..c2c6197e58e866e46e0250b2f466884b2aca7330 100644 (file)
@@ -86,7 +86,7 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a session id into an Universal Node Locator. The opposite method
+        * Resolves a session id into an instance of a LocateableNode class. The opposite method
         * is resolveSessionIdByUniversalNodeLocator()
         *
         * @param       $sessionId                      A valid session id
@@ -94,7 +94,8 @@ class HubTools extends BaseHubSystem {
         */
        protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
                // Init variable
-               $recipientUniversalNodeLocator = 'invalid:invalid';
+               die(__METHOD__ . ': Unfinished' . PHP_EOL);
+               $recipientUniversalNodeLocator = 'invalid://invalid:invalid';
 
                // And ask it for Universal Node Locator by given session id
                $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
@@ -109,7 +110,7 @@ class HubTools extends BaseHubSystem {
 
                        // Is the session id the same?
                        if ($nodeInstance->getSessionId() == $sessionId) {
-                               // Then get the Universal Node Locator from it, assume TCP by default
+                               // Then get an instance of a LocateableNode class from it, assume TCP by default
                                $recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
                        } // END - if
                }
@@ -122,23 +123,23 @@ class HubTools extends BaseHubSystem {
         * Resolves a Universal Node Locator into a session id. The "opposite" method
         * is resolveUniversalNodeLocatorBySessionId().
         *
-        * @param       $unl            Universal Node Locator
-        * @return      $sessionId      Valid session id
+        * @param       $unlInstance    Universal Node Locator
+        * @return      $sessionId              Valid session id
         */
-       public static function resolveSessionIdByUniversalNodeLocator ($unl) {
+       public static function resolveSessionIdByUniversalNodeLocator (LocateableNode $unlInstance) {
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
                // And ask it for session id by given Universal Node Locator
-               $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unl);
-               die(__METHOD__.':recipient=<pre>'.print_r($recipient, TRUE).'</pre>' . PHP_EOL);
+               $recipient = $selfInstance->getDhtInstance()->findNodeByUniversalNodeLocator($unlInstance);
+               die(__METHOD__.':recipient='.print_r($recipient, TRUE));
 
                // Return result
                return $sessionId;
        }
 
        /**
-        * Resolves given session id into an Universal Node Locator, if Universal Node Locator is set, it won't be translated
+        * Resolves given session id into an instance of a LocateableNode class, if Universal Node Locator is set, it won't be translated
         *
         * @param       $address        Session id or Universal Node Locator
         * @return      $recipient      Recipient as Universal Node Locator
@@ -170,7 +171,7 @@ class HubTools extends BaseHubSystem {
                        // Debug message
                        self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
 
-                       // Resolve session id into an Universal Node Locator
+                       // Resolve session id into an instance of a LocateableNode class
                        $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
 
                        // Debug message
index 42c841b1d553e7b7243fe00ef01c6d13dc245d4d..63ef594b458b57b1ff537da8d930602173d37357 100644 (file)
@@ -188,7 +188,7 @@ class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements Look
                $senderData = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER]));
 
                // Just make sure that 'invalid:invalid' is not being processed
-               assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid'));
+               assert(($senderData[0] != 'invalid') && ($senderData[1] != 'invalid') && ($senderData[2] != 'invalid'));
 
                // Add ip address and port
                $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP  , $senderData[0]);
diff --git a/core b/core
index 1613679bba663e7d92c2194fd14a047770befe2c..6339d66e421f4514ec9de8f61d96e38cb34005e6 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit 1613679bba663e7d92c2194fd14a047770befe2c
+Subproject commit 6339d66e421f4514ec9de8f61d96e38cb34005e6