]> git.mxchange.org Git - hub.git/commitdiff
More rewrites (and code stops):
authorRoland Haeder <roland@mxchange.org>
Sat, 25 Oct 2014 11:13:32 +0000 (13:13 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 25 Oct 2014 11:13:32 +0000 (13:13 +0200)
- Renamed a lot variables towards UNL (universal node locator) which allows not
  just ip:port locators but in a more URI-like style: protocol://address[:port]
  'address' could also be a fax number where you want to establish a
  "connection" to by sending the serialized base64-encoded data to.
- Renamed methods to reflect latest rewrites
- Updated core to latest changes

Signed-off-by: Roland Haeder <roland@mxchange.org>
23 files changed:
application/hub/interfaces/helper/nodes/class_NodeHelper.php
application/hub/interfaces/recipient/class_Recipient.php
application/hub/main/discovery/class_BaseNodeDiscovery.php
application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
application/hub/main/factories/handler/class_ProtocolHandlerFactory.php
application/hub/main/handler/network/class_BaseRawDataHandler.php
application/hub/main/handler/network/udp/class_UdpRawDataHandler.php
application/hub/main/listener/class_BaseListenerDecorator.php
application/hub/main/lists/recipient/class_RecipientList.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/pools/peer/class_DefaultPeerPool.php
application/hub/main/recipient/class_
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/statistics/connection/class_ConnectionStatisticsHelper.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 9717de9b5e5954b6d862b92a31f3081480d6a00c..83d4fca5a76756a3867904965720b956bef8a37f 100644 (file)
@@ -109,18 +109,18 @@ interface NodeHelper extends Helper, AddableCriteria {
        function doSelfConnection (Taskable $taskInstance);
 
        /**
-        * "Getter for address:port combination
+        * Determines the universal node locator
         *
-        * @return      $addressPort    A address:port combination for this node
+        * @return      $unl    A an universal node locator for this node
         */
-       function getAddressPort ();
+       function determineUniversalNodeLocator ();
 
        /**
-        * "Getter for address:port array
+        * "Getter for an universal node locator array
         *
-        * @return      $addressPortArray       An array address:port combination for this node
+        * @return      $unlArray       An array an universal node locator for this node
         */
-       function getAddressPortArray ();
+       function getUniversalNodeLocatorArray ();
 
        /**
         * Updates/refreshes node data (e.g. state).
index f1a137d5fd37dcd09c5b1624bfcaf830d7d3cf5b..bf01e643f953babf8adf2bd79a04ef7f70f20bfb 100644 (file)
@@ -23,7 +23,7 @@
  */
 interface Recipient extends FrameworkInterface {
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern)
         *
         * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
index 52df19cde3c34a08a481fbe4a1ef2a54f6e8ec1a..2e5ff6a529203b5277be669191725455d7914487 100644 (file)
@@ -55,7 +55,7 @@ class BaseNodeDiscovery extends BaseDiscovery implements Discoverable {
                 * the actual data transmission. In this process we will find out if
                 * the recipient of this package has already a known (registered) socket
                 * and if so we can re-use it. If there is no socket registered, we try
-                * to make a new connection (TCP or UDP) to the given IP:port.
+                * to make a new connection to the given universal node locator.
                 */
                $protocolInstance = $tagsInstance->chooseProtocolFromPackageData($packageData);
 
index 12973457d5362ca6cb8285b0d5d48f9c24c1d96a..ee4c3b1aee670b896e294f5520d0dd7a9f1d7df1 100644 (file)
@@ -83,7 +83,7 @@ class PackageRecipientDiscovery extends BaseNodeDiscovery implements Discoverabl
         *
         * @param       $decodedData    Raw raw package data array
         * @return      void
-        * @todo        Add some validation of recipient field, e.g. ip:port is found
+        * @todo        Add some validation of recipient field, e.g. an universal node locator is found
         * @todo        The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
         */
        public function discoverRawRecipients (array $decodedData) {
@@ -111,7 +111,7 @@ class PackageRecipientDiscovery extends BaseNodeDiscovery implements Discoverabl
                        /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external ip (' .  HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
 
                        // This package is to be delivered to someone else, so add it
-                       $this->getListInstance()->addEntry('ip_port', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+                       $this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
                }
        }
 }
index f7e5832df862f3ba6c2c9fef13eaed034af3094a..6955bd0a4f1ef49d3e684b42825ee5c6e0efe835 100644 (file)
@@ -34,24 +34,27 @@ class ProtocolHandlerFactory extends ObjectFactory {
        }
 
        /**
-        * Returns a singleton protocol handler 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 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       $messageType            Protocol to create an object from
+        * @param       $helperInstance         An instance of a HubHelper class
         * @return      $handlerInstance        A protocol handler instance
         */
-       public static final function createProtocolHandlerInstance ($messageType) {
+       public static final function createProtocolHandlerFromRecipientHelper (HubHelper $helperInstance) {
+               // Get the protocol type from given helper instance
+               die(__METHOD__ . ':' . print_r($helperInstance, TRUE));
+
                // Do we have an instance in the registry?
-               if (Registry::getRegistry()->instanceExists($messageType . '_protocol_handler')) {
+               if (Registry::getRegistry()->instanceExists($protocolType . '_protocol_handler')) {
                        // Then use this instance
-                       $handlerInstance = Registry::getRegistry()->getInstance($messageType . '_protocol_handler');
+                       $handlerInstance = Registry::getRegistry()->getInstance($protocolType . '_protocol_handler');
                } else {
                        // Now prepare the tags instance
-                       $handlerInstance = self::createObjectByConfiguredName($messageType . '_protocol_handler_class');
+                       $handlerInstance = self::createObjectByConfiguredName($protocolType . '_protocol_handler_class');
 
                        // Set the instance in registry for further use
-                       Registry::getRegistry()->addInstance($messageType . '_protocol_handler', $handlerInstance);
+                       Registry::getRegistry()->addInstance($protocolType . '_protocol_handler', $handlerInstance);
                }
 
                // Return the instance
index 9f8c9cbf7f233f1e22392803d3353ea0266d72e7..1098d473b78782212fc57310da0227219019ad81 100644 (file)
@@ -140,16 +140,16 @@ class BaseRawDataHandler extends BaseHandler {
        }
 
        /**
-        * Checks whether the 'recipient' field matches our own address:port
-        * combination.
+        * Checks whether the 'recipient' field matches our own an universal node
+        * locator.
         *
         * @param       $packageData    Raw package data
         * @return      $matches                Whether it matches
         * @todo        This method will be moved to a better place
         */
-       protected function ifRecipientMatchesOwnAddress (array $packageData) {
+       protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
                // Construct own address first
-               $ownAddress = NodeObjectFactory::createNodeInstance()->getAddressPort();
+               $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
 
                // Does it match?
                $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
index d1ce04e24bf9d6cccbffd7de43a969164d0f9af2..9bb47a18287745252b65755e6d14f82b14def96e 100644 (file)
@@ -49,8 +49,8 @@ class UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
        }
 
        /**
-        * Processes raw data from given resource. This is mostly useful for TCP
-        * package handling and is implemented in the TcpListener class
+        * Processes raw data from given resource. This is mostly useful for UDP
+        * package handling and is implemented in the UdpListener class
         *
         * @param       $socketArray    A valid socket resource array
         * @return      void
index e252a517510f77159fd5cc9f187cde831a6dd151..87292e4de815b4a8639c79b3331b7be3ecf7c1c0 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * A decorator for the TcpListener to communicate to hubs
+ * A general decorator for listeners to communicate to hubs
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
index a5432de2cd02acc43ca786f00f35c5d80562976c..3debbe0bd973dfcbab62ac47ca64acae8add53b7 100644 (file)
@@ -42,8 +42,8 @@ class RecipientList extends BaseList implements Listable, Registerable {
                $listInstance = new RecipientList();
 
                // Add groups:
-               // 1.) ip:port combinations
-               $listInstance->addGroup('ip_port');
+               // 1.) universal node locators
+               $listInstance->addGroup('unl');
 
                // 2.) Session ids
                $listInstance->addGroup('session_id');
@@ -68,7 +68,7 @@ class RecipientList extends BaseList implements Listable, Registerable {
         */
        public function clearList () {
                // Clear both groups
-               $this->clearGroups(array('ip_port', 'session_id'));
+               $this->clearGroups(array('unl', 'session_id'));
        }
 }
 
index c3d1767ca526a6ae4463682250d604f80137b15a..935c3c708ef8c94ebf5c4820a460b1d4fbac495a 100644 (file)
@@ -58,18 +58,21 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable {
         * @todo        add some more special bootstrap things for this boot node
         */
        public function doBootstrapping () {
+               // @TODO Unfinished
+               die(__METHOD__ . ':' . print_r($this, TRUE));
+
                // Now check if the IP address matches one of the bootstrap nodes
                if ($this->ifAddressMatchesBootstrapNodes($this->getConfigInstance()->detectServerAddress())) {
                        // Get our port from configuration
                        $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port');
 
                        // Extract port
-                       $bootPort = substr($this->getBootIpPort(), -strlen($ourPort), strlen($ourPort));
+                       $bootPort = substr($this->getBootUniversalNodeLocator(), -strlen($ourPort), strlen($ourPort));
 
                        // Is the port the same?
                        if ($bootPort == $ourPort) {
                                // It is the same!
-                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrap node ' . $this->getBootIpPort() . '.');
+                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: IP/port matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
 
                                // Now, does the mode match
                                if ($this->getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
index bacb47134709339c6ae3f7ee9926b2e6b594d0bb..08746675e1db898d2c5dde09f0ce4f5f01580f60 100644 (file)
@@ -37,9 +37,9 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        const OBJECT_LIST_SEPARATOR = ',';
 
        /**
-        * IP/port number of bootstrap node
+        * Universal node locator of bootstrap node
         */
-       private $bootIpPort = '';
+       private $bootUniversalNodeLocator = '';
 
        /**
         * Whether this node is anncounced (keep on FALSE!)
@@ -111,7 +111,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
                $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
 
                // Generate a pseudo-random string
-               $randomString = $rngInstance->randomString($length) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
+               $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode');
 
                // Add UUID for even more entropy for the hasher
                $randomString .= $this->getCryptoInstance()->createUuid();
@@ -147,10 +147,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        /**
         * Getter for boot IP/port combination
         *
-        * @return      $bootIpPort             The IP/port combination of the boot node
+        * @return      $bootUniversalNodeLocator               The IP/port combination of the boot node
         */
-       protected final function getBootIpPort () {
-               return $this->bootIpPort;
+       protected final function getBootUniversalNodeLocator () {
+               return $this->bootUniversalNodeLocator;
        }
 
        /**
@@ -164,24 +164,26 @@ 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 $ipPort) {
-                       // Split it up in IP/port
-                       $ipPortArray = explode(':', $ipPort);
+               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);
+                       // @TODO Unfinished
+                       die(__METHOD__ . ':' . print_r($unlArray, TRUE));
 
                        // Does it match?
-                       if ($ipPortArray[0] == $remoteAddr) {
+                       if ($unlArray[0] == $remoteAddr) {
                                // Found it!
                                $isFound = TRUE;
 
                                // Remember the port number
-                               $this->bootIpPort = $ipPort;
+                               $this->bootUniversalNodeLocator = $unl;
 
                                // Output message
-                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $ipPort . '.');
+                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl . '.');
 
                                // Stop further searching
                                break;
-                       } elseif ($ipPortArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
+                       } elseif ($unlArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) {
                                /*
                                 * IP matches listen address. At this point we really don't care
                                 * if we can really listen on that address
@@ -189,10 +191,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
                                $isFound = TRUE;
 
                                // Remember the port number
-                               $this->bootIpPort = $ipPort;
+                               $this->bootUniversalNodeLocator = $unl;
 
                                // Output message
-                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $ipPort . '.');
+                               self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl . '.');
 
                                // Stop further searching
                                break;
@@ -684,29 +686,31 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria {
        }
 
        /**
-        * "Getter" for address:port combination
+        * Determines the universal node locator
         *
-        * @return      $addressPort    A address:port combination for this node
+        * @return      $unl    A an universal node locator for this node
         */
-       public final function getAddressPort () {
+       public final function determineUniversalNodeLocator () {
                // Get IP and port
-               $addressPort = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
+               $unl = $this->getConfigInstance()->detectServerAddress() . ':' . $this->getConfigInstance()->getConfigEntry('node_listen_port');
 
                // Return it
-               return $addressPort;
+               return $unl;
        }
 
        /**
-        * "Getter" for address:port array
+        * "Getter" for universal node locator array
         *
-        * @return      $addressPortArray       An array of a address:port combination for this node
+        * @return      $unlArray       An array of the universal node locator for this node
         */
-       public final function getAddressPortArray () {
+       public final function getUniversalNodeLocatorArray () {
                // Get IP and port
-               $addressPortArray = explode(':', $this->getAddressPort());
+               // @TODO Unfinished
+               die(__METHOD__ . ':' . print_r($this, TRUE));
+               $unlArray = explode(':', $this->determineUniversalNodeLocator());
 
                // Return it
-               return $addressPortArray;
+               return $unlArray;
        }
 
        /**
index a325f471a2320f999c8679730979ce5f0af9aabc..a7832b99d29c58279804db7a355ccf7a90ddfd38 100644 (file)
@@ -616,7 +616,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
 
                // Is it the same?
                //$isSignatureValid = 
-               exit(__METHOD__.': signature='.$signature.chr(10).',decodedArray='.print_r($decodedArray, TRUE));
+               exit(__METHOD__ . ': signature=' . $signature . chr(10) . ',decodedArray=' . print_r($decodedArray, TRUE));
        }
 
        /**
@@ -629,7 +629,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R
         */
        public function enqueueRawDataFromTemplate (HubHelper $helperInstance) {
                // Get protocol instance for recipient
-               $protocolInstance = ProtocolHandlerFactory::createProtocolFromRecipientHelper($helperInstance);
+               $protocolInstance = ProtocolHandlerFactory::createProtocolHandlerFromRecipientHelper($helperInstance);
 
                // Get the raw content ...
                $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
index 9289d11b7e252c9bc2895c38f60e14ea10ff4bb1..8f3e2a1f5ee80ec058f289087ad103eb9528ace4 100644 (file)
@@ -223,8 +223,8 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
                // Temporary resolve recipient field
                $recipientIpArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]));
 
-               // Make sure it is a valid ip:port array (2 elements)
-               assert(count($recipientIpArray) == 2);
+               // Make sure it is a valid universal node locator array (3 elements)
+               assert(count($recipientIpArray) == 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] . ' ...');
index 43e2cdac0b8461ee921d5cfdf6ac83fefb82fe64..c5a6f2e4e4436697481d26e773f816c38ea1b18a 100644 (file)
@@ -46,7 +46,7 @@ class ???Recipient extends BaseRecipient implements Recipient {
        }
 
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern)
         *
         * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
index 82f694344b6bfe523effebb7d3bf830c6404b126..40daab4a4861c5a8a1fc085c55bff6b55f887cfc 100644 (file)
@@ -46,7 +46,7 @@ class DhtRecipient extends BaseRecipient implements Recipient {
        }
 
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern). This
         * implementation will add more than one recipient to the list as a DHT is
         * distributed and the package might go to more than one recipient.
@@ -73,15 +73,17 @@ class DhtRecipient extends BaseRecipient implements Recipient {
                // Now "walk" through all elements and add them to the list
                foreach ($recipients as $recipient) {
                        // These array elements must exist for this loop:
+                       // @TODO Unfinished
+                       die(__METHOD__ . ':' . print_r($recipient, TRUE));
                        assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP]));
                        assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]));
 
                        // Put ip and port both together
-                       $ipPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+                       $unl = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
 
                        // Add it to the list
-                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $ipPort . ') ...');
-                       $listInstance->addEntry('ip_port', $ipPort);
+                       //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DHT-RECIPIENT[' . __METHOD__ . ':' . __LINE__ . ']: Calling listInstance->addEntry(' . $unl . ') ...');
+                       $listInstance->addEntry('unl', $unl);
                } // END - foreach
 
                // Debug message
index 10f365fa660cfb55cdd89d184c60bc99178b0c89..71e61d392256bcf24b0df1dd0a67e802be3d04a3 100644 (file)
@@ -46,7 +46,7 @@ class DirectRecipient extends BaseRecipient implements Recipient {
        }
 
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern)
         *
         * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
@@ -68,10 +68,10 @@ class DirectRecipient extends BaseRecipient implements Recipient {
                // Try it on all
                foreach ($recipients as $recipient) {
                        // Try to sole a single recipient
-                       $ipPort = HubTools::resolveSessionId($recipient);
+                       $unl = HubTools::resolveSessionId($recipient);
 
                        // Add it as recipient
-                       $listInstance->addEntry('ip_port', $ipPort);
+                       $listInstance->addEntry('unl', $unl);
                } // END - foreach
        }
 }
index 33a2fbaf1a797843670ced4c12246d3938771c35..f0a0c89e5f8de276a69d63559321664d630fcb0b 100644 (file)
@@ -46,7 +46,7 @@ class SelfRecipient extends BaseRecipient implements Recipient {
        }
 
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern)
         *
         * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
@@ -58,6 +58,8 @@ 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__ . ':' . print_r($this, TRUE));
                assert($recipient == NetworkPackage::NETWORK_TARGET_SELF);
 
                // Determine own port
@@ -69,7 +71,7 @@ class SelfRecipient extends BaseRecipient implements Recipient {
                // Is it not empty?
                if (!empty($ip)) {
                        // Add it to the list
-                       $listInstance->addEntry('ip_port', $ip . ':' . $port);
+                       $listInstance->addEntry('unl', $ip . ':' . $port);
                } // END - if
        }
 }
index 6436a556f3b5b87d79b90f2440bd655d4b939a1b..f391d8faee07be4645eab01c1ddde72198d2f30f 100644 (file)
@@ -46,7 +46,7 @@ class UpperRecipient extends BaseRecipient implements Recipient {
        }
 
        /**
-        * Tries to resolve given recipient into session ids or ip:port combination
+        * Tries to resolve given recipient into session ids or universal node locator
         * depending on implementation (hint: Template Method Pattern)
         *
         * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
@@ -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 $ipPort) {
+               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) {
                        // 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 ' . $ipPort . ' as recipient.');
+                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $unl . ' as recipient.');
 
                        // Add the entry
-                       $listInstance->addEntry('ip_port', $ipPort);
+                       $listInstance->addEntry('unl', $unl);
                } // END - foreach
        }
 }
index 0237d9cef871e01a6a24f25c2701aa595a77498d..d04835a0ca0b4749b494d4dd56a4e5a748aab516 100644 (file)
@@ -26,6 +26,7 @@
 class ConnectionStatisticsHelper extends BaseHubSystem {
        /**
         * Statistics array
+        * @TODO Add more protocols to use
         */
        private static $connectionStatistics = array(
                // Statistics for TCP connections
index f8ef190621577ab8fe5dca3b792505432a4a688b..c41aa047e6b47e306b499c04196e85ef8eeaa483 100644 (file)
@@ -86,51 +86,51 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a session id into an ip:port combination. The opposite method
-        * is resolveSessionIdByIpPort()
+        * Resolves a session id into an universal node locator. The opposite method
+        * is resolveSessionIdByUniversalNodeLocator()
         *
         * @param       $sessionId                      A valid session id
-        * @return      $recipientIpPort        Recipient as ip:port combination
+        * @return      $recipientUniversalNodeLocator  Recipient as universal node locator
         */
-       protected function resolveIpPortBySessionId ($sessionId) {
+       protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
                // Init variable
-               $recipientIpPort = 'invalid:invalid';
+               $recipientUniversalNodeLocator = 'invalid:invalid';
 
-               // And ask it for ip:port by given session id
+               // And ask it for universal node locator by given session id
                $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId);
 
                // Is the recipient valid?
                if ((isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP])) && (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]))) {
                        // Then use this
-                       $recipientIpPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+                       $recipientUniversalNodeLocator = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
                } else {
                        // Get the instance, this might throw a NPE
                        $nodeInstance = NodeObjectFactory::createNodeInstance();
 
                        // Is the session id the same?
                        if ($nodeInstance->getSessionId() == $sessionId) {
-                               // Then get the ip:port from it, assume TCP by default
-                               $recipientIpPort = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
+                               // Then get the universal node locator from it, assume TCP by default
+                               $recipientUniversalNodeLocator = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
                        } // END - if
                }
 
                // Return result
-               return $recipientIpPort;
+               return $recipientUniversalNodeLocator;
        }
 
        /**
-        * Resolves a ip:port combination into a session id. The "opposite" method
-        * is resolveIpPortBySessionId().
+        * Resolves a universal node locator into a session id. The "opposite" method
+        * is resolveUniversalNodeLocatorBySessionId().
         *
-        * @param       $ipPort         Ip:port combination
+        * @param       $unl            Universal node locator
         * @return      $sessionId      Valid session id
         */
-       public static function resolveSessionIdByIpPort ($ipPort) {
+       public static function resolveSessionIdByUniversalNodeLocator ($unl) {
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
-               // And ask it for session id by given ip:port
-               $recipient = $selfInstance->getDhtInstance()->findNodeByIpPort($ipPort);
+               // 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);
 
                // Return result
@@ -138,66 +138,46 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves given session id into an ip:port combination, if ip:port is set, it won't be translated
+        * Resolves given session id into an universal node locator, if universal node locator is set, it won't be translated
         *
-        * @param       $sessionId      Session id or ip:port combination
-        * @return      $recipient      Recipient as ip:port combination
-        * @throws      InvalidSessionIdException       If the provided session id is invalid (and no ip:port combination)
+        * @param       $address        Session id or universal node locator
+        * @return      $recipient      Recipient as universal node locator
+        * @throws      InvalidSessionIdException       If the provided session id is invalid (and no universal node locator)
         * @throws      NoValidHostnameException        If the provided hostname cannot be resolved into an IP address
         */
-       public static function resolveSessionId ($sessionId) {
+       public static function resolveSessionId ($address) {
                // Get an own instance
                $selfInstance = self::getSelfInstance();
 
-               // Default is direct ip:port
-               $recipient = $sessionId;
+               // Default is direct universal node locator
+               $recipient = $address;
 
-               // Does it match a direct ip:port? (hint: see www.regexlib.com for the regular expression)
-               if (preg_match('/((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})/', $sessionId)) {
-                       // Direct ip:port found
-                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct ip:port ' . $sessionId . ' detected.');
-               } elseif (isset($selfInstance->sessionIdCache[$sessionId])) {
+               // Does it match a direct universal node locator? (hint: see www.regexlib.com for the regular expression)
+               if (preg_match('/([a-z0-9]{3,10})\/\/:([a-z0-9\.]{5,})/', $address)) {
+                       // @TODO ((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])):([0-9]{3,5})
+                       // Direct universal node locator found
+                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Direct universal node locator ' . $address . ' detected.');
+               } elseif (isset($selfInstance->sessionIdCache[$address])) {
                        // Debug message
                        self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using entry from sessionIdCache[] array.');
 
                        // Found in cache!
-                       $recipient = $selfInstance->sessionIdCache[$sessionId];
+                       $recipient = $selfInstance->sessionIdCache[$address];
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $sessionId . ']=' . $recipient);
-               } elseif (preg_match('/([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}:([0-9]{3,5})/', $sessionId)) {
-                       // Hostname:port found
-                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: hostname:port ' . $sessionId . ' detected.');
-
-                       // Hostname:port found
-                       $hostnameArray = explode(':', $sessionId);
-
-                       /*
-                        * Try to resolve it and add port again
-                        * @TODO Please try to encapsulate this PHP call into an own class
-                        */
-                       $recipient = gethostbyname($hostnameArray[0]) . ':' . $hostnameArray[1];
-
-                       // Is it valid?
-                       if ($recipient == $sessionId) {
-                               // Resolving hostname->IP failed!
-                               throw new NoValidHostnameException($hostnameArray, self::EXCEPTION_HOSTNAME_NOT_FOUND);
-                       } // END - if
-
-                       // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: hostname:port ' . $sessionId . ' resolved to ' . $recipient);
-               } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
+                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: sessionIdCache[' . $address . ']=' . $recipient);
+               } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $address)) {
                        // Debug message
                        self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Using internal session id resolver.');
 
-                       // Resolve session id into a ip:port combination
-                       $recipient = $selfInstance->resolveIpPortBySessionId($sessionId);
+                       // Resolve session id into an universal node locator
+                       $recipient = $selfInstance->resolveUniversalNodeLocatorBySessionId($address);
 
                        // Debug message
-                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $sessionId . ' resolved to ' . $recipient);
+                       self::createDebugInstance(__CLASS__)->debugOutput('HUB-TOOLS[' . __METHOD__ . ':' . __LINE__ . ']: Session id ' . $address . ' resolved to ' . $recipient);
                } else {
-                       // Invalid session id
-                       throw new InvalidSessionIdException($sessionId, self::EXCEPTION_SESSION_ID_IS_INVALID);
+                       // Invalid session id/UNL
+                       throw new InvalidSessionIdException($address, self::EXCEPTION_SESSION_ID_IS_INVALID);
                }
 
                // Return it
index 64af36939f080eaebdbbb52ebf4930b939266060..34b0b63fabe3475ac9d69c75cbaec6ec10336e3c 100644 (file)
@@ -146,11 +146,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
                // Set the primary key
                $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
 
-               // Get ip:port combination and "explode" it
-               $ipPort = $nodeInstance->getAddressPortArray();
+               // Get universal node locator and "explode" it
+               $unl = $nodeInstance->getUniversalNodeLocatorArray();
 
                // Make sure both is valid
-               assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
+               assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
 
                // Get an array of all accepted object types
                $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
@@ -160,8 +160,8 @@ 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_IP     , $ipPort[0]);
-               $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT     , $ipPort[1]);
+               $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP     , $unl[0]);
+               $dataSetInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT     , $unl[1]);
                $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());
@@ -187,18 +187,18 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
                // Get node instance
                $nodeInstance = NodeObjectFactory::createNodeInstance();
 
-               // Get ip:port combination and "explode" it
-               $ipPort = $nodeInstance->getAddressPortArray();
+               // Get universal node locator and "explode" it
+               $unl = $nodeInstance->getUniversalNodeLocatorArray();
 
                /*
                 * Make sure both is not 'invalid' which means that the resolver
                 * didn't work.
                 */
-               assert(($ipPort[0] !== 'invalid') && ($ipPort[1] !== 'invalid'));
+               assert(($unl[0] !== 'invalid') && ($unl[1] !== 'invalid') && ($unl[2] !== 'invalid'));
 
-               // Add ip:port/node id as criteria
-               $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $ipPort[0]);
-               $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $ipPort[1]);
+               // Add universal node locator/node id as criteria
+               $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_IP, $unl[0]);
+               $searchInstance->addCriteria(self::DB_COLUMN_LISTEN_PORT, $unl[1]);
                $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID    , $nodeInstance->getNodeId());
                $searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
                $searchInstance->setLimit(1);
index 850d5adea6b81e9318da111747f1d7a518fbbd77..d2765903c1785db1f50b2d38df8435c675f04f22 100644 (file)
@@ -56,8 +56,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        //-->
                        <object-max-spread>1</object-max-spread>
                        <!--
-                       The protocol we should use for transmission. Valid values can be
-                       'tcp' or 'udp', without the quotes.
+                       The protocol we should use for transmission. Valid is 'unl' without
+                       the quotes.
                        //-->
                        <object-protocol>tcp</object-protocol>
                        <!--
@@ -74,49 +74,49 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        <object-name>self_connect</object-name>
                        <object-recipient-limitation>self</object-recipient-limitation>
                        <object-max-spread>self</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>announcement_answer</object-name>
                        <object-recipient-limitation>direct</object-recipient-limitation>
                        <object-max-spread>1</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>request_node_list</object-name>
                        <object-recipient-limitation>upper</object-recipient-limitation>
                        <object-max-spread>1</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>request_node_list_answer</object-name>
                        <object-recipient-limitation>direct</object-recipient-limitation>
                        <object-max-spread>1</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>dht_bootstrap</object-name>
                        <object-recipient-limitation>all</object-recipient-limitation>
                        <object-max-spread>3</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>all</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>dht_bootstrap_answer</object-name>
                        <object-recipient-limitation>direct</object-recipient-limitation>
                        <object-max-spread>1</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
                <object-list-entry>
                        <object-name>dht_publish_entry</object-name>
                        <object-recipient-limitation>all</object-recipient-limitation>
                        <object-max-spread>4</object-max-spread>
-                       <object-protocol>tcp</object-protocol>
+                       <object-protocol>unl</object-protocol>
                        <object-recipient-type>hub</object-recipient-type>
                </object-list-entry>
        </object-list>
diff --git a/core b/core
index fc986df5800daabbd777eae81ec44f63c7cd84f5..584f44fab69cbffea39a99f0b169e3bdbb98b385 160000 (submodule)
--- a/core
+++ b/core
@@ -1 +1 @@
-Subproject commit fc986df5800daabbd777eae81ec44f63c7cd84f5
+Subproject commit 584f44fab69cbffea39a99f0b169e3bdbb98b385