// Get Universal Node Locator and "explode" it
$unlInstance = $nodeInstance->determineUniversalNodeLocator();
- // Get UNL data from it
- $unlData = $unlInstance->getUnlData();
+ // Get external UNL
+ $externalUnl = $unlInstance->getExternalUnl();
// Make sure both is valid
// @TODO Bad check on UNL, better use a proper validator
- assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
- assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] !== 'invalid');
+ assert($externalUnl !== 'invalid');
// Get an array of all accepted object types
$objectList = $nodeInstance->getListFromAcceptedObjectTypes();
// Add public node data
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode'));
- $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
+ $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $externalUnl);
$dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
$dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getPrivateKeyHash());
$nodeInstance = NodeObjectFactory::createNodeInstance();
// Get Universal Node Locator and "explode" it
- $unlData = $nodeInstance->getUniversalNodeLocatorArray();
+ $unlInstance = $nodeInstance->determineUniversalNodeLocator();
// Make sure the external address is set and not invalid
// @TODO Bad check on UNL, better use a proper validator
- assert(isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]));
- assert($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] != 'invalid');
+ $externalUnl = $unlInstance->getExternalUnl();
+ assert($externalUnl != 'invalid');
// Add Universal Node Locator/node id as criteria
- $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL]);
+ $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $externalUnl);
$searchInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId());
$searchInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId());
$searchInstance->setLimit(1);
// If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
// Mark it as working
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
$this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
} else {
// Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
}
// Are all tests passed?
// If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
// Mark it as working
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
$this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
} else {
// Not working (not all have ext-scrypt installed
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
}
// If uuid_create() is not found (ext-uuid) then some keys are a bit weaker
if ((extension_loaded('uuid')) && (is_callable('uuid_create'))) {
// Mark it as working
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-uuid and a callable uuid_create() function found. UUID "entropy" available.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-uuid and a callable uuid_create() function found. UUID "entropy" available.');
$this->getConfigInstance()->setConfigEntry('extension_uuid_loaded', TRUE);
} else {
// Not working (not all have ext-uuid installed
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER ext-uuid not found or uuid_create() function not found. UUID "entropy" disabled.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('FILTER: ext-uuid not found or uuid_create() function not found. UUID "entropy" disabled.');
}
// Are all tests passed?
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Locator\Node;
+
+// Import application-specific stuff
+use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
+use Hub\Generic\BaseHubSystem;
+
+/**
+ * A class for UNLs (Universal Node Locator)
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class UniversalNodeLocator extends BaseHubSystem implements LocateableNode {
+ //------- UNL parts -------
+ // Protocol
+ const UNL_PART_PROTOCOL = 'protocol';
+ // Address
+ const UNL_PART_ADDRESS = 'address';
+ // Extra part
+ const UNL_PART_EXTRA = 'extra';
+ // Port (if any)
+ const UNL_PART_PORT = 'port';
+
+ /**
+ * UNL data array
+ */
+ private $unlData = array();
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ public final static function createUniversalNodeLocator (array $current = array()) {
+ // Get new instance
+ $unlInstance = new UniversalNodeLocator();
+
+ // Init instance
+ $unlInstance->initUniversalNodeLocator($current);
+
+ // Return the prepared instance
+ return $unlInstance;
+ }
+
+ /**
+ * Initializes the UNL instance by givena array. If an entry is found, it
+ * will be copied, otherwise the entry is set empty.
+ *
+ * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
+ * @return void
+ */
+ private function initUniversalNodeLocator (array $current = array()) {
+ // Init UNL array
+ $this->unlData = array();
+
+ // Copy all found entries
+ foreach (array(
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
+ NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
+ NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
+ NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
+ NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
+ // Init entry
+ $this->unlData[$key] = NULL;
+
+ // Is the key found?
+ if (isset($current[$key])) {
+ // The copy the entry
+ $this->unlData[$key] = $current[$key];
+ } // END - if
+ } // END - foreach
+ }
+
+ /**
+ * Getter for UNL data array
+ *
+ * @return $unlData An array with UNL data
+ */
+ private function getUnlData () {
+ return $this->unlData;
+ }
+
+ /**
+ * Getter for external UNL
+ *
+ * @return $externalUnl External UNL
+ * @throws MissingArrayElementsException If DB_COLUMN_EXTERNAL_UNL is missing
+ */
+ public function getExternalUnl () {
+ // Get array
+ $unlData = $this->getUnlData();
+
+ // Is the element there?
+ if (!isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL])) {
+ // Is not there
+ throw new MissingArrayElementsException(array($this, 'unlData', array(NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL)), self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
+ } elseif ($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL] == 'invalid') {
+ // Is not valid/method to early used
+ throw new BadMethodCallException(sprintf('unlData[%s] is invalid. Maybe called this method to early?', NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL));
+ }
+
+ // Return it
+ return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL];
+ }
+
+ /**
+ * Getter for internal UNL
+ *
+ * @return $internalUnl Internal UNL
+ * @throws MissingArrayElementsException If DB_COLUMN_INTERNAL_UNL is missing
+ */
+ public function getInternalUnl () {
+ // Get array
+ $unlData = $this->getUnlData();
+
+ // Is the element there?
+ if (!isset($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL])) {
+ // Is not there
+ throw new MissingArrayElementsException(array($this, 'unlData', array(NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL)), self::EXCEPTION_ARRAY_ELEMENTS_MISSING);
+ } elseif ($unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL] == 'invalid') {
+ // Is not valid/method to early used
+ throw new BadMethodCallException(sprintf('unlData[%s] is invalid. Maybe called this method to early?', NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL));
+ }
+
+ // Return it
+ return $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
+ }
+
+}
// Is the port the same?
if ($bootPort == $ourPort) {
// It is the same!
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: UNL matches bootstrap node ' . $this->getBootUniversalNodeLocator() . '.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: UNL matches bootstrap node "%s".', $this->getBootUniversalNodeLocator()));
// Now, does the mode match
if (FrameworkBootstrap::getRequestInstance()->getRequestElement('mode') == self::NODE_TYPE_BOOT) {
self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: Our node is a valid bootstrap node.');
} else {
// Output warning
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: WARNING: Mismatching mode ' . FrameworkBootstrap::getRequestInstance()->getRequestElement('mode') . '!=' . BaseHubNode::NODE_TYPE_BOOT . ' detected.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: WARNING: Mismatching mode %s!=%s detected.', FrameworkBootstrap::getRequestInstance()->getRequestElement('mode'), BaseHubNode::NODE_TYPE_BOOT));
}
} else {
// IP does match, but no port
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does match a known bootstrap-node but not the port ' . $ourPort . '/' . $bootPort . '.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: WARNING: Our UNL "%s" does match a known bootstrap-node but not the port %d/%d.', $unl, $ourPort, $bootPort));
}
} else {
// Node does not match any know bootstrap-node
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: WARNING: Our UNL ' . $unl . ' does not match any known bootstrap-nodes.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: WARNING: Our UNL "%s" does not match any known bootstrap-nodes.', $unl));
}
// Enable acceptance of announcements
$this->bootUnl = $unl;
// Output message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . ': UNL matches remote address ' . $unl . '.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: UNL matches remote address "%s".', $unl));
// Stop further searching
break;
$this->bootUnl = $unl;
// Output message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BOOTSTRAP: ' . __FUNCTION__ . ': UNL matches listen address ' . $unl . '.');
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BOOTSTRAP: UNL matches listening UNL "%s".', $unl));
// Stop further searching
break;
// Is "cache" set?
if (!isset($GLOBALS[__METHOD__])) {
// Get the UNL array back
- $unlData = $this->getUniversalNodeLocatorArray();
+ $unlInstance = $this->determineUniversalNodeLocator();
// There are 2 UNLs, internal and external.
if ($this->getConfigInstance()->getConfigEntry('allow_publish_internal_address') == 'N') {
// Public "external" UNL address
- $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL];
+ $GLOBALS[__METHOD__] = $unlInstance->getExternalUnl();
} else {
// Non-public "internal" UNL address
- $GLOBALS[__METHOD__] = $unlData[NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL];
+ $GLOBALS[__METHOD__] = $unlInstance->getInternalUnl();
}
} // END - if
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: CALLED!');
- // Determine UNL based on this node:
- // 1) Get discovery class
- $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
-
- // 2) "Determine" it
- $unlInstance = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
-
- // 3) Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unlInstance= ' . $unlInstance->__toString() . ' - EXIT!');
- return $unlInstance;
- }
-
- /**
- * "Getter" for an array of an instance of a LocateableNode class
- *
- * @return $unlData An array from an instance of a LocateableNode class for this node
- */
- public final function getUniversalNodeLocatorArray () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: CALLED!');
-
- // Get the Universal Node Locator (UNL) instance
- $unlInstance = $this->determineUniversalNodeLocator();
+ // Is there cache?
+ if (!isset($GLOBALS[__METHOD__])) {
+ // Determine UNL based on this node:
+ // 1) Get discovery class
+ $discoveryInstance = ObjectFactory::createObjectByConfiguredName('unl_discovery_class');
- // Make sure the instance is valid
- if (!$unlInstance instanceof LocateableNode) {
- // No valid instance, so better debug this
- $this->debugBackTrace('unlInstance[' . gettype($unlInstance) . ']=' . $unlInstance);
+ // 2) "Determine" it
+ $GLOBALS[__METHOD__] = $discoveryInstance->discoverUniversalNodeLocatorByNode($this);
} // END - if
- // ... and the array from it
- $unlData = $unlInstance->getUnlData();
-
// Return it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: EXIT!');
- return $unlData;
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE: unlInstance= ' . $GLOBALS[__METHOD__]->__toString() . ' - EXIT!');
+ return $GLOBALS[__METHOD__];
}
/**
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Locator\Node;
-
-// Import application-specific stuff
-use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
-use Hub\Generic\BaseHubSystem;
-
-/**
- * A class for UNLs (Universal Node Locator)
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-class UniversalNodeLocator extends BaseHubSystem implements LocateableNode {
- //------- UNL parts -------
- // Protocol
- const UNL_PART_PROTOCOL = 'protocol';
- // Address
- const UNL_PART_ADDRESS = 'address';
- // Extra part
- const UNL_PART_EXTRA = 'extra';
- // Port (if any)
- const UNL_PART_PORT = 'port';
-
- /**
- * UNL data array
- */
- private $unlData = array();
-
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
- * @return $unlInstance An instance of a LocateableNode class
- */
- public final static function createUniversalNodeLocator (array $current = array()) {
- // Get new instance
- $unlInstance = new UniversalNodeLocator();
-
- // Init instance
- $unlInstance->initUniversalNodeLocator($current);
-
- // Return the prepared instance
- return $unlInstance;
- }
-
- /**
- * Initializes the UNL instance by givena array. If an entry is found, it
- * will be copied, otherwise the entry is set empty.
- *
- * @param $current An array with "raw" data from the database layer for the UNL. This parameter is optional.
- * @return void
- */
- private function initUniversalNodeLocator (array $current = array()) {
- // Init UNL array
- $this->unlData = array();
-
- // Copy all found entries
- foreach (array(
- NodeInformationDatabaseWrapper::DB_COLUMN_NODE_ID,
- NodeInformationDatabaseWrapper::DB_COLUMN_SESSION_ID,
- NodeInformationDatabaseWrapper::DB_COLUMN_PRIVATE_KEY_HASH,
- NodeInformationDatabaseWrapper::DB_COLUMN_NODE_MODE,
- NodeInformationDatabaseWrapper::DB_COLUMN_INTERNAL_UNL,
- NodeInformationDatabaseWrapper::DB_COLUMN_EXTERNAL_UNL) as $key) {
- // Init entry
- $this->unlData[$key] = NULL;
-
- // Is the key found?
- if (isset($current[$key])) {
- // The copy the entry
- $this->unlData[$key] = $current[$key];
- } // END - if
- } // END - foreach
- }
-
- /**
- * Getter for UNL data array
- *
- * @return $unlData An array with UNL data
- */
- public final function getUnlData () {
- return $this->unlData;
- }
-}
-
-// [EOF]
-?>
*/
function determineUniversalNodeLocator ();
- /**
- * "Getter for an array of an instance of a LocateableNode class
- *
- * @return $unlData An array of an instance of a LocateableNode class
- */
- function getUniversalNodeLocatorArray ();
-
/**
* Updates/refreshes node data (e.g. state).
*
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
interface LocateableNode extends HubInterface {
-}
+ /**
+ * Getter for external UNL
+ *
+ * @return $externalUnl External UNL
+ * @throws MissingArrayElementsException If DB_COLUMN_EXTERNAL_UNL is missing
+ */
+ function getExternalUnl ();
+
+ /**
+ * Getter for internal UNL
+ *
+ * @return $internalUnl Internal UNL
+ * @throws MissingArrayElementsException If DB_COLUMN_INTERNAL_UNL is missing
+ */
+ function getInternalUnl ();
-// [EOF]
-?>
+}
#!/bin/sh
# Really lame ...
-find application/ -type f -print0 | xargs -0 sed -i 's/2015 Hub/2016 Hub/g'
+find application/ -type f -print0 | xargs -0 sed -i 's/2015 Hub/2017 Hub/g'
-Subproject commit d9d2b0266fc21f4664087a8488d05c6d6068073b
+Subproject commit aa76ddf7f1d5d302f1d752efcd113515ecf152a2