]> git.mxchange.org Git - hub.git/commitdiff
Generation of session id basicly added. IP/port added
authorRoland Häder <roland@mxchange.org>
Sat, 1 Aug 2009 21:31:02 +0000 (21:31 +0000)
committerRoland Häder <roland@mxchange.org>
Sat, 1 Aug 2009 21:31:02 +0000 (21:31 +0000)
application/hub/main/nodes/class_BaseHubNode.php

index 07045edd82773c4b72a3670e2535f2cbcd955670..6325a94fbb3c6a7298f2064203c03036a285c8f8 100644 (file)
@@ -27,6 +27,11 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         */
        private $nodeId = '';
 
+       /**
+        * Session id
+        */
+       private $sessionId = '';
+
        /**
         * IP/port number of bootstrapping node
         */
@@ -77,6 +82,25 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                return $this->nodeId;
        }
 
+       /**
+        * Setter for session id
+        *
+        * @param       $sessionId              Our new session id
+        * @return      void
+        */
+       private final function setSessionId ($sessionId) {
+               $this->sessionId = (string) $sessionId;
+       }
+
+       /**
+        * Getter for session id
+        *
+        * @return      $sessionId              Our new session id
+        */
+       private final function getSessionId () {
+               return $this->sessionId;
+       }
+
        /**
         * Setter for query instance
         *
@@ -202,7 +226,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                        $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
 
                        // Generate a pseudo-random string
-                       $randomString = $rngInstance->randomString(255) . ':' . $this->getRequestInstance()->getRequestElement('mode');
+                       $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort()  . ':' . $this->getRequestInstance()->getRequestElement('mode');
 
                        // Get a crypto instance
                        $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
@@ -218,6 +242,34 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
                }
        }
 
+       /**
+        * Generates a session id which will be sent to the other hubs and clients
+        *
+        * @return      void
+        */
+       public function bootstrapGenerateSessionId () {
+               // Get an RNG instance
+               $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+
+               // Generate a pseudo-random string
+               $randomString = $rngInstance->randomString(255) . ':' . $this->getBootIpPort() . ':' . $this->getRequestInstance()->getRequestElement('mode');
+
+               // Get a crypto instance
+               $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+
+               // Hash and encrypt the string so we become a "node id" aka Hub-Id
+               $this->setSessionId($cryptoInstance->hashString($cryptoInstance->encryptString($randomString)));
+
+               // Get a wrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_info_db_wrapper_class');
+
+               // Register the node id with our wrapper
+               $wrapperInstance->registerNodeId($this, $this->getRequestInstance());
+
+               // Output message
+               $this->debugOutput('BOOTSTRAP: Created new session-id: ' . $this->getSessionId() . '');
+       }
+
        /**
         * Getter for boot IP/port combination
         *
@@ -238,6 +290,9 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
 
                // Run a test query
                $this->getQueryInstance()->doTestQuery();
+
+               // Query queue initialized
+               $this->debugOutput('BOOTSTRAP: Query queue initialized.');
        }
        
        /**