From: Roland Häder Date: Sat, 1 Aug 2009 21:31:02 +0000 (+0000) Subject: Generation of session id basicly added. IP/port added X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c9b904e6149aa009e3b8c808430ff29c5f8514c2;p=hub.git Generation of session id basicly added. IP/port added --- diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 07045edd8..6325a94fb 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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.'); } /**