]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
Added template class for entries in a request-node-list
[hub.git] / application / hub / main / discovery / package / class_PackageRecipientDiscovery.php
index 73a4638677de2d291897a6fe6d2054cfcd803214..896f5b4c6bcc50b5ab1b8ac3b5edcce440ac100f 100644 (file)
@@ -62,27 +62,39 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                // We do some rudimentary checks but this might be a bit ugly
                switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
                        // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
-                       case NetworkPackage::NETWORK_TARGET_UPPER_HUBS:
+                       case NetworkPackage::NETWORK_TARGET_UPPER_NODES:
                                // Get all bootstrap nodes
-                               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $node) {
+                               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
+                                       // Is maximum reached?
+                                       if ($this->getListInstance()->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
+                                               // Debug message
+                                               /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
+
+                                               // Then stop adding more
+                                               break;
+                                       } // END - if
+
                                        // Debug message
-                                       /* DEBUG: */ $this->debugOutput('DISCOVERY: Adding node ' . $node . ' as recipient.');
+                                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Adding node ' . $ipPort . ' as recipient.');
 
                                        // Add the entry
-                                       $this->getListInstance()->addEntry('ip_port', $node);
+                                       $this->getListInstance()->addEntry('ip_port', $ipPort);
                                } // END - foreach
                                break;
 
                        // The target 'self' is always the external IP address!
                        case NetworkPackage::NETWORK_TARGET_SELF:
+                               // Determine own port
+                               $port = $this->getConfigInstance()->getConfigEntry('node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port');
+
                                // Determine IP or 'external_ip' if set
                                $ip = HubTools::determineOwnExternalIp();
 
-                               // Get port and add it
-                               $ipPort = $ip . ':' . $this->getConfigInstance()->getConfigEntry('node_' . $this->determineProtocolByPackageData($packageData) . '_listen_port');
-
-                               // Add it to the list
-                               $this->getListInstance()->addEntry('ip_port', $ipPort);
+                               // Is it not empty?
+                               if (!empty($ip)) {
+                                       // Add it to the list
+                                       $this->getListInstance()->addEntry('ip_port', $ip . ':' . $port);
+                               } // END - if
                                break;
 
                        // This may be a direct recipient (node's session id)
@@ -117,12 +129,12 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
        /**
         * Tries to discover all recipients by given decoded package data.
         *
-        * @param       $decodedData    Decoded raw package data array
+        * @param       $decodedData    Raw raw package data array
         * @return      void
         * @todo        Add some validation of recipient field, e.g. ip:port is found
         * @todo        The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
         */
-       public function discoverDecodedRecipients (array $decodedData) {
+       public function discoverRawRecipients (array $decodedData) {
                // First clear all recipients
                $this->clearRecipients();
 
@@ -138,10 +150,10 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                         */
 
                        // Debug output (may flood)
-                       /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' matches own ip (' .  HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' matches own ip (' .  HubTools::determineOwnExternalIp() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
                } else {
                        // Debug output (may flood)
-                       /* NOISY-DEBUG: */ $this->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $recipient[0] . ' is different than own external ip (' .  HubTools::determineOwnExternalIp() . ') nor internal ip (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
+                       /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY: 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]);