// At least 2 entries must be found
if (count($recipient) < 2) {
// Not valid
- throw new InvalidArgumentException(sprintf('packageInstance with recipientType=%s has no valid UNL=%s set.', $packageInstance->getRecipientType(), $packageInstance->getRecipientUnl()));
+ throw new InvalidArgumentException(sprintf('packageInstance with recipientType=%s has no valid UNL=%s set.',
+ $packageInstance->getRecipientType(),
+ $packageInstance->getRecipientUnl()
+ ));
}
// Now get the first part (protocol type) and make all lower-case
use Org\Shipsimu\Hub\Discovery\Recipient\BaseRecipientDiscovery;
use Org\Shipsimu\Hub\Discovery\Recipient\Node\DiscoverableNodeRecipient;
use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory;
-use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils;
use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException;
use Org\Shipsimu\Hub\Tools\HubTools;
*/
public function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance) {
// Init instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$recipientInstance = NULL;
// First try out the direct recipient (session id)
try {
- /*
- * Check if recipient is a valid UNL which indicates that the
- * recipient must be direct recipient then, otherwise a "virtual"
- * recipient.
- */
- if (NodeLocatorUtils::isValidUniversalNodeLocator($packageInstance->getRecipientUnl())) {
- // Get instance (should not break)
- $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
- } else {
- // Try to find the right class
- $recipientInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_recipient_class', strtolower($packageInstance->getRecipientType())));
- }
+ // Try to find the right class
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance->recipientType=%s', $packageInstance->getRecipientType()));
+ $recipientInstance = ObjectFactory::createObjectByConfiguredName(sprintf('%s_recipient_class',
+ $packageInstance->getRecipientType()
+ ));
// Try to solve it
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Calling recipientInstance->resolveRecipientByPackageInstance(%s, %s) ...', $packageInstance->__toString(), $this->getListInstance()->__toString()));
// Could not find class, what ever failed
$this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage()));
}
+
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-DISCOVERY: EXIT!');
}
/**
*/
public function discoverRawRecipients (DeliverablePackage $packageInstance) {
// First clear all recipients
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: packageInstance=%s - CALLED!', $packageInstance->__toString()));
$this->clearRecipients();
// Get a protocol handler back from decoded data
$socketInstance = NULL;
// Construct registry key
- $registryKey = sprintf('socket_%s_%s', $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);
* @return $isAvailable Whether this feature is available
*/
public function isFeatureAvailable () {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
-
// Testing this feature is pretty simple:
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: CALLED!', __METHOD__, __LINE__));
$isAvailable = (($this->getConfigInstance()->getConfigEntry('extension_scrypt_loaded') === TRUE) && (extension_loaded('scrypt')) && (is_callable('scrypt')));
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
-
// Return status
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isAvailable=%d - EXIT!', __METHOD__, __LINE__, intval($isAvailable)));
return $isAvailable;
}
* @return $hash Finished hash
*/
public function featureMethodGenerateHash ($data) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
-
// Make sure the feature is available
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d - CALLED!', __METHOD__, __LINE__, strlen($data)));
assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
// Call inner class
$hash = Scrypt::hashScrypt($data);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
-
// Return generated hash
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: hash=%s - EXIT!', __METHOD__, __LINE__, $hash));
return $hash;
}
* @return $isValid Whether the given hash matches a new one from given data
*/
public function featureMethodCheckHash ($data, $hash) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
-
// Make sure the feature is available
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: data()=%d,hash=%s - CALLED!', __METHOD__, __LINE__, strlen($data), $hash));
assert(FrameworkFeature::isFeatureAvailable('hubcoin_reward'));
// Determine it
$isValid = Scrypt::checkScrypt($data, $hash);
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
-
// Return status
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('[%s:%d]: isValid=%d - EXIT!', __METHOD__, __LINE__, intval($isValid)));
return $isValid;
}
*/
const NETWORK_TARGET_DHT = 'dht';
+ /**
+ * Network target (alias): 'direct'
+ */
+ const NETWORK_TARGET_DIRECT = 'direct';
+
/**
* TCP package size in bytes
*/
// Set all data
$packageInstance->setSenderAddress($this->getNodeInstance()->getSessionId());
$packageInstance->setSenderPort('0');
+ $packageInstance->setRecipientId($helperInstance->getRecipientId());
$packageInstance->setRecipientType($helperInstance->getRecipientType());
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Setting packageContent=%s ...', $packageContent));
$packageInstance->setPackageContent($packageContent);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseHubSystemHelper extends BaseHubSystem implements HubHelper {
+ /**
+ * Recipient id
+ */
+ private $recipientId = '';
+
/**
* Recipient type
*/
parent::__construct($className);
}
+ /**
+ * Setter for recipient id
+ *
+ * @return $recipientId Receipient id (mostly session id)
+ */
+ protected final function setRecipientId ($recipientId) {
+ $this->recipientId = $recipientId;
+ }
+
+ /**
+ * Getter for recipient id
+ *
+ * @return $recipientId Receipient id (mostly session id)
+ */
+ public final function getRecipientId () {
+ return $this->recipientId;
+ }
+
/**
* Setter for recipient type
*
// Import application-specific stuff
use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
use Org\Shipsimu\Hub\Node\Node;
use Org\Shipsimu\Hub\Template\Engine\Xml\Announcement\XmlAnnouncementTemplateEngine;
$helperInstance = new NodeAnnouncementMessageAnswerHelper();
// Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
+ $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+ $helperInstance->setRecipientId($messageData[XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID]);
// Set message data
$helperInstance->setMessageData($messageData);
// Import application-specific stuff
use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
use Org\Shipsimu\Hub\Node\Node;
use Org\Shipsimu\Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
$helperInstance = new NodeDhtBootstrapMessageAnswerHelper();
// Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
+ $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+ $helperInstance->setRecipientId($messageData[XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID]);
// Set message data
$helperInstance->setMessageData($messageData);
// Import application-specific stuff
use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory;
use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory;
+use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler;
use Org\Shipsimu\Hub\Helper\Node\HelpableNode;
use Org\Shipsimu\Hub\Node\Node;
use Org\Shipsimu\Hub\Template\Engine\Xml\Request\NodeList\XmlRequestNodeListTemplateEngine;
$helperInstance = new NodeRequestNodeListMessageAnswerHelper();
// Set session id of other peer as recipient
- $helperInstance->setRecipientType($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
+ $helperInstance->setRecipientType(NetworkPackageHandler::NETWORK_TARGET_DIRECT);
+ $helperInstance->setRecipientId($messageData[XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID]);
// Set message data
$helperInstance->setMessageData($messageData);