]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/tools/class_HubTools.php
Code cleanups and project continued:
[hub.git] / application / hub / main / tools / class_HubTools.php
index 4d8227f2f80799908c20fcda9da453cf1936d780..231078411ce8e6f3fc2b5482044acb6a09f2e94b 100644 (file)
@@ -92,6 +92,18 @@ class HubTools extends BaseFrameworkSystem {
                // And ask it for the session id
                $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId);
 
+               // Is the recipient invalid?
+               if ($recipient == 'invalid:invalid') {
+                       // Get the instance, this might throw a NPE
+                       $nodeInstance = Registry::getRegistry()->getInstance('node');
+
+                       // Is the session id the same?
+                       if ($nodeInstance->getSessionId() == $sessionId) {
+                               // Then get the ip:port from it, assume TCP by default
+                               $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_tcp_listen_port');
+                       } // END - if
+               } // END - if
+
                // Return result
                return $recipient;
        }
@@ -151,6 +163,25 @@ class HubTools extends BaseFrameworkSystem {
                // Return it
                return $recipient;
        }
+
+       /**
+        * Determine IP or 'external_ip' if set
+        *
+        * @return      $ip             The determined external ip of this node
+        */
+       public static function determineOwnExternalIp () {
+               // Is the external_ip config entry set?
+               if (FrameworkConfiguration::getInstance()->getConfigEntry('external_ip') != '') {
+                       // Use it as external ip
+                       $ip = FrameworkConfiguration::getInstance()->getConfigEntry('external_ip');
+               } else {
+                       // Determine own external ip by connecting to my (coder) server at 188.138.90.169
+                       $ip = ConsoleTools::determineExternalIp();
+               }
+
+               // Return it
+               return $ip;
+       }
 }
 
 // [EOF]