]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/tools/class_HubTools.php
Rewrites, some more methods:
[hub.git] / application / hub / main / tools / class_HubTools.php
index 95198e7a6aac5c1ef0effe67628cc183fb9247e6..e69c4f7dcde1beacc24676c31e68dbbde5323015 100644 (file)
@@ -80,18 +80,20 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a session id into an ip:port combination
+        * Resolves a session id into an ip:port combination. The opposite method
+        * is resolveSessionIdByIpPort()
         *
         * @param       $sessionId      A valid session id
         * @param       $protocol       Name of the used protocol: TCP/UDP
         * @return      $recipient      Recipient as ip:port combination
         */
        protected function resolveIpPortBySessionId ($sessionId, $protocol) {
-               // Get a wrapper instance
-               $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+               // Get a DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
-               // And ask it for the session id
-               $recipient = $wrapperInstance->resolveIpPortBySessionId($sessionId, $protocol);
+               // And ask it for ip:port by given session id
+               $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol);
+               die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
 
                // Is the recipient invalid?
                if ($recipient == 'invalid:invalid') {
@@ -101,7 +103,7 @@ class HubTools extends BaseHubSystem {
                        // 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_' . strtolower($protocol) . '_listen_port');
+                               $recipient = self::determineOwnExternalIp() . ':' . $nodeInstance->getConfigInstance()->getConfigEntry('node_listen_port');
                        } // END - if
                } // END - if
 
@@ -110,18 +112,20 @@ class HubTools extends BaseHubSystem {
        }
 
        /**
-        * Resolves a ip:port combination into a session id
+        * Resolves a ip:port combination into a session id. The "opposite" method
+        * is resolveIpPortBySessionId().
         *
         * @param       $ipPort         Ip:port combination
         * @param       $protocol       Name of used protocol (TCP/UDP)
         * @return      $sessionId      Valid session id
         */
        public static function resolveSessionIdByIpPort ($ipPort, $protocol) {
-               // Get a wrapper instance
-               $wrapperInstance = DatabaseWrapperFactory::createWrapperByConfiguredName('node_list_db_wrapper_class');
+               // Get a DHT instance
+               $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node');
 
-               // And ask it for the session id
-               $sessionId = $wrapperInstance->resolveSessionIdByIpPort($ipPort, $protocol);
+               // And ask it for session id by given ip:port
+               $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol);
+               die(__METHOD__.':recipient=<pre>'.print_r($recipient, true).'</pre>' . PHP_EOL);
 
                // Return result
                return $sessionId;
@@ -211,6 +215,28 @@ class HubTools extends BaseHubSystem {
                // Return it
                return $ip;
        }
+
+       /**
+        * Determine IP or 'internal_ip' if set
+        *
+        * @return      $ip             The determined external ip of this node
+        */
+       public static function determineOwnInternalIp () {
+               // Is the internal_ip config entry set?
+               if (FrameworkConfiguration::getSelfInstance()->getConfigEntry('allow_publish_internal_ip') == 'N') {
+                       // Not allowed to publish internal IP, so use external
+                       $ip = self::determineOwnExternalIp();
+               } elseif (FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip') != '') {
+                       // Use it as internal ip
+                       $ip = FrameworkConfiguration::getSelfInstance()->getConfigEntry('internal_ip');
+               } else {
+                       // Determine own internal ip by connecting to my (coder) server at 188.138.90.169
+                       $ip = ConsoleTools::acquireSelfIPAddress();
+               }
+
+               // Return it
+               return $ip;
+       }
 }
 
 // [EOF]