use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter;
use Org\Shipsimu\Hub\Network\Receive\Receivable;
use Org\Shipsimu\Hub\Node\Generic\InvalidPrivateKeyHashException;
+use Org\Shipsimu\Hub\RawData\InvalidDataChecksumException;
use Org\Shipsimu\Hub\Tag\Tagable;
use Org\Shipsimu\Hub\Tools\HubTools;
use Org\Mxchange\CoreFramework\Visitor\Visitor;
// Import SPL stuff
+use \InvalidArgumentException;
use \Iterator;
/**
const PACKAGE_CONTENT_ARRAY_SIZE = 4;
/**
- * Separator for checksum
+ * Mask for content's checksum generation
*/
- const PACKAGE_CHECKSUM_SEPARATOR = '_';
+ const CONTENT_CHECKSUM_MASK = '%s_%s_%s';
/**
* Array indexes for above mask, start with zero
* @return $hash Hash for given package content
*/
private function getHashFromContent ($content) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
-
// Create the hash
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: content[md5]=%s - CALLED!', md5($content)));
// @TODO md5() is very weak, but it needs to be fast
- $hash = md5(
- $content .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $this->getNodeInstance()->getSessionId() .
- self::PACKAGE_CHECKSUM_SEPARATOR .
+ $hash = md5(sprintf(self::CONTENT_CHECKSUM_MASK,
+ $content,
+ $this->getNodeInstance()->getSessionId(),
$this->getCompressorInstance()->getCompressorExtension()
- );
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($content) . ',sender=' . $this->getNodeInstance()->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension());
+ ));
// And return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: content[md5]=%s,sender=%s,hash=%s,compressor=%s - EXIT!', md5($content), $this->getNodeInstance()->getSessionId(), $hash, $this->getCompressorInstance()->getCompressorExtension()));
return $hash;
}
*/
private function isChecksumValid (array $decodedContent, DeliverablePackage $packageInstance) {
// Get checksum
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: decodedContent()=%d,packageInstance=%s - CALLED!', count($decodedContent), $packageInstance->__toString()));
$checksum = $this->getHashFromContentSessionId($decodedContent, $packageInstance->getSenderAddress());
// Is it the same?
$isChecksumValid = ($checksum == $decodedContent[self::PACKAGE_CONTENT_CHECKSUM]);
// Return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: isChecksumValid=%d - EXIT!', intval($isChecksumValid)));
return $isChecksumValid;
}
* @param $stackerName Name of the stacker
* @param $newStatus New status to set
* @return void
+ * @throws InvalidArgumentException If hashes are mismatching
*/
private function changePackageStatus (DeliverablePackage $packageInstance, $stackerName, $newStatus) {
// Skip this for empty stacks
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,stackerName=%s,newStatus=%s - CALLED!', $packageInstance->__toString(), $stackerName, $newStatus));
if ($this->getStackInstance()->isStackEmpty($stackerName)) {
// This avoids an exception after all packages has failed
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: stackerName=%s is empty - EXIT!', $stackerName));
return;
} // END - if
// Pop the entry (it should be it)
- $nextData = $this->getStackInstance()->popNamed($stackerName);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Getting next stack from stackerName=%s ...', $stackerName));
+ $nextPackageInstance = $this->getStackInstance()->popNamed($stackerName);
// Compare both hashes
- assert($nextData->getPackageHash() == $packageInstance->getPackageHash());
+ if ($nextPackageInstance->getPackageHash() != $packageInstance->getPackageHash()) {
+ // Hash is not matching
+ throw new InvalidArgumentException(sprintf('Hashes "%s" and "%s" are mismatching.', $packageInstance->getPackageHash(), $nextPackageInstance->getPackageHash()));
+ }
// Temporary set the new status
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Setting newStatus=%s ....', $newStatus));
$packageInstance->setPackageStatus($newStatus);
// And push it again
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Adding packageInstance=%s to stackerName=%s ...', $packageInstance->__toString(), $stackerName));
$this->getStackInstance()->pushNamed($stackerName, $packageInstance);
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!');
}
/**
* @return $hash Hash for given package content
*/
public function getHashFromContentSessionId (array $decodedContent, $sessionId) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]);
-
// Create the hash
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: decodedContent()=%d,sessionId=%s - CALLED!', count($decodedContent), $sessionId));
// @TODO md5() is very weak, but it needs to be fast
- $hash = md5(
- $decodedContent[self::PACKAGE_CONTENT_MESSAGE] .
- self::PACKAGE_CHECKSUM_SEPARATOR .
- $sessionId .
- self::PACKAGE_CHECKSUM_SEPARATOR .
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content[md5]=' . md5($decodedContent[self::PACKAGE_CONTENT_MESSAGE]) . ',sender=' . $sessionId . ',compressor=' . $decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]);
+ $hash = md5(sprintf(self::CONTENT_CHECKSUM_MASK,
+ $decodedContent[self::PACKAGE_CONTENT_MESSAGE],
+ $sessionId,
$decodedContent[self::PACKAGE_CONTENT_COMPRESSOR]
- );
+ ));
// And return it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: hash=%s - EXIT!', $hash));
return $hash;
}
* target because it causes an overload on the network and may be
* abused for attacking the network with large packages.
*/
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance();
// Discover all recipients, this may throw an exception
// Push the declared package to the next stack.
$this->getStackInstance()->pushNamed(self::STACKER_NAME_DECLARED, $packageInstance);
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package declared for recipient ' . $currentRecipient);
// Skip to next entry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Package declared for recipient ' . $currentRecipient);
$iteratorInstance->next();
} // END - while
* shall be delivered has already been added for all entries from the
* list.
*/
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Calling discoveryInstance->clearRecipients() ...');
$discoveryInstance->clearRecipients();
}
* @return void
*/
private function deliverRawPackageData (DeliverablePackage $packageInstance) {
- // Trace message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
-
/*
* This package may become big, depending on the shared object size or
* delivered message size which shouldn't be so long (to save
* which (configurable!) protocol should be used for that type of
* package.
*/
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$discoveryInstance = SocketDiscoveryFactory::createSocketDiscoveryInstance();
// Now discover the right socket instance from given package data
$socketInstance = $discoveryInstance->discoverSocket($packageInstance, StorableSocket::CONNECTION_TYPE_OUTGOING);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
-
// Get the connection helper from registry
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after discoverSocket() has been called.');
$helperInstance = GenericRegistry::getRegistry()->getInstance('connection');
// Debug message
// Will the info instance with connection helper data
$infoInstance->fillWithConnectionHelperInformation($helperInstance);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
-
// Is it not there?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' before isSocketRegistered() has been called.');
if (($socketInstance->isValidSocket()) && (!$this->getRegistryInstance()->isSocketRegistered($infoInstance, $socketInstance))) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Registering socket ' . $socketInstance . ' ...');
-
// Then register it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Registering socket ' . $socketInstance . ' ...');
$this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance);
} elseif (!$helperInstance->getStateInstance()->isPeerStateConnected()) {
// Is not connected, then we cannot send
$socketInstance->shutdownSocket();
}
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
-
// Make sure the connection is up
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after isSocketRegistered() has been called.');
$helperInstance->getStateInstance()->validatePeerStateConnected();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
-
// Enqueue it again on the out-going queue, the connection is up and working at this point
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after validatePeerStateConnected() has been called.');
$this->getStackInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageInstance);
- // Debug message
+ // Trace message
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Reached line ' . __LINE__ . ' after pushNamed() has been called.');
}
*
* @param $rawPackageContent The raw package content to be "decoded"
* @return $packageInstance An instance of a DeliverablePackage class
+ * @throws InvalidArgumentException If $rawPackageContent contains double seperators
*/
public function decodeRawContent ($rawPackageContent) {
- // Use the separator '#' to "decode" it
+ // Check if no double seperator is found
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent(%d)=%s - CALLED!', strlen($rawPackageContent), $rawPackageContent));
+ if (strpos($rawPackageContent, self::PACKAGE_DATA_SEPARATOR . self::PACKAGE_DATA_SEPARATOR) !== FALSE) {
+ // Opps, should never happend
+ throw new InvalidArgumentException(sprintf('rawPackageContent=%s has 2x or more "%s" in it.', $rawPackageContent, self::PACKAGE_DATA_SEPARATOR));
+ }
+
+ // Use the separator '#' to "decode" it
$decodedArray = explode(self::PACKAGE_DATA_SEPARATOR, $rawPackageContent);
- // Assert on count (should be always 3)
- assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE);
- //* DEBUG-DIE: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
+ // Assert on count (should be always 6)
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: decodedArray()=%d', count($decodedArray)));
+ /* DEBUG-DIE: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE)));
+ if (count($decodedArray) != self::DECODED_DATA_ARRAY_SIZE) {
+ // Count of array elements not expected
+ throw new InvalidArgumentException(sprintf('decodedArray()=%d does not match expected size %d. rawPackageContent=%s',
+ count($decodedArray),
+ self::DECODED_DATA_ARRAY_SIZE,
+ $rawPackageContent
+ ));
+ }
// Create package instance
$packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class');
*
* @param $packageInstance An instance of a DeliverablePackage class
* @return void
+ * @throws InvalidArgumentException If the package content does not have expected amount of entries
* @throws InvalidDataChecksumException If the checksum doesn't match
*/
public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) {
+ // Is the package content set?
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString()));
+ if ($packageInstance->getPackageContent() == '') {
+ // Package content is not set
+ throw new InvalidArgumentException(sprintf('Package with receipientId=%s,recipientType=%s has empty packageContent',
+ $packageInstance->getRecipientId(),
+ $packageInstance->getRecipientType()
+ ));
+ }
+
/*
* "Decode" the package's content by a simple explode() call, for
* details of the array elements, see comments for constant
$decodedContent = explode(self::PACKAGE_MASK_SEPARATOR, $packageInstance->getPackageContent());
// Assert on array count for a very basic validation
- assert(count($decodedContent) == self::PACKAGE_CONTENT_ARRAY_SIZE);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: decodedContent()=%d', count($decodedContent)));
+ if (count($decodedContent) != self::PACKAGE_CONTENT_ARRAY_SIZE) {
+ // Not valid decoded content
+ throw new InvalidArgumentException(sprintf('decodedContent()=%d does not match expected %d. packageContent=%s',
+ count($decodedContent),
+ self::PACKAGE_CONTENT_ARRAY_SIZE,
+ $packageInstance->getPackageContent()
+ ));
+ }
/*
* Convert the indexed array into an associative array. This is much
* better to remember than plain numbers, isn't it?
*/
- $decodedContent = array(
+ $decodedMessage = array(
// Compressor's extension used to compress the data
self::PACKAGE_CONTENT_COMPRESSOR => $decodedContent[self::INDEX_COMPRESSOR_EXTENSION],
// Package data (aka "message") in BASE64-decoded form but still compressed
);
// Is the checksum valid?
- if (!$this->isChecksumValid($decodedContent, $packageInstance)) {
+ if (!$this->isChecksumValid($decodedMessage, $packageInstance)) {
// Is not the same, so throw an exception here
- throw new InvalidDataChecksumException(array($this, $decodedContent, $packageInstance), self::EXCEPTION_INVALID_DATA_CHECKSUM);
+ throw new InvalidDataChecksumException(array($this, $decodedMessage, $packageInstance), self::EXCEPTION_INVALID_DATA_CHECKSUM);
} // END - if
/*
* The checksum is the same, then it can be decompressed safely. The
* original message is at this point fully decoded.
*/
- $decodedContent[self::PACKAGE_CONTENT_MESSAGE] = $this->getCompressorInstance()->decompressStream($decodedContent[self::PACKAGE_CONTENT_MESSAGE]);
+ $decodedMessage[self::PACKAGE_CONTENT_MESSAGE] = $this->getCompressorInstance()->decompressStream($decodedMessage[self::PACKAGE_CONTENT_MESSAGE]);
// And push it on the next stack
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $decodedContent);
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_NEW_MESSAGE, $decodedMessage);
}
/**
assert($this->isNewMessageArrived());
// Get it from the stacker, it is the full array with the decoded message
- $decodedContent = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
+ $decodedMessage = $this->getStackInstance()->popNamed(self::STACKER_NAME_NEW_MESSAGE);
// Generate the hash of comparing it
- if (!$this->isPackageHashValid($decodedContent)) {
+ if (!$this->isPackageHashValid($decodedMessage)) {
// Is not valid, so throw an exception here
exit(__METHOD__ . ':INVALID HASH! UNDER CONSTRUCTION!' . chr(10));
} // END - if
// Now get a filter chain back from factory with given tags array
- $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedContent[self::PACKAGE_CONTENT_TAGS]);
+ $chainInstance = PackageFilterChainFactory::createChainByTagsArray($decodedMessage[self::PACKAGE_CONTENT_TAGS]);
/*
* Process the message through all filters, note that all other
- * elements from $decodedContent are no longer needed.
+ * elements from $decodedMessage are no longer needed.
*/
- $chainInstance->processMessage($decodedContent, $this);
+ $chainInstance->processMessage($decodedMessage, $this);
/*
* Post-processing of message data (this won't remove the message from
* @return $isRegistered Whether the given socket resource is registered
*/
public function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!');
-
// Default is not registered
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ' - CALLED!');
$isRegistered = FALSE;
// First, check for the instance, there can be only once
} // END - if
} // END - if
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
-
// Return the result
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getSocketResource() . ',isRegistered=' . intval($isRegistered) . ' - EXIT!');
return $isRegistered;
}
* @throws NoSocketRegisteredException If the requested socket is not registered
*/
public function getRegisteredSocketResource (Listenable $listenerInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ' - CALLED!');
-
// The socket must be registered before we can return it
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY:listener=' . $listenerInstance->getProtocolName() . ' - CALLED!');
if (!$this->isInfoRegistered($listenerInstance)) {
// Throw the exception
throw new NoSocketRegisteredException ($listenerInstance, self::EXCEPTION_SOCKET_NOT_REGISTERED);
// And the final socket resource
$socketInstance = $registryInstance->getInstance($socketKey);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: listener=' . $listenerInstance->getProtocolName() . ',socketInstance[]=' . gettype($socketInstance) . ' - EXIT!');
-
// Return the resource
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: listener=' . $listenerInstance->getProtocolName() . ',socketInstance[]=' . gettype($socketInstance) . ' - EXIT!');
return $socketInstance;
}
*/
public function getInfoInstanceFromPackageInstance (DeliverablePackage $packageInstance) {
// Init info instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-REGISTRY: packageInstance=%s - CALLED!', $packageInstance));
$infoInstance = NULL;
//* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE));
// Get all keys and check them
foreach ($this->getInstanceRegistry() as $key => $registryInstance) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
-
// This is always a SubRegistry instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',registryInstance=' . $registryInstance->__toString());
foreach ($registryInstance->getInstanceRegistry() as $subKey => $socketInstance) {
- // Debug message
- //* 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?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',socketInstance=' . $socketInstance->__toString());
if (($socketInstance instanceof StorableSocket) && ($socketInstance->ifAddressMatches($packageInstance->getRecipientUnl()))) {
- // Debug die
- //* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE));
-
- // Trace message
- //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: Calling socketInstance->getListenerInstance() ...');
-
// Get listener and helper instances
+ //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: Calling socketInstance->getListenerInstance() ...');
+ //* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE));
$listenerInstance = $socketInstance->getListenerInstance();
$helperInstance = $socketInstance->getHelperInstance();
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
-
// Is a listener or helper set?
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: key=' . $key . ',subKey=' . $subKey . ',listenerInstance[]=' . gettype($listenerInstance) . ',helperInstance[]=' . gettype($helperInstance));
if ($listenerInstance instanceof Listenable) {
// Found a listener, so get the info instance first
$infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($listenerInstance->getProtocolName(), 'helper');
} // END - if
} // END - foreach
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: infoInstance[]=' . gettype($infoInstance) . ' - EXIT!');
-
// Return the info instance
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-REGISTRY: infoInstance[]=' . gettype($infoInstance) . ' - EXIT!');
return $infoInstance;
}