From 35ee91cae32ef1060c3b5da2b6962cc562d75a1d Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 15 Dec 2014 19:30:01 +0100 Subject: [PATCH] Continued with refacturing: - renamed some variables - expanded bootstrap node with protocol to fit UNL scheme (protocol://address[:port]) - added another die() as this part needs overworking, too - introduced detectOwnUniversalNodeLocator() Signed-off-by: Roland Haeder --- application/hub/config-local.php-dist | 2 +- .../hub/main/nodes/boot/class_HubBootNode.php | 9 +- .../hub/main/nodes/class_BaseHubNode.php | 82 +++++++++++-------- .../main/pools/peer/class_DefaultPeerPool.php | 1 + 4 files changed, 53 insertions(+), 41 deletions(-) diff --git a/application/hub/config-local.php-dist b/application/hub/config-local.php-dist index 9722460b0..33430f29c 100644 --- a/application/hub/config-local.php-dist +++ b/application/hub/config-local.php-dist @@ -52,7 +52,7 @@ $cfg->setConfigEntry('node_default_mode', 'regular'); // Use this in intranet-only environment: $cfg->setConfigEntry('allow_publish_internal_ip', 'Y'); // CFG: HUB-BOOTSTRAP-NODES -$cfg->setConfigEntry('hub_bootstrap_nodes', '188.138.90.169:9060'); +$cfg->setConfigEntry('hub_bootstrap_nodes', 'tcp://188.138.90.169:9060'); // [EOF] ?> diff --git a/application/hub/main/nodes/boot/class_HubBootNode.php b/application/hub/main/nodes/boot/class_HubBootNode.php index 935c3c708..984e2c861 100644 --- a/application/hub/main/nodes/boot/class_HubBootNode.php +++ b/application/hub/main/nodes/boot/class_HubBootNode.php @@ -58,11 +58,8 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { * @todo add some more special bootstrap things for this boot node */ public function doBootstrapping () { - // @TODO Unfinished - die(__METHOD__ . ':' . print_r($this, TRUE)); - // Now check if the IP address matches one of the bootstrap nodes - if ($this->ifAddressMatchesBootstrapNodes($this->getConfigInstance()->detectServerAddress())) { + if ($this->ifAddressMatchesBootstrapNodes($this->detectOwnUniversalNodeLocator())) { // Get our port from configuration $ourPort = $this->getConfigInstance()->getConfigEntry('node_listen_port'); @@ -84,11 +81,11 @@ class HubBootNode extends BaseHubNode implements NodeHelper, Registerable { } } else { // IP does match, but no port - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->detectOwnUniversalNodeLocator() . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.'); } } else { // Node does not match any know bootstrap-node - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->getConfigInstance()->detectServerAddress() . ' does not match any known bootstrap-nodes.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: WARNING: Our IP ' . $this->detectOwnUniversalNodeLocator() . ' does not match any known bootstrap-nodes.'); } // Enable acceptance of announcements diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index ce3637cc1..398f32aa8 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -39,7 +39,7 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { /** * Universal node locator of bootstrap node */ - private $bootUnlInstance = ''; + private $bootUnl = ''; /** * Whether this node is anncounced (keep on FALSE!) @@ -98,28 +98,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { NodeStateFactory::createNodeStateInstanceByName('init', $this); } - /** - * Generates a random string from various data inluding UUID if PECL - * extension uuid is installed. - * - * @param $length Length of the random part - * @return $randomString Random string - * @todo Make this code more generic and move it to CryptoHelper or - */ - protected function generateRamdomString ($length) { - // Get an RNG instance - $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); - - // Generate a pseudo-random string - $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode'); - - // Add UUID for even more entropy for the hasher - $randomString .= $this->getCryptoInstance()->createUuid(); - - // Return it - return $randomString; - } - /** * Generates a private key and hashes it (for speeding up things) * @@ -144,13 +122,35 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: Created new private key with hash: ' . $this->getPrivateKeyHash() . ''); } + /** + * Generates a random string from various data inluding UUID if PECL + * extension uuid is installed. + * + * @param $length Length of the random part + * @return $randomString Random string + * @todo Make this code more generic and move it to CryptoHelper or + */ + protected function generateRamdomString ($length) { + // Get an RNG instance + $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); + + // Generate a pseudo-random string + $randomString = $rngInstance->randomString($length) . ':' . $this->getBootUniversalNodeLocator() . ':' . $this->getRequestInstance()->getRequestElement('mode'); + + // Add UUID for even more entropy for the hasher + $randomString .= $this->getCryptoInstance()->createUuid(); + + // Return it + return $randomString; + } + /** * Getter for boot IP/port combination * - * @return $bootUnlInstance The IP/port combination of the boot node + * @return $bootUnl The IP/port combination of the boot node */ protected final function getBootUniversalNodeLocator () { - return $this->bootUnlInstance; + return $this->bootUnl; } /** @@ -164,24 +164,25 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $isFound = FALSE; // Run through all configured IPs - foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlArray) { + foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unl) { // @TODO Unfinished - die(__METHOD__ . ':' . print_r($unlArray, TRUE)); + die(__METHOD__ . ':' . print_r($this, TRUE)); + die(__METHOD__ . ': unl=' . $unl . ',remoteAddr=' . $remoteAddr); // Does it match? - if ($unlArray[0] == $remoteAddr) { + if ($unl == $remoteAddr) { // Found it! $isFound = TRUE; - // Remember the UNL array - $this->bootUnlInstance = $unlArray; + // Remember the UNL + $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unlArray->__toString() . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches remote address ' . $unl->__toString() . '.'); // Stop further searching break; - } elseif ($unlArray[0] == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) { + } elseif ($unl == $this->getConfigInstance()->getConfigEntry('node_listen_addr')) { /* * IP matches listen address. At this point we really don't care * if we can really listen on that address @@ -189,10 +190,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { $isFound = TRUE; // Remember the port number - $this->bootUnlInstance = $unlArray; + $this->bootUnl = $unl; // Output message - self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unlArray->__toString() . '.'); + self::createDebugInstance(__CLASS__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . '[' . __METHOD__ . ':' . __LINE__ . ']: IP matches listen address ' . $unl->__toString() . '.'); // Stop further searching break; @@ -203,6 +204,19 @@ class BaseHubNode extends BaseHubSystem implements Updateable, AddableCriteria { return $isFound; } + /** + * Tries to detect own UNL (Universal Node Locator) + * + * @return $unl Node's own universal node locator + */ + public function detectOwnUniversalNodeLocator () { + // Get the UNL array back + $unlArray = $this->getUniversalNodeLocatorArray(); + + // @TODO + die(__METHOD__ . ':unlArray=' . print_r($unlArray, TRUE)); + } + /** * Outputs the console teaser. This should only be executed on startup or * full restarts. This method generates some space around the teaser. diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 5c5fdbcbc..22069fcb6 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -221,6 +221,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { $socketResource = FALSE; // Temporary resolve recipient field + die(__METHOD__ . ': UNFINISHED!' . PHP_EOL); $unlArray = explode(':', HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])); // Make sure it is a valid Universal Node Locator array (3 elements) -- 2.39.5