* @param $packageInstance An instance of a DeliverablePackage class
* @return $hash Private key's hash
* @throws InvalidPrivateKeyHashException If the private key's hash is not valid
+ * @throws InvalidArgumentException If $packageInstance does not contain senderId/senderAddress
*/
private function determineSenderPrivateKeyHash (DeliverablePackage $packageInstance) {
// Get DHT instance
$dhtInstance = DhtObjectFactory::createDhtInstance('node');
- // Ask DHT for session id
- /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderId=%s ...', $packageInstance->getSenderId()));
- $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderId());
-
- // Debugging:
- //* DEBUG-DIE: */ die(sprintf('[%s:%d]: senderData=%s', __METHOD__, __LINE__, print_r($senderData, TRUE)));
+ // Init sender data array
+ $senderData = array();
+
+ // Ask DHT for sender's id or address (both session id)
+ if ($packageInstance->getSenderId() != '') {
+ // Field senderId is given
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderId=%s ...', $packageInstance->getSenderId()));
+ $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderId());
+ } elseif ($packageInstance->getSenderAddress() != '') {
+ // Field senderAddress is given
+ /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Finding local node data for packageInstance->senderAddress=%s ...', $packageInstance->getSenderAddress()));
+ $senderData = $dhtInstance->findNodeLocalBySessionId($packageInstance->getSenderAddress());
+ } else {
+ // Invalid $packageInstance
+ throw new InvalidArgumentException('packageInstance does not contain senderId/senderAddress');
+ }
// Is an entry found?
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: senderData=%s', __METHOD__, __LINE__, print_r($senderData, TRUE)));
if (count($senderData) > 0) {
// Make sure the element 'private_key_hash' is there
//* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderData=' . print_r($senderData, TRUE));
use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* This class contains static helper functions for our hub
*
*
* @param $sessionId A valid session id
* @return $recipientUniversalNodeLocator Recipient as Universal Node Locator
+ * @throws InvalidArgumentException If $sessionId is not valid
*/
protected function resolveUniversalNodeLocatorBySessionId ($sessionId) {
- // Init variable
+ // Validate parameter
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
+ if (empty($sessionId)) {
+ // Throw exception
+ throw new InvalidArgumentException('Parameter "sessionId" is empty');
+ }
+
+ // Init variable
$recipientUniversalNodeLocator = 'invalid://invalid:invalid';
// And ask it for Universal Node Locator by given session id
*
* @param $sessionId Session id
* @return $nodeId Node id
+ * @throws InvalidArgumentException If $sessionId is not valid
*/
public static function resolveNodeIdBySessionId ($sessionId) {
- // Get an own instance
+ // Validate parameter
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TOOLS: sessionId=%s - CALLED!', $sessionId));
+ if (empty($sessionId)) {
+ // Throw exception
+ throw new InvalidArgumentException('Parameter "sessionId" is empty');
+ }
+
+ // Get an own instance
$selfInstance = self::getSelfInstance();
// And ask it for session id by given Universal Node Locator
// Init argument string
$argsString = '';
- // Convert arguments type into human-readable
- foreach ($traceArray['args'] as $arg) {
- $argsString .= ', ' . gettype($arg);
- } // END - foreach
- $argsString = substr($argsString, 2);
+ // Arguments given?
+ if (isset($traceArray['args'])) {
+ // Convert arguments type into human-readable
+ foreach ($traceArray['args'] as $arg) {
+ $argsString .= ', ' . gettype($arg);
+ } // END - foreach
+ $argsString = substr($argsString, 2);
+ }
// Set missing file/line
if (!isset($traceArray['file'])) $traceArray['file'] = 'unknown';