use Org\Mxchange\CoreFramework\Generic\FrameworkException;
use Org\Mxchange\CoreFramework\Registry\Registerable;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A PackageRecipient discovery class
*
*
* @param $packageInstance An instance of a DeliverablePackage class
* @return void
+ * @throws InvalidArgumentException If the package instance does not contain id and UNL
* @todo Add some validation of recipient field, e.g. an Universal Node Locator is found
* @todo Enrich both messages with recipient data
*/
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$this->clearRecipients();
+ // Is the UNL empty but id given?
+ if ($packageInstance->getRecipientUnl() == '' && $packageInstance->getRecipientId() == '') {
+ // Uh, both is empty!
+ throw new InvalidArgumentException('packageInstance has both recipientUnl and recipientId empty.');
+ } elseif ($packageInstance->getRecipientUnl() == '' && $packageInstance->getRecipientId() != '') {
+ // Id is set, this might be resolved to an UNL
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Resolving recipientId=%s to UNL ...', $packageInstance->getRecipientId()));
+ $recipientUnl = HubTools::resolveSessionId($packageInstance->getRecipientId());
+
+ // And set it in package instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: recipientUnl=%s', $recipientUnl));
+ $packageInstance->setRecipientUnl($recipientUnl);
+ }
+
// Get a protocol handler back from decoded data
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)));
$handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance);
// Is the 'recipient' field same as this peer's IP?
use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
use Org\Mxchange\CoreFramework\Lists\Listable;
+// Import SPL stuff
+use \InvalidArgumentException;
+
/**
* A DHT recipient
*
// Debug message
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString());
- // Get recipient UNL
- $recipientUnl = $packageInstance->getRecipientUnl();
-
- // Make sure the recipient is valid
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipientUnl=' . $recipientUnl);
- assert($recipientUnl == NetworkPackageHandler::RECIPIENT_TYPE_DHT);
+ // Make sure the recipient type is valid
+ if ($packageInstance->getRecipientType() != NetworkPackageHandler::RECIPIENT_TYPE_DHT) {
+ // Not expected here
+ throw new InvalidArgumentException(sprintf('recipientType=%s is unexpected.', $packageInstance->getRecipientType()));
+ }
// Get recipient discovery instance
$discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class');