From 6ee059cc5885e372c1a5860449fe969f47553f21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 21 Aug 2020 18:48:39 +0200 Subject: [PATCH] Continued: - Added $socketFile and $socketType properties to PackageData class - moved delivery/receiving classes/interfaces to proper packages MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.php | 6 +-- .../socket/class_SocketContainer.php | 4 +- .../factories/socket/class_SocketFactory.php | 7 ++- .../handler/chunks/class_ChunkHandler.php | 2 +- .../handler/data/class_BaseDataHandler.php | 2 +- .../package/class_NetworkPackageHandler.php | 22 +++++--- .../assembler/class_PackageAssembler.php | 4 +- .../package/deliverable/class_PackageData.php | 52 +++++++++++++++++++ .../fragmenter/class_PackageFragmenter.php | 2 +- .../class_HalfShutdownSocketVisitor.php | 2 +- .../socket/class_ShutdownSocketVisitor.php | 2 +- application/hub/config.php | 4 +- .../class_FinalChunkVerificationException.php | 2 +- .../{package => delivery}/.htaccess | 0 .../class_Deliverable.php | 2 +- .../fragmenter}/.htaccess | 0 .../fragmenter/class_Fragmentable.php | 2 +- .../fragmenter => delivery/package}/.htaccess | 0 .../package/class_DeliverablePackage.php | 33 ++++++++++++ .../{package/package => receiver}/.htaccess | 0 .../interfaces/receiver/assembler/.htaccess | 1 + .../assembler/class_Assembler.php | 2 +- .../class_Receivable.php | 0 23 files changed, 124 insertions(+), 27 deletions(-) rename application/hub/interfaces/{package => delivery}/.htaccess (100%) rename application/hub/interfaces/{package => delivery}/class_Deliverable.php (98%) rename application/hub/interfaces/{package/assembler => delivery/fragmenter}/.htaccess (100%) rename application/hub/interfaces/{package => delivery}/fragmenter/class_Fragmentable.php (97%) rename application/hub/interfaces/{package/fragmenter => delivery/package}/.htaccess (100%) rename application/hub/interfaces/{package => delivery}/package/class_DeliverablePackage.php (64%) rename application/hub/interfaces/{package/package => receiver}/.htaccess (100%) create mode 100644 application/hub/interfaces/receiver/assembler/.htaccess rename application/hub/interfaces/{package => receiver}/assembler/class_Assembler.php (96%) rename application/hub/interfaces/{package => receiver}/class_Receivable.php (100%) diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 89c498073..92e0ac5ba 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -12,10 +12,10 @@ use Org\Shipsimu\Hub\Information\ShareableInfo; use Org\Shipsimu\Hub\Listener\BaseListener; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Locator\Node\LocateableNode; -use Org\Shipsimu\Hub\Network\Deliver\Deliverable; -use Org\Shipsimu\Hub\Network\Package\Assembler\Assembler; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; +use Org\Shipsimu\Hub\Network\Package\Receiver\Assembler\Assembler; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; -use Org\Shipsimu\Hub\Network\Package\Fragment\Fragmentable; +use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\Fragmentable; use Org\Shipsimu\Hub\Network\Receive\Receivable; use Org\Shipsimu\Hub\Pool\Poolable; diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index fc57d7338..266af0e0e 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -115,8 +115,8 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita $socketInstance->setSocketProtocol($socketProtocol); // Set content/hash to null - $packageInstance->setContent(NULL); - $packageInstance->setHash(NULL); + $packageInstance->setPackageContent(NULL); + $packageInstance->setContentHash(NULL); // Set the resource ... $socketInstance->setSocketResource($socketResource); diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index ac6a9d1c2..46f99b17f 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -282,7 +282,12 @@ class SocketFactory extends ObjectFactory { ); // Create socket instance - $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData, NULL)); + $socketInstance = self::createObjectByConfiguredName('socket_container_class', array( + $socketResource, + StorableSocket::SOCKET_PROTOCOL_TCP, + $packageData, + NULL + )); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { diff --git a/application/hub/classes/handler/chunks/class_ChunkHandler.php b/application/hub/classes/handler/chunks/class_ChunkHandler.php index 3a5eb5fde..f3c508a23 100644 --- a/application/hub/classes/handler/chunks/class_ChunkHandler.php +++ b/application/hub/classes/handler/chunks/class_ChunkHandler.php @@ -5,7 +5,7 @@ namespace Org\Shipsimu\Hub\Handler\Network\RawData\Chunks; // Import application-specific stuff use Org\Shipsimu\Hub\Factory\Fragmenter\FragmenterFactory; use Org\Shipsimu\Hub\Handler\BaseHubHandler; -use Org\Shipsimu\Hub\Network\Package\Fragment\PackageFragmenter; +use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter; // Import framework stuff use Org\Mxchange\CoreFramework\Assertion\AssertionException; diff --git a/application/hub/classes/handler/data/class_BaseDataHandler.php b/application/hub/classes/handler/data/class_BaseDataHandler.php index b93588508..59a939740 100644 --- a/application/hub/classes/handler/data/class_BaseDataHandler.php +++ b/application/hub/classes/handler/data/class_BaseDataHandler.php @@ -6,7 +6,7 @@ namespace Org\Shipsimu\Hub\Handler\Data; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Handler\BaseHubHandler; -use Org\Shipsimu\Hub\Network\Deliver\Deliverable; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\ObjectFactory; diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 84aa1d584..92259970b 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -18,10 +18,10 @@ use Org\Shipsimu\Hub\Handler\Network\RawData\HandleableRawData; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; use Org\Shipsimu\Hub\Helper\HubHelper; use Org\Shipsimu\Hub\Information\ShareableInfo; -use Org\Shipsimu\Hub\Network\Deliver\Deliverable; +use Org\Shipsimu\Hub\Network\Delivery\Deliverable; use Org\Shipsimu\Hub\Network\Networkable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; -use Org\Shipsimu\Hub\Network\Package\Fragment\PackageFragmenter; +use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter; use Org\Shipsimu\Hub\Network\Receive\Receivable; use Org\Shipsimu\Hub\Node\Generic\InvalidPrivateKeyHashException; use Org\Shipsimu\Hub\Tag\Tagable; @@ -837,9 +837,9 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setSenderAddress($this->getSessionId()); $packageInstance->setSenderPort('0'); $packageInstance->setRecipientType($helperInstance->getRecipientType()); - $packageInstance->setContent($packageContent); + $packageInstance->setPackageContent($packageContent); $packageInstance->setStatus(self::PACKAGE_STATUS_NEW); - $packageInstance->setHash($this->generatePackageHash($content, $this->getSessionId())); + $packageInstance->setContentHash($this->generatePackageHash($content, $this->getSessionId())); $packageInstance->setPrivateKeyHash($this->getPrivateKeyHash()); // Now prepare the temporary array and push it on the 'undeclared' stack @@ -856,7 +856,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isPackageEnqueued () { // Check whether the stacker is not empty - $isEnqueued = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED))); + $isEnqueued = ( + ($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_UNDECLARED)) && + (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_UNDECLARED)) + ); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isEnqueued=%d - EXIT!', intval($isEnqueued))); @@ -872,7 +875,10 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei */ public function isPackageDeclared () { // Check whether the stacker is not empty - $isDeclared = (($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECLARED))); + $isDeclared = ( + ($this->getStackInstance()->isStackInitialized(self::STACKER_NAME_DECLARED)) && + (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECLARED)) + ); // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NETWORK-PACKAGE: isDeclared=%d - EXIT!', intval($isDeclared))); @@ -1368,9 +1374,9 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei $packageInstance->setSenderAddress($decodedArray[self::INDEX_PACKAGE_SENDER_ADDRESS]); $packageInstance->setSenderPort($decodedArray[self::INDEX_PACKAGE_SENDER_PORT]); $packageInstance->setRecipient($decodedArray[self::INDEX_PACKAGE_RECIPIENT]); - $packageInstance->setContent($decodedArray[self::INDEX_PACKAGE_CONTENT]); + $packageInstance->setPackageContent($decodedArray[self::INDEX_PACKAGE_CONTENT]); $packageInstance->setStatus(self::PACKAGE_STATUS_DECODED); - $packageInstance->setHash($decodedArray[self::INDEX_PACKAGE_HASH]); + $packageInstance->setContentHash($decodedArray[self::INDEX_PACKAGE_HASH]); $packageInstance->setPrivateKeyHash($decodedArray[self::INDEX_PACKAGE_PRIVATE_KEY_HASH]); // And return it diff --git a/application/hub/classes/package/assembler/class_PackageAssembler.php b/application/hub/classes/package/assembler/class_PackageAssembler.php index 836ac7605..b14d0095b 100644 --- a/application/hub/classes/package/assembler/class_PackageAssembler.php +++ b/application/hub/classes/package/assembler/class_PackageAssembler.php @@ -1,6 +1,6 @@ . */ class PackageData extends BaseHubSystem implements DeliverablePackage, Registerable { + + /** + * An instance of a SplFileInfo class + */ + private $socketFile; + + /** + * Socket type + */ + private $socketType; + /** * Protected constructor * @@ -54,4 +68,42 @@ class PackageData extends BaseHubSystem implements DeliverablePackage, Registera return $packageInstance; } + /** + * Getter for socket file instance + * + * @return $socketFile An instance of a SplFileInfo class + */ + public function getSocketFile () { + return $this->socketFile; + } + + /** + * Setter for socket file instance + * + * @param $socketFile An instance of a SplFileInfo class + * @return void + */ + public function setSocketFile (SplFileInfo $socketFile) { + $this->socketFile = $socketFile; + } + + /** + * Getter for socket type + * + * @return $socketFile Stocket type + */ + public function getSocketType () { + return $this->socketType; + } + + /** + * Setter for socket type + * + * @param $socketType Socket type + * @return void + */ + public function setSocketType ($socketType) { + $this->socketType = $socketType; + } + } diff --git a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php index 7869833a9..5e10f3fc1 100644 --- a/application/hub/classes/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/classes/package/fragmenter/class_PackageFragmenter.php @@ -1,6 +1,6 @@ setConfigEntry('allow_publish_internal_address', 'N'); $cfg->setConfigEntry('node_status', 'invalid'); // CFG: PACKAGE-FRAGMENTER-CLASS -$cfg->setConfigEntry('package_fragmenter_class', 'Org\Shipsimu\Hub\Network\Package\Fragment\PackageFragmenter'); +$cfg->setConfigEntry('package_fragmenter_class', 'Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter'); // CFG: PACKAGE-ASSEMBLER-CLASS -$cfg->setConfigEntry('package_assembler_class', 'Org\Shipsimu\Hub\Network\Package\Assembler\PackageAssembler'); +$cfg->setConfigEntry('package_assembler_class', 'Org\Shipsimu\Hub\Network\Package\Receiver\Assembler\PackageAssembler'); // CFG: PACKAGE-CHUNK-SIZE $cfg->setConfigEntry('package_chunk_size', 256*8); diff --git a/application/hub/exceptions/package/class_FinalChunkVerificationException.php b/application/hub/exceptions/package/class_FinalChunkVerificationException.php index 94fa3e745..ae04a1699 100644 --- a/application/hub/exceptions/package/class_FinalChunkVerificationException.php +++ b/application/hub/exceptions/package/class_FinalChunkVerificationException.php @@ -3,7 +3,7 @@ namespace Org\Shipsimu\Hub\Node\Network\Chunk; // Import application-specific stuff -use Org\Shipsimu\Hub\Network\Package\Fragment\PackageFragmenter; +use Org\Shipsimu\Hub\Network\Package\Delivery\Fragment\PackageFragmenter; // Import framework stuff use Org\Mxchange\CoreFramework\Generic\FrameworkException; diff --git a/application/hub/interfaces/package/.htaccess b/application/hub/interfaces/delivery/.htaccess similarity index 100% rename from application/hub/interfaces/package/.htaccess rename to application/hub/interfaces/delivery/.htaccess diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/delivery/class_Deliverable.php similarity index 98% rename from application/hub/interfaces/package/class_Deliverable.php rename to application/hub/interfaces/delivery/class_Deliverable.php index 53b7906d3..966db5559 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/delivery/class_Deliverable.php @@ -1,6 +1,6 @@