//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getSocketProtocol()) . '-SOCKET: unl=' . $unl . ',packageInstance=' . print_r($packageInstance, true));
// So, does both match?
- $matches = (($packageInstance->getRecipientType() !== '') && ($packageInstance->getRecipientType() === $unl));
+ $matches = (($packageInstance->getRecipientUnl() !== '') && ($packageInstance->getRecipientUnl() === $unl));
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: matches=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($matches)));
$packageInstance = $this->getPackageDataInstance();
// Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: packageInstance.recipient=%s - EXIT!', strtoupper($this->getSocketProtocol()), $packageInstance->getRecipientType()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: packageInstance.recipient=%s - EXIT!', strtoupper($this->getSocketProtocol()), $packageInstance->getRecipientUnl()));
// Return it
- return $packageInstance->getRecipientType();
+ return $packageInstance->getRecipientUnl();
}
/**
* "Explode" the 'recipient' array element into a new one, giving at
* least two entries: protocol://address
*/
- $recipient = explode(':', $packageInstance->getRecipientType());
+ $recipient = explode(':', $packageInstance->getRecipientUnl());
// At least 2 entries must be found
assert(count($recipient) >= 2);
* recipient must be direct recipient then, otherwise a "virtual"
* recipient.
*/
- if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientType())) {
+ if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientUnl())) {
// Get instance (should not break)
$recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
} else {
}
// Try to solve it
- $recipientInstance->resolveRecipient($packageInstance->getRecipientType(), $this->getListInstance(), $packageInstance);
+ $recipientInstance->resolveRecipient($packageInstance->getRecipientUnl(), $this->getListInstance(), $packageInstance);
} catch (FrameworkException $e) {
// Could not find class, what ever failed
$this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage()));
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
// Is the 'recipient' field same as this peer's IP?
- if ($handlerInstance->isOwnAddress($packageInstance->getRecipientType())) {
+ if ($handlerInstance->isOwnAddress($packageInstance->getRecipientUnl())) {
/*
* Is same as own external address + TCP/UDP listen port or
* internal address, don't do anything here so other classes found
*/
// Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientType() . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientUnl() . ' matches own ip (external=' . HubTools::determineOwnExternalAddress() . ' or internal=' . HubTools::determineOwnInternalAddress() . ')');
} else {
// Debug output (may flood)
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientType() . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: Recipient ' . $packageInstance->getRecipientUnl() . ' is different than own external address (' . HubTools::determineOwnExternalAddress() . ') nor internal address (' . HubTools::determineOwnInternalAddress() . '), need to forward (not yet implemented)!');
// This package is to be delivered to someone else, so add it
- // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $packageInstance->getRecipientType());
+ // @TODO Unfinished: $this->getListInstance()->addEntry('unl', $packageInstance->getRecipientUnl());
}
}
// Try to create a new socket resource
try {
// Possibly noisy debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance->getProtocolName()) . ' connection to ' . $packageInstance->getRecipientType() . ' ...');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($listenerInstance->getProtocolName()) . ' connection to ' . $packageInstance->getRecipientUnl() . ' ...');
// Get a socket resource from our factory (if succeeded)
$socketInstance = SocketFactory::createSocketFromPackageInstance($packageInstance, $protocolInstance);
PeerStateResolver::resolveStateByPackage($helperInstance, $packageInstance, $socketInstance);
} catch (InvalidSocketException $e) {
// This cannot be fixed, so log it away
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageInstance->getRecipientType() . ': ' . $e->getMessage());
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Cannot discover socket resource for recipient ' . $packageInstance->getRecipientUnl() . ': ' . $e->getMessage());
// Make any failed attempts to 'FALSE'
$socketInstance = NULL;
$socketInstance = NULL;
// Construct registry key
- $registryKey = 'socket_' . $protocolInstance->getProtocolName() . '_' . $packageInstance->getRecipientType();
+ $registryKey = sprintf('socket_%s_%s', $protocolInstance->getProtocolName(), $packageInstance->getRecipientType());
// Debug message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Trying to find a socket with registryKey=' . $registryKey);
// Get current entry
$currentRecipient = $iteratorInstance->current();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Setting recipient to ' . $currentRecipient . ',previous=' . $packageInstance->getRecipientType());
-
// Set the recipient
- $packageInstance->setRecipient($currentRecipient);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Setting recipient to ' . $currentRecipient . ',previous=' . $packageInstance->getRecipientUnl());
+ $packageInstance->setRecipientUnl($currentRecipient);
// Push the declared package to the next stack.
$this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageInstance);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package declared for recipient ' . $currentRecipient);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package declared for recipient ' . $currentRecipient);
// Skip to next entry
$iteratorInstance->next();
*/
public function decodeRawContent ($rawPackageContent) {
// Use the separator '#' to "decode" it
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent()=%d - CALLED!', strlen($rawPackageContent)));
$decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: decodedArray=' . print_r($decodedArray, TRUE));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: decodedArray=' . print_r($decodedArray, TRUE));
// Assert on count (should be always 3)
assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE);
+ /* PRINTR-DEBUG: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
// Create package instance
$packageInstance = PackageDataFactory::createPackageDataInstance();
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: CALLED!');
// Is the correct handler choosen?
- assert(substr($packageInstance->getRecipientType(), 0, strlen($this->getHandlerName())) != $this->getHandlerName());
+ assert(substr($packageInstance->getRecipientUnl(), 0, strlen($this->getHandlerName())) != $this->getHandlerName());
// Default is from generic validation
- $isValid = NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientType());
+ $isValid = NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientUnl());
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: packageInstance.recipient=' . $packageInstance->getRecipientType() . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('IPV4-PROTOCOL-HANDLER: packageInstance.recipient=' . $packageInstance->getRecipientUnl() . ',isValid[' . gettype($isValid) . ']=' . intval($isValid));
// If this doesn't fail, continue validating the IP:port combination
if ($isValid === TRUE) {
// ... and validate IP:port, first "parse" the UNL
- $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientType());
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
// Set whole UNL instance
// @TODO don't do this in a isValidFoo() method
$ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
// Does it match?
- $matches = ($ownAddress === $packageInstance->getRecipientType());
+ $matches = ($ownAddress === $packageInstance->getRecipientUnl());
// Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RAW-DATA-HANDLER: matches=%d - EXIT!', intval($matches)));
$helperInstance->setHandlerInstance($handlerInstance);
} catch (NoValidHostnameException $e) {
// Debug message
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageInstance->getRecipientType() . ':' . $e->getMessage());
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CONNECTION-HELPER: Failed to resolve ' . $packageInstance->getRecipientUnl() . ':' . $e->getMessage());
// Is the recipient equal as configured UNL?
- if (substr($packageInstance->getRecipientType(), 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
+ if (substr($packageInstance->getRecipientUnl(), 0, strlen($helperInstance->getConfigInstance()->getConfigEntry('external_address'))) == $helperInstance->getConfigInstance()->getConfigEntry('external_address')) {
// This may connect to shipsimu.org and requests 'ip.php' which will return our external IP address
$unlAddress = HubTools::determineExternalAddress();
// Do we have ip:port match?
// @TODO Rewrite this test for UNLs
- if (strpos($packageInstance->getRecipientType(), ':') === FALSE) {
+ if (strpos($packageInstance->getRecipientUnl(), ':') === FALSE) {
// No ip:port!
- $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageInstance->getRecipientType()));
+ $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s does not contain ":". Please fix this.', __METHOD__, __LINE__, $packageInstance->getRecipientUnl()));
} // END - if
// "explode" the ip:port, so index 1 will be the port number
// @TODO Rewrite this test for UNLs
- $recipientArray = explode(':', $packageInstance->getRecipientType());
+ $recipientArray = explode(':', $packageInstance->getRecipientUnl());
// Add the port
$unlPort = $recipientArray[LocateableNode::UNL_PART_PORT];
//$unlInstance =;
} else {
// It doesn't match, we need to take care of this later
- $helperInstance->debugInstance(sprintf('[%s:%d]: recipient=%s!=%s', __METHOD__, __LINE__, $packageInstance->getRecipientType(), $helperInstance->getConfigInstance()->getConfigEntry('external_address')));
+ $helperInstance->debugInstance(sprintf(
+ '[%s:%d]: recipient=%s!=%s',
+ __METHOD__,
+ __LINE__,
+ $packageInstance->getRecipientUnl(),
+ $helperInstance->getConfigInstance()->getConfigEntry('external_address')
+ ));
}
}
// Set all required data
$socketInstance->setSenderAddres($peerAddress . $peerSuffix);
$socketInstance->setSenderPort($peerPort);
- $socketInstance->setRecipient($nodeInstance->getSessionId());
+ $socketInstance->setRecipientId($nodeInstance->getSessionId());
$socketInstance->setStatus(NetworkPackageHandler::PACKAGE_STATUS_FAKED);
die(__METHOD__.': UNFINISHED!');
$socketProtocol = $this->getSocketInstance()->getSocketProtocol();
// Get UNL instance
- $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientType());
+ $unlInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
// Get protocol from it
$unlProtocol = $unlInstance->getUnlProtocol();
*/
private $recipientType;
+ /**
+ * Recipient UNL
+ */
+ private $recipientUnl;
+
/**
* Status
*/
$this->recipientType = $recipientType;
}
+ /**
+ * Getter for recipient UNL
+ *
+ * @return $recipientUnl Recipient UNL
+ */
+ public function getRecipientUnl () {
+ return $this->recipientUnl;
+ }
+
+ /**
+ * Setter for recipient UNL
+ *
+ * @param $recipientUnl Recipient UNL
+ * @return void
+ */
+ public function setRecipientUnl ($recipientUnl) {
+ $this->recipientUnl = $recipientUnl;
+ }
+
/**
* Getter for status
*
private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) {
return (
$packageInstance->getSenderAddress() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
- $packageInstance->getRecipientType() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
+ $packageInstance->getRecipientUnl() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR .
$packageInstance->getPackageContent() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR
);
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',socketInstance=' . $socketInstance->__toString());
// Is this a StorableSocket instance and is the address the same?
- if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageInstance->getRecipientType()))) {
+ if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageInstance->getRecipientUnl()))) {
// Debug die
//* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE));
use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
use Org\Shipsimu\Hub\Listener\Listenable;
use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
+use Org\Shipsimu\Hub\Node\Tagging\InvalidTagException;
use Org\Shipsimu\Hub\Tag\BaseTag;
use Org\Shipsimu\Hub\Tag\Tagable;
use Org\Shipsimu\Hub\Template\Engine\Xml\ObjectRegistry\XmlObjectRegistryTemplateEngine;
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] Unexpected package status %s!=%s detected, recipientType=%s, sender=%s:%d, hash=%s.',
+ $message = sprintf('[%s:%d] Unexpected package status %s!=%s detected, recipientUnl=%s, sender=%s:%d, hash=%s.',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[1]->getPackageStatus(),
$messageArray[2],
- $messageArray[1]->getRecipientType(),
+ $messageArray[1]->getRecipientUnl(),
$messageArray[1]->getSenderAddress(),
$messageArray[1]->getSenderPort(),
$messageArray[1]->getHash()
*/
public function __construct (array $messageArray, $code) {
// Construct the message
- $message = sprintf('[%s:%d] The protocol handler %s cannot validate recipient %s.',
+ $message = sprintf('[%s:%d] The protocol handler %s cannot validate recipientUnl=%s.',
$messageArray[0]->__toString(),
$this->getLine(),
$messageArray[1]->__toString(),
- $messageArray[2]->getRecipientType()
+ $messageArray[2]->getRecipientUnl()
);
// Call parent exception constructor