// Import application-specific stuff
use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper;
use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory;
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
use Org\Shipsimu\Hub\Node\BaseHubNode;
// Make sure the external address is set and not invalid
// @TODO Bad check on UNL, better use a proper validator
$externalUnl = $locatorInstance->getExternalUnl();
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl);
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $externalUnl));
assert($externalUnl != 'invalid');
// Add Universal Node Locator/node id as criteria
$isRegistered = $resultInstance->valid();
// Return result
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: isRegistered=%d - EXIT!', intval($isRegistered)));
return $isRegistered;
}
* Finds a node locally by given session id
*
* @param $sessionId Session id to lookup
- * @return $nodeData Node data array
+ * @return $resultInstance An instance of a SearchableResult class
*/
public function findNodeLocalBySessionId ($sessionId) {
// Get search criteria
$resultInstance = $this->doSelectByCriteria($searchInstance);
// Return result instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: resultInstance->valid()=' . intval($resultInstance->valid()) . ' - EXIT!');
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid())));
+ return $resultInstance;
+ }
+
+ /**
+ * Finds a node locally by given UNL instance
+ *
+ * @param $locatorInstance An instance of a LocateableNode class
+ * @return $resultInstance An instance of a SearchableResult class
+ */
+ public function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance) {
+ // Get search criteria
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: locatorInstance=%s - CALLED!', $locatorInstance->__toString()));
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Search for session id and limit it to one entry
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $locatorInstance->getExternalUnl()));
+ $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $locatorInstance->getExternalUnl());
+ $searchInstance->setLimit(1);
+
+ // Query database and get a result instance back
+ $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+ // Return result instance
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid())));
return $resultInstance;
}
$nodeData = array();
// Query database
- $resultInstance = $this->getWrapperInstance()->findNodeLocalByUnlInstance($locatorInstance);
+ $resultInstance = $this->getWrapperInstance()->findNodeLocalByLocatorInstance($locatorInstance);
// Make sure the result instance is valid
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: resultInstance=%s', __METHOD__, __LINE__, print_r($resultInstance, TRUE)));
assert($resultInstance instanceof SearchableResult);
+ // Is the next entry valid?
+ if (($resultInstance->valid()) && ($resultInstance->next())) {
+ /*
+ * Then load the first entry (more entries are being ignored and
+ * should not happen).
+ */
+ $nodeData = $resultInstance->current();
+ } // END - if
+
// Return node data
- /* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
+ //* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE)));
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData)));
return $nodeData;
}
/* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl(%d)=%s,recipientId(%d)=%s', strlen($packageInstance->getRecipientUnl()), $packageInstance->getRecipientUnl(), strlen($packageInstance->getRecipientId()), $packageInstance->getRecipientId()));
if ($packageInstance->getRecipientUnl() != '' && $packageInstance->getRecipientId() == '') {
// Need to resolve UNL -> session id ("recipient id"), so prepare UNL instance
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl=%s is being solved into session id ...', $packageInstance->getRecipientUnl()));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: recipientUnl=%s is being solved into a session id ...', $packageInstance->getRecipientUnl()));
$locatorInstance = UniversalNodeLocatorFactory::createUnlInstanceFromString($packageInstance->getRecipientUnl());
// Get session id and set it back
<?php
// Import framework stuff
use Org\Mxchange\CoreFramework\Assertion\AssertionException;
+use Org\Mxchange\CoreFramework\Error\FatalErrorException;
use Org\Mxchange\CoreFramework\Generic\FrameworkException;
use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem;
} // END - function
// Set error handler
-set_error_handler('hub_error_handler');
+//set_error_handler('hub_error_handler');
// Set the new handler
set_exception_handler('hub_exception_handler');
namespace Org\Shipsimu\Hub\Database\Frontend\Node\Dht;
// Import application-specific stuff
+use Org\Shipsimu\Hub\Locator\Node\LocateableNode;
use Org\Shipsimu\Hub\Network\Package\DeliverablePackage;
// Import framework stuff
* Finds a node locally by given session id
*
* @param $sessionId Session id to lookup
- * @return $nodeData Node data array
+ * @return $resultInstance An instance of a SearchableResult class
*/
function findNodeLocalBySessionId ($sessionId);
+ /**
+ * Finds a node locally by given UNL instance
+ *
+ * @param $locatorInstance An instance of a LocateableNode class
+ * @return $resultInstance An instance of a SearchableResult class
+ */
+ function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance);
+
/**
* Registeres a node by given message data.
*
-Subproject commit 22758e48b312f672167569bbe674476fc19769b2
+Subproject commit b2ea555ca8062721bba3bc565770a3da27577ced