From: Roland Häder Date: Mon, 26 Oct 2020 13:23:10 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f53307783fb677921320d905e5fc556a7eeb6a38;p=hub.git Continued: - implemented PackageData::getAllAsArray() with PHP's reflection classes - added more debug code - fixed various bugs - updated core framework Signed-off-by: Roland Häder --- diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index fed990f13..bad9de069 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -12,7 +12,7 @@ use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\BaseListener; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; -use Org\Shipsimu\Hub\Network\Package\NetworkPackageHandler; +use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\ObjectFactory; @@ -119,14 +119,14 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita */ public static final function createSocketContainer ($socketResource, $socketProtocol, DeliverablePackage $packageInstance) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource[%s]=%s,socketProtocol=%s,packageInstance[]=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol, gettype($packageInstance))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketResource[%s]=%s,socketProtocol=%s,packageInstance[]=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol, gettype($packageInstance))); //* DEBUG-PRINT: */ printf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE)); // Get a new instance $socketInstance = new SocketContainer(); // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-CONTAINER: socketResource=%s,socketProtocol=%s', $socketResource, $socketProtocol)); // Set protocol $socketInstance->setSocketProtocol($socketProtocol); @@ -161,7 +161,6 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $packageDataInstance An instance of a DeliverablePackage class */ public function getPackageDataInstance () { - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: Getting packageDataInstance=%s', strtoupper($this->getSocketProtocol()), $this->packageDataInstance)); return $this->packageDataInstance; } @@ -893,8 +892,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita // Valid? if ($result === TRUE) { // Set both - $this->getPackageDataInstance()->setAddress($peerAddress); - $this->getPackageDataInstance()->setPort($peerPort); + $this->setPeerAddress($peerAddress); + $this->setPeerPort($peerPort); } // END - if // Trace message diff --git a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php index 752efd55b..ba1a180d7 100644 --- a/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\Dht; // Import application-specific stuff use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Node\BaseHubNode; @@ -122,10 +121,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp * @return $searchInstance An instance of a SearchCriteria class */ private function prepareSearchInstance (array $nodeData) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); - // Assert on array elements + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); // Get instance @@ -135,10 +132,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp $searchInstance->addCriteria(self::DB_COLUMN_NODE_ID, $nodeData[self::DB_COLUMN_NODE_ID]); $searchInstance->setLimit(1); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); - // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); return $searchInstance; } @@ -160,7 +155,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp */ private function prepareLocalDataSetInstance () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); // Get node/request instances $nodeInstance = NodeObjectFactory::createNodeInstance(); @@ -180,27 +175,29 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp // Make sure both is valid // @TODO Bad check on UNL, better use a proper validator + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl); assert($externalUnl !== 'invalid'); // Get an array of all accepted object types $objectList = $nodeInstance->getListFromAcceptedObjectTypes(); // Make sure this is an array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: objectList()=' . count($objectList)); assert(is_array($objectList)); // Add public node data $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_MODE , $requestInstance->getRequestElement('mode')); $dataSetInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $externalUnl); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeInstance->nodeId=' . $nodeInstance->getNodeId()); $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $nodeInstance->getNodeId()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeInstance->sessionId=' . $nodeInstance->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $nodeInstance->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $nodeInstance->getNodePrivateKeyHash()); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($nodeInstance->isAcceptingDhtBootstrap())); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); - // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: dataSetInstance=' . $dataSetInstance->__toString() . ' - EXIT!'); return $dataSetInstance; } @@ -211,10 +208,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp * @return $isRegistered Whether *this* node is registered in the DHT */ public function isLocalNodeRegistered () { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); - // Get a search criteria instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Get node instance @@ -226,6 +221,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp // Make sure the external address is set and not invalid // @TODO Bad check on UNL, better use a proper validator $externalUnl = $unlInstance->getExternalUnl(); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: externalUnl=' . $externalUnl); assert($externalUnl != 'invalid'); // Add Universal Node Locator/node id as criteria @@ -240,10 +236,8 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp // Cache result of if there is an entry, valid() will tell us if an entry is there $isRegistered = $resultInstance->valid(); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!'); - // Return result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!'); return $isRegistered; } @@ -254,7 +248,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp */ public function registerLocalNode () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); // Assert to make sure this method is called with no record in DB (the actual backend of the DHT) assert(!$this->isLocalNodeRegistered()); @@ -263,10 +257,11 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper imp $dataSetInstance = $this->prepareLocalDataSetInstance(); // "Insert" this dataset instance completely into the database + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Calling this->queryInsertDataSet(' . $dataSetInstance->__toString() . ') ...'); $this->queryInsertDataSet($dataSetInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); } /** diff --git a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php index a5c7c918b..1a9c356ff 100644 --- a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseWrapper.php @@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Database\Frontend\Node\PeerState; // Import application-specific sutff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Database\Frontend\BaseHubDatabaseWrapper; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\LookupTable\Lookupable; diff --git a/application/hub/classes/decoder/package/class_PackageDecoder.php b/application/hub/classes/decoder/package/class_PackageDecoder.php index 01f767f64..22123edc3 100644 --- a/application/hub/classes/decoder/package/class_PackageDecoder.php +++ b/application/hub/classes/decoder/package/class_PackageDecoder.php @@ -154,7 +154,7 @@ class PackageDecoder extends BaseDecoder implements Decodeable, Registerable { $packageInstance = $this->getHandlerInstance()->getStackInstance()->popNamed(self::STACKER_NAME_DECODED_PACKAGE); // Handle it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: decodedData(' . count($packageInstance) . ')=' . print_r($packageInstance, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DECODER: packageInstance=' . $packageInstance->__toString() . ')=' . print_r($packageInstance, TRUE)); $this->getPackageHandlerInstance()->handleRawData($packageInstance); } diff --git a/application/hub/classes/dht/class_BaseDht.php b/application/hub/classes/dht/class_BaseDht.php index c1d79621e..dc6ba5a00 100644 --- a/application/hub/classes/dht/class_BaseDht.php +++ b/application/hub/classes/dht/class_BaseDht.php @@ -245,6 +245,7 @@ abstract class BaseDht extends BaseHubSystem implements Distributable { $this->publishHelperInstance->getTemplateInstance()->assignMultipleVariables($entry); // "Publish" the descriptor by sending it to the bootstrap/list nodes + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT: Calling this->publishHelperInstance->sendPackage(' . $this->__toString() . ') ...'); $this->publishHelperInstance->sendPackage($this); } diff --git a/application/hub/classes/dht/node/class_NodeDhtFacade.php b/application/hub/classes/dht/node/class_NodeDhtFacade.php index cb66fa372..9d042119b 100644 --- a/application/hub/classes/dht/node/class_NodeDhtFacade.php +++ b/application/hub/classes/dht/node/class_NodeDhtFacade.php @@ -78,20 +78,26 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { */ protected function insertDataIntoDht (array $dhtData) { // Check if there is already an entry for given node_id + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: dhtData()=%d - CALLED!', count($dhtData))); if ($this->getWrapperInstance()->isNodeRegistered($dhtData)) { /* * Update existing record. Please note that this step is not secure * (e.g. DHT poisoning) it would be good to implement some checks if * the both node owner trust each other (see sub-project 'DSHT'). */ + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Updating existing node data ...'); $this->getWrapperInstance()->updateNode($dhtData); } else { /* * Inserts given node data into the DHT. As above, this step does * currently not perform any security checks. */ + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Registering node data ...'); $this->getWrapperInstance()->registerNode($dhtData); } + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!'); } /** @@ -101,16 +107,22 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { */ public function initDht () { // Is the local node registered? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: CALLED!'); if ($this->getWrapperInstance()->isLocalNodeRegistered()) { // Then only update session id + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Updating local node data ...'); $this->getWrapperInstance()->updateLocalNode(); } else { // No, so register it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: Registering local node data ...'); $this->getWrapperInstance()->registerLocalNode(); } // Change state $this->getStateInstance()->dhtHasInitialized(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!'); } /** @@ -131,10 +143,14 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { $helperInstance->getTemplateInstance()->compileConfigInVariables(); // "Publish" the descriptor by sending it to the bootstrap/list nodes + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $this->__toString())); $helperInstance->sendPackage($this); // Change state $this->getStateInstance()->dhtIsBooting(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: EXIT!'); } /** @@ -145,7 +161,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { */ public function findNodeLocalBySessionId ($sessionId) { // Default is empty data array - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FACADE: sessionid=%s - CALLED!', $sessionId)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: sessionId=%s - CALLED!', $sessionId)); $nodeData = array(); /* @@ -168,7 +184,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Return node data //* DEBUG-DIE: */ die(sprintf('[%s:%d]: nodeData=%s', __METHOD__, __LINE__, print_r($nodeData, TRUE))); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeData()=%d - EXIT!', count($nodeData))); return $nodeData; } @@ -191,18 +207,18 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE) . ',handlerInstance=' . $handlerInstance->__toString() . ',forceUpdate=' . intval($forceUpdate) . ',count(getSearchData())=' . count($handlerInstance->getSearchData())); // Search for the node's session id and external address/hostname + TCP/UDP listen port foreach ($handlerInstance->getSearchData() as $key) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',key=' . $key); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',key=' . $key); // Is it there? assert(isset($messageData[$key])); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData[' . $key . ']=' . $messageData[$key]); // Add criteria $searchInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]); @@ -249,10 +265,11 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { */ public function queryLocalNodeListExceptByMessageData (array $messageData, HandleableDataSet $handlerInstance, $excludeKey, $andKey, $separator) { // Make sure both keys are there + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: messageData()=%d,handlerInstance=%s,excludeKey=%s,andKey=%s,separator=%s - CALLED!', count($messageData), $handlerInstance->__toString(), $excludeKey, $andKey, $separator)); assert((isset($messageData[$excludeKey])) && (isset($messageData[$andKey]))); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: state=' . $this->getPrintableState() . ',messageData=' . print_r($messageData, TRUE)); // Get a search criteria class $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -260,7 +277,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // Add all keys foreach (explode($separator, $messageData[$andKey]) as $criteria) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: andKey=' . $andKey . ',criteria=' . $criteria); // Add it and leave any 'my-' prefix out $searchInstance->addChoiceCriteria(str_replace('my-', '', $andKey), $criteria); @@ -290,7 +307,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { assert(count($current) > 0); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: current(' . count($current) . ')[' . gettype($current) . ']=' . print_r($current, TRUE)); /* * Remove some keys as they should not be published. @@ -305,6 +322,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { $handlerInstance->setLastException($this->getWrapperInstance()->getLastException()); // Return node list (array) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: nodeList()=%d - EXIT!', count($nodeList))); return $nodeList; } @@ -320,7 +338,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { // If no node is in the list (array), skip the rest of this method if (count($nodeList) == 0) { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: No node record has been returned.'); + self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: No node record has been returned.'); // Abort here return; @@ -359,7 +377,7 @@ class NodeDhtFacade extends BaseDht implements DistributableNode, Registerable { while ($resultInstance->next()) { // Get current entry $current = $resultInstance->current(); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FACADE: current=' . print_r($current, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-DHT-FACADE: current=' . print_r($current, TRUE)); // Add instance to recipient list array_push($recipients, $current); diff --git a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php index ed01b2369..d4288d02c 100644 --- a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php +++ b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php @@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Discovery\Protocol; // Import application-specific stuff use Org\Shipsimu\Hub\Discovery\Node\BaseNodeDiscovery; use Org\Shipsimu\Hub\Factory\Tag\Package\PackageTagsFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; // Import framework stuff diff --git a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php index 29edd20f1..164792757 100644 --- a/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php +++ b/application/hub/classes/discovery/recipient/package/class_PackageRecipientDiscovery.php @@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Discovery\Network\Recipient; 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\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Node\Data\InvalidSessionIdException; @@ -69,7 +68,7 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov * @param $packageInstance An instance of a DeliverablePackage class array * @return void */ - public function discoverRecipients (DeliverablePackage $packageInstance) { + public function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance) { // Init instance $recipientInstance = NULL; @@ -89,7 +88,8 @@ class PackageRecipientDiscovery extends BaseRecipientDiscovery implements Discov } // Try to solve it - $recipientInstance->resolveRecipient($packageInstance->getRecipientUnl(), $this->getListInstance(), $packageInstance); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('RECIPIENT-DISCOVERY: Calling recipientInstance->resolveRecipientByPackageInstance(%s, %s) ...', $packageInstance->__toString(), $this->getListInstance()->__toString())); + $recipientInstance->resolveRecipientByPackageInstance($packageInstance, $this->getListInstance()); } catch (FrameworkException $e) { // Could not find class, what ever failed $this->debugInstance(sprintf('[%s:%d]: Exception: %s,message=%s', __METHOD__, __LINE__, $e->__toString(), $e->getMessage())); diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index 9c8e0d7ac..7881fa9a6 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -10,7 +10,6 @@ use Org\Shipsimu\Hub\Discovery\Socket\DiscoverableSocket; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; @@ -83,7 +82,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera */ public function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: protocolInstance=' . $protocolInstance->__toString() . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: protocolInstance=' . $protocolInstance->__toString() . ',packageInstance=' . $packageInstance->__toString() . ' - CALLED!'); /* * Get the listener pool instance, we need to lookup the matching @@ -130,10 +129,8 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Listener is NOT accepting package data.'); } // END - foreach - // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance->__toString()); - // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: listenerInstance=' . $listenerInstance->__toString() . ' - EXIT!'); return $listenerInstance; } diff --git a/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php b/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php index 13398f47b..34cb97932 100644 --- a/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php +++ b/application/hub/classes/factories/handler/class_ProtocolHandlerFactory.php @@ -87,12 +87,12 @@ class ProtocolHandlerFactory extends ObjectFactory { /** * Creates an instance of a protocol handler from given (raw) package data * - * @param $packageData An array with raw package data + * @param $packageInstance An array with raw package data * @return $handlerInstance A protocol handler instance */ public static final function createProtocolHandlerFromPackageInstance (DeliverablePackage $packageInstance) { // "Discover" the protocol type - $protocolType = ProtocolDiscovery::discoverProtocolByPackageInstance($packageData); + $protocolType = ProtocolDiscovery::discoverProtocolByPackageInstance($packageInstance); // Call super factory method return self::createProtocolHandlerByType($protocolType); diff --git a/application/hub/classes/factories/package/data/class_PackageDataFactory.php b/application/hub/classes/factories/package/data/class_PackageDataFactory.php index 9fbbb64ff..7d6dceec9 100644 --- a/application/hub/classes/factories/package/data/class_PackageDataFactory.php +++ b/application/hub/classes/factories/package/data/class_PackageDataFactory.php @@ -1,69 +1,2 @@ - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2018 Hub Developer Team - * @license GNU GPL 3.0 or any newer version - * @link http://www.shipsimu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class PackageDataFactory extends ObjectFactory { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Returns a singleton DeliverablePackage instance. If an instance is found - * in the registry it will be returned, else a new instance is created and - * stored in the same registry entry. - * - * @return $packageInstance An instance of a DeliverablePackage class - */ - public static final function createPackageDataInstance () { - // Do we have an instance in the registry? - if (GenericRegistry::getRegistry()->instanceExists('package_data')) { - // Then use this instance - $packageInstance = GenericRegistry::getRegistry()->getInstance('package_data'); - } else { - /* - * Now prepare the network package for delivery so only need to do this - * once just before the "big announcement loop". - */ - $packageInstance = self::createObjectByConfiguredName('package_data_class'); - - // Set the instance in registry for further use - GenericRegistry::getRegistry()->addInstance('package_data', $packageInstance); - } - - // Return the instance - return $packageInstance; - } - -} +// @DEPRECATED diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index 9ddf52870..b9cabf147 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -4,8 +4,6 @@ namespace Org\Shipsimu\Hub\Factory\Socket; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; -use Org\Shipsimu\Hub\Factory\Network\PackageDataFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Listener\BaseListener; use Org\Shipsimu\Hub\Listener\Listenable; @@ -125,7 +123,7 @@ class SocketFactory extends ObjectFactory { assert(!empty($socketFile)); // Init package instance - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Init main socket $socketResource = socket_create(AF_UNIX, SOCK_STREAM, 0); @@ -283,7 +281,7 @@ class SocketFactory extends ObjectFactory { $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // Init fake "package" instance, the SocketContainer class requires this - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Create socket instance $socketInstance = self::createObjectByConfiguredName('socket_container_class', array( @@ -362,7 +360,7 @@ class SocketFactory extends ObjectFactory { $socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); // Init fake package instance - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Create socket instance $socketInstance = self::createObjectByConfiguredName('socket_container_class', array( @@ -488,17 +486,21 @@ class SocketFactory extends ObjectFactory { * @return $socketInstance An instance of a StorableSocket class */ public static final function createIncomingSocketInstance ($socketResource, $socketProtocol) { - // Create socket instance + // Create package instance /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol)); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); + + // Create socket instance $socketInstance = self::createObjectByConfiguredName('socket_container_class', array( $socketResource, $socketProtocol, + $packageInstance, )); // Set all socket data $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_INCOMING); - $socketInstance->setSocketAddress('invalid'); - $socketInstance->setSocketPort('0'); + $socketInstance->setPeerAddress('invalid'); + $socketInstance->setPeerPort('0'); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { diff --git a/application/hub/classes/factories/states/peer/class_PeerStateFactory.php b/application/hub/classes/factories/states/peer/class_PeerStateFactory.php index 0f2f95d37..f2df80ef1 100644 --- a/application/hub/classes/factories/states/peer/class_PeerStateFactory.php +++ b/application/hub/classes/factories/states/peer/class_PeerStateFactory.php @@ -68,11 +68,11 @@ class PeerStateFactory extends ObjectFactory { /** * Creates a peer state instance based on errorCode if no entry is found in the lookup table - * for the peer given in $packageData 'sender' element or it changes the state if it differs + * for the peer given in $packageInstance 'sender' element or it changes the state if it differs * from current state. * * @param $helperInstance An instance of a ConnectionHelper class - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @param $socketInstance A valid socket resource * @param $errorCode The last error code * @return $stateInstance A Stateable class instance @@ -97,12 +97,12 @@ class PeerStateFactory extends ObjectFactory { } // Do we have an entry? - if ($tableInstance->isSenderNewPeer($packageData)) { + if ($tableInstance->isSenderNewPeer($packageInstance)) { // Debug output /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: errorCode=' . $errorCode); // Register the new peer with its session id - $tableInstance->registerPeerByPackageInstance($packageData, $socketInstance); + $tableInstance->registerPeerByPackageInstance($packageInstance, $socketInstance); /* * It is a new peer so create the state instance based on error @@ -111,8 +111,8 @@ class PeerStateFactory extends ObjectFactory { $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class'); // And register it with the lookup table - $tableInstance->registerPeerState($stateInstance, $packageData); - } elseif ($tableInstance->isSamePeerState($helperInstance, $packageData)) { + $tableInstance->registerPeerState($stateInstance, $packageInstance); + } elseif ($tableInstance->isSamePeerState($helperInstance, $packageInstance)) { // Debug output /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-FACTORY: Peer state unchanged, re-generating old state ...'); @@ -132,7 +132,7 @@ class PeerStateFactory extends ObjectFactory { $stateInstance = self::createObjectByConfiguredName('peer_' . $errorCode . '_state_class'); // The peer's state has changed, update database now - $tableInstance->registerPeerState($stateInstance, $packageData); + $tableInstance->registerPeerState($stateInstance, $packageInstance); } // Debug message diff --git a/application/hub/classes/handler/data/class_BaseDataHandler.php b/application/hub/classes/handler/data/class_BaseDataHandler.php index 59a939740..df149e5fc 100644 --- a/application/hub/classes/handler/data/class_BaseDataHandler.php +++ b/application/hub/classes/handler/data/class_BaseDataHandler.php @@ -130,6 +130,7 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { $helperInstance->getTemplateInstance()->compileConfigInVariables(); // Deliver the package + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString())); $helperInstance->sendPackage($nodeInstance); /* @@ -171,6 +172,7 @@ abstract class BaseDataHandler extends BaseHubHandler implements HubInterface { $helperInstance->getTemplateInstance()->compileConfigInVariables(); // Deliver the package + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-DHT-FACADE: Calling helperInstance->sendPackage(%s) ...', $nodeInstance->__toString())); $helperInstance->sendPackage($nodeInstance); /* diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 621c0423d..ad5726a22 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -12,7 +12,6 @@ use Org\Shipsimu\Hub\Factory\Discovery\Socket\SocketDiscoveryFactory; use Org\Shipsimu\Hub\Factory\FilterChain\Package\PackageFilterChainFactory; use Org\Shipsimu\Hub\Factory\Handler\Message\MessageTypeHandlerFactory; use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory; -use Org\Shipsimu\Hub\Factory\Network\PackageDataFactory; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\BaseHubHandler; @@ -554,7 +553,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $discoveryInstance = PackageDiscoveryFactory::createPackageDiscoveryInstance(); // Discover all recipients, this may throw an exception - $discoveryInstance->discoverRecipients($packageInstance); + $discoveryInstance->discoverRecipientsByPackageInstance($packageInstance); // Now get an iterator $iteratorInstance = $discoveryInstance->getIterator(); @@ -722,7 +721,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ private function generatePackageHash ($content, $senderId) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!'); // Assert on variables assert(!empty($content)); @@ -731,12 +730,12 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Is the feature enabled? if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { // Feature is not enabled - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Feature "hubcoin_reward" not available, not generating package hash. Returning NULL ...'); return NULL; } // END - if // Fake package instance - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Set all fields $packageInstance->setSenderId($senderId); @@ -744,7 +743,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setSenderPrivateKeyHash($this->getNodeInstance()->getNodePrivateKeyHash()); // Hash content and sender id together, use scrypt - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderId=' . $senderId . ',content()=' . strlen($content)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: senderId=' . $senderId . ',content()=' . strlen($content)); $hash = FrameworkFeature::callFeature('hubcoin_reward', 'generateHash', array( sprintf('%s:%s:%s', $senderId, @@ -753,10 +752,8 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei ) )); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: hash=' . $hash . ' - EXIT!'); - // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: hash=' . $hash . ' - EXIT!'); return $hash; } @@ -805,11 +802,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function enqueueRawDataFromTemplate (HubHelper $helperInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: helperInstance=' . $helperInstance->__toString() . ' - CALLED!'); // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('content(' . strlen($content) . ')=' . $content); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('content(' . strlen($content) . ')=' . $content); // ... and compress it $compressed = $this->getCompressorInstance()->compressStream($content); @@ -833,28 +830,29 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei ); // Make sure required data is there - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: Enqueueing package for recipientType=' . $helperInstance->getRecipientType() . ' ...'); assert(!empty($content)); assert($this->getNodeInstance()->getSessionId() != ''); // Init package instance - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Set all data $packageInstance->setSenderAddress($this->getNodeInstance()->getSessionId()); $packageInstance->setSenderPort('0'); $packageInstance->setRecipientType($helperInstance->getRecipientType()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Setting packageContent=%s ...', $packageContent)); $packageInstance->setPackageContent($packageContent); $packageInstance->setStatus(self::PACKAGE_STATUS_NEW); $packageInstance->setContentHash($this->generatePackageHash($content, $this->getNodeInstance()->getSessionId())); $packageInstance->setSenderPrivateKeyHash($this->getNodeInstance()->getNodePrivateKeyHash()); // Now prepare the temporary array and push it on the 'undeclared' stack - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Pushing packageInstance=%s to stack %s ...', $packageInstance->__toString(), self::STACKER_NAME_UNDECLARED)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: Pushing packageInstance=%s to stack %s ...', $packageInstance->__toString(), self::STACKER_NAME_UNDECLARED)); $this->getStackInstance()->pushNamed(self::STACKER_NAME_UNDECLARED, $packageInstance); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -936,7 +934,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function declareEnqueuedPackage () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: CALLED!'); // Make sure this method isn't working if there is no package enqueued if (!$this->isPackageEnqueued()) { @@ -952,10 +950,11 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_UNDECLARED); // Declare the raw package data for delivery + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance->recipientType=%s is undeclared, declaring now ...', $packageInstance->getRecipientType())); $this->declareRawPackageData($packageInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE-HANDLER: EXIT!'); } /** @@ -1376,10 +1375,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Assert on count (should be always 3) assert(count($decodedArray) == self::DECODED_DATA_ARRAY_SIZE); - /* PRINTR-DEBUG: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE))); + /* PRINTR-DIE: */ die(sprintf('[%s:%d] decodedArray=%s', __METHOD__, __LINE__, print_r($decodedArray, TRUE))); // Create package instance - $packageInstance = PackageDataFactory::createPackageDataInstance(); + $packageInstance = ObjectFactory::createObjectByConfiguredName('package_data_class'); // Set all data $packageInstance->setSenderAddress($decodedArray[self::INDEX_PACKAGE_SENDER_ADDRESS]); @@ -1391,7 +1390,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setSenderPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]); // And return it - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - EXIT!', $packageInstance->__toString())); return $packageInstance; } diff --git a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php index f289c729d..7eaf4863f 100644 --- a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php +++ b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php @@ -4,7 +4,6 @@ namespace Org\Shipsimu\Hub\Handler\Protocol\Network\IpV4; // Import application-specific stuff use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Handler\Protocol\BaseProtocolHandler; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Locator\Node\Tools\NodeLocatorUtils; diff --git a/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php b/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php index 576e85c81..f3422631f 100644 --- a/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php +++ b/application/hub/classes/handler/raw_data/class_BaseRawDataHandler.php @@ -7,7 +7,6 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Handler\BaseHubHandler; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; // Import framework stuff diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 46be16fc9..ef78abe86 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -177,7 +177,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit * 1) Request a chunk from set fragmenter instance * 2) Finally return the chunk (array) to the caller * - * @param $packageData An instance of a DeliverablePackage class array + * @param $packageInstance An instance of a DeliverablePackage class array * @return $chunkData Raw data chunk */ private function getRawDataFromPackageArray (DeliverablePackage $packageInstance) { @@ -239,18 +239,18 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit /** * Sends An instance of a DeliverablePackage class to the recipient * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return void */ public function sendRawPackageData (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageData()=%d - CALLED!', count($packageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // The helper's state must be 'connected' $this->getStateInstance()->validatePeerStateConnected(); // Implode the package data array and fragement the resulting string, returns the final hash - $finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageData, $this); + $finalHash = $this->getFragmenterInstance()->fragmentPackageArray($packageInstance, $this); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: finalHash[%s]=%s', gettype($finalHash), $finalHash)); @@ -277,7 +277,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - BEFORE!', strlen($dataStream))); // Convert the package data array to a raw data stream - $dataStream = $this->getRawDataFromPackageArray($packageData); + $dataStream = $this->getRawDataFromPackageArray($packageInstance); // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-HELPER: dataStream()=%d - AFTER!', strlen($dataStream))); diff --git a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php index 90edd763d..0f8931f3f 100644 --- a/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/tcp/class_TcpConnectionHelper.php @@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Helper\Connection\Network\IpV4\Tcp; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; use Org\Shipsimu\Hub\Helper\Connection\Network\IpV4\BaseIpV4ConnectionHelper; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; @@ -56,7 +55,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection * recipient in package data. After you called this method you still need to * connect to the other node. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $socketInstance An instance of a StorableSocket class */ public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) { @@ -64,7 +63,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection $helperInstance = new TcpConnectionHelper(); // Construct container class, this won't be reached if an exception is thrown - $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageData); + $socketInstance = SocketFactory::createTcpOutgoingSocketFromPackageInstance($packageInstance); // Set the resource $helperInstance->setSocketInstance($socketInstance); @@ -76,7 +75,7 @@ class TcpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection // Try to solve the recipient try { // Get protocol handler back from package data - $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageData); + $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance); // Get UNL instance $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance(); diff --git a/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php index c541b4744..39ac62817 100644 --- a/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/udp/class_UdpConnectionHelper.php @@ -50,11 +50,11 @@ class UdpConnectionHelper extends BaseIpV4ConnectionHelper implements Connection * recipient in package data. After you called this method you still need to * connect to the other node. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $socketInstance An instance of a StorableSocket class */ public static function createConnectionFromPackageInstance (DeliverablePackage $packageInstance) { - $this->debugBackTrace(': Unfinished method, packageData[]=' . count($packageData)); + $this->debugBackTrace('Unfinished method, packageInstance=' . print_r($packageInstance, TRUE)); } /** diff --git a/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php b/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php index 96fe37025..65b978c26 100644 --- a/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php +++ b/application/hub/classes/helper/node/connection/class_NodeSelfConnectHelper.php @@ -74,10 +74,8 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { * @return void */ public function loadDescriptorXml (Node $nodeInstance) { - // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HELPER: Attempting self-connect...'); - // Get a XML template instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: nodeInstance=' . $nodeInstance->__toString() . ' - CALLED!'); $templateInstance = XmlTemplateEngineFactory::createXmlTemplateEngineInstance('node_self_connect_template_class'); // Set it for later use @@ -88,6 +86,9 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { // Render the XML content $templateInstance->renderXmlContent(); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!'); } /** @@ -98,6 +99,7 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { */ public function sendPackage (Node $nodeInstance) { // Sanity check: Is the node in the approx. state? (active) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: nodeInstance=' . $nodeInstance->__toString() . ' - CALLED!'); $nodeInstance->getStateInstance()->validateNodeStateIsActiveOrAnnouncing(); // Compile the template, this inserts the loaded node data into the gaps. @@ -107,7 +109,11 @@ class NodeSelfConnectHelper extends BaseNodeHelper implements HelpableNode { $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance(); // Next, feed the content in. The network package class is a pipe-through class. + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: Calling packageInstance->enqueueRawDataFromTemplate(' . $this->__toString() . ') ...'); $packageInstance->enqueueRawDataFromTemplate($this); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-SELF-CONNECT-HELPER: EXIT!'); } } diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index a57e8c3e4..2adc9de93 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -403,11 +403,9 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { //* DEBUG-DIE: */ $infoInstance->debugInstance(); // Set all required data - $socketInstance->setSenderAddres($peerAddress . $peerSuffix); + $socketInstance->setSenderAddress($peerAddress . $peerSuffix); $socketInstance->setSenderPort($peerPort); $socketInstance->setRecipientId($nodeInstance->getSessionId()); - $socketInstance->setStatus(NetworkPackageHandler::PACKAGE_STATUS_FAKED); - die(__METHOD__.': UNFINISHED!'); // Register the socket with the registry and with the faked array $this->getRegistryInstance()->registerSocketInstance($infoInstance, $socketInstance); diff --git a/application/hub/classes/listener/socket/class_SocketFileListener.php b/application/hub/classes/listener/socket/class_SocketFileListener.php index a72c6a7b5..e73e8b54c 100644 --- a/application/hub/classes/listener/socket/class_SocketFileListener.php +++ b/application/hub/classes/listener/socket/class_SocketFileListener.php @@ -120,15 +120,15 @@ class SocketFileListener extends BaseListener implements Listenable { /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageData()=%d - CALLED!', count($packageData))); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Call parent method - if (!parent::ifListenerAcceptsPackageData($packageData)) { + if (!parent::ifListenerAcceptsPackageData($packageInstance)) { // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.'); @@ -137,13 +137,13 @@ class SocketFileListener extends BaseListener implements Listenable { } // END - if // Debugging - /* DEBUG-DIE: */ die(__METHOD__.':packageData='.print_r($packageData, TRUE)); + /* DEBUG-DIE: */ die(__METHOD__.':packageInstance='.print_r($packageInstance, TRUE)); // Get a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); // So is the package accepted with this listener? - $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: accepts=%d - EXIT!', $accepts)); diff --git a/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php b/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php index 6da509810..119bcfa46 100644 --- a/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php +++ b/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php @@ -93,7 +93,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { @@ -101,7 +101,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Calling this->getListenerInstance()->ifListenerAcceptsPackageData() ...'); // Call inner method, no decoration is wanted in this method - return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageData); + return $this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance); } } diff --git a/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php b/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php index a1b3ad23b..532498afb 100644 --- a/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php +++ b/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php @@ -93,15 +93,15 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Invoke decorated listener's method - if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) { + if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.'); @@ -110,13 +110,13 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen } // END - if // Debugging - /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE)); // Get a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); // So is the package accepted with this listener? - $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: accepts=%d - EXIT!', $accepts)); diff --git a/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php b/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php index 7f83f22d1..66dab9fad 100644 --- a/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php +++ b/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php @@ -93,15 +93,15 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageData()=%d - CALLED!', count($packageData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // // Invoke decorated listener's method - if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) { + if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.'); @@ -110,13 +110,13 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl } // END - if // Debugging - //* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + //* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE)); // Get a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); // So is the package accepted with this listener? - $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: accepts=%d - EXIT!', $accepts)); diff --git a/application/hub/classes/listener/udp/class_UdpListener.php b/application/hub/classes/listener/udp/class_UdpListener.php index 08f55d407..671da1efb 100644 --- a/application/hub/classes/listener/udp/class_UdpListener.php +++ b/application/hub/classes/listener/udp/class_UdpListener.php @@ -119,7 +119,7 @@ class UdpListener extends BaseListener implements Listenable { /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept * @throws UnsupportedOperationException If this method is called */ diff --git a/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php b/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php index 209c538db..028738c22 100644 --- a/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php +++ b/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php @@ -93,15 +93,15 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Invoke decorated listener's method - if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) { + if (!$this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.'); @@ -110,13 +110,13 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen } // END - if // Debugging - /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE)); // Get a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); // So is the package accepted with this listener? - $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: accepts=%d - EXIT!', $accepts)); diff --git a/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php b/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php index 9baa90d0c..d67923d70 100644 --- a/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php +++ b/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php @@ -93,15 +93,15 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl /** * Checks whether the listener would accept the given package data array * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { // Trace message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageData()=%d - CALLED!', count($packageData))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Invoke decorated listener's method - if ($this->getListenerInstance()->ifListenerAcceptsPackageData($packageData)) { + if ($this->getListenerInstance()->ifListenerAcceptsPackageData($packageInstance)) { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Protocol mismatching, not accepting package.'); @@ -110,13 +110,13 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl } // END - if // Debugging - /* DEBUG-DIE: */ die(__METHOD__ . ':packageData=' . print_r($packageData, TRUE)); + /* DEBUG-DIE: */ die(__METHOD__ . ':packageInstance=' . print_r($packageInstance, TRUE)); // Get a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); // So is the package accepted with this listener? - $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageData, $this); + $accepts = $tagsInstance->ifPackageDataIsAcceptedByListener($packageInstance, $this); // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: accepts=%d - EXIT!', $accepts)); diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index bbe3a881f..98f7395dd 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -489,6 +489,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC $helperInstance->getTemplateInstance()->compileConfigInVariables(); // "Publish" the descriptor by sending it to the bootstrap/list nodes + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: Calling helperInstance->sendPackage(%s) ...', $this->__toString())); $helperInstance->sendPackage($this); // Change the state, this should be the last line except debug output @@ -520,6 +521,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC $helperInstance->getTemplateInstance()->compileConfigInVariables(); // And send the package away + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: Calling helperInstance->sendPackage(%s) ...', $this->__toString())); $helperInstance->sendPackage($this); // Debug output diff --git a/application/hub/classes/package/deliverable/class_PackageData.php b/application/hub/classes/package/deliverable/class_PackageData.php index badb7b7eb..93beeecc6 100644 --- a/application/hub/classes/package/deliverable/class_PackageData.php +++ b/application/hub/classes/package/deliverable/class_PackageData.php @@ -8,6 +8,10 @@ use Org\Shipsimu\Hub\Generic\BaseHubSystem; // Import framework stuff use Org\Mxchange\CoreFramework\Registry\Registerable; +// Import SPL stuff +use \ReflectionClass; +use \ReflectionProperty; + /** * A DeliverablePackage class for raw package data * @@ -271,4 +275,45 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera return $this->senderPrivateKeyHash; } + /** + * Collecting "getter" for all class fields as array + * + * @return $packageData An array with all fields from this class + */ + public final function getAllAsArray () { + // Get reflection from this + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-DATA: CALLED!'); + $reflectionInstance = new ReflectionClass($this); + + // Get all properties + $properties = $reflectionInstance->getProperties(ReflectionProperty::IS_PRIVATE); + + // Init array + $packageData = array(); + + // Loop through all + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: properties()=%d', count($properties))); + foreach ($properties as $propertyInstance) { + // Is the declaring class this one? + //* DEBUG-DIE: */ die(sprintf('[%s:%d] propertyInstance=%s', __METHOD__, __LINE__, print_r($propertyInstance))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: propertyInstance->declaringClass->name=%s', $propertyInstance->getDeclaringClass()->getName())); + if ($propertyInstance->getDeclaringClass()->getName() !== $this->__toString()) { + // No, then skip this one + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: propertyInstance->declaringClass->name=%s is not matching - skip!', $propertyInstance->getDeclaringClass()->getName())); + continue; + } + + // Invoke getter method + $value = call_user_func_array(array($this, sprintf('get%s', ucfirst($propertyInstance->getName()))), array()); + + // Add name/value + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: Adding %s[%s]=%s', $propertyInstance->getName(), gettype($value), $value)); + $packageData[$propertyInstance->getName()] = $value; + } + + // Return array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-DATA: packageData()=%d - EXIT!', count($packageData))); + return $packageData; + } + } diff --git a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php index 837c88b98..271c9a804 100644 --- a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php @@ -130,6 +130,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ public static final function createPackageFragmenter () { // Get new instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!'); $fragmenterInstance = new PackageFragmenter(); // Get a crypto instance and set it here @@ -147,11 +148,15 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function initFragmenter () { // Load some configuration entries and "cache" them: + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: CALLED!'); // - Chunk size in bits $this->chunkSize = $this->getConfigInstance()->getConfigEntry('package_chunk_size'); // - Maximum serial number $this->maxSerialNumber = $this->hex2dec(str_repeat('f', self::MAX_SERIAL_LENGTH)); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } /** @@ -161,6 +166,8 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera * @return void */ private function initPointer ($finalHash) { + // Init counter + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); $this->chunkPointers[$finalHash] = 0; } @@ -171,6 +178,8 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera * @return $index Array index for processedPackages */ private function getProcessedPackagesIndex (DeliverablePackage $packageInstance) { + // Generate array index + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString())); return ( $packageInstance->getSenderAddress() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . $packageInstance->getRecipientUnl() . NetworkPackageHandler::PACKAGE_DATA_SEPARATOR . @@ -186,6 +195,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function isPackageProcessed (DeliverablePackage $packageInstance) { // Get array index + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString())); $index = $this->getProcessedPackagesIndex($packageInstance); // Is the array index there? @@ -196,6 +206,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera ); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: isProcessed=%d - EXIT!', intval($isProcessed))); return $isProcessed; } @@ -207,6 +218,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function markPackageDataProcessed (DeliverablePackage $packageInstance) { // Remember it (until we may remove it) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString())); $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = TRUE; } @@ -218,6 +230,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function getFinalHashFromPackageInstance (DeliverablePackage $packageInstance) { // Make sure it is there + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s - CALLED!', $packageInstance->__toString())); assert(isset($this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)])); // Return it @@ -231,13 +244,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function getCurrentChunkPointer ($finalHash) { // Is the final hash valid? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); assert(strlen($finalHash) > 0); // Is the pointer already initialized? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash); assert(isset($this->chunkPointers[$finalHash])); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: Returning chunk pointers for finalHash=%s - EXIT!', $finalHash)); return $this->chunkPointers[$finalHash]; } @@ -248,10 +262,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function nextChunkPointer ($finalHash) { // Is the pointer already initialized? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); assert(isset($this->chunkPointers[$finalHash])); // Count one up - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s', gettype($finalHash), $finalHash)); $this->chunkPointers[$finalHash]++; } @@ -263,6 +278,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function getDataChunkSizeFromHash ($hash) { // Calculate real (data) chunk size + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - CALLED!', $hash)); $dataChunkSize = ( // Real chunk size ($this->chunkSize / 8) - @@ -278,6 +294,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera assert($dataChunkSize > 0); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: dataChunkSize=%d - CALLED!', $dataChunkSize)); return $dataChunkSize; } @@ -293,9 +310,11 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera * Get the crypto instance and hash the data with no extra salt because * the other peer doesn't have *this* peer's salt. */ + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s - CALLED!', $rawData)); $hash = $this->getCryptoInstance()->hashString($rawData, '', FALSE); // Return it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: hash=%s - EXIT!', $hash)); return $hash; } @@ -310,16 +329,20 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function appendEndOfPackageChunk ($lastChunk, $finalHash) { // Generate end-of-package marker + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: lastChunk=%s,finalHash[%s]=%s - CALLED!', $lastChunk, gettype($finalHash), $finalHash)); $chunkData = self::END_OF_PACKAGE_IDENTIFIER . $finalHash . self::CHUNK_HASH_SEPARATOR . $this->generateHashFromRawData($lastChunk); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Adding EOP chunk with size of ' . strlen($chunkData) . ',finalHash=' . $finalHash . ' ...'); // Add it as regular chunk $this->addChunkData($finalHash, $chunkData); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } /** @@ -333,6 +356,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function splitEncodedDataIntoChunks ($rawData, $finalHash) { // Make sure final hashes with at least 32 bytes can pass + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData=%s,finalHash[%s]=%s - CALLED!', $rawData, gettype($finalHash), $finalHash)); assert(strlen($finalHash) >= 32); // Calculate real (data) chunk size @@ -353,10 +377,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera } // END - for // Debug output - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Raw data of ' . strlen($rawData) . ' bytes has been fragmented into ' . count($this->chunks[$finalHash]) . ' chunk(s).'); // Add end-of-package chunk $this->appendEndOfPackageChunk($chunkData, $finalHash); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } /** @@ -370,6 +397,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function addChunkData ($finalHash, $chunkData, $prepend = FALSE) { // Hash it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s,chunkData=%s,prepend=%d - CALLED!', gettype($finalHash), $finalHash, $chunkData, intval($prepend))); $rawDataHash = $this->getCryptoInstance()->hashString($chunkData, '', FALSE); // Prepend the hash to the chunk @@ -380,7 +408,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera ); // Make sure the chunk is not larger than a TCP package can hold - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: assert: ' . strlen($rawData) . '/' . NetworkPackageHandler::TCP_PACKAGE_SIZE . ' ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: assert: ' . strlen($rawData) . '/' . NetworkPackageHandler::TCP_PACKAGE_SIZE . ' ...'); // @TODO This assert broke packages where the hash chunk was very large: assert(strlen($rawData) <= NetworkPackageHandler::TCP_PACKAGE_SIZE); // Add it to the array @@ -404,6 +432,9 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera array_push($this->chunks[$finalHash] , $rawData); array_push($this->chunkHashes[$finalHash], $rawDataHash); } + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } /** @@ -414,10 +445,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ private function prependHashChunk ($finalHash) { // "Implode" the whole array of hashes into one string + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); $rawData = self::HASH_CHUNK_IDENTIFIER . implode(self::CHUNK_HASH_SEPARATOR, $this->chunkHashes[$finalHash]); // Prepend chunk $this->addChunkData($finalHash, $rawData, TRUE); + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } /** @@ -428,6 +463,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ public function getNextHexSerialNumber ($finalHash) { // Assert on maximum serial number length + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); assert(isset($this->serialNumber[$finalHash])); assert($this->serialNumber[$finalHash] <= $this->maxSerialNumber); @@ -439,7 +475,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera $this->serialNumber[$finalHash]++; // Return the encoded serial number - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: encodedSerialNumber=' . $encodedSerialNumber); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: encodedSerialNumber=' . $encodedSerialNumber . ' - EXIT!'); return $encodedSerialNumber; } @@ -456,14 +492,19 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ public function fragmentPackageArray (DeliverablePackage $packageInstance, ConnectionHelper $helperInstance) { // Is this package already fragmented? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: packageInstance=%s,helperInstance=%s - CALLED!', $packageInstance->__toString(), $helperInstance->__toString())); if (!$this->isPackageProcessed($packageInstance)) { // First we need to "implode" the array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is not processed., getting all raw data ...'); $rawData = implode(NetworkPackageHandler::PACKAGE_DATA_SEPARATOR, $packageInstance->getAllAsArray()); // Generate the final hash from the raw data (not encoded!) + //* DEBUG-DIE: */ die(sprintf('[%s:%d]: rawData[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($rawData), $rawData)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: rawData(%d)=%s', strlen($rawData), $rawData)); $finalHash = $this->generateHashFromRawData($rawData); // Remember it + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash)); $this->processedPackages[$this->getProcessedPackagesIndex($packageInstance)] = $finalHash; // Init pointer and reset serial number @@ -480,11 +521,13 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera $this->markPackageDataProcessed($packageInstance); } else { // Get the final hash from the package data + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Package is already processed, getting final hash ...'); $finalHash = $this->getFinalHashFromPackageInstance($packageInstance); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash=%s', $finalHash)); } // Return final hash - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - EXIT!', gettype($finalHash), $finalHash)); return $finalHash; } @@ -499,7 +542,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ public function getNextRawDataChunk ($finalHash) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash[' . gettype($finalHash) . ']=' . $finalHash); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); try { // Get current chunk index @@ -518,12 +561,12 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera // If there is no entry left, return an empty array if ((!isset($this->chunkHashes[$finalHash][$current])) || (!isset($this->chunks[$finalHash][$current]))) { // No more entries found - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ' - No more entries found!'); return array(); } // END - if // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(__METHOD__. ': finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: finalHash=' . $finalHash . ',current=' . $current . ',chunkHashes()=' . count($this->chunkHashes[$finalHash]) .' - Entry choosen ...'); // Generate the array $rawDataChunk = array( @@ -534,6 +577,7 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera $this->nextChunkPointer($finalHash); // Return the chunk array + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: Returning rawDataChunk ... - EXIT!'); return $rawDataChunk; } @@ -545,10 +589,14 @@ class PackageFragmenter extends BaseHubSystem implements Fragmentable, Registera */ public function resetSerialNumber ($finalHash) { // Final hash must be set + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-FRAGMENTER: finalHash[%s]=%s - CALLED!', gettype($finalHash), $finalHash)); assert((is_string($finalHash)) && (!empty($finalHash))); // Reset/set serial number $this->serialNumber[$finalHash] = 0; + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-FRAGMENTER: EXIT!'); } } diff --git a/application/hub/classes/pools/peer/class_DefaultPeerPool.php b/application/hub/classes/pools/peer/class_DefaultPeerPool.php index 4f1ddec50..0c6634b6c 100644 --- a/application/hub/classes/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/classes/pools/peer/class_DefaultPeerPool.php @@ -6,7 +6,6 @@ namespace Org\Shipsimu\Hub\Pool\Peer; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Connection\InvalidConnectionTypeException; use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; @@ -221,7 +220,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { /** * "Getter" for a valid socket resource from given packae data. * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @param $connectionType Type of connection, can be 'incoming', 'outgoing', 'server' or default * @return $socketInstance An instance of a StorableSocket class * @throws InvalidConnectionTypeException If the provided connection type is not valid @@ -229,13 +228,13 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { */ public function getSocketFromPackageInstance (DeliverablePackage $packageInstance, $connectionType = NULL) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL:packageData()=%d,connectionType[%s]=%s - CALLED!', count($packageData), gettype($connectionType), $connectionType)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DEFAULT-PEER-POOL:packageInstance=%s,connectionType[%s]=%s - CALLED!', $packageInstance->__toString(), gettype($connectionType), $connectionType)); // Default is no socket $socketInstance = NULL; // Resolve recipient (UNL) into a handler instance - $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageData); + $handlerInstance = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance); // Get UNL data $unlInstance = $handlerInstance->getUniversalNodeLocatorInstance(); diff --git a/application/hub/classes/recipient/dht/class_DhtRecipient.php b/application/hub/classes/recipient/dht/class_DhtRecipient.php index 781c077e4..cb043fe35 100644 --- a/application/hub/classes/recipient/dht/class_DhtRecipient.php +++ b/application/hub/classes/recipient/dht/class_DhtRecipient.php @@ -61,22 +61,23 @@ class DhtRecipient extends BaseRecipient implements Recipient { /** * Tries to resolve given recipient into session ids or Universal Node Locator - * depending on implementation (hint: Template Method Pattern). This - * implementation will add more than one recipient to the list as a DHT is - * distributed and the package might go to more than one recipient. + * depending on implementation (hint: Template Method Pattern) * - * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) - * @param $listInstance An instance of a Listable class * @param $packageInstance An instance of a DeliverablePackage class - * @return void + * @param $listInstance An instance of a Listable class + * @return $resolved Resolved recipient or VOID if only the set list has been filled * @throws FrameworkException Could throw different exceptions depending on implementation */ - public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) { + public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient . ' - CALLED!'); + /* 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 - assert($recipient == NetworkPackageHandler::NETWORK_TARGET_DHT); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipientUnl=' . $recipientUnl); + assert($recipientUnl == NetworkPackageHandler::NETWORK_TARGET_DHT); // Get recipient discovery instance $discoverInstance = ObjectFactory::createObjectByConfiguredName('dht_recipient_discovery_class'); @@ -87,6 +88,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { // Now "walk" through all elements and add them to the list foreach ($recipients as $recipient) { // These array elements must exist for this loop: + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient); // @TODO Unfinished die(__METHOD__ . ':recipient=' . print_r($recipient, TRUE)); assert(!empty($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_ADDRESS])); @@ -100,7 +102,7 @@ class DhtRecipient extends BaseRecipient implements Recipient { } // END - foreach // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: recipient=' . $recipient . ' - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-RECIPIENT: EXIT!'); } } diff --git a/application/hub/classes/recipient/direct/class_DirectRecipient.php b/application/hub/classes/recipient/direct/class_DirectRecipient.php index 5497d48d2..8164e72e7 100644 --- a/application/hub/classes/recipient/direct/class_DirectRecipient.php +++ b/application/hub/classes/recipient/direct/class_DirectRecipient.php @@ -62,18 +62,21 @@ class DirectRecipient extends BaseRecipient implements Recipient { * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * - * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) - * @param $listInstance An instance of a Listable class * @param $packageInstance An instance of a DeliverablePackage class + * @param $listInstance An instance of a Listable class * @return $resolved Resolved recipient or VOID if only the set list has been filled * @throws FrameworkException Could throw different exceptions depending on implementation */ - public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) { + public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString()); + + // Get recipient UNL + $recipientUnl = $packageInstance->getRecipientUnl(); // "Explode" all recipients - $recipients = explode(NetworkPackageHandler::PACKAGE_RECIPIENT_SEPARATOR, $recipient); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipientUnl=' . $recipientUnl); + $recipients = explode(NetworkPackageHandler::PACKAGE_RECIPIENT_SEPARATOR, $recipientUnl); // Is maximum reached? assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')); @@ -81,11 +84,15 @@ class DirectRecipient extends BaseRecipient implements Recipient { // Try it on all foreach ($recipients as $recipient) { // Try to sole a single recipient + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: recipient=' . $recipient); $unlData = HubTools::resolveSessionId($recipient); // Add it as recipient $listInstance->addEntry('unl', $unlData); } // END - foreach + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DIRECT-RECIPIENT: EXIT!'); } } diff --git a/application/hub/classes/recipient/self/class_SelfRecipient.php b/application/hub/classes/recipient/self/class_SelfRecipient.php index a08741b7f..0aa0ee454 100644 --- a/application/hub/classes/recipient/self/class_SelfRecipient.php +++ b/application/hub/classes/recipient/self/class_SelfRecipient.php @@ -3,7 +3,6 @@ namespace Org\Shipsimu\Hub\Network\Recipient\Loopback; // Import application-specific sutff -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Network\Recipient\BaseRecipient; use Org\Shipsimu\Hub\Network\Recipient\Recipient; @@ -12,6 +11,9 @@ use Org\Shipsimu\Hub\Tools\HubTools; // Import framework stuff use Org\Mxchange\CoreFramework\Lists\Listable; +// Import SPL stuff +use \InvalidArgumentException; + /** * A Self recipient * @@ -62,26 +64,28 @@ class SelfRecipient extends BaseRecipient implements Recipient { * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * - * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) - * @param $listInstance An instance of a Listable class * @param $packageInstance An instance of a DeliverablePackage class + * @param $listInstance An instance of a Listable class * @return $resolved Resolved recipient or VOID if only the set list has been filled * @throws FrameworkException Could throw different exceptions depending on implementation */ - public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) { - // Make sure the recipient is valid - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: recipient=' . $recipient); - // @TODO Add more checks on data - assert($recipient == NetworkPackageHandler::NETWORK_TARGET_SELF); + public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString()); // Determine IP or 'external_address' if set $unl = HubTools::determineOwnExternalAddress(); // Is it not empty? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: unl=' . $unl); if (!empty($unl)) { // Add it to the list $listInstance->addEntry('unl', $unl); } // END - if + + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-RECIPIENT: EXIT!'); } } diff --git a/application/hub/classes/recipient/upper/class_UpperRecipient.php b/application/hub/classes/recipient/upper/class_UpperRecipient.php index f0d1f4c3e..c12a771e7 100644 --- a/application/hub/classes/recipient/upper/class_UpperRecipient.php +++ b/application/hub/classes/recipient/upper/class_UpperRecipient.php @@ -62,34 +62,40 @@ class UpperRecipient extends BaseRecipient implements Recipient { * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * - * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) - * @param $listInstance An instance of a Listable class * @param $packageInstance An instance of a DeliverablePackage class + * @param $listInstance An instance of a Listable class * @return $resolved Resolved recipient or VOID if only the set list has been filled * @throws FrameworkException Could throw different exceptions depending on implementation */ - public function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance) { - // Make sure the recipient is valid - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: recipient=' . $recipient); - assert($recipient == NetworkPackageHandler::NETWORK_TARGET_UPPER); + public function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance) { + // Debug message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: packageInstance=' . $packageInstance->__toString() . ',listInstance=' . $listInstance->__toString()); + + // Get recipient UNL + $recipientUnl = $packageInstance->getRecipientUnl(); + + // Check recipient UNL + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: recipientUnl=' . $recipientUnl); + assert($recipientUnl == NetworkPackageHandler::NETWORK_TARGET_UPPER); // Get all bootstrap nodes foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $unlData) { // Is maximum reached? if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) { - // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); - // Then stop adding more + /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!'); break; } // END - if // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . print_r($unlData, TRUE) . ' as recipient.'); + /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: Adding node ' . print_r($unlData, TRUE) . ' as recipient.'); // Add the entry $listInstance->addEntry('unl', $unlData); } // END - foreach + + // Trace message + /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UPPER-RECIPIENT: EXIT!'); } } diff --git a/application/hub/classes/registry/socket/class_SocketRegistry.php b/application/hub/classes/registry/socket/class_SocketRegistry.php index 6e944b170..d16cfa63c 100644 --- a/application/hub/classes/registry/socket/class_SocketRegistry.php +++ b/application/hub/classes/registry/socket/class_SocketRegistry.php @@ -5,7 +5,6 @@ namespace Org\Shipsimu\Hub\Registry\Socket; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory; -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\BaseListener; diff --git a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php index 30584132f..8706dc1eb 100644 --- a/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php +++ b/application/hub/classes/resolver/state/peer/class_PeerStateResolver.php @@ -66,7 +66,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver { * Returns an state instance for a given raw package data and socket resource * * @param $helperInstance An instance of a ConnectionHelper class - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @param $socketInstance An instance of a StorableSocket class * @return $stateInstance An instance of the resolved state * @throws InvalidSocketException If socketResource, even from getSocketResource() is no valid resource @@ -96,7 +96,7 @@ class PeerStateResolver extends BaseStateResolver implements StateResolver { $errorName = $socketInstance->translateLastSocketErrorCodeToName(); // Create a state instance based on $errorCode. This factory does the hard work for us - $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketInstance, $errorName); + $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageInstance, $socketInstance, $errorName); // Return the prepared instance return $stateInstance; diff --git a/application/hub/classes/tags/package/class_PackageTags.php b/application/hub/classes/tags/package/class_PackageTags.php index 7079839cc..b348edfaf 100644 --- a/application/hub/classes/tags/package/class_PackageTags.php +++ b/application/hub/classes/tags/package/class_PackageTags.php @@ -86,10 +86,8 @@ class PackageTags extends BaseTag implements Tagable { * @return void */ private function initObjectRegistry () { - // Output debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - CALLED!'); - // Get the application instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Initializing object registry - CALLED!'); $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); // Get a XML template instance @@ -111,12 +109,13 @@ class PackageTags extends BaseTag implements Tagable { /** * Extracts the tags from given package data * - * @param $packageData An instance of a DeliverablePackage class + * @param $packageInstance An instance of a DeliverablePackage class * @return void */ private function extractTagsFromPackageInstance (DeliverablePackage $packageInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: packageData=' . print_r($packageData, TRUE)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); + //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: packageInstance' . print_r($packageInstance, TRUE)); /* * We take a look at the tags (in most cases only one is needed) so @@ -125,6 +124,7 @@ class PackageTags extends BaseTag implements Tagable { $contentData = explode(NetworkPackageHandler::PACKAGE_MASK_SEPARATOR, $packageInstance->getPackageContent()); // Get the tags and store them locally + //* PRINTR-DIE: */ die(sprintf('[%s:%d]: contentData(%d)=%s', __METHOD__, __LINE__, count($contentData), print_r($contentData, TRUE))); $this->setTags(explode(NetworkPackageHandler::PACKAGE_TAGS_SEPARATOR, $contentData[NetworkPackageHandler::INDEX_TAGS])); } @@ -140,6 +140,7 @@ class PackageTags extends BaseTag implements Tagable { */ private function verifyAllTags (DeliverablePackage $packageInstance) { // Get the registry + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance(); // "Walk" over all tags @@ -154,6 +155,8 @@ class PackageTags extends BaseTag implements Tagable { * If it is no array or the array is empty or an entry is missing * the entry is invalid. */ + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: entry[]=%s', gettype($entry))); + //* PRINTR-DIE: */ die(sprintf('[%s:%d] entry=%s', __METHOD__, __LINE__, print_r($entry, TRUE))); if ((!is_array($entry)) || (count($entry) == 0) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_PROTOCOL])) || (!isset($entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]))) { // Invalid entry found throw new InvalidTagException(array($this, $tag), self::EXCEPTION_INVALID_TAG); @@ -163,6 +166,9 @@ class PackageTags extends BaseTag implements Tagable { $this->lastProtocol = ProtocolHandlerFactory::createProtocolHandlerFromPackageInstance($packageInstance); $this->lastRecipientType = $entry[XmlObjectRegistryTemplateEngine::OBJECT_TYPE_DATA_RECIPIENT_TYPE]; } // END - foreach + + // Trace message + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!'); } /** @@ -173,12 +179,14 @@ class PackageTags extends BaseTag implements Tagable { */ public function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance) { // Extract the tags + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $this->extractTagsFromPackageInstance($packageInstance); // Now we need to verify every single tag $this->verifyAllTags($packageInstance); // Return the last (and only) found protocol (e.g. 'tcp' is very usual) + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: this->lastProtocol=%s - EXIT!', $this->lastProtocol->__toString())); return $this->lastProtocol; } @@ -191,6 +199,7 @@ class PackageTags extends BaseTag implements Tagable { */ public function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance) { // Extract the tags + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $this->extractTagsFromPackageInstance($packageInstance); // Now every single tag needs to be validated @@ -200,6 +209,7 @@ class PackageTags extends BaseTag implements Tagable { $accepts = (($this->lastRecipientType == $listenerInstance->getListenerType()) && ($listenerInstance->getListenerType() != 'invalid')); // And return the result + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('TAGS: accepts=%d - EXIT!', $accepts)); return $accepts; } diff --git a/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php index 3e8d6df18..6101c514f 100644 --- a/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/classes/template/objects/class_XmlObjectRegistryTemplateEngine.php @@ -119,11 +119,11 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C if ($nodeName == self::OBJECT_TYPE_DATA_NAME) { // Output debug message /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: Adding object type ' . $characters . ' to registry.'); - $this->objectRegistryInstance->addEntry($nodeName, $characters); } // END - if // Add it to the registry //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TAGS: EXIT!'); + $this->objectRegistryInstance->addEntry($nodeName, $characters); } /** diff --git a/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php b/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php index 4b2cf7dfc..b7e79f978 100644 --- a/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php +++ b/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php @@ -2,9 +2,6 @@ // Own namespace namespace Org\Shipsimu\Hub\Peer; -// Import application-specific stuff -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; - // Import framework stuff use Org\Mxchange\CoreFramework\Generic\FrameworkException; diff --git a/application/hub/exceptions/unl/class_InvalidUnlException.php b/application/hub/exceptions/unl/class_InvalidUnlException.php index ecf8aac05..3da76fa75 100644 --- a/application/hub/exceptions/unl/class_InvalidUnlException.php +++ b/application/hub/exceptions/unl/class_InvalidUnlException.php @@ -2,9 +2,6 @@ // Own namespace namespace Org\Shipsimu\Hub\Unl; -// Import application-specific stuff -use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; - // Import framework stuff use Org\Mxchange\CoreFramework\Generic\FrameworkException; diff --git a/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php b/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php index 98175d3f6..07d03b92a 100644 --- a/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php +++ b/application/hub/interfaces/discovery/recipient/node/class_DiscoverableNodeRecipient.php @@ -35,7 +35,7 @@ interface DiscoverableNodeRecipient extends DiscoverableRecipient { * @param $packageInstance An instance of a DeliverablePackage class array * @return void */ - function discoverRecipients (DeliverablePackage $packageInstance); + function discoverRecipientsByPackageInstance (DeliverablePackage $packageInstance); /** * Tries to discover all recipients by given decoded package data. diff --git a/application/hub/interfaces/recipient/class_Recipient.php b/application/hub/interfaces/recipient/class_Recipient.php index 3cdc5a60e..58840d4e0 100644 --- a/application/hub/interfaces/recipient/class_Recipient.php +++ b/application/hub/interfaces/recipient/class_Recipient.php @@ -36,11 +36,10 @@ interface Recipient extends HubInterface { * Tries to resolve given recipient into session ids or Universal Node Locator * depending on implementation (hint: Template Method Pattern) * - * @param $recipient Recipient to resolve (e.g. could be a virtual recipient or direct session id) - * @param $listInstance An instance of a Listable class * @param $packageInstance An instance of a DeliverablePackage class + * @param $listInstance An instance of a Listable class * @return $resolved Resolved recipient or VOID if only the set list has been filled * @throws FrameworkException Could throw different exceptions depending on implementation */ - function resolveRecipient ($recipient, Listable $listInstance, DeliverablePackage $packageInstance); + function resolveRecipientByPackageInstance (DeliverablePackage $packageInstance, Listable $listInstance); } diff --git a/core b/core index e1220edf0..b4d42594f 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit e1220edf0b09e635b818aba6465f2b7d47e7d310 +Subproject commit b4d42594f7eb8c7f254a14901743ffdef168e84f