From: Roland Haeder Date: Sat, 25 Oct 2014 11:13:32 +0000 (+0200) Subject: More rewrites (and code stops): X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4243633833e9e46509b05df13b617d52180d8b8f;p=hub.git More rewrites (and code stops): - 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 --- diff --git a/application/hub/interfaces/helper/nodes/class_NodeHelper.php b/application/hub/interfaces/helper/nodes/class_NodeHelper.php index 9717de9b5..83d4fca5a 100644 --- a/application/hub/interfaces/helper/nodes/class_NodeHelper.php +++ b/application/hub/interfaces/helper/nodes/class_NodeHelper.php @@ -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). diff --git a/application/hub/interfaces/recipient/class_Recipient.php b/application/hub/interfaces/recipient/class_Recipient.php index f1a137d5f..bf01e643f 100644 --- a/application/hub/interfaces/recipient/class_Recipient.php +++ b/application/hub/interfaces/recipient/class_Recipient.php @@ -23,7 +23,7 @@ */ interface Recipient extends FrameworkInterface { /** - * Tries to resolve given recipient into session ids or 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) diff --git a/application/hub/main/discovery/class_BaseNodeDiscovery.php b/application/hub/main/discovery/class_BaseNodeDiscovery.php index 52df19cde..2e5ff6a52 100644 --- a/application/hub/main/discovery/class_BaseNodeDiscovery.php +++ b/application/hub/main/discovery/class_BaseNodeDiscovery.php @@ -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); diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 12973457d..ee4c3b1ae 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -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]); } } } diff --git a/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php b/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php index f7e5832df..6955bd0a4 100644 --- a/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php +++ b/application/hub/main/factories/handler/class_ProtocolHandlerFactory.php @@ -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 diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index 9f8c9cbf7..1098d473b 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -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]); diff --git a/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php b/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php index d1ce04e24..9bb47a182 100644 --- a/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php +++ b/application/hub/main/handler/network/udp/class_UdpRawDataHandler.php @@ -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 diff --git a/application/hub/main/listener/class_BaseListenerDecorator.php b/application/hub/main/listener/class_BaseListenerDecorator.php index e252a5175..87292e4de 100644 --- a/application/hub/main/listener/class_BaseListenerDecorator.php +++ b/application/hub/main/listener/class_BaseListenerDecorator.php @@ -1,6 +1,6 @@ * @version 0.0.0 diff --git a/application/hub/main/lists/recipient/class_RecipientList.php b/application/hub/main/lists/recipient/class_RecipientList.php index a5432de2c..3debbe0bd 100644 --- a/application/hub/main/lists/recipient/class_RecipientList.php +++ b/application/hub/main/lists/recipient/class_RecipientList.php @@ -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')); } } diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index c3d1767ca..935c3c708 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -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) { diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index bacb47134..08746675e 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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; } /** diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index a325f471a..a7832b99d 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -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(); diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 9289d11b7..8f3e2a1f5 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -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] . ' ...'); diff --git a/application/hub/main/recipient/class_ b/application/hub/main/recipient/class_ index 43e2cdac0..c5a6f2e4e 100644 --- a/application/hub/main/recipient/class_ +++ b/application/hub/main/recipient/class_ @@ -46,7 +46,7 @@ class ???Recipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or 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) diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php index 82f694344..40daab4a4 100644 --- a/application/hub/main/recipient/dht/class_DhtRecipient.php +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -46,7 +46,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or 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 diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php index 10f365fa6..71e61d392 100644 --- a/application/hub/main/recipient/direct/class_DirectRecipient.php +++ b/application/hub/main/recipient/direct/class_DirectRecipient.php @@ -46,7 +46,7 @@ class DirectRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or 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 } } diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php index 33a2fbaf1..f0a0c89e5 100644 --- a/application/hub/main/recipient/self/class_SelfRecipient.php +++ b/application/hub/main/recipient/self/class_SelfRecipient.php @@ -46,7 +46,7 @@ class SelfRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or 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 } } diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php index 6436a556f..f391d8fae 100644 --- a/application/hub/main/recipient/upper/class_UpperRecipient.php +++ b/application/hub/main/recipient/upper/class_UpperRecipient.php @@ -46,7 +46,7 @@ class UpperRecipient extends BaseRecipient implements Recipient { } /** - * Tries to resolve given recipient into session ids or 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 } } diff --git a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php index 0237d9cef..d04835a0c 100644 --- a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php +++ b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php @@ -26,6 +26,7 @@ class ConnectionStatisticsHelper extends BaseHubSystem { /** * Statistics array + * @TODO Add more protocols to use */ private static $connectionStatistics = array( // Statistics for TCP connections diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index f8ef19062..c41aa047e 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -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=
'.print_r($recipient, TRUE).'
' . 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 diff --git a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 64af36939..34b0b63fa 100644 --- a/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -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); diff --git a/application/hub/templates/xml/object_registry/object_registry.xml b/application/hub/templates/xml/object_registry/object_registry.xml index 850d5adea..d2765903c 100644 --- a/application/hub/templates/xml/object_registry/object_registry.xml +++ b/application/hub/templates/xml/object_registry/object_registry.xml @@ -56,8 +56,8 @@ along with this program. If not, see //--> 1 tcp