From c2b6b87b9ec1947af642fcbe1337612cc1c29bbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 2 Dec 2020 13:45:01 +0100 Subject: [PATCH] Refacturing: - introduced FragmentableTrait trait - database wrappers are no more, they are now called frontends - updated core framework MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- ...deDistributedHashTableDatabaseFrontend.php | 94 +++++++++---------- .../class_NodeInformationDatabaseFrontend.php | 2 +- .../class_PeerStateLookupDatabaseFrontend.php | 18 ++-- .../handler/chunks/class_ChunkHandler.php | 13 +-- .../connection/class_BaseConnectionHelper.php | 32 +------ application/hub/config.php | 8 +- .../fragmenter/class_FragmentableTrait.php | 55 +++++++++++ core | 2 +- 8 files changed, 126 insertions(+), 98 deletions(-) create mode 100644 application/hub/traits/fragmenter/class_FragmentableTrait.php diff --git a/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php b/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php index 2e81da98f..bf910e173 100644 --- a/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php @@ -95,7 +95,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $frontendInstance->setTableName(self::DB_TABLE_NODE_DHT); // Get node instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Creating node instance ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Creating node instance ...'); $nodeInstance = NodeObjectFactory::createNodeInstance(); // And set it here @@ -134,7 +134,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ private function prepareSearchInstance (array $nodeData) { // Assert on array elements - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); // Get instance @@ -145,7 +145,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $searchInstance->setLimit(1); // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); return $searchInstance; } @@ -158,7 +158,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ private function prepareLocalDataSetInstance () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Get request instances $requestInstance = FrameworkBootstrap::getRequestInstance(); @@ -177,29 +177,29 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i // 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); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: externalUnl=' . $externalUnl); assert($externalUnl !== 'invalid'); // Get an array of all accepted object types $objectList = $this->getNodeInstance()->getListFromAcceptedObjectTypes(); // Make sure this is an array - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: objectList()=' . count($objectList)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: 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=' . $this->getNodeInstance()->getNodeId()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: nodeInstance->nodeId=' . $this->getNodeInstance()->getNodeId()); $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_ID , $this->getNodeInstance()->getNodeId()); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeInstance->sessionId=' . $this->getNodeInstance()->getSessionId()); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: nodeInstance->sessionId=' . $this->getNodeInstance()->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_SESSION_ID , $this->getNodeInstance()->getSessionId()); $dataSetInstance->addCriteria(self::DB_COLUMN_PRIVATE_KEY_HASH, $this->getNodeInstance()->getNodePrivateKeyHash()); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList)); $dataSetInstance->addCriteria(self::DB_COLUMN_ACCEPT_BOOTSTRAP, $this->translateBooleanToYesNo($this->getNodeInstance()->isAcceptingDhtBootstrap())); // Return it - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: dataSetInstance=' . $dataSetInstance->__toString() . ' - EXIT!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: dataSetInstance=' . $dataSetInstance->__toString() . ' - EXIT!'); return $dataSetInstance; } @@ -220,7 +220,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function isLocalNodeRegistered () { // Get a search criteria instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Get Universal Node Locator and "explode" it @@ -229,7 +229,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i // Make sure the external address is set and not invalid // @TODO Bad check on UNL, better use a proper validator $externalUnl = $locatorInstance->getExternalUnl(); - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $externalUnl)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: externalUnl=%s', $externalUnl)); assert($externalUnl != 'invalid'); // Add Universal Node Locator/node id as criteria @@ -245,7 +245,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $isRegistered = $resultInstance->valid(); // Return result - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: isRegistered=%d - EXIT!', intval($isRegistered))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: isRegistered=%d - EXIT!', intval($isRegistered))); return $isRegistered; } @@ -256,7 +256,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function registerLocalNode () { // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Assert to make sure this method is called with no record in DB (the actual backend of the DHT) assert(!$this->isLocalNodeRegistered()); @@ -265,11 +265,11 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $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() . ') ...'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: 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-FRONTEND: EXIT!'); } /** @@ -280,7 +280,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function updateLocalNode () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Assert to make sure this method is called with one record in DB (the actual backend of the DHT) assert($this->isLocalNodeRegistered()); @@ -302,7 +302,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $this->queryUpdateDataSet($dataSetInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); } /** @@ -314,7 +314,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function findNodeLocalBySessionId (string $sessionId) { // Validate parameter - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: sessionId=%s - CALLED!', $sessionId)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: sessionId=%s - CALLED!', $sessionId)); if (empty($sessionId)) { // Cannot be empty throw new InvalidArgumentException('Parameter "sessionId" is empty.'); @@ -331,7 +331,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $resultInstance = $this->doSelectByCriteria($searchInstance); // Return result instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid()))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid()))); return $resultInstance; } @@ -343,11 +343,11 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance) { // Get search criteria - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: locatorInstance=%s - CALLED!', $locatorInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: locatorInstance=%s - CALLED!', $locatorInstance->__toString())); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Search for session id and limit it to one entry - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: externalUnl=%s', $locatorInstance->getExternalUnl())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: externalUnl=%s', $locatorInstance->getExternalUnl())); $searchInstance->addCriteria(self::DB_COLUMN_EXTERNAL_ADDRESS, $locatorInstance->getExternalUnl()); $searchInstance->setLimit(1); @@ -355,7 +355,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $resultInstance = $this->doSelectByCriteria($searchInstance); // Return result instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid()))); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: resultInstance->valid()=%d - EXIT!', intval($resultInstance->valid()))); return $resultInstance; } @@ -367,10 +367,8 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return void */ public function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance) { - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!'); - // Get a data set instance + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: handlerInstance=' . $handlerInstance->__toString() . ' - CALLED!'); $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT)); // Set primary key (session id) @@ -385,8 +383,8 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i // Run the "INSERT" query $this->queryInsertDataSet($dataSetInstance); - // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER - EXIT!'); + // Trace message + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND - EXIT!'); } /** @@ -399,7 +397,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function updateNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Get a data set instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_DHT)); @@ -420,7 +418,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $this->queryUpdateDataSet($dataSetInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); } /** @@ -431,13 +429,13 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function isNodeRegistered (array $nodeData) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: node-id=' . $nodeData[self::DB_COLUMN_NODE_ID]); // Get search criteria $searchInstance = $this->prepareSearchInstance($nodeData); @@ -457,7 +455,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $isRegistered = $resultInstance->valid(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: isRegistered=' . intval($isRegistered) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: isRegistered=' . intval($isRegistered) . ' - EXIT!'); // Return registration status return $isRegistered; @@ -473,7 +471,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function registerNode (array $nodeData) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); @@ -488,7 +486,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $this->partialStub('nodeData=' . print_r($nodeData, TRUE)); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); } /** @@ -502,14 +500,14 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function updateNode (array $nodeData) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: nodeData=' . print_r($nodeData, TRUE)); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: nodeData=' . print_r($nodeData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Assert on array elements assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Updating DHT entry for node-id=' . $nodeData[self::DB_COLUMN_NODE_ID] . ' ...'); // Is the node registered? if (!$this->isNodeRegistered($nodeData)) { @@ -539,7 +537,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $this->queryUpdateDataSet($dataSetInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); } /** @@ -565,7 +563,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $hasUnpublished = $this->unpublishedEntriesInstance->valid(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); // Return it return $hasUnpublished; @@ -581,7 +579,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function initEntryPublication () { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); /* * Make sure that hasUnpublishedEntries() has been called first by @@ -613,7 +611,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $this->queryUpdateDataSet($dataSetInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); } /** @@ -624,9 +622,9 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function removeNonPublicDataFromArray(array $data) { // Currently call only inner method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Calling parent::removeNonPublicDataFromArray(data) ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Calling parent::removeNonPublicDataFromArray(data) ...'); $data = parent::removeNonPublicDataFromArray($data); - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: data[]=' . gettype($data)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: data[]=' . gettype($data)); // Return cleaned data return $data; @@ -640,7 +638,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function getResultFromExcludedSender (DeliverablePackage $packageInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); // Get max recipients $maxRecipients = FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('max_dht_recipients'); @@ -658,7 +656,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $resultInstance = $this->doSelectByCriteria($searchInstance); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: EXIT!'); // Return result instance return $resultInstance; @@ -675,7 +673,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function getResultFromKeyValue (string $key, $value) { // Is key parameter valid? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: key=%s,value[%s]=%s - CALLED!', $key, gettype($value), $value)); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: key=%s,value[%s]=%s - CALLED!', $key, gettype($value), $value)); if (empty($key)) { // Throw exception throw new InvalidArgumentException('Parameter key is empty'); @@ -694,7 +692,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i $resultInstance = $this->doSelectByCriteria($searchInstance); // Return result instance - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-WRAPPER: resultInstance=%s - EXIT!', $resultInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: resultInstance=%s - EXIT!', $resultInstance->__toString())); return $resultInstance; } @@ -705,7 +703,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i */ public function enableAcceptDhtBootstrap () { // Debug message - /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-WRAPPER: Enabling DHT bootstrap requests ...'); + /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Enabling DHT bootstrap requests ...'); // Is the node already registered? if ($this->isLocalNodeRegistered()) { diff --git a/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php b/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php index 51945050b..dbba15fd3 100644 --- a/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php @@ -183,7 +183,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements */ public function removeNonPublicDataFromArray(array $data) { // Currently call only inner method - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-WRAPPER: Calling parent::removeNonPublicDataFromArray(data) ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FRONTEND: Calling parent::removeNonPublicDataFromArray(data) ...'); $data = parent::removeNonPublicDataFromArray($data); // Return cleaned data diff --git a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseFrontend.php b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseFrontend.php index 8e8e4f447..4ecb4ea16 100644 --- a/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/states/class_PeerStateLookupDatabaseFrontend.php @@ -91,7 +91,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements */ private function getSenderSearchInstanceFromPackageInstance (DeliverablePackage $packageInstance) { // Get the instance - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: Searching for sender ' . $packageInstance->getSenderAddress()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: Searching for sender ' . $packageInstance->getSenderAddress()); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Add 'sender' as the peer's IP address @@ -111,7 +111,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements */ public function isSenderNewPeer (DeliverablePackage $packageInstance, StoreableCriteria $dataSetInstance = NULL) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: packageInstance=' . $packageInstance . ' - CALLED!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: packageInstance=' . $packageInstance . ' - CALLED!'); // Get a search criteria instance from package data $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance); @@ -126,11 +126,11 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements $entries = $this->doSelectCountByCriteria($searchInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE)); // Is it there? - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: entries=' . $entries); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: entries=' . $entries); $isNewPeer = ($entries != 1); // Return the result - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: isNewPeer=' . intval($isNewPeer) . ' - EXIT!'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: isNewPeer=' . intval($isNewPeer) . ' - EXIT!'); return $isNewPeer; } @@ -177,7 +177,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements $this->queryInsertDataSet($dataSetInstance, array(self::DB_COLUMN_PEER_SESSION_ID => TRUE)); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: Peer ' . $packageInstance->getSenderAddress() . ' has been registered.'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: Peer ' . $packageInstance->getSenderAddress() . ' has been registered.'); } /** @@ -220,7 +220,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements } // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: Peer ' . $packageInstance->getSenderAddress() . ' has been registered/updated with state ' . $stateInstance->getStateName()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: Peer ' . $packageInstance->getSenderAddress() . ' has been registered/updated with state ' . $stateInstance->getStateName()); } /** @@ -245,7 +245,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements */ public function isSamePeerState (ConnectionHelper $helperInstance, DeliverablePackage $packageInstance) { // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...'); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: State ' . $helperInstance->getPrintableState() . ' needs to be checked it has changed ...'); // Now get the search instance from given package data $searchInstance = $this->getSenderSearchInstanceFromPackageInstance($packageInstance); @@ -263,7 +263,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements $rowData = $resultInstance->current(); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: rowData[' . gettype($rowData) . ']=' . print_r($rowData, TRUE)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: rowData[' . gettype($rowData) . ']=' . print_r($rowData, TRUE)); // Assert on important elements assert(isset($rowData[self::DB_COLUMN_PEER_STATE])); @@ -272,7 +272,7 @@ class PeerStateLookupDatabaseFrontend extends BaseHubDatabaseFrontend implements $isSamePeerState = ($rowData[self::DB_COLUMN_PEER_STATE] == $helperInstance->getPrintableState()); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-WRAPPER: state in database: ' . $rowData[self::DB_COLUMN_PEER_STATE] . ', new state: ' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState)); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PEER-STATE-DATABASE-FRONTEND: state in database: ' . $rowData[self::DB_COLUMN_PEER_STATE] . ', new state: ' . $helperInstance->getPrintableState() . ',isSamePeerState=' . intval($isSamePeerState)); // Return it return $isSamePeerState; diff --git a/application/hub/classes/handler/chunks/class_ChunkHandler.php b/application/hub/classes/handler/chunks/class_ChunkHandler.php index 26f0e7d40..e2d016914 100644 --- a/application/hub/classes/handler/chunks/class_ChunkHandler.php +++ b/application/hub/classes/handler/chunks/class_ChunkHandler.php @@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Handler\Network\RawData\Chunks; use Org\Shipsimu\Hub\Factory\Fragmenter\FragmenterFactory; use Org\Shipsimu\Hub\Handler\BaseHubHandler; use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter; +use Org\Shipsimu\Hub\Traits\Fragmenter\FragmentableTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Assertion\AssertionException; @@ -40,6 +41,7 @@ use Org\Mxchange\CoreFramework\Traits\Crypto\CryptoTrait; class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registerable { // Load traits use CryptoTrait; + use FragmentableTrait; /** * Stacker for chunks with final EOP @@ -84,11 +86,6 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera */ private $rawPackageData = ''; - /** - * Fragmenter instance, needs to be set here again - */ - private $fragmenterInstance = NULL; - /** * Protected constructor * @@ -108,7 +105,7 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera $fragmenterInstance = FragmenterFactory::createFragmenterInstance('package'); // Set it in this handler - $this->fragmenterInstance = $fragmenterInstance; + $this->setFragmenterInstance($fragmenterInstance); } /** @@ -335,14 +332,14 @@ class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registera // Reset the serial number generator /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: finalHash=%s', $finalHash)); - $this->fragmenterInstance->resetSerialNumber($finalHash); + $this->getFragmenterInstance()->resetSerialNumber($finalHash); // "Walk" through all (content) chunks /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: this->finalPackageChunks[content]()=%d', count($this->finalPackageChunks['content']))); foreach ($this->finalPackageChunks['content'] as $serialNumber => $content) { // Get next serial number /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s,content=%s', $serialNumber, $content)); - $nextSerial = $this->fragmenterInstance->getNextHexSerialNumber($finalHash); + $nextSerial = $this->getFragmenterInstance()->getNextHexSerialNumber($finalHash); // Is it not the same? Then re-request it /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CHUNK-HANDLER: serialNumber=%s,nextSerial=%s', $serialNumber, $nextSerial)); diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 4fe7cc178..22e7edd54 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -13,6 +13,7 @@ use Org\Shipsimu\Hub\Helper\BaseHubSystemHelper; use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; +use Org\Shipsimu\Hub\Traits\Fragmenter\FragmentableTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; @@ -49,6 +50,7 @@ use Org\Mxchange\CoreFramework\Visitor\Visitor; */ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visitable, Registerable { // Load traits + use FragmentableTrait; use OutputStreamTrait; use StateableTrait; @@ -85,11 +87,6 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit */ private $packageHandlerInstance = NULL; - /** - * Fragmenter instance - */ - private $fragmenterInstance = NULL; - /** * Protected constructor * @@ -110,10 +107,10 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit $this->setOutputStreamInstance($streamInstance); // Get package instance from factory - $packageInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance(); + $handlerInstance = NetworkPackageHandlerFactory::createNetworkPackageHandlerInstance(); // ... and set it here - $this->setPackageHandlerInstance($packageInstance); + $this->setPackageHandlerInstance($handlerInstance); // Register this connection helper GenericRegistry::getRegistry()->addInstance('connection', $this); @@ -161,7 +158,7 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit /** * Getter for isInitialized (NOTE: no 'get' prefix for boolean attributes!) * - * @return $isInitialized Name of used protocol in this connection + * @return $isInitialized Name of used protocol in this connection */ protected final function isInitialized () { return $this->isInitialized; @@ -186,25 +183,6 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit return $this->packageHandlerInstance; } - /** - * Setter for fragmenter instance - * - * @param $fragmenterInstance A Fragmentable instance - * @return void - */ - private final function setFragmenterInstance (Fragmentable $fragmenterInstance) { - $this->fragmenterInstance = $fragmenterInstance; - } - - /** - * Getter for fragmenter instance - * - * @return $fragmenterInstance A Fragmentable instance - */ - protected final function getFragmenterInstance () { - return $this->fragmenterInstance; - } - /** * Static "getter" for this connection class' name * diff --git a/application/hub/config.php b/application/hub/config.php index bccfb4988..a6de31980 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -45,16 +45,16 @@ $cfg->setConfigEntry('enable_feature_hubcoin_reward', 'Y'); // CFG: FEATURE-HUBCOIN-REWARD-CLASS $cfg->setConfigEntry('feature_hubcoin_reward_class', 'Org\Shipsimu\Hub\Feature\CoinReward\HubcoinRewardFeature'); -// CFG: NODE-INFO-DB-WRAPPER-CLASS +// CFG: NODE-INFO-DB-FRONTEND-CLASS $cfg->setConfigEntry('node_info_db_frontend_class', 'Org\Shipsimu\Hub\Database\Frontend\Node\Information\NodeInformationDatabaseFrontend'); -// CFG: NODE-DHT-DB-WRAPPER-CLASS +// CFG: NODE-DHT-DB-FRONTEND-CLASS $cfg->setConfigEntry('node_dht_db_frontend_class', 'Org\Shipsimu\Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseFrontend'); // CFG: NODE-DHT-LIST-LIMIT $cfg->setConfigEntry('node_dht_list_limit', 20); -// CFG: PEER-LOOKUP-DB-WRAPPER-CLASS +// CFG: PEER-LOOKUP-DB-FRONTEND-CLASS $cfg->setConfigEntry('peer_state_lookup_db_frontend_class', 'Org\Shipsimu\Hub\Database\Frontend\Node\PeerState\PeerStateLookupDatabaseFrontend'); // CFG: WEB-CONTENT-TYPE @@ -1167,7 +1167,7 @@ $cfg->setConfigEntry('stacker_outgoing_queue_max_size', 2000); // CFG: CRUNCHER-TEST-UNIT-MAX-COUNT $cfg->setConfigEntry('cruncher_test_unit_max_count', 1000); -// CFG: CRUNCHER-UNIT-DB-WRAPPER-CLASS +// CFG: CRUNCHER-UNIT-DB-FRONTEND-CLASS $cfg->setConfigEntry('cruncher_unit_db_frontend_class', 'Org\Shipsimu\Hub\Database\Frontend\Cruncher\Unit\CruncherUnitDatabaseFrontend'); // CFG: CRUNCHER-RANDOM-SECRET-MESSAGE-LENGTH diff --git a/application/hub/traits/fragmenter/class_FragmentableTrait.php b/application/hub/traits/fragmenter/class_FragmentableTrait.php new file mode 100644 index 000000000..c47d4716d --- /dev/null +++ b/application/hub/traits/fragmenter/class_FragmentableTrait.php @@ -0,0 +1,55 @@ + + * @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 . + */ +trait FragmentableTrait { + /** + * Fragmenter instance + */ + private $fragmenterInstance = NULL; + + /** + * Setter for fragmenter instance + * + * @param $fragmenterInstance A Fragmentable instance + * @return void + */ + private final function setFragmenterInstance (Fragmentable $fragmenterInstance) { + $this->fragmenterInstance = $fragmenterInstance; + } + + /** + * Getter for fragmenter instance + * + * @return $fragmenterInstance A Fragmentable instance + */ + protected final function getFragmenterInstance () { + return $this->fragmenterInstance; + } + +} diff --git a/core b/core index 00571e55f..035b3221b 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 00571e55f7ea67ec80e36a3a293b0b7162c83572 +Subproject commit 035b3221bff7b542e264a9d0a4a6d086833487ef -- 2.39.5