* @param $decodedData Raw raw package data array
* @return void
* @todo Add some validation of recipient field, e.g. an Universal Node Locator is found
- * @todo The if() does only check for TCP, not UDP, e.g. try to get a $handlerInstance here
+ * @todo Enrich both messages with recipient data
*/
public function discoverRawRecipients (array $decodedData) {
// This must be available
*/
// Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' matches own ip (' . HubTools::determineOwnExternalAddress() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient matches own ip (' . HubTools::determineOwnExternalAddress() . ' or ' . $this->getConfigInstance()->getServerAddress() . ')');
} else {
// Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient ' . $recipient[0] . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-DISCOVERY[' . __METHOD__ . ':' . __LINE__ . ']: Recipient is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . $this->getConfigInstance()->getServerAddress() . '), need to forward (not yet implemented)!');
// This package is to be delivered to someone else, so add it
//$this->getListInstance()->addEntry('unl', $decodedData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
$stateInstance = self::createObjectByConfiguredName($className, array($cruncherInstance));
// Debug message
- self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Cruncher state has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+ self::createDebugInstance(__CLASS__)->debugOutput('CRUNCHER-STATE-FACTORY[' . __METHOD__ . ':' . __LINE__ . ']: Cruncher state has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
// Once we have that state, set it in the cruncher instance
$cruncherInstance->setStateInstance($stateInstance);
*
* @return $unlData The UNL data array
*/
- public final function getUniversalNodeLocatorData () {
+ public final function getUniversalNodeLocatorDataArray () {
// Return UNL data array
return $this->universalNodeLocatorData;
}
// Return the generic array
return $unlData;
}
+
+ /**
+ * Gets an element from universalNodeLocatorData array
+ *
+ * @param $element Element in universalNodeLocatorData array
+ * @return $value Found value
+ */
+ protected final function getUniversalNodeLocatorDataElement ($element) {
+ // Is the element there?
+ assert(isset($this->universalNodeLocatorData[$element]));
+
+ // Return it
+ return $this->universalNodeLocatorData[$element];
+ }
+
+ /**
+ * "Getter" for currently saved UNL
+ *
+ * @return $unl Currently saved Universal Node Locator
+ */
+ public final function getCurrentUniversalNodeLocator () {
+ // Construct generic UNL
+ $unl = sprintf('%s://%s',
+ $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PROTOCOL),
+ $this->getAddressPart()
+ );
+
+ // Return it
+ return $unl;
+ }
+
+ /**
+ * Default implementation for returning address part, may not be suitable
+ * for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
+ *
+ * @return $address Address part for the final UNL
+ */
+ public function getAddressPart () {
+ // Return it
+ return $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_ADDRESS);
+ }
+
+ /**
+ * If the found UNL (address) matches own external or internal address
+ *
+ * @return $ifMatches Whether the found UNL matches own addresss
+ */
+ public function isOwnAddress () {
+ // Get current UNL (from universalNodeLocatorData array)
+ $currentUnl = $this->getCurrentUniversalNodeLocator();
+
+ // Get own external UNL
+ $externalUnl = HubTools::determineOwnExternalAddress();
+
+ // Get internal UNL
+ $internalUnl = HubTools::determineOwnInternalAddress();
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: currentUnl=' . $currentUnl . ',externalUnl=' . $externalUnl . ',internalUnl=' . $internalUnl);
+ //* DIE-DEBUG: */ die(__METHOD__.':currentUnl=' . $currentUnl . ',this='.print_r($this, TRUE));
+
+ // Is it the same?
+ $ifMatches = (($currentUnl === $externalUnl) || ($currentUnl === $internalUnl));
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: ifMatches=' . intval($ifMatches));
+
+ // Return result
+ return $ifMatches;
+ }
}
// [EOF]
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: isValid=' . intval($isValid) . ' - EXIT!');
return $isValid;
}
+
+ /**
+ * This implementation uses it's parent method and combines it with the
+ * port part to construct a valid address:port combination.
+ *
+ * @return $address Address part for the final UNL
+ */
+ public function getAddressPart () {
+ // Construct address
+ $address = sprintf('%s:%s',
+ parent::getAddressPart(),
+ $this->getUniversalNodeLocatorDataElement(UniversalNodeLocator::UNL_PART_PORT)
+ );
+
+ // Return it
+ return $address;
+ }
}
// [EOF]
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
// Get UNL data
- $unlData = $handlerInstance->getUniversalNodeLocatorData();
+ $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
+
+ // Make sure it is a valid Universal Node Locator array (3 elements)
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_ADDRESS]));
+ assert(isset($unlData[UniversalNodeLocator::UNL_PART_PORT]));
// Set handler instance
$helperInstance->setHandlerInstance($handlerInstance);
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageData($packageData);
// Get UNL data
- $unlData = $handlerInstance->getUniversalNodeLocatorData();
+ $unlData = $handlerInstance->getUniversalNodeLocatorDataArray();
// Make sure it is a valid Universal Node Locator array (3 elements)
assert(isset($unlData[UniversalNodeLocator::UNL_PART_PROTOCOL]));
-Subproject commit 12417a7382d7ab76dacb985819e30b57db01f1fd
+Subproject commit f4b9cbebe8ad3c6be3a6292c9f227dc04dc43667