From 506b1b974ebbf7df9411aaa9c90d5f254bacbffa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 22 Aug 2025 05:38:23 +0200 Subject: [PATCH] Upgrade to latest 'core' changes: - missing type-hints added - some new methods added - SocketRegistryFactory moved from 'core' - many small bugfixes - updated 'core' framework --- application/hub/class_ApplicationHelper.php | 17 ++- .../socket/class_SocketContainer.php | 140 ++++++++++-------- ...deDistributedHashTableDatabaseFrontend.php | 44 +++--- .../class_NodeInformationDatabaseFrontend.php | 13 +- .../protocol/class_ProtocolDiscovery.php | 5 +- .../socket/class_PackageSocketDiscovery.php | 12 +- .../info/class_ConnectionInfoFactory.php | 3 +- .../class_ObjectTypeRegistryFactory.php | 0 .../socket/class_SocketRegistryFactory.php | 79 ++++++++++ .../factories/socket/class_SocketFactory.php | 18 +-- .../package/class_NetworkPackageHandler.php | 92 ++++++------ .../protocol/class_BaseProtocolHandler.php | 11 +- .../ipv4/class_BaseIpV4ProtocolHandler.php | 8 +- .../connection/class_BaseConnectionHelper.php | 4 +- .../ipv4/class_BaseIpV4ConnectionHelper.php | 8 +- .../info/connection/class_ConnectionInfo.php | 24 +-- .../classes/listener/class_BaseListener.php | 45 +++--- .../listener/class_BaseListenerDecorator.php | 31 ++-- .../socket/class_SocketFileListener.php | 10 +- .../class_SocketFileListenerDecorator.php | 8 +- .../listener/tcp/class_TcpListener.php | 6 +- .../class_ClientTcpListenerDecorator.php | 8 +- .../class_HubTcpListenerDecorator.php | 8 +- .../listener/udp/class_UdpListener.php | 8 +- .../class_ClientUdpListenerDecorator.php | 8 +- .../class_HubUdpListenerDecorator.php | 8 +- .../hub/classes/lists/hub/class_HubList.php | 11 +- .../lists/pool/class_PoolEntriesList.php | 11 +- .../lists/recipient/class_RecipientList.php | 11 +- .../hub/classes/nodes/class_BaseHubNode.php | 86 +++++------ .../pools/peer/class_DefaultPeerPool.php | 8 +- .../registry/socket/class_SocketRegistry.php | 22 +-- .../protocol/class_BaseProtocolResolver.php | 4 +- .../tags/package/class_PackageTags.php | 13 +- .../class_XmlObjectRegistryTemplateEngine.php | 38 ++--- .../class_NoSocketRegisteredException.php | 2 +- .../container/socket/class_StorableSocket.php | 81 +++++----- .../node_dht/class_NodeDhtFrontend.php | 37 ++--- .../socket/class_DiscoverableSocket.php | 6 +- .../protocol/class_HandleableProtocol.php | 10 +- .../connections/class_ConnectionHelper.php | 4 +- .../interfaces/listener/class_Listenable.php | 19 +-- .../pool/peer/class_PoolablePeer.php | 2 +- .../socket/class_RegisterableSocket.php | 8 +- .../shareable/info/class_ShareableInfo.php | 4 +- .../hub/interfaces/socket/class_SocketTag.php | 3 +- .../hub/interfaces/tags/class_Tagable.php | 5 +- .../socket/class_StorableSocketTrait.php | 13 +- core | 2 +- 49 files changed, 572 insertions(+), 446 deletions(-) rename application/hub/classes/factories/registry/{ => object}/class_ObjectTypeRegistryFactory.php (100%) create mode 100644 application/hub/classes/factories/registry/socket/class_SocketRegistryFactory.php diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 8680157e4..667b76543 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -69,9 +69,9 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * * @return $selfInstance An instance of this class */ - public static final function getSelfInstance () { + public static final function getSelfInstance (): ManageableApplication { // Is the instance there? - if (is_null(self::getApplicationInstance())) { + if (!self::isApplicationInstanceSet()) { self::setApplicationInstance(new ApplicationHelper()); } @@ -84,7 +84,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * * @return void */ - public function setupApplicationData () { + public function setupApplicationData (): void { // Set all application data $this->setAppName('Generic Object Sharing Hub'); $this->setAppVersion('0.0.0'); @@ -96,7 +96,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * * @return void */ - public function initApplication () { + public function initApplication (): void { // Get config instance $cfg = FrameworkBootstrap::getConfigurationInstance(); @@ -118,7 +118,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * * @return void */ - public function launchApplication () { + public function launchApplication (): void { // Get request/response instances $requestInstance = FrameworkBootstrap::getRequestInstance(); $responseInstance = FrameworkBootstrap::getResponseInstance(); @@ -183,7 +183,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * @return void * @todo Nothing to add? */ - public function assignExtraTemplateData (CompileableTemplate $templateInstance) { + public function assignExtraTemplateData (CompileableTemplate $templateInstance): void { } /** @@ -193,7 +193,7 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * @param $messageList An array of fatal messages * @return void */ - public function handleFatalMessages (array $messageList) { + public function handleFatalMessages (array $messageList): void { // Walk through all messages foreach ($messageList as $message) { exit(__METHOD__ . ':MSG:' . $message); @@ -205,7 +205,8 @@ class ApplicationHelper extends BaseApplication implements ManageableApplication * * @return $masterTemplateName Name of the master template */ - public function buildMasterTemplateName () { + public function buildMasterTemplateName (): string { return 'node_daemon'; } + } diff --git a/application/hub/classes/container/socket/class_SocketContainer.php b/application/hub/classes/container/socket/class_SocketContainer.php index deb1f36fe..b84889c14 100644 --- a/application/hub/classes/container/socket/class_SocketContainer.php +++ b/application/hub/classes/container/socket/class_SocketContainer.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Container\Socket; // Import application-specific stuff use Org\Shipsimu\Hub\Container\BaseHubContainer; +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; @@ -156,7 +157,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $containerInstance An instance of a StorableSocket class * @throws InvalidArgumentException If a parameter is not valid */ - public static final function createSocketContainer (Socket $socketResource, string $socketProtocol, DeliverablePackage $packageInstance, string $socketType) { + public static final function createSocketContainer (Socket $socketResource, string $socketProtocol, DeliverablePackage $packageInstance, string $socketType): StorableSocket { // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-CONTAINER: socketResource[]=%s,socketProtocol=%s,packageInstance=%s,socketType=%s - CALLED!', gettype($socketResource), $socketProtocol, $packageInstance->__toString(), $socketType)); if (empty($socketProtocol)) { @@ -191,7 +192,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $matches Whether $address matches with the one from package data * @throws InvalidArgumentException If a parameter is not valid */ - public function ifAddressMatches (string $unl) { + public function ifAddressMatches (string $unl): bool { // Is parameter valid? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: unl=%s - CALLED!', strtoupper($this->getSocketProtocol()), $unl)); if (empty($unl)) { @@ -220,7 +221,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $socketResource An instance of a Socket class * @return $matches Whether given socket matches */ - public function ifSocketResourceMatches (Socket $socketResource) { + public function ifSocketResourceMatches (Socket $socketResource): bool { // So, does both match? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: socketResource[]=%s,storedResource[]=%s - CALLED!', strtoupper($this->getSocketProtocol()), gettype($socketResource)), gettype($this->getSocketResource())); $matches = ($socketResource === $this->getSocketResource()); @@ -236,9 +237,9 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return void */ - public function shutdownSocket () { + public function shutdownSocket (): void { // Debug message - self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getPrintableName() . ' with state ' . ($this->getHelperInstance() instanceof Helper ? $this->getHelperInstance()->getPrintableState() : 'NULL') . ' ...'); + self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(strtoupper($this->getSocketProtocol()) . '-SOCKET: Shutting down socket ' . $this->getPrintableName() . ' with state ' . ($this->isHelperInstanceSet() ? $this->getHelperInstance()->getPrintableState() : 'NULL') . ' ...'); // Get a visitor instance $visitorInstance = ObjectFactory::createObjectByConfiguredName('shutdown_socket_visitor_class'); @@ -259,7 +260,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return void */ - public function halfShutdownSocket () { + public function halfShutdownSocket (): void { // Debug message self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(strtoupper($this->getSocketProtocol()) . '-SOCKET: Half-shutting down socket resource ' . $this->getPrintableName() . ' with state ' . $this->getHelperInstance()->getPrintableState() . ' ...'); @@ -299,7 +300,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $result Result from asking for peer address * @throws InvalidSocketException If socket is invalid */ - public function determineSocketPeerName (string &$peerAddress, int &$peerPort) { + public function determineSocketPeerName (string &$peerAddress, int &$peerPort): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: peerAddress[%s]=%s,peerPort[%s]=%d - CALLED!', strtoupper($this->getSocketProtocol()), gettype($peerAddress), $peerAddress, gettype($peerPort), $peerPort)); if (!$this->isValidSocket()) { @@ -333,7 +334,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $socketProtocol Socket protocol */ - public function getSocketProtocol () { + public function getSocketProtocol (): string { // Return it return $this->socketProtocol; } @@ -345,7 +346,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws LogicException If 'recipient' array element is not found * @throws InvalidSocketException If socket is invalid */ - public function getSocketRecipientUnl () { + public function getSocketRecipientUnl (): string { // Should be valid socket //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -367,7 +368,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $recipientAddress Recipient's address part * @throws InvalidSocketException If socket is invalid */ - public function getSocketRecipientAddress () { + public function getSocketRecipientAddress (): string { // Should be valid socket //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -396,7 +397,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $recipientPort Recipient's port part * @throws InvalidSocketException If socket is invalid */ - public function getSocketRecipientPort () { + public function getSocketRecipientPort (): int { // Should be valid socket //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -424,7 +425,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $isValidSocket Whether the stored socket is valid */ - public function isValidSocket () { + public function isValidSocket (): bool { // Is it valid? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); // @TODO maybe add more checks? instanceof is still to less @@ -441,7 +442,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $errorCode Last socket error * @throws InvalidSocketException If socket is invalid */ - public function getLastSocketErrorCode () { + public function getLastSocketErrorCode (): int { // Should be valid socket //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -463,7 +464,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $errorMessage Last socket error message * @throws InvalidSocketException If socket is invalid */ - public function getLastSocketErrorMessage () { + public function getLastSocketErrorMessage (): string { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -484,7 +485,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $codeName Code name to used e.g. with some_$codeName_socket_error_class or so */ - public function translateLastSocketErrorCodeToName () { + public function translateLastSocketErrorCodeToName (): string { // Get last error code /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $errorCode = $this->getLastSocketErrorCode(); @@ -505,13 +506,13 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws InvalidSocketException If socket is invalid * @throws NullPointerException If listener instance is not given */ - public function bindSocketToFile () { + public function bindSocketToFile (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { // Throw exception throw new InvalidSocketException([$this], self::EXCEPTION_INVALID_SOCKET); - } elseif (is_null($this->getSocketFile())) { + } elseif (!$this->isSocketFileSet()) { // Throw exception throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); } @@ -534,7 +535,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws InvalidSocketException If socket is invalid * @throws NullPointerException If listener instance is not given */ - public function bindSocketToListener () { + public function bindSocketToListener (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -564,7 +565,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $result Result from listening on socket * @throws InvalidSocketException If stored socket is invalid */ - public function listenToSocket () { + public function listenToSocket (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -586,7 +587,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $result Result of changing to non-blocking I/O * @throws InvalidSocketException If stored socket is invalid */ - public function enableSocketNonBlocking () { + public function enableSocketNonBlocking (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -605,10 +606,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita /** * Tries to enable option "reuse address" * - * @return void + * @return $result Result of setting socket option * @throws InvalidSocketException If stored socket is invalid */ - public function enableSocketReuseAddress () { + public function enableSocketReuseAddress (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -630,7 +631,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $result Result from calling socket_connect() * @throws InvalidSocketException If stored socket is invalid */ - public function connectToSocketRecipient () { + public function connectToSocketRecipient (): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -711,7 +712,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $isValid Whether the provided connection type is valid * @throws InvalidArgumentException If $connectionType is empty */ - public function isValidConnectionType (string $connectionType) { + public function isValidConnectionType (string $connectionType): bool { // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: connectionType=%d - CALLED!', strtoupper($this->getSocketProtocol()), $connectionType)); if (empty($connectionType)) { @@ -730,10 +731,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita /** * Calls socket_select() on stored socket resource * - * @return $socketInstance An instance of a StorableSocket class + * @return $socketInstance An instance of a StorableSocket class or NULL if no new socket was detected * @throws InvalidSocketException If stored socket is invalid */ - public function acceptNewIncomingSocket () { + public function acceptNewIncomingSocket (): ?StorableSocket { // Should be valid socket /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -790,10 +791,10 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita /** * Reads (binary) data from socket instance * - * @return $rawData Raw data being read + * @return $rawData Raw data being read or FALSE on error * @throws InvalidSocketException If the stored socket is not valid */ - public function readDataFromSocket () { + public function readDataFromSocket (): mixed { // Should be valid socket /* EXTREME-NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -819,7 +820,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $result Whether identifying socket peer was successfull */ - public function identifySocketPeer () { + public function identifySocketPeer (): bool { // Init peer address (IP)/port /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $peerAddress = '0.0.0.0'; @@ -846,7 +847,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $result Whether the option has been set */ - public function setSocketTimeoutOptions () { + public function setSocketTimeoutOptions (): bool { // Call setter method with configured values /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $result = $this->setSocketOption(SOL_SOCKET, SO_RCVTIMEO, [ @@ -866,7 +867,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $result Whether OOB has been enabled */ - public function enableSocketOutOfBandData () { + public function enableSocketOutOfBandData (): bool { // Call inner method /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $result = $this->setSocketOption(SOL_SOCKET, SO_OOBINLINE, 1); @@ -883,7 +884,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws InvalidSocketException If stored socket is invalid * @throws BadMethodCallException If no socket error was reported but method called */ - public function clearLastSocketError () { + public function clearLastSocketError (): void { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: Clearing socket error, this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); if (!$this->isValidSocket()) { @@ -908,11 +909,11 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $infoInstance An instance of a ShareableInfo class * @return void */ - public function registerInfoInstance (ShareableInfo $infoInstance) { + public function registerInfoInstance (ShareableInfo $infoInstance): void { // Get listener/helper from info class /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: infoInstance=%s,this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $infoInstance->__toString(), $this->getPrintableName())); $listenerInstance = $infoInstance->getListenerInstance(); - $helperInstance = $infoInstance->getHelperInstance(); + $helperInstance = $infoInstance->isHelperInstanceSet() ? $infoInstance->getHelperInstance() : NULL; // Is there a listener or a connection helper instance set? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-SOCKET: listenerInstance[]=%s,helperInstance[]=%s', strtoupper($this->getSocketProtocol()), gettype($listenerInstance), gettype($helperInstance))); @@ -944,7 +945,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws InvalidSocketException If stored socket is invalid * @throws InvalidArgumentException If an array element is missing */ - public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes) { + public function writeBufferToSocketByArray (array &$socketBuffer, &$sentBytes): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: socketBuffer()=%d,sentBytes=%d - CALLED!', strtoupper($this->getSocketProtocol()), count($socketBuffer), $sentBytes)); //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('%s-SOCKET: socketBuffer=%s', strtoupper($this->getSocketProtocol()), print_r($socketBuffer, TRUE))); @@ -1026,7 +1027,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @throws InvalidSocketException If the stored socket resource is no socket resource * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back */ - public function handleSocketError (string $method, int $line) { + public function handleSocketError (string $method, int $line): void { // This method handles only socket resources /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: method=%s,line=%d,lastSocketErrorCode=%d - CALLED!', strtoupper($this->getSocketProtocol()), $method, $line, $this->getLastSocketErrorCode())); if (!$this->isValidSocket()) { @@ -1065,7 +1066,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $handlerName Call-back method name for the error handler * @throws UnsupportedSocketErrorHandlerException If the error handler is not implemented */ - protected function getSocketErrorHandlerFromCode (int $errorCode) { + protected function getSocketErrorHandlerFromCode (int $errorCode): string { // Create a name from translated error code /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: errorCode=%d - CALLED!', strtoupper($this->getSocketProtocol()), $errorCode)); $handlerName = 'handleSocketError' . StringUtils::convertToClassName($this->translateSocketErrorCodeToName($errorCode)); @@ -1092,7 +1093,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketBindingException The socket could not be bind to */ - protected function handleSocketErrorPermissionDenied () { + protected function handleSocketErrorPermissionDenied (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1114,7 +1115,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorConnectionTimedOut () { + protected function handleSocketErrorConnectionTimedOut (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1136,7 +1137,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorResourceUnavailable () { + protected function handleSocketErrorResourceUnavailable (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1158,7 +1159,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorConnectionRefused () { + protected function handleSocketErrorConnectionRefused (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1180,7 +1181,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorNoRouteToHost () { + protected function handleSocketErrorNoRouteToHost (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1202,7 +1203,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorOperationAlreadyProgress () { + protected function handleSocketErrorOperationAlreadyProgress (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1224,7 +1225,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketConnectionException The connection attempts fails with a time-out */ - protected function handleSocketErrorConnectionResetByPeer () { + protected function handleSocketErrorConnectionResetByPeer (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1246,7 +1247,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return void * @throws SocketOperationException The connection attempts fails with a time-out */ - protected function handleSocketErrorOperationNotSupported () { + protected function handleSocketErrorOperationNotSupported (): void { // Get socket error code for verification /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); $socketError = $this->getLastSocketErrorCode(); @@ -1267,7 +1268,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return void */ - protected function handleSocketErrorOperationInProgress () { + protected function handleSocketErrorOperationInProgress (): void { // Very common with non-blocking I/O /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: this->socketResource=%s - CALLED!', strtoupper($this->getSocketProtocol()), $this->getPrintableName())); self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(strtoupper($this->getSocketProtocol()) . '-HELPER: Operation is now in progress, this is usual for non-blocking connections and is no bug.'); @@ -1284,7 +1285,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $errorCode The error code from socket_last_error() to be translated * @return $errorName The translated name (all lower-case, with underlines) */ - private function translateSocketErrorCodeToName (int $errorCode) { + private function translateSocketErrorCodeToName (int $errorCode): string { // Unknown error code by default /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: errorCode=%d - CALLED!', strtoupper($this->getSocketProtocol()), $errorCode)); $errorName = StorableSocket::SOCKET_ERROR_UNKNOWN; @@ -1361,7 +1362,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @return $result Whether calling socket_set_option() was successfull * @throws InvalidSocketException If stored socket is invalid */ - private function setSocketOption (int $level, int $optionName, $optionValue) { + private function setSocketOption (int $level, int $optionName, mixed $optionValue): bool { // Should be valid socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-SOCKET: level=%d,optionName=%d,optionValue[]=%s - CALLED!', strtoupper($this->getSocketProtocol()), $level, $optionName, gettype($optionValue))); if (!$this->isValidSocket()) { @@ -1383,7 +1384,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $socketProtocol Socket protocol * @return void */ - private function setSocketProtocol (string $socketProtocol) { + private function setSocketProtocol (string $socketProtocol): void { $this->socketProtocol = $socketProtocol; } @@ -1393,7 +1394,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $packageDataInstance An instance of a DeliverablePackage class * @return void */ - public function setPackageDataInstance (DeliverablePackage $packageDataInstance) { + public function setPackageDataInstance (DeliverablePackage $packageDataInstance): void { $this->packageDataInstance = $packageDataInstance; } @@ -1402,7 +1403,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $packageDataInstance An instance of a DeliverablePackage class */ - public function getPackageDataInstance () { + public function getPackageDataInstance (): DeliverablePackage { return $this->packageDataInstance; } @@ -1411,7 +1412,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $socketFile An instance of a SplFileInfo class */ - public function getSocketFile () { + public function getSocketFile (): SplFileInfo { return $this->socketFile; } @@ -1421,16 +1422,25 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $socketFile An instance of a SplFileInfo class * @return void */ - public function setSocketFile (SplFileInfo $socketFile) { + public function setSocketFile (SplFileInfo $socketFile): void { $this->socketFile = $socketFile; } + /** + * Checks whether a socket file instance is set + * + * @return $isset Whether a socket file instance is set + */ + public function isSocketFileSet (): bool { + return ($this->socketFile instanceof SplFileInfo); + } + /** * Getter for socket type * * @return $socketType Socket type */ - public function getSocketType () { + public function getSocketType (): string { return $this->socketType; } @@ -1440,7 +1450,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $socketType Socket type * @return void */ - protected function setSocketType (string $socketType) { + protected function setSocketType (string $socketType): void { $this->socketType = $socketType; } @@ -1449,7 +1459,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $peerAddress Peer address */ - public function getPeerAddress () { + public function getPeerAddress (): string { return $this->peerAddress; } @@ -1459,7 +1469,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $peerAddress Peer address * @return void */ - public function setPeerAddress (string $peerAddress) { + public function setPeerAddress (string $peerAddress): void { $this->peerAddress = $peerAddress; } @@ -1468,7 +1478,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $peerPort Peer port */ - public function getPeerPort () { + public function getPeerPort (): int { return $this->peerPort; } @@ -1478,7 +1488,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $peerPort Peer port * @return void */ - public function setPeerPort (int $peerPort) { + public function setPeerPort (int $peerPort): void { $this->peerPort = $peerPort; } @@ -1487,7 +1497,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $senderAddress Sender address */ - public function getSenderAddress () { + public function getSenderAddress (): string { return $this->senderAddress; } @@ -1497,7 +1507,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $senderAddress Sender address * @return void */ - public function setSenderAddress (string $senderAddress) { + public function setSenderAddress (string $senderAddress): void { $this->senderAddress = $senderAddress; } @@ -1506,7 +1516,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $senderPort Sender port */ - public function getSenderPort () { + public function getSenderPort (): int { return $this->senderPort; } @@ -1516,7 +1526,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $senderPort Sender port * @return void */ - public function setSenderPort (int $senderPort) { + public function setSenderPort (int $senderPort): void { $this->senderPort = $senderPort; } @@ -1526,7 +1536,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * @param $socketResource An instance of a Socket class * @return void */ - public final function setSocketResource (Socket $socketResource) { + public final function setSocketResource (Socket $socketResource): void { $this->socketResource = $socketResource; } @@ -1535,7 +1545,7 @@ class SocketContainer extends BaseHubContainer implements StorableSocket, Visita * * @return $socketResource A valid socket resource */ - public final function getSocketResource () { + public final function getSocketResource (): Socket { return $this->socketResource; } 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 a00289b8d..ed82befd4 100644 --- a/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/node_dht/class_NodeDistributedHashTableDatabaseFrontend.php @@ -90,7 +90,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return $frontendInstance An instance of the created frontend class */ - public static final function createNodeDistributedHashTableDatabaseFrontend () { + public static final function createNodeDistributedHashTableDatabaseFrontend (): NodeDhtFrontend { // Get a new instance $frontendInstance = new NodeDistributedHashTableDatabaseFrontend(); @@ -113,7 +113,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return $elements All elements for the DHT dabase */ - public static final function getAllElements () { + public static final function getAllElements (): array { // Create array and ... $elements = [ self::DB_COLUMN_NODE_ID, @@ -135,7 +135,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $nodeData An array with valid node data * @return $searchInstance An instance of a SearchCriteria class */ - private function prepareSearchInstance (array $nodeData) { + private function prepareSearchInstance (array $nodeData): SearchableResult { // Assert on array elements /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); assert(isset($nodeData[self::DB_COLUMN_NODE_ID])); @@ -159,7 +159,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return $dataSetInstance An instance of a StoreableCriteria class */ - private function prepareLocalDataSetInstance () { + private function prepareLocalDataSetInstance (): StoreableCriteria { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -211,7 +211,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return $unpublishedEntriesInstance Result instance */ - public final function getUnpublishedEntriesInstance () { + public final function getUnpublishedEntriesInstance (): SearchableResult { return $this->unpublishedEntriesInstance; } @@ -221,7 +221,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return $isRegistered Whether *this* node is registered in the DHT */ - public function isLocalNodeRegistered () { + public function isLocalNodeRegistered (): bool { // Get a search criteria instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -257,7 +257,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return void */ - public function registerLocalNode () { + public function registerLocalNode (): void { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -282,7 +282,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return void * @throws BadMethodCallException If node is not locally registered */ - public function updateLocalNode () { + public function updateLocalNode (): void { // Check condition //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); if (!$this->isLocalNodeRegistered()) { @@ -317,7 +317,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return $resultInstance An instance of a SearchableResult class * @throws InvalidArgumentException If parameter $sessionId is not valid */ - public function findNodeLocalBySessionId (string $sessionId) { + public function findNodeLocalBySessionId (string $sessionId): SearchableResult { // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: sessionId=%s - CALLED!', $sessionId)); if (empty($sessionId)) { @@ -346,7 +346,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $locatorInstance An instance of a LocateableNode class * @return $resultInstance An instance of a SearchableResult class */ - public function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance) { + public function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance): SearchableResult { // Get search criteria /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: locatorInstance=%s - CALLED!', $locatorInstance->__toString())); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -371,7 +371,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $handlerInstance An instance of a HandleableDataSet class * @return void */ - public function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance) { + public function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance): void { // 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)); @@ -400,7 +400,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $searchInstance An instance of LocalSearchCriteria class * @return void */ - public function updateNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance) { + public function updateNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance): void { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -432,7 +432,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $nodeData An array with valid node data * @return $isRegistered Whether the given node data is already inserted */ - public function isNodeRegistered (array $nodeData) { + public function isNodeRegistered (array $nodeData): bool { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -474,7 +474,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return void * @throws NodeAlreadyRegisteredException If the node is already registered */ - public function registerNode (array $nodeData) { + public function registerNode (array $nodeData): void { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -503,7 +503,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return void * @throws NodeDataMissingException If the node's data is missing */ - public function updateNode (array $nodeData) { + public function updateNode (array $nodeData): void { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: nodeData=' . print_r($nodeData, TRUE)); //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -551,7 +551,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return $hasUnpublished Whether there are unpublished entries * @todo Add minimum/maximum age limitations */ - public function hasUnpublishedEntries () { + public function hasUnpublishedEntries (): bool { // Get search instance $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -582,7 +582,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return void * @todo Add timestamp to dataset instance */ - public function initEntryPublication () { + public function initEntryPublication (): void { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -625,7 +625,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @param $data An array with possible non-public data that needs to be removed. * @return $data A cleaned up array with only public data. */ - public function removeNonPublicDataFromArray(array $data) { + public function removeNonPublicDataFromArray(array $data): array { // Currently call only inner method //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Invoking parent::removeNonPublicDataFromArray(data) ...'); $data = parent::removeNonPublicDataFromArray($data); @@ -639,9 +639,9 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * Find recipients for given package data and exclude the sender * * @param $packageInstance An instance of a DeliverablePackage class - * @return $recipients An indexed array with DHT recipients + * @return $resultInstance An instance of a SearchableResult class */ - public function getResultFromExcludedSender (DeliverablePackage $packageInstance) { + public function getResultFromExcludedSender (DeliverablePackage $packageInstance): SearchableResult { // Debug message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: CALLED!'); @@ -676,7 +676,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * @return $recipients An indexed array with DHT recipients * @throws InvalidArgumentException If $key is empty */ - public function getResultFromKeyValue (string $key, $value) { + public function getResultFromKeyValue (string $key, mixed $value): array { // Is key parameter valid? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('DHT-FRONTEND: key=%s,value[%s]=%s - CALLED!', $key, gettype($value), $value)); if (empty($key)) { @@ -706,7 +706,7 @@ class NodeDistributedHashTableDatabaseFrontend extends BaseHubDatabaseFrontend i * * @return void */ - public function enableAcceptDhtBootstrap () { + public function enableAcceptDhtBootstrap (): void { // Debug message /* DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-FRONTEND: Enabling DHT bootstrap requests ...'); 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 f843bf4ed..5556678a4 100644 --- a/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php +++ b/application/hub/classes/database/frontend/node_information/class_NodeInformationDatabaseFrontend.php @@ -12,6 +12,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Registry\Registerable; +use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; /** * A database frontend for node informations @@ -64,7 +65,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * * @return $frontendInstance An instance of the created frontend class */ - public static final function createNodeInformationDatabaseFrontend () { + public static final function createNodeInformationDatabaseFrontend (): NodeInformationFrontend { // Get a new instance $frontendInstance = new NodeInformationDatabaseFrontend(); @@ -80,7 +81,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * * @return $resultInstance An instance of a SearchableResult class */ - public function findFirstNodeData () { + public function findFirstNodeData (): ?SearchableResult { // Is there cache? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FRONTEND: CALLED!'); if (!isset($GLOBALS[__METHOD__])) { @@ -112,7 +113,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * @param $nodeInstance An instance of a Node class * @return void */ - public function registerNodeId (Node $nodeInstance) { + public function registerNodeId (Node $nodeInstance): void { // Get a dataset instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION)); @@ -134,7 +135,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * @param $searchInstance An instance of a LocalSearchCriteria class * @return void */ - public function registerSessionId (Node $nodeInstance, LocalSearchCriteria $searchInstance) { + public function registerSessionId (Node $nodeInstance, LocalSearchCriteria $searchInstance): void { // Get a dataset instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION)); @@ -159,7 +160,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * @param $searchInstance An instance of a LocalSearchCriteria class * @return void */ - public function registerPrivateKey (Node $nodeInstance, LocalSearchCriteria $searchInstance) { + public function registerPrivateKey (Node $nodeInstance, LocalSearchCriteria $searchInstance): void { // Get a dataset instance $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION)); @@ -182,7 +183,7 @@ class NodeInformationDatabaseFrontend extends BaseHubDatabaseFrontend implements * @param $data An array with possible non-public data that needs to be removed. * @return $data A cleaned up array with only public data. */ - public function removeNonPublicDataFromArray(array $data) { + public function removeNonPublicDataFromArray(array $data): array { // Currently call only inner method //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FRONTEND: Invoking parent::removeNonPublicDataFromArray(data) ...'); $data = parent::removeNonPublicDataFromArray($data); diff --git a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php index d1caa2845..626e3e47c 100644 --- a/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php +++ b/application/hub/classes/discovery/protocol/class_ProtocolDiscovery.php @@ -5,6 +5,7 @@ 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\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; // Import framework stuff @@ -65,7 +66,7 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco * @param $packageInstance An instance of a DeliverablePackage class * @return $protocolInstance An instance of a HandleableProtocol class */ - public static final function determineProtocolByPackageInstance (DeliverablePackage $packageInstance) { + public static final function determineProtocolByPackageInstance (DeliverablePackage $packageInstance): HandleableProtocol { // First we need a tags instance $tagsInstance = PackageTagsFactory::createPackageTagsInstance(); @@ -90,7 +91,7 @@ class ProtocolDiscovery extends BaseNodeDiscovery implements DiscoverableProtoco * @return $protocolType Type of protocol, e.g. 'tcp' for TCP/IPv4 connections * @throws InvalidArgumentException If $packageInstance has no valid recipient UNL set */ - public static final function discoverProtocolByPackageInstance (DeliverablePackage $packageInstance) { + public static final function discoverProtocolByPackageInstance (DeliverablePackage $packageInstance): string { /* * "Explode" the 'recipient' array element into a new one, giving at * least two entries: protocol://address diff --git a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php index a48f8eb47..12455c931 100644 --- a/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php +++ b/application/hub/classes/discovery/recipient/socket/class_PackageSocketDiscovery.php @@ -63,7 +63,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * * @return $discoveryInstance An instance of this discovery class */ - public static final function createPackageSocketDiscovery () { + public static final function createPackageSocketDiscovery (): DiscoverableSocket { // Get an instance of this class $discoveryInstance = new PackageSocketDiscovery(); @@ -81,7 +81,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * @param $packageInstance An instance of a DeliverablePackage class * @return $listenerInstance An instance of a Listenable instance or null */ - public function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance) { + public function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance): Listenable { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: protocolInstance=' . $protocolInstance->__toString() . ',packageInstance=' . $packageInstance->__toString() . ' - CALLED!'); @@ -149,7 +149,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera * @throws InvalidArgumentException If one of the parameters are not valid * @throws LogicException If the discovered listener instance has no pool set */ - public function discoverSocket (DeliverablePackage $packageInstance, string $connectionType) { + public function discoverSocket (DeliverablePackage $packageInstance, string $connectionType): StorableSocket { // Make sure all parameters are valid /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISOVERY: packageInstance=%s,connectionType=%s - CALLED!', $packageInstance->__toString(), $connectionType)); //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISOVERY: packageInstance=' . print_r($packageInstance, TRUE)); @@ -186,7 +186,7 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera if (is_null($listenerInstance)) { // Abort with no resource throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); - } elseif (is_null($listenerInstance->getPoolInstance())) { + } elseif (!$listenerInstance->isPoolInstanceSet()) { // Opps another one throw new LogicException(sprintf('PACKAGE-SOCKET-DISCOVERY: listenerInstance=%s has no poolInstance set.', $listenerInstance->__toString()), self::EXCEPTION_IS_NULL_POINTER); } @@ -219,8 +219,8 @@ class PackageSocketDiscovery extends BaseRecipientDiscovery implements Discovera $helperInstance = ObjectRegistry::getRegistry('hub')->getInstance('connection'); // Is a state set and it's name is other than socket's error code? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: helperInstance->stateInstance[]=%s', gettype($helperInstance->getStateInstance()))); - if ($helperInstance->getStateInstance() instanceof PeerStateable && $helperInstance->getPrintableState() !== $socketInstance->translateLastSocketErrorCodeToName()) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-SOCKET-DISCOVERY: helperInstance->isStateInstanceSet()=%d', $helperInstance->isStateInstanceSet())); + if ($helperInstance->isStateInstanceSet() && $helperInstance->getStateInstance() instanceof PeerStateable && $helperInstance->getPrintableState() !== $socketInstance->translateLastSocketErrorCodeToName()) { // Resolve the peer's state (but ignore return value) /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-SOCKET-DISCOVERY: Going to resolve socket from peer state and given package data ...'); PeerStateResolver::createStateByPackageInstance($helperInstance, $packageInstance, $socketInstance); diff --git a/application/hub/classes/factories/info/class_ConnectionInfoFactory.php b/application/hub/classes/factories/info/class_ConnectionInfoFactory.php index 8f6d5dbbc..a9d206248 100644 --- a/application/hub/classes/factories/info/class_ConnectionInfoFactory.php +++ b/application/hub/classes/factories/info/class_ConnectionInfoFactory.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Factory\Information\Connection; // Import application-specific stuff use Org\Shipsimu\Hub\Container\Socket\StorableSocket; +use Org\Shipsimu\Hub\Information\ShareableInfo; // Import framework stuff use Org\Mxchange\CoreFramework\Factory\BaseFactory; @@ -68,7 +69,7 @@ class ConnectionInfoFactory extends BaseFactory { * @throws InvalidArgumentException If one of the arguments are not valid * @todo Also validate protocol to be sure if there is really a protocol handler for it available */ - public static final function createConnectionInfoInstance (string $protocolName, string $connectionType) { + public static final function createConnectionInfoInstance (string $protocolName, string $connectionType): ShareableInfo { // Init factory instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO-FACTORY: protocolName=%s,connectionType=%s - CALLED!', $protocolName, $connectionType)); $factoryInstance = new ConnectionInfoFactory(); diff --git a/application/hub/classes/factories/registry/class_ObjectTypeRegistryFactory.php b/application/hub/classes/factories/registry/object/class_ObjectTypeRegistryFactory.php similarity index 100% rename from application/hub/classes/factories/registry/class_ObjectTypeRegistryFactory.php rename to application/hub/classes/factories/registry/object/class_ObjectTypeRegistryFactory.php diff --git a/application/hub/classes/factories/registry/socket/class_SocketRegistryFactory.php b/application/hub/classes/factories/registry/socket/class_SocketRegistryFactory.php new file mode 100644 index 000000000..8eeeaa7ab --- /dev/null +++ b/application/hub/classes/factories/registry/socket/class_SocketRegistryFactory.php @@ -0,0 +1,79 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2023 Core 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 SocketRegistryFactory extends BaseFactory { + /** + * Protected constructor + * + * @return void + */ + private function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Returns a singleton socket registry 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 $registryInstance A socket registry instance + */ + public static final function createSocketRegistryInstance (): RegisterableSocket { + // Get registry instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SOCKET-REGISTRY-FACTORY: CALLED!'); + $objectRegistryInstance = ObjectRegistry::getRegistry('factory'); + + // Do we have an instance in the registry? + if ($objectRegistryInstance->instanceExists('socket_registry')) { + // Then use this instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SOCKET-REGISTRY-FACTORY: Getting socket registry instance ...'); + $registryInstance = $objectRegistryInstance->getInstance('socket_registry'); + } else { + // Get the registry instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SOCKET-REGISTRY-FACTORY: Creating new socket registry instance ...'); + $registryInstance = ObjectFactory::createObjectByConfiguredName('socket_registry_class'); + + // Set the instance in registry for further use + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage('SOCKET-REGISTRY-FACTORY: Adding socket registry instance ...'); + $objectRegistryInstance->addInstance('socket_registry', $registryInstance); + } + + // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY-FACTORY: registryInstance=%s - EXIT!', $registryInstance->__toString())); + return $registryInstance; + } + +} diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index 6fa1317e4..eecdeb4b9 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -70,7 +70,7 @@ class SocketFactory extends BaseFactory { * * @return void */ - public final static function staticInitializer () { + public final static function staticInitializer (): void { // Is it initialized? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: self::socketRegistryInstance[]=%s - CALLED!', gettype(self::$socketRegistryInstance))); if (is_null(self::$socketRegistryInstance)) { @@ -89,7 +89,7 @@ class SocketFactory extends BaseFactory { * @param $protocolInstance An instance of a HandleableProtocol class * @return $socketInstance An instance of a StorableSocket class */ - public static function createSocketFromPackageInstance (DeliverablePackage $packageInstance, HandleableProtocol $protocolInstance) { + public static function createSocketFromPackageInstance (DeliverablePackage $packageInstance, HandleableProtocol $protocolInstance): StorableSocket { // Invoke static initializer /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: packageInstance=%s,protocolInstance=%s - CALLED!', $packageInstance->__toString(), $protocolInstance->__toString())); self::staticInitializer(); @@ -137,7 +137,7 @@ class SocketFactory extends BaseFactory { * @throws InvalidSocketException If the socket cannot be completed * @throws UnexpectedValueException If $socketFile is empty */ - public static final function createListenFileSocket (Listenable $listenerInstance) { + public static final function createListenFileSocket (Listenable $listenerInstance): StorableSocket { // Create SplFileInfo /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString())); $fileInfo = new SplFileInfo(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry('ipc_socket_file_name')); @@ -231,7 +231,7 @@ class SocketFactory extends BaseFactory { * @throws SocketCreationException If the socket cannot be created * @todo Rewrite this to also handle IPv6 addresses and sockets */ - public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance) { + public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance): StorableSocket { // Create a socket instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString())); $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); @@ -293,7 +293,7 @@ class SocketFactory extends BaseFactory { * @throws UnexpectedValueException If a socket resource has not been created * @throws InvalidSocketException Thrown if the socket could not be initialized */ - public static function createListenTcpSocket (Listenable $listenerInstance) { + public static function createListenTcpSocket (Listenable $listenerInstance): StorableSocket { // Create a streaming socket, of type TCP/IP /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString())); $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); @@ -375,7 +375,7 @@ class SocketFactory extends BaseFactory { * @throws UnexpectedValueException If a socket resource has not been created * @throws InvalidSocketException Thrown if the socket could not be initialized */ - public static function createListenUdpSocket (Listenable $listenerInstance) { + public static function createListenUdpSocket (Listenable $listenerInstance): StorableSocket { // Create a streaming socket, of type UDP /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: listenerInstance=%s - CALLED!', $listenerInstance->__toString())); $socketResource = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); @@ -452,7 +452,7 @@ class SocketFactory extends BaseFactory { * @return $socketInstance A new instance of a StorableSocket or NULL if no changes has been detected. * @throws LogicException If the current instance is not valid */ - public static final function createNextAcceptedSocketFromPool (Poolable $poolInstance, StorableSocket $socketInstance) { + public static final function createNextAcceptedSocketFromPool (Poolable $poolInstance, StorableSocket $socketInstance): ?StorableSocket { // Invoke static initializer /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: poolInstance=%s,socketInstance->socketResource=%s - CALLED!', $poolInstance->__toString(), $socketInstance->getPrintableName())); self::staticInitializer(); @@ -519,7 +519,7 @@ class SocketFactory extends BaseFactory { * @return $socketInstance An instance of a StorableSocket class * @throws InvalidArgumentException If a parameter is not valid */ - public static final function createIncomingSocketInstance (Socket $socketResource, string $socketProtocol) { + public static final function createIncomingSocketInstance (Socket $socketResource, string $socketProtocol): StorableSocket { // Validate parameter /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-FACTORY: socketResource[]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketProtocol)); if (empty($socketProtocol)) { @@ -541,7 +541,7 @@ class SocketFactory extends BaseFactory { // Set all socket data $socketInstance->setPeerAddress('invalid'); - $socketInstance->setPeerPort('0'); + $socketInstance->setPeerPort(0); // Is the socket resource valid? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-FACTORY: socketInstance=%s', $socketInstance->__toString())); diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 5e565a2d2..08142a9eb 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -16,6 +16,7 @@ use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory; use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Org\Shipsimu\Hub\Factory\Network\Message\NetworkMessageFactory; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; +use Org\Shipsimu\Hub\Factory\Registry\Socket\SocketRegistryFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\BaseHubHandler; use Org\Shipsimu\Hub\Helper\Connection\ConnectionHelper; @@ -36,7 +37,6 @@ use Org\Shipsimu\Hub\Tools\HubTools; use Org\Mxchange\CoreFramework\Compressor\Compressor; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; -use Org\Mxchange\CoreFramework\Factory\Registry\Socket\SocketRegistryFactory; use Org\Mxchange\CoreFramework\Feature\FrameworkFeature; use Org\Mxchange\CoreFramework\Generic\FrameworkInterface; use Org\Mxchange\CoreFramework\Generic\NullPointerException; @@ -357,7 +357,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $compressorInstance A Compressor instance for compressing the content * @return $handlerInstance An instance of a Deliverable class */ - public static final function createNetworkPackageHandler (Compressor $compressorInstance) { + public static final function createNetworkPackageHandler (Compressor $compressorInstance): NetworkPackageHandler { // Get new instance $handlerInstance = new NetworkPackageHandler(); @@ -412,7 +412,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $compressorInstance An instance of a Compressor class * @return void */ - protected final function setCompressorInstance (Compressor $compressorInstance) { + protected final function setCompressorInstance (Compressor $compressorInstance): void { $this->compressorInstance = $compressorInstance; } @@ -421,7 +421,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $compressorInstance An instance of a Compressor class */ - private function getCompressorInstance () { + private function getCompressorInstance (): Compressor { return $this->compressorInstance; } @@ -431,7 +431,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $forceReInit Whether to force reinitialization of all stacks * @return void */ - protected function initStacks ($forceReInit = FALSE) { + protected function initStacks ($forceReInit = FALSE): void { // Initialize all $this->getStackInstance()->initStacks([ self::STACKER_NAME_UNDECLARED, @@ -451,9 +451,9 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * Determines private key hash from given session id * * @param $packageInstance An instance of a DeliverablePackage class - * @return $hash Private key's hash + * @return $hash Private key's hash */ - private function determineSenderPrivateKeyHash (DeliverablePackage $packageInstance) { + private function determineSenderPrivateKeyHash (DeliverablePackage $packageInstance): string { // Get DHT instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); $dhtInstance = DhtObjectFactory::createDhtInstance('node'); @@ -482,7 +482,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $content Raw package content * @return $hash Hash for given package content */ - private function getHashFromContent ($content) { + private function getHashFromContent ($content): string { // Create the hash /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: content[md5]=%s - CALLED!', md5($content))); // @TODO md5() is very weak, but it needs to be fast @@ -503,7 +503,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $packageInstance An instance of a DeliverablePackage class * @return $isChecksumValid Whether the checksum is the same */ - private function isChecksumValid (DeliverablePackage $packageInstance) { + private function isChecksumValid (DeliverablePackage $packageInstance): bool { // Get checksum /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); $checksum = $this->getHashFromPackageSessionId($packageInstance); @@ -525,7 +525,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws InvalidArgumentException If hashes are mismatching */ - private function changePackageStatus (DeliverablePackage $packageInstance, $stackerName, $newStatus) { + private function changePackageStatus (DeliverablePackage $packageInstance, $stackerName, $newStatus): void { // Skip this for empty stacks /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s,stackerName=%s,newStatus=%s - CALLED!', $packageInstance->__toString(), $stackerName, $newStatus)); if ($this->getStackInstance()->isStackEmpty($stackerName)) { @@ -564,7 +564,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return $hash Hash for given package content * @throws InvalidArgumentException If $packageInstance has no sessionId set */ - public function getHashFromPackageSessionId (DeliverablePackage $packageInstance) { + public function getHashFromPackageSessionId (DeliverablePackage $packageInstance): string { // Is session id set? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); /* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: packageInstance=%s', __METHOD__, __LINE__, print_r($packageInstance, TRUE))); @@ -596,7 +596,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $packageInstance An instance of a DeliverablePackage class in an array * @return void */ - private function declareRawPackageData (DeliverablePackage $packageInstance) { + private function declareRawPackageData (DeliverablePackage $packageInstance): void { /* * We need to disover every recipient, just in case we have a * multi-recipient entry like 'upper' is. 'all' may be a not so good @@ -656,7 +656,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $packageInstance An instance of a DeliverablePackage class in an array * @return void */ - private function deliverRawPackageData (DeliverablePackage $packageInstance) { + private function deliverRawPackageData (DeliverablePackage $packageInstance): void { /* * This package may become big, depending on the shared object size or * delivered message size which shouldn't be so long (to save @@ -719,7 +719,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $packageInstance An instance of a DeliverablePackage class * @return void */ - private function sendOutgoingRawPackageData (DeliverablePackage $packageInstance) { + private function sendOutgoingRawPackageData (DeliverablePackage $packageInstance): void { // Init sent bytes /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); $sentBytes = 0; @@ -763,7 +763,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $senderId Sender id to generate a hash for * @return $hash Hash as hex-encoded string */ - private function generatePackageHash (string $content, string $senderId) { + private function generatePackageHash (string $content, string $senderId): string { // Assert on variables /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: content()=' . strlen($content) . ',senderId=' . $senderId . ' - CALLED!'); assert(!empty($content)); @@ -806,7 +806,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $packageInstance An instance of a DeliverablePackage class * @return $isHashValid Whether the hash is valid */ - private function isPackageContentHashValid (DeliverablePackage $packageInstance) { + private function isPackageContentHashValid (DeliverablePackage $packageInstance): bool { // Is the feature enabled? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { @@ -847,7 +847,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws UnexpectedValueException If the helper instance contains now raw template data */ - public function enqueueRawDataFromTemplate (HubHelper $helperInstance) { + public function enqueueRawDataFromTemplate (HubHelper $helperInstance): void { // Get the raw content ... /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: helperInstance=' . $helperInstance->__toString() . ' - CALLED!'); $rawTemplateData = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -908,7 +908,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isEnqueued Whether a package is enqueued */ - public function isPackageEnqueued () { + public function isPackageEnqueued (): bool { // Check whether the stacker is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isEnqueued = ( @@ -927,7 +927,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isDeclared Whether a package is declared */ - public function isPackageDeclared () { + public function isPackageDeclared (): bool { // Check whether the stacker is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isDeclared = ( @@ -945,7 +945,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isWaitingDelivery Whether a package is waiting for delivery */ - public function isPackageWaitingForDelivery () { + public function isPackageWaitingForDelivery (): bool { // Check whether the stacker is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isWaitingDelivery = ( @@ -966,7 +966,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isPending Whether encoded data is pending */ - public function isEncodedDataPending () { + public function isEncodedDataPending (): bool { // Check whether the stacker is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isPending = ( @@ -992,7 +992,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws NoTargetException If no target can't be determined */ - public function declareEnqueuedPackage () { + public function declareEnqueuedPackage (): void { // Make sure this method isn't working if there is no package enqueued /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); if (!$this->isPackageEnqueued()) { @@ -1022,7 +1022,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function processDeclaredPackage () { + public function processDeclaredPackage (): void { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); @@ -1061,7 +1061,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws UnexpectedValueException If $sessionId is empty */ - public function sendWaitingPackage () { + public function sendWaitingPackage (): void { // Sanity check if we have packages waiting for delivery /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); if (!$this->isPackageWaitingForDelivery()) { @@ -1121,7 +1121,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @throws UnexpectedValueException If an instance of StorableSocket was expected but not provided * @throws LogicException If the socket is somehow invalid but this method was called */ - public function sendEncodedData () { + public function sendEncodedData (): void { // Make sure there is pending encoded data /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); if (!$this->isEncodedDataPending()) { @@ -1191,7 +1191,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isPending Whether decoded raw data is pending */ - private function isRawDataPending () { + private function isRawDataPending (): bool { // Just return whether the stack is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_INCOMING)); @@ -1206,7 +1206,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $hasArrived Whether new raw package data has arrived for processing */ - public function isNewRawDataPending () { + public function isNewRawDataPending (): bool { // Visit the pool. This monitors the pool for incoming raw data. /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: Invoking this->getListenerPoolInstance()->accept(%s) ... - CALLED!', $this->getVisitorInstance())); $this->getListenerPoolInstance()->accept($this->getVisitorInstance()); @@ -1227,7 +1227,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws BadMethodCallException If no incoming decoded data was on stack */ - public function handleIncomingDecodedData () { + public function handleIncomingDecodedData (): void { /* * This method should only be called if decoded raw data is pending, * so check it again. @@ -1268,7 +1268,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @param $handlerInstance An instance of a Networkable class * @return void */ - public function addRawDataToIncomingStack (Networkable $handlerInstance) { + public function addRawDataToIncomingStack (Networkable $handlerInstance): void { /* * Get the decoded data from the handler, this is an array with * 'raw_data' and 'error_code' as elements. @@ -1289,7 +1289,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isHandled Whether incoming decoded data is handled */ - public function isIncomingRawDataHandled () { + public function isIncomingRawDataHandled (): bool { // Determine if the stack is not empty $isHandled = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_DECODED_HANDLED)); @@ -1302,7 +1302,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isHandled Whether the assembler has pending data left */ - public function ifAssemblerHasPendingDataLeft () { + public function ifAssemblerHasPendingDataLeft (): bool { // Determine if the stack is not empty $isHandled = (!$this->getAssemblerInstance()->isPendingDataEmpty()); @@ -1315,7 +1315,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isPending Whether the assembler has multiple packages pending */ - public function ifMultipleMessagesPending () { + public function ifMultipleMessagesPending (): bool { // Determine if the stack is not empty $isPending = ($this->getAssemblerInstance()->ifMultipleMessagesPending()); @@ -1329,7 +1329,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function handleAssemblerPendingData () { + public function handleAssemblerPendingData (): void { // Handle it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: Invoking this->getAssemblerInstance()->handlePendingData() ...'); $this->getAssemblerInstance()->handlePendingData(); @@ -1340,7 +1340,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function handleMultipleMessages () { + public function handleMultipleMessages (): void { // Handle it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: Invoking this->getAssemblerInstance()->handleMultipleMessages() ...'); $this->getAssemblerInstance()->handleMultipleMessages(); @@ -1353,7 +1353,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function assembleDecodedDataToPackage () { + public function assembleDecodedDataToPackage (): void { // Make sure the raw decoded package data is handled assert($this->isIncomingRawDataHandled()); @@ -1393,7 +1393,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function clearAllStacks () { + public function clearAllStacks (): void { // Call the init method to force re-initialization $this->initStacks(TRUE); @@ -1409,7 +1409,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @throws UnexpectedPackageStatusException If the package status is not 'failed' * @todo This may be enchanced for outgoing packages? */ - public function removeFirstFailedPackage () { + public function removeFirstFailedPackage (): void { // Get the package again /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $packageInstance = $this->getStackInstance()->getNamed(self::STACKER_NAME_DECLARED); @@ -1434,7 +1434,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return $packageInstance An instance of a DeliverablePackage class * @throws InvalidArgumentException If $rawPackageContent contains double seperators */ - public function decodeRawContent ($rawPackageContent) { + public function decodeRawContent (string $rawPackageContent): DeliverablePackage { // Check if no double seperator is found /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: rawPackageContent(%d)=%s - CALLED!', strlen($rawPackageContent), $rawPackageContent)); if (strpos($rawPackageContent, self::PACKAGE_DATA_SEPARATOR . self::PACKAGE_DATA_SEPARATOR) !== FALSE) { @@ -1484,7 +1484,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @throws InvalidArgumentException If the package content does not have expected amount of entries */ - public function handleReceivedPackageInstance (DeliverablePackage $packageInstance) { + public function handleReceivedPackageInstance (DeliverablePackage $packageInstance): void { // Is the package content set? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); if (empty($packageInstance->getPackageContent())) { @@ -1537,7 +1537,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $hasArrived Whether a new message has arrived for processing */ - public function isNewMessageArrived () { + public function isNewMessageArrived (): bool { // Determine if the stack is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_NEW_MESSAGE)); @@ -1552,7 +1552,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $hasArrived Whether a new package has arrived for processing */ - public function isDecodedPackageXmlPending () { + public function isDecodedPackageXmlPending (): bool { // Determine if the stack is not empty /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $hasArrived = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PACKAGE_DECOMPRESSED_XML)); @@ -1571,7 +1571,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @throws InvalidPrivateKeyHashException If the private key-hash is empty * @todo Implement verification of all sent tags here? */ - public function handleNewlyArrivedMessage () { + public function handleNewlyArrivedMessage (): void { // Make sure there is at least one message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); if (!$this->isNewMessageArrived()) { @@ -1624,7 +1624,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @throws InvalidPrivateKeyHashException If the private key-hash is empty * @todo Implement verification of all sent tags here? */ - public function handleDecodedPackageXml () { + public function handleDecodedPackageXml (): void { // Make sure there is at least one package /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); if (!$this->isDecodedPackageXmlPending()) { @@ -1662,7 +1662,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return $isPending Whether a processed message is pending */ - public function isProcessedMessagePending () { + public function isProcessedMessagePending (): bool { // Check it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_PROCESSED_MESSAGE)); @@ -1677,7 +1677,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * * @return void */ - public function handleProcessedMessage () { + public function handleProcessedMessage (): void { // Get it from the stacker, it is the full array with the processed message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('NETWORK-PACKAGE-HANDLER: CALLED!'); $messageInstance = $this->getStackInstance()->popNamed(self::STACKER_NAME_PROCESSED_MESSAGE); @@ -1711,7 +1711,7 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return void * @todo ~10% done? */ - public function feedHashToMiner (DeliverableMessage $messageInstance) { + public function feedHashToMiner (DeliverableMessage $messageInstance): void { // Is the feature enabled? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('NETWORK-PACKAGE-HANDLER: messageInstance=%s - CALLED!', $messageInstance->__toString())); if (!FrameworkFeature::isFeatureAvailable('hubcoin_reward')) { diff --git a/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php b/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php index 199064d91..12806b6c6 100644 --- a/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php +++ b/application/hub/classes/handler/protocol/class_BaseProtocolHandler.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Handler\Protocol; // Import application-specific sutff +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Handler\BaseHubHandler; use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Tools\HubTools; @@ -37,7 +38,7 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP /** * Name of used protocol */ - private $protocolName = 'invalid'; + private $protocolName = StorableSocket::SOCKET_PROTOCOL_INVALID; /** * Protected constructor @@ -55,7 +56,7 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } @@ -65,7 +66,7 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } @@ -75,7 +76,7 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP * * @return $address Address part for the final UNL */ - public function getAddressPart () { + public function getAddressPart (): string { // Get UNL instance $locatorInstance = $this->getUniversalNodeLocatorInstance(); die(__METHOD__.':'.print_r($locatorInstance, TRUE)); @@ -87,7 +88,7 @@ abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableP * @param $unl UNL to test * @return $ifMatches Whether the found UNL matches own addresss */ - public function isOwnAddress (string $unl) { + public function isOwnAddress (string $unl): bool { // Get own external UNL $externalUnl = HubTools::determineOwnExternalAddress(); diff --git a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php index ff34d4301..91676e3c2 100644 --- a/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php +++ b/application/hub/classes/handler/protocol/ipv4/class_BaseIpV4ProtocolHandler.php @@ -60,7 +60,7 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler { * @para $port The port number * @return void */ - protected final function setPort ($port) { + protected final function setPort (int $port): void { // Set new port number $this->port = $port; } @@ -70,7 +70,7 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler { * * @return $port The port number */ - public final function getPort () { + public final function getPort (): int { // Return port number return $this->port; } @@ -83,7 +83,7 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler { * @return $isValid Whether the UNL can be validated * @throws BadMethodCallException If protocol of package's recipient UNL is not matching handler's name */ - public function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance) { + public function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance): bool { // Is the correct handler choosen? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('IPV4-PROTOCOL-HANDLER: packageInstance=%s - CALLED!', $packageInstance->__toString())); if (substr($packageInstance->getRecipientUnl(), 0, strlen($this->getProtocolName())) != $this->getProtocolName()) { @@ -119,7 +119,7 @@ abstract class BaseIpV4ProtocolHandler extends BaseProtocolHandler { * * @return $address Address part for the final UNL */ - public function getAddressPart () { + public function getAddressPart (): string { // Construct address $address = sprintf('%s:%s', parent::getAddressPart(), diff --git a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php index 8b81844d4..ab21f91ba 100644 --- a/application/hub/classes/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/classes/helper/connection/class_BaseConnectionHelper.php @@ -200,8 +200,8 @@ abstract class BaseConnectionHelper extends BaseHubSystemHelper implements Visit $recipientPort = 0; // Is a socket instance set? - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: socketInstance[]=%s', gettype($this->getSocketInstance()))); - if ($this->getSocketInstance() instanceof StorableSocket) { + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-CONNECTION-HELPER: this->isSocketInstanceSet()=%d', $this->isSocketInstanceSet())); + if ($this->isSocketInstanceSet()) { // Get recipient address/port $recipientAddress = $this->getSocketInstance()->getSocketRecipientAddress(); $recipientPort = $this->getSocketInstance()->getSocketRecipientPort(); diff --git a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php index d27cacf5a..e8afd1302 100644 --- a/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php +++ b/application/hub/classes/helper/connection/ipv4/class_BaseIpV4ConnectionHelper.php @@ -65,7 +65,7 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } @@ -74,7 +74,7 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } @@ -88,7 +88,7 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { * @see Please see http://de.php.net/manual/en/function.socket-connect.php#84465 for original code * @todo Rewrite the while() loop to a iterator to not let the software stay very long here */ - protected function connectToPeerBySocketRecipient () { + protected function connectToPeerBySocketRecipient (): bool { // Only call this if the connection is fully initialized //* DEBUG-DIE: */ die(__METHOD__.':socketInstance='.print_r($this->getSocketInstance(), TRUE)); if (!$this->isInitialized()) { @@ -182,7 +182,7 @@ abstract class BaseIpV4ConnectionHelper extends BaseConnectionHelper { * * @return void */ - protected final function markConnectionShuttedDown () { + protected final function markConnectionShuttedDown (): void { /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-IPV4-CONNECTION-HELPER: ' . $this->__toString() . ' has been marked as shutted down'); $this->shuttedDown = TRUE; diff --git a/application/hub/classes/info/connection/class_ConnectionInfo.php b/application/hub/classes/info/connection/class_ConnectionInfo.php index e9873a4f7..da40a6660 100644 --- a/application/hub/classes/info/connection/class_ConnectionInfo.php +++ b/application/hub/classes/info/connection/class_ConnectionInfo.php @@ -50,12 +50,12 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { /** * Connection type: 'incoming', 'outgoing', 'server' */ - private $connectionType = 'invalid'; + private $connectionType = StorableSocket::CONNECTION_TYPE_INVALID; /** * Name of used protocol */ - private $protocolName = 'invalid'; + private $protocolName = StorableSocket::SOCKET_PROTOCOL_INVALID; /** * Protected constructor @@ -74,7 +74,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @return $infoInstance An instance of a ShareableInfo class * @throws InvalidArgumentException If $connectionType is empty */ - public final static function createConnectionInfo (string $connectionType) { + public final static function createConnectionInfo (string $connectionType): ShareableInfo { // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: connectionType=%s - CALLED!', $connectionType)); if (empty($connectionType)) { @@ -99,7 +99,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @param $connectionType Connection type * @return void */ - private function setConnectionType (string $connectionType) { + private function setConnectionType (string $connectionType): void { $this->connectionType = $connectionType; } @@ -108,7 +108,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * * @return $connectionType Connection type */ - public final function getConnectionType () { + public final function getConnectionType (): string { return $this->connectionType; } @@ -117,7 +117,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } @@ -127,7 +127,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } @@ -136,7 +136,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * * @return $address Address from shared information */ - public final function getAddress () { + public final function getAddress (): string { // Return it from generic array return $this->getGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_ADDRESS); } @@ -146,7 +146,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * * @return $port Port from shared information */ - public final function getPort () { + public final function getPort (): int { // Return it from generic array return $this->getGenericArrayElement('connection', 'dummy', 'dummy', LocateableNode::UNL_PART_PORT); } @@ -157,7 +157,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @param $listenerInstance An instance of a Listenable class * @return void */ - public function fillWithListenerInformation (Listenable $listenerInstance) { + public function fillWithListenerInformation (Listenable $listenerInstance): void { // Fill the generic array with several data from the listener: /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: protocolName=%s,listenerInstance=%s - CALLED!', $listenerInstance->getProtocolName(), $listenerInstance->__toString())); $this->setProtocolName($listenerInstance->getProtocolName()); @@ -177,7 +177,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @param $helperInstance An instance of a ConnectionHelper class * @return void */ - public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance) { + public function fillWithConnectionHelperInformation (ConnectionHelper $helperInstance): void { // Fill the generic array with several data from the listener: /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: protocolName=%s,helperInstance=%s - CALLED!', $helperInstance->getProtocolName(), $helperInstance->__toString())); $this->setProtocolName($helperInstance->getSocketInstance()->getSocketProtocol()); @@ -198,7 +198,7 @@ class ConnectionInfo extends BaseInfo implements ShareableInfo, Registerable { * @return void * @throws InvalidSocketException If no peer data can be retrived from socket */ - public function fillWithSocketPeerInformation (StorableSocket $socketInstance) { + public function fillWithSocketPeerInformation (StorableSocket $socketInstance): void { // Init variables /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CONNECTION-INFO: socketInstance=%s - CALLED!', $socketInstance->__toString())); $socketAddress = '0.0.0.0'; diff --git a/application/hub/classes/listener/class_BaseListener.php b/application/hub/classes/listener/class_BaseListener.php index 966f22db0..f46fedd96 100644 --- a/application/hub/classes/listener/class_BaseListener.php +++ b/application/hub/classes/listener/class_BaseListener.php @@ -7,6 +7,7 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Information\Connection\ConnectionInfoFactory; use Org\Shipsimu\Hub\Factory\Network\Locator\UniversalNodeLocatorFactory; use Org\Shipsimu\Hub\Factory\Node\NodeObjectFactory; +use Org\Shipsimu\Hub\Factory\Registry\Socket\SocketRegistryFactory; use Org\Shipsimu\Hub\Factory\Socket\SocketFactory; use Org\Shipsimu\Hub\Generic\BaseHubSystem; use Org\Shipsimu\Hub\Handler\Package\NetworkPackageHandler; @@ -19,7 +20,6 @@ use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; // Import framework stuff use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; -use Org\Mxchange\CoreFramework\Factory\Registry\Socket\SocketRegistryFactory; use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Socket\InvalidServerSocketException; use Org\Mxchange\CoreFramework\Socket\SocketAlreadyRegisteredException; @@ -112,7 +112,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $socketInstance An instance of a StorableSocket class * @return void */ - private function handleIncomingSocket (StorableSocket $socketInstance) { + private function handleIncomingSocket (StorableSocket $socketInstance): void { // Handle it here, if not main server socket /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: socketInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $socketInstance->__toString())); $this->getHandlerInstance()->processRawDataFromSocketInstance($socketInstance); @@ -127,7 +127,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $listenAddress The address this listener should listen on * @return void */ - protected final function setListenAddress (string $listenAddress) { + protected final function setListenAddress (string $listenAddress): void { $this->listenAddress = $listenAddress; } @@ -136,7 +136,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * * @return $listenAddress The address this listener should listen on */ - public final function getListenAddress () { + public final function getListenAddress (): string { return $this->listenAddress; } @@ -146,7 +146,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $listenPort The port this listener should listen on * @return void */ - protected final function setListenPort (int $listenPort) { + protected final function setListenPort (int $listenPort): void { $this->listenPort = $listenPort; } @@ -155,7 +155,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * * @return $listenPort The port this listener should listen on */ - public final function getListenPort () { + public final function getListenPort (): int { return $this->listenPort; } @@ -165,7 +165,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $configEntry The configuration entry holding our listen address * @return void */ - public final function setListenAddressByConfiguration (string $configEntry) { + public final function setListenAddressByConfiguration (string $configEntry): void { $this->setListenAddress(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry)); } @@ -175,7 +175,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $configEntry The configuration entry holding our listen port * @return void */ - public final function setListenPortByConfiguration (string $configEntry) { + public final function setListenPortByConfiguration (string $configEntry): void { $this->setListenPort(FrameworkBootstrap::getConfigurationInstance()->getConfigEntry($configEntry)); } @@ -185,7 +185,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $poolInstance An instance of a PoolablePeer class * @return void */ - protected final function setPoolInstance (PoolablePeer $poolInstance) { + protected final function setPoolInstance (PoolablePeer $poolInstance): void { $this->poolInstance = $poolInstance; } @@ -194,16 +194,25 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * * @return $poolInstance An instance of a PoolablePeer class */ - public final function getPoolInstance () { + public final function getPoolInstance (): PoolablePeer { return $this->poolInstance; } + /** + * Checks whether a pool instance is set + * + * @return $isset Whether a pool instance is set + */ + public final function isPoolInstanceSet (): bool { + return ($this->poolInstance instanceof PoolablePeer); + } + /** * Getter for protocol name * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } @@ -213,7 +222,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } @@ -227,7 +236,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @throws SocketAlreadyRegisteredException If the given resource is already registered * @throws LogicException If no info instance can be created */ - protected function registerServerSocketInstance (StorableSocket $socketInstance) { + protected function registerServerSocketInstance (StorableSocket $socketInstance): void { // First check if it is valid /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: socketInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $socketInstance->__toString())); if ($this->isServerSocketRegistered($socketInstance)) { @@ -266,7 +275,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @return $isRegistered Whether given server socket is registered * @throws LogicException If no info instance can be created */ - protected function isServerSocketRegistered (StorableSocket $socketInstance) { + protected function isServerSocketRegistered (StorableSocket $socketInstance): bool { // Get a connection info instance //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: socketInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $socketInstance->__toString())); $infoInstance = ConnectionInfoFactory::createConnectionInfoInstance($this->getProtocolName(), StorableSocket::CONNECTION_TYPE_SERVER); @@ -304,7 +313,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { $visitorInstance->visitListener($this); // Visit the pool if set - if ($this->getPoolInstance() instanceof Poolable) { + if ($this->isPoolInstanceSet()) { // Visit pool instance $this->getPoolInstance()->accept($visitorInstance); } @@ -319,7 +328,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * * @return void */ - public function monitorIncomingRawData () { + public function monitorIncomingRawData (): void { // Check if an incoming socket is registered /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: CALLED!', strtoupper($this->getProtocolName()))); if (!$this->getRegistryInstance()->isIncomingSocketRegistered($this)) { @@ -390,7 +399,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @return void * @throws LogicException If no info instance can be created */ - protected function doListenSocketSelect () { + protected function doListenSocketSelect (): void { // Validate parameter and socket instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: CALLED!', strtoupper($this->getProtocolName()))); if(!$this->getSocketInstance()->isValidSocket()) { @@ -458,7 +467,7 @@ abstract class BaseListener extends BaseHubSystem implements Visitable { * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Check if same socket protocol /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('%s-LISTENER: packageInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $packageInstance)); $socketProtocol = $this->getSocketInstance()->getSocketProtocol(); diff --git a/application/hub/classes/listener/class_BaseListenerDecorator.php b/application/hub/classes/listener/class_BaseListenerDecorator.php index 36750577f..17c0f75fa 100644 --- a/application/hub/classes/listener/class_BaseListenerDecorator.php +++ b/application/hub/classes/listener/class_BaseListenerDecorator.php @@ -7,6 +7,7 @@ use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Factory\Handler\Network\NetworkPackageHandlerFactory; use Org\Shipsimu\Hub\Factory\Network\NetworkPackageFactory; use Org\Shipsimu\Hub\Network\Networkable; +use Org\Shipsimu\Hub\Pool\Peer\PoolablePeer; use Org\Shipsimu\Hub\Traits\Listener\ListenableTrait; use Org\Shipsimu\Hub\Traits\Container\Socket\StorableSocketTrait; @@ -55,7 +56,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable /** * Name of used protocol */ - private $protocolName = 'invalid'; + private $protocolName = StorableSocket::SOCKET_PROTOCOL_INVALID; /** * Protected constructor @@ -74,7 +75,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } @@ -83,7 +84,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $listenAddress The address this listener should listen on */ - public final function getListenAddress () { + public final function getListenAddress (): string { // Trace message //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER-DECORATOR: Invoking this->getListenerInstance()->getListenAddress() ...'); return $this->getListenerInstance()->getListenAddress(); @@ -94,7 +95,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $listenPort The port this listener should listen on */ - public final function getListenPort () { + public final function getListenPort (): int { // Trace message //* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER-DECORATOR: Invoking this->getListenerInstance()->getListenPort() ...'); return $this->getListenerInstance()->getListenPort(); @@ -128,7 +129,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $listenerType The listener's type (hub/peer) */ - public final function getListenerType () { + public final function getListenerType (): string { return $this->listenerType; } @@ -138,7 +139,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * @param $listenerType The listener's type (hub/peer) * @return void */ - protected final function setListenerType (string $listenerType) { + protected final function setListenerType (string $listenerType): void { $this->listenerType = $listenerType; } @@ -147,14 +148,20 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $poolInstance A peer pool instance */ - public final function getPoolInstance () { - // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-LISTENER-DECORATOR: Getting poolInstance from inner listenerInstance=%s - CALLED!', strtoupper($this->getProtocolName()), $this->getListenerInstance()->__toString())); - + public final function getPoolInstance (): PoolablePeer { // Get it return $this->getListenerInstance()->getPoolInstance(); } + /** + * Checks whether a pool instance is set + * + * @return $isset Whether a pool instance is set + */ + public final function isPoolInstanceSet (): bool { + return $this->getListenerInstance()->isPoolInstanceSet(); + } + /** * Monitors incoming raw data from the handler and transfers it to the * given receiver instance. @@ -163,7 +170,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * @throws NullPointerException If no handler instance is set in listener instance * @throws LogicException If the given handler instance is not implementing a required interface */ - public function monitorIncomingRawData () { + public function monitorIncomingRawData (): void { // Get the handler instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(strtoupper($this->getProtocolName()) . '-LISTENER-DECORATOR: CALLED!'); $handlerInstance = $this->getListenerInstance()->getHandlerInstance(); @@ -210,7 +217,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } diff --git a/application/hub/classes/listener/socket/class_SocketFileListener.php b/application/hub/classes/listener/socket/class_SocketFileListener.php index dc5391652..32d104cc4 100644 --- a/application/hub/classes/listener/socket/class_SocketFileListener.php +++ b/application/hub/classes/listener/socket/class_SocketFileListener.php @@ -56,7 +56,7 @@ class SocketFileListener extends BaseListener implements Listenable { * * @return $listenerInstance An instance a prepared listener class */ - public final static function createSocketFileListener () { + public final static function createSocketFileListener (): Listenable { // Get new instance $listenerInstance = new SocketFileListener(); @@ -69,7 +69,7 @@ class SocketFileListener extends BaseListener implements Listenable { * * @return void */ - public function initListener () { + public function initListener (): void { // Create socket with factory /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: CALLED!'); $socketInstance = SocketFactory::createListenFileSocket($this); @@ -108,7 +108,7 @@ class SocketFileListener extends BaseListener implements Listenable { * * @return void */ - public function doListen() { + public function doListen(): void { // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Invoking this->doListenSocketSelect() ... - CALLED!'); @@ -125,7 +125,7 @@ class SocketFileListener extends BaseListener implements Listenable { * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FILE-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); @@ -160,7 +160,7 @@ class SocketFileListener extends BaseListener implements Listenable { * * @return void */ - public function monitorIncomingRawData () { + public function monitorIncomingRawData (): void { DebugMiddleware::getSelfInstance()->partialStub('Need to implement this method.'); } diff --git a/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php b/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php index 607a3946a..5e141c027 100644 --- a/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php +++ b/application/hub/classes/listener/socket/decorator/class_SocketFileListenerDecorator.php @@ -55,7 +55,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public static final function createSocketFileListenerDecorator (Listenable $listenerInstance) { + public static final function createSocketFileListenerDecorator (Listenable $listenerInstance): Listenable { // Get new instance $decoratorInstance = new SocketFileListenerDecorator(); @@ -71,7 +71,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste * * @return void */ - public function initListener () { + public function initListener (): void { DebugMiddleware::getSelfInstance()->partialStub('WARNING: This method should not be called.'); } @@ -80,7 +80,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Invoking this->getListenerInstance()->doListen() ...'); @@ -97,7 +97,7 @@ class SocketFileListenerDecorator extends BaseListenerDecorator implements Liste * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Debug message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FILE-LISTENER: Invoking this->getListenerInstance()->ifListenerAcceptsPackageData() ...'); diff --git a/application/hub/classes/listener/tcp/class_TcpListener.php b/application/hub/classes/listener/tcp/class_TcpListener.php index 333ad2a38..0c9a33c9c 100644 --- a/application/hub/classes/listener/tcp/class_TcpListener.php +++ b/application/hub/classes/listener/tcp/class_TcpListener.php @@ -52,7 +52,7 @@ class TcpListener extends BaseListener implements Listenable { * * @return $listenerInstance An instance a prepared listener class */ - public static final function createTcpListener () { + public static final function createTcpListener (): Listenable { // Get new instance $listenerInstance = new TcpListener(); @@ -65,7 +65,7 @@ class TcpListener extends BaseListener implements Listenable { * * @return void */ - public function initListener () { + public function initListener (): void { // Get instance from socket factory $socketInstance = SocketFactory::createListenTcpSocket($this); @@ -103,7 +103,7 @@ class TcpListener extends BaseListener implements Listenable { * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-LISTENER: Invoking this->doListenSocketSelect() ... - CALLED!'); diff --git a/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php b/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php index 122dfbe87..63bee9572 100644 --- a/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php +++ b/application/hub/classes/listener/tcp/decorators/class_ClientTcpListenerDecorator.php @@ -55,7 +55,7 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public static final function createClientTcpListenerDecorator (Listenable $listenerInstance) { + public static final function createClientTcpListenerDecorator (Listenable $listenerInstance): Listenable { // Get new instance $decoratorInstance = new ClientTcpListenerDecorator(); @@ -71,7 +71,7 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen * * @return void */ - public function initListener () { + public function initListener (): void { DebugMiddleware::getSelfInstance()->partialStub('WARNING: This method should not be called.'); } @@ -80,7 +80,7 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CLIENT-TCP-LISTENER: Invoking this->getListenerInstance() ...'); @@ -97,7 +97,7 @@ class ClientTcpListenerDecorator extends BaseListenerDecorator implements Listen * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); diff --git a/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php b/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php index b280f6bc7..7f12ef862 100644 --- a/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php +++ b/application/hub/classes/listener/tcp/decorators/class_HubTcpListenerDecorator.php @@ -55,7 +55,7 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public static final function createHubTcpListenerDecorator (Listenable $listenerInstance) { + public static final function createHubTcpListenerDecorator (Listenable $listenerInstance): Listenable { // Get new instance $decoratorInstance = new HubTcpListenerDecorator(); @@ -71,7 +71,7 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function initListener () { + public function initListener (): void { DebugMiddleware::getSelfInstance()->partialStub('WARNING: This method should not be called.'); } @@ -80,7 +80,7 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-TCP-LISTENER: Invoking this->getListenerInstance() ...'); @@ -97,7 +97,7 @@ class HubTcpListenerDecorator extends BaseListenerDecorator implements Listenabl * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-TCP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); diff --git a/application/hub/classes/listener/udp/class_UdpListener.php b/application/hub/classes/listener/udp/class_UdpListener.php index ae4c2d7ca..5d78a06ee 100644 --- a/application/hub/classes/listener/udp/class_UdpListener.php +++ b/application/hub/classes/listener/udp/class_UdpListener.php @@ -55,7 +55,7 @@ class UdpListener extends BaseListener implements Listenable { * * @return $listenerInstance An instance a prepared listener class */ - public static final function createUdpListener () { + public static final function createUdpListener (): Listenable { // Get new instance $listenerInstance = new UdpListener(); @@ -68,7 +68,7 @@ class UdpListener extends BaseListener implements Listenable { * * @return void */ - public function initListener () { + public function initListener (): void { // Get instance from socket factory $socketInstance = SocketFactory::createListenUdpSocket($this); @@ -106,7 +106,7 @@ class UdpListener extends BaseListener implements Listenable { * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('UDP-LISTENER: Invoking this->doListenSocketSelect() ... - CALLED!'); @@ -124,7 +124,7 @@ class UdpListener extends BaseListener implements Listenable { * @return $accepts Whether this listener does accept * @throws UnsupportedOperationException If this method is called */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { throw new UnsupportedOperationException([$this, __FUNCTION__], FrameworkInterface::EXCEPTION_UNSPPORTED_OPERATION); } diff --git a/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php b/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php index c3e6cc70f..e56bb8e53 100644 --- a/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php +++ b/application/hub/classes/listener/udp/decorators/class_ClientUdpListenerDecorator.php @@ -55,7 +55,7 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public static final function createClientUdpListenerDecorator (Listenable $listenerInstance) { + public static final function createClientUdpListenerDecorator (Listenable $listenerInstance): Listenable { // Get new instance $decoratorInstance = new ClientUdpListenerDecorator(); @@ -71,7 +71,7 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen * * @return void */ - public function initListener () { + public function initListener (): void { DebugMiddleware::getSelfInstance()->partialStub('WARNING: This method should not be called.'); } @@ -80,7 +80,7 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('CLIENT-UDP-LISTENER: Invoking this->getListenerInstance() ...'); @@ -97,7 +97,7 @@ class ClientUdpListenerDecorator extends BaseListenerDecorator implements Listen * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('CLIENT-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); diff --git a/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php b/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php index 20fe13812..9c3f67931 100644 --- a/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php +++ b/application/hub/classes/listener/udp/decorators/class_HubUdpListenerDecorator.php @@ -55,7 +55,7 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl * @param $listenerInstance A Listener instance * @return $decoratorInstance An instance a prepared listener decorator class */ - public static final function createHubUdpListenerDecorator (Listenable $listenerInstance) { + public static final function createHubUdpListenerDecorator (Listenable $listenerInstance): Listenable { // Get new instance $decoratorInstance = new HubUdpListenerDecorator(); @@ -71,7 +71,7 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function initListener () { + public function initListener (): void { DebugMiddleware::getSelfInstance()->partialStub('WARNING: This method should not be called.'); } @@ -80,7 +80,7 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl * * @return void */ - public function doListen () { + public function doListen (): void { // Trace message /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('HUB-UDP-LISTENER: Invoking this->getListenerInstance() ...'); @@ -97,7 +97,7 @@ class HubUdpListenerDecorator extends BaseListenerDecorator implements Listenabl * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance) { + public function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool { // Trace message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-UDP-LISTENER: packageInstance=%s - CALLED!', $packageInstance->__toString())); diff --git a/application/hub/classes/lists/hub/class_HubList.php b/application/hub/classes/lists/hub/class_HubList.php index f8562cc8c..7fed14285 100644 --- a/application/hub/classes/lists/hub/class_HubList.php +++ b/application/hub/classes/lists/hub/class_HubList.php @@ -6,6 +6,9 @@ namespace Org\Shipsimu\Hub\Lists\Hub; use Org\Mxchange\CoreFramework\Lists\BaseList; use Org\Mxchange\CoreFramework\Lists\Listable; +// Import SPL stuff +use \Iterator; + /** * A Hub list * @@ -44,7 +47,7 @@ class HubList extends BaseList implements Listable { * * @return $listInstance An instance a Listable class */ - public static final function createHubList () { + public static final function createHubList (): Listable { // Get new instance $listInstance = new HubList(); @@ -61,7 +64,7 @@ class HubList extends BaseList implements Listable { * * @return $iteratorInstance An instance of a Iterator class */ - public function getListIterator () { + public function getListIterator (): Iterator { $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__)); } @@ -70,9 +73,9 @@ class HubList extends BaseList implements Listable { * * @return void */ - public function clearList () { + public function clearList (): void { // Clear both groups together - $this->clearGroups(array('connected', 'disconnected')); + $this->clearGroups(['connected', 'disconnected']); } } diff --git a/application/hub/classes/lists/pool/class_PoolEntriesList.php b/application/hub/classes/lists/pool/class_PoolEntriesList.php index 466f84f97..08164adb5 100644 --- a/application/hub/classes/lists/pool/class_PoolEntriesList.php +++ b/application/hub/classes/lists/pool/class_PoolEntriesList.php @@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Factory\Object\ObjectFactory; use Org\Mxchange\CoreFramework\Lists\BaseList; use Org\Mxchange\CoreFramework\Lists\Listable; +// Import SPL stuff +use \Iterator; + /** * A list for pool entries * @@ -43,9 +46,9 @@ class PoolEntriesList extends BaseList implements Listable { /** * Creates an instance of this class * - * @return $listInstance An instance a Listable class + * @return $listInstance An instance a Listable class */ - public static final function createPoolEntriesList () { + public static final function createPoolEntriesList (): Listable { // Get new instance $listInstance = new PoolEntriesList(); @@ -61,7 +64,7 @@ class PoolEntriesList extends BaseList implements Listable { * * @return $iteratorInstance An instance of a Iterator class */ - public function getListIterator () { + public function getListIterator (): Iterator { // Get the iterator instance from the factory $iteratorInstance = ObjectFactory::createObjectByConfiguredName('node_ping_iterator_class', [$this]); @@ -77,7 +80,7 @@ class PoolEntriesList extends BaseList implements Listable { * * @return void */ - public function clearList () { + public function clearList (): void { // Clear the only one group $this->clearGroup('pool'); } diff --git a/application/hub/classes/lists/recipient/class_RecipientList.php b/application/hub/classes/lists/recipient/class_RecipientList.php index e3c2b3d45..539420808 100644 --- a/application/hub/classes/lists/recipient/class_RecipientList.php +++ b/application/hub/classes/lists/recipient/class_RecipientList.php @@ -7,6 +7,9 @@ use Org\Mxchange\CoreFramework\Lists\BaseList; use Org\Mxchange\CoreFramework\Lists\Listable; use Org\Mxchange\CoreFramework\Registry\Registerable; +// Import SPL stuff +use \Iterator; + /** * A Recipient list * @@ -43,9 +46,9 @@ class RecipientList extends BaseList implements Listable, Registerable { /** * Creates an instance of this class * - * @return $listInstance An instance a Listable class + * @return $listInstance An instance a Listable class */ - public static final function createRecipientList () { + public static final function createRecipientList (): Listable { // Get new instance $listInstance = new RecipientList(); @@ -65,7 +68,7 @@ class RecipientList extends BaseList implements Listable, Registerable { * * @return $iteratorInstance An instance of a Iterator class */ - public function getListIterator () { + public function getListIterator (): Iterator { $this->debugInstance(sprintf('[%s:%d]: uses the default iterator. Please call getIterator() instead!', __METHOD__, __LINE__)); } @@ -74,7 +77,7 @@ class RecipientList extends BaseList implements Listable, Registerable { * * @return void */ - public function clearList () { + public function clearList (): void { // Clear both groups $this->clearGroups(['unl', 'session_id']); } diff --git a/application/hub/classes/nodes/class_BaseHubNode.php b/application/hub/classes/nodes/class_BaseHubNode.php index b60afc265..c1142182e 100644 --- a/application/hub/classes/nodes/class_BaseHubNode.php +++ b/application/hub/classes/nodes/class_BaseHubNode.php @@ -172,7 +172,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return void */ - private function initState() { + private function initState(): void { // Get the state factory and create the initial state. NodeStateFactory::createNodeStateInstanceByName('init'); } @@ -183,7 +183,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $searchInstance An instance of a LocalSearchCriteria class * @return void */ - private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance) { + private function generatePrivateKeyAndHash (LocalSearchCriteria $searchInstance): void { // Get an RNG instance $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); @@ -209,7 +209,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return $randomString Random string * @todo Make this code more generic and move it to CryptoHelper or */ - protected function generateRamdomString ($length) { + protected function generateRamdomString (int $length): string { // Get an RNG instance $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class'); @@ -228,7 +228,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $bootUnl The UNL (Universal Node Locator) of the boot node */ - protected final function getBootUniversalNodeLocator () { + protected final function getBootUniversalNodeLocator (): string { return $this->bootUnl; } @@ -239,7 +239,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return $isFound Whether the IP is found * @throws InvalidArgumentException If a parameter is empty */ - protected function ifAddressMatchesBootstrapNodes (string $remoteAddr) { + protected function ifAddressMatchesBootstrapNodes (string $remoteAddr): bool { // Check parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: remoteAddr=%s - CALLED!', $remoteAddr)); if (empty($remoteAddr)) { @@ -292,7 +292,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $unl Node's own universal node locator */ - public function detectOwnUniversalNodeLocator () { + public function detectOwnUniversalNodeLocator (): string { // Is "cache" set? if (!isset($GLOBALS[__METHOD__])) { // Get the UNL array back @@ -324,7 +324,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return void */ - public function outputConsoleTeaser () { + public function outputConsoleTeaser (): void { // Get the app instance (for shortening our code) $applicationInstance = ApplicationHelper::getSelfInstance(); @@ -348,7 +348,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $responseInstance A Responseable class * @return void */ - public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance) { + public function bootstrapAcquireNodeId (Requestable $requestInstance, Responseable $responseInstance): void { // Find node by id /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: requestInstance=%s,responseInstance=%s - CALLED!', $requestInstance->__toString(), $responseInstance->__toString())); $resultInstance = $this->getFrontendInstance()->findFirstNodeData(); @@ -392,7 +392,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return void */ - public function bootstrapGenerateSessionId () { + public function bootstrapGenerateSessionId (): void { // Now get a search criteria instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); @@ -432,7 +432,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @throws UnexpectedValueException If private_key_hash is "invalid" * @throws OutOfBoundsException If an array element is not found */ - public function bootstrapGeneratePrivateKey () { + public function bootstrapGeneratePrivateKey (): void { // Find node by id /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $resultInstance = $this->getFrontendInstance()->findFirstNodeData(); @@ -484,7 +484,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $criteriaInstance An instance of a StoreableCriteria class * @return void */ - public function addElementsToDataSet (StoreableCriteria $criteriaInstance) { + public function addElementsToDataSet (StoreableCriteria $criteriaInstance): void { // Get request instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: criteriaInstance=%s - CALLED!', $criteriaInstance->__toString())); $requestInstance = FrameworkBootstrap::getRequestInstance(); @@ -527,7 +527,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @throws DatabaseUpdateSupportException If this class does not support database updates * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem */ - public function updateDatabaseField ($fieldName, $fieldValue) { + public function updateDatabaseField (string $fieldName, mixed $fieldValue): void { // Unfinished DebugMiddleware::getSelfInstance()->partialStub('Unfinished!'); return; @@ -567,7 +567,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @throws NodeAlreadyAnnouncedException If this hub is already announced * @todo Change the first if() block to check for a specific state */ - public function announceToUpperNodes (Taskable $taskInstance) { + public function announceToUpperNodes (Taskable $taskInstance): void { // Is this hub node announced? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NOCE: taskInstance=%s - CALLED!', $taskInstance->__toString())); if ($this->hubIsAnnounced === TRUE) { @@ -606,7 +606,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $taskInstance The task instance running this announcement * @return void */ - public function doSelfConnection (Taskable $taskInstance) { + public function doSelfConnection (Taskable $taskInstance): void { // Debug output self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: Self Connection: START (taskInstance=' . $taskInstance->__toString(). ')'); @@ -635,7 +635,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $responseInstance A Responseable class * @return void */ - public function activateNode (Requestable $requestInstance, Responseable $responseInstance) { + public function activateNode (Requestable $requestInstance, Responseable $responseInstance): void { // Checks whether a listener is still active and shuts it down if one // is still listening. if (($this->determineIfListenerIsActive()) && ($this->isNodeActive())) { @@ -660,7 +660,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return void */ - public function initializeListenerPool () { + public function initializeListenerPool (): void { // Debug output self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: Initialize listener: START'); @@ -742,7 +742,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $isActive Whether the hub is active */ - public final function isNodeActive () { + public final function isNodeActive (): bool { return $this->isActive; } @@ -752,7 +752,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $isActive Whether the hub is active * @return void */ - public final function enableIsActive (bool $isActive = TRUE) { + public final function enableIsActive (bool $isActive = TRUE): void { $this->isActive = $isActive; } @@ -762,7 +762,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $acceptAnnouncements Whether this node accepts announcements (default: TRUE) * @return void */ - protected final function enableAcceptingAnnouncements (bool $acceptAnnouncements = TRUE) { + protected final function enableAcceptingAnnouncements (bool $acceptAnnouncements = TRUE): void { $this->acceptAnnouncements = $acceptAnnouncements; } @@ -772,7 +772,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests (default: TRUE) * @return void */ - public final function enableAcceptDhtBootstrap (bool $acceptDhtBootstrap = TRUE) { + public final function enableAcceptDhtBootstrap (bool $acceptDhtBootstrap = TRUE): void { //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: Enabling DHT bootstrap requests ...'); $this->acceptDhtBootstrap = $acceptDhtBootstrap; } @@ -783,7 +783,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $listenerPoolInstance The new listener pool instance * @return void */ - protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) { + protected final function setListenerPoolInstance (Poolable $listenerPoolInstance): void { $this->listenerPoolInstance = $listenerPoolInstance; } @@ -792,7 +792,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $listenerPoolInstance Our current listener pool instance */ - public final function getListenerPoolInstance () { + public final function getListenerPoolInstance (): Poolable { return $this->listenerPoolInstance; } @@ -802,7 +802,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $nodeId The new node id * @return void */ - protected final function setNodeId (string $nodeId) { + protected final function setNodeId (string $nodeId): void { $this->nodeId = $nodeId; } @@ -811,7 +811,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $nodeId Current node id */ - public final function getNodeId () { + public final function getNodeId (): string { return $this->nodeId; } @@ -821,7 +821,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $privateKey The new private key * @return void */ - protected final function setPrivateKey (string $privateKey) { + protected final function setPrivateKey (string $privateKey): void { $this->privateKey = $privateKey; } @@ -830,7 +830,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $privateKey Current private key */ - public final function getPrivateKey () { + public final function getPrivateKey (): string { return $this->privateKey; } @@ -840,7 +840,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $nodePrivateKeyHash The new private key hash * @return void */ - protected final function setNodePrivateKeyHash (string $nodePrivateKeyHash) { + protected final function setNodePrivateKeyHash (string $nodePrivateKeyHash): void { $this->nodePrivateKeyHash = $nodePrivateKeyHash; } @@ -849,7 +849,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $privateKeyHash Current private key hash */ - public final function getNodePrivateKeyHash () { + public final function getNodePrivateKeyHash (): string { return $this->nodePrivateKeyHash; } @@ -859,7 +859,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @param $sessionId The new session id * @return void */ - protected final function setSessionId (string $sessionId) { + protected final function setSessionId (string $sessionId): void { $this->sessionId = $sessionId; } @@ -868,7 +868,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $sessionId Current session id */ - public final function getSessionId () { + public final function getSessionId (): string { return $this->sessionId; } @@ -877,7 +877,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $acceptAnnouncements Whether this node accepts announcements */ - public final function isAcceptingAnnouncements () { + public final function isAcceptingAnnouncements (): bool { // Check it (this node must be active and not shutdown!) /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $acceptAnnouncements = (($this->acceptAnnouncements === TRUE) && ($this->isNodeActive())); @@ -892,7 +892,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $acceptDhtBootstrap Whether this node accepts DHT bootstrap requests */ - public final function isAcceptingDhtBootstrap () { + public final function isAcceptingDhtBootstrap (): bool { // Check it (this node must be active and not shutdown!) /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $acceptDhtBootstrap = (($this->acceptDhtBootstrap === TRUE) && ($this->isNodeActive())); @@ -908,10 +908,10 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return $hasAnnounced Whether this node has attempted to announce itself * @todo Add checking if this node has been announced to the sender node */ - public function ifNodeIsAnnouncing () { + public function ifNodeIsAnnouncing (): bool { // Simply check the state of this node //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: state=' . $this->getStateInstance()->getStateName()); - $hasAnnounced = ($this->getStateInstance() instanceof NodeAnnouncingState); + $hasAnnounced = ($this->isStateInstanceSet() && $this->getStateInstance() instanceof NodeAnnouncingState); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: hasAnnounced=' . intval($hasAnnounced)); @@ -924,10 +924,10 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return $hasAnnouncementCompleted Whether this node has attempted to announce itself and completed it * @todo Add checking if this node has been announced to the sender node */ - public function ifNodeHasAnnouncementCompleted () { + public function ifNodeHasAnnouncementCompleted (): bool { // Simply check the state of this node //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: state=' . $this->getStateInstance()->getStateName()); - $hasAnnouncementCompleted = ($this->getStateInstance() instanceof NodeAnnouncementCompletedState); + $hasAnnouncementCompleted = ($this->isStateInstanceSet() && $this->getStateInstance() instanceof NodeAnnouncementCompletedState); // Return it //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: hasAnnouncementCompleted=' . intval($hasAnnouncementCompleted)); @@ -939,7 +939,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $acceptsRequest Wether this node accepts node-list requests */ - public function isAcceptingNodeListRequests () { + public function isAcceptingNodeListRequests (): bool { /* * Only 'regular' nodes does not accept such requests, checking * HubRegularNode is faster, but if e.g. HubRegularI2PNode will be @@ -958,7 +958,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $locatorInstance An instance of a LocateableNode class for this node */ - public function determineUniversalNodeLocator () { + public function determineUniversalNodeLocator (): LocateableNode { // Is there cache? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); if (!isset($GLOBALS[__METHOD__])) { @@ -981,7 +981,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return void * @todo Find more to do here */ - public function updateNodeData () { + public function updateNodeData (): void { // Set some dummy configuration entries, e.g. node_status FrameworkBootstrap::getConfigurationInstance()->setConfigEntry('node_status', $this->getStateInstance()->getStateName()); } @@ -994,7 +994,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return void * @todo Handle thrown exception */ - public function handleAnswerStatusByMessageInstance (DeliverableMessage $messageInstance, Receivable $handlerInstance) { + public function handleAnswerStatusByMessageInstance (DeliverableMessage $messageInstance, Receivable $handlerInstance): void { // Construct configuration entry for handling class' name /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: messageInstance=%s,handlerInstance=%s - CALLED!', $messageInstance->__toString(), $handlerInstance->__toString())); $classConfigEntry = strtolower($messageData[NetworkPackageHandler::MESSAGE_ARRAY_TYPE] . '_status_' . $messageData[BaseXmlAnswerTemplateEngine::ANSWER_STATUS]) . '_handler_class'; @@ -1014,7 +1014,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $objectList Array of all accepted object types */ - public function getListFromAcceptedObjectTypes () { + public function getListFromAcceptedObjectTypes (): array { // Get registry instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance(); @@ -1035,7 +1035,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * @return void * @throws InvalidArgumentException If $nodeData is empty */ - public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData) { + public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $nodeData): void { // Validate parameter /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('BASE-HUB-NODE: dataSetInstance=%s,nodeData()=%d - EXIT!', $dataSetInstance->__toString(), count($nodeData))); if (count($nodeData) == 0) { @@ -1066,7 +1066,7 @@ abstract class BaseHubNode extends BaseHubSystem implements Updateable, AddableC * * @return $nodeData Node's data */ - public function createNodeDataArray () { + public function createNodeDataArray (): array { // Get request instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('BASE-HUB-NODE: CALLED!'); $requestInstance = FrameworkBootstrap::getRequestInstance(); diff --git a/application/hub/classes/pools/peer/class_DefaultPeerPool.php b/application/hub/classes/pools/peer/class_DefaultPeerPool.php index 27361313a..45cba288f 100644 --- a/application/hub/classes/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/classes/pools/peer/class_DefaultPeerPool.php @@ -60,7 +60,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { * @param $listenerInstance A Listenable instance * @return $poolInstance An instance a PoolablePeer class */ - public static final function createDefaultPeerPool (Listenable $listenerInstance) { + public static final function createDefaultPeerPool (Listenable $listenerInstance): PoolablePeer { // Get new instance $poolInstance = new DefaultPeerPool(); @@ -78,7 +78,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { * @return void * @throws InvalidSocketException If the given socket has an error */ - private function validateSocket (StorableSocket $socketInstance) { + private function validateSocket (StorableSocket $socketInstance): void { // Is it a valid resource? //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('HUB-SYSTEM: socketInstance->socketResource=%s - CALLED!', $socketInstance->getPrintableName())); if (!$socketInstance->isValidSocket()) { @@ -234,12 +234,12 @@ class DefaultPeerPool extends BasePool implements PoolablePeer { * * @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 + * @return $socketInstance An instance of a StorableSocket class or NULL if it cannot be discovered * @throws InvalidArgumentException If a parameter is not valid * @throws InvalidConnectionTypeException If the provided connection type is not valid * @throws LogicException If an expected array element is missing */ - public function getSocketFromPackageInstance (DeliverablePackage $packageInstance, string $connectionType = NULL) { + public function getSocketFromPackageInstance (DeliverablePackage $packageInstance, string $connectionType = NULL): ?StorableSocket { // Validate parameter //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('DEFAULT-PEER-POOL: packageInstance=%s,connectionType[%s]=%s - CALLED!', $packageInstance->__toString(), gettype($connectionType), $connectionType)); if (empty($connectionType)) { diff --git a/application/hub/classes/registry/socket/class_SocketRegistry.php b/application/hub/classes/registry/socket/class_SocketRegistry.php index d0bc80fb7..533ab7a3d 100644 --- a/application/hub/classes/registry/socket/class_SocketRegistry.php +++ b/application/hub/classes/registry/socket/class_SocketRegistry.php @@ -90,7 +90,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * * @return $registryInstance An instance of this class */ - public static final function createSocketRegistry () { + public static final function createSocketRegistry (): RegisterableSocket { // Is there an instance? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: self::selfInstance[]=%s - CALLED!', gettype(self::$selfInstance))); if (is_null(self::$selfInstance)) { @@ -108,7 +108,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * * @return $registryInstances An array with all registry instances */ - public final function getInstanceRegistry () { + public final function getInstanceRegistry (): array { return self::$registryInstances; } @@ -119,7 +119,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @param $infoInstance An instance of a ShareableInfo class * @return $key A string representation of the socket for the registry */ - private function generateObjectRegistryKeyFromInfoInstance (ShareableInfo $infoInstance) { + private function generateObjectRegistryKeyFromInfoInstance (ShareableInfo $infoInstance): string { // Get connection type and port number and add both together /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: infoInstance=%s - CALLED!', $infoInstance->__toString())); $key = sprintf('%s:%s:%s:%s:%s', @@ -141,7 +141,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @param $infoInstance An instance of a ShareableInfo class * @return $key A string representation of the listener for the registry */ - private function getRegistryKeyFromInfo (ShareableInfo $infoInstance) { + private function getRegistryKeyFromInfo (ShareableInfo $infoInstance): string { // Get the key /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: infoInstance=%s - CALLED!', $infoInstance->__toString())); $key = $infoInstance->getProtocolName(); @@ -157,7 +157,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @param $infoInstance An instance of a ShareableInfo class * @return $isRegistered Whether the listener is registered */ - private function isInfoRegistered (ShareableInfo $infoInstance) { + private function isInfoRegistered (ShareableInfo $infoInstance): bool { // Get the key /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ' - CALLED!'); $key = $this->generateObjectRegistryKeyFromInfoInstance($infoInstance); @@ -178,7 +178,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @param $socketInstance An instance of a StorableSocket class * @return $isRegistered Whether the given socket resource is registered */ - public function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance) { + public function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance): bool { // Default is not registered /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage('SOCKET-REGISTRY: protocolName=' . $infoInstance->getProtocolName() . ',socketResource[' . gettype($socketInstance->getSocketResource()) . ']=' . $socketInstance->getPrintableName() . ' - CALLED!'); $isRegistered = FALSE; @@ -223,7 +223,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @throws SocketAlreadyRegisteredException If the given socket is already registered * @return void */ - public function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance) { + public function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance): void { // Is the socket already registered? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: infoInstance->protocolName=%s,infoInstance->socketResource[%s]=%s - CALLED!', $infoInstance->getProtocolName(), gettype($socketInstance->getSocketResource()), $socketInstance->getPrintableName())); if ($this->isSocketRegistered($infoInstance, $socketInstance)) { @@ -257,7 +257,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @return $socketInstance An instance of a StorableSocket class * @throws NoSocketRegisteredException If the requested socket is not registered */ - public function getRegisteredSocketResource (Listenable $listenerInstance) { + public function getRegisteredSocketResource (Listenable $listenerInstance): StorableSocket { // The socket must be registered before we can return it /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: listenerInstance=%s - CALLED!', $listenerInstance->__toString())); if (!$this->isInfoRegistered($listenerInstance)) { @@ -283,7 +283,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @param $packageInstance An instance of a DeliverablePackage class * @return $infoInstance An instance of a ShareableInfo class */ - public function determineInfoInstanceByPackageInstance (DeliverablePackage $packageInstance) { + public function determineInfoInstanceByPackageInstance (DeliverablePackage $packageInstance): ShareableInfo { // Init info instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: packageInstance=%s - CALLED!', $packageInstance)); $infoInstance = NULL; @@ -302,7 +302,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke /* NOSY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-REGISTRY: key=%s,subKey=%s, calling socketInstance->getListenerInstance() ...', $key, $subKey)); //* DEBUG-DIE: */ die(__METHOD__ . ': socketInstance=' . print_r($socketInstance, TRUE)); $listenerInstance = $socketInstance->getListenerInstance(); - $helperInstance = $socketInstance->getHelperInstance(); + $helperInstance = $socketInstance->isHelperInstanceSet() ? $socketInstance->getHelperInstance() : NULL; // Is a listener or helper set? /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugMessage(sprintf('SOCKET-REGISTRY: key=%s,subKey=%s,listenerInstance[]=%s,helperInstance[]=%s', $key, $subKey, gettype($listenerInstance), gettype($helperInstance))); @@ -354,7 +354,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke * @return $isRegistered Whether such a socket is registered * @todo May extract this loop into private method and invoke it with CONNECTION_TYPE_INCOMING for later expansion also on outgoing/file sockets? */ - public function isIncomingSocketRegistered (Listenable $listenerInstance) { + public function isIncomingSocketRegistered (Listenable $listenerInstance): bool { // Default is not found /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->traceMessage(sprintf('SOCKET-REGISTRY: listenerInstance=%s (protocol: %s) - CALLED!', $listenerInstance->__toString(), strtoupper($listenerInstance->getProtocolName()))); //* DEBUG-DIE: */ ApplicationEntryPoint::exitApplication(sprintf('[%s:%d]: this=%s', __METHOD__, __LINE__, print_r($this, TRUE))); diff --git a/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php b/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php index 3c8ded6ef..c3e71ccb6 100644 --- a/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php +++ b/application/hub/classes/resolver/protocol/class_BaseProtocolResolver.php @@ -49,7 +49,7 @@ abstract class BaseProtocolResolver extends BaseHubSystem implements ProtocolRes * * @return $protocolName Name of used protocol */ - public final function getProtocolName () { + public final function getProtocolName (): string { return $this->protocolName; } @@ -59,7 +59,7 @@ abstract class BaseProtocolResolver extends BaseHubSystem implements ProtocolRes * @param $protocolName Name of used protocol * @return void */ - protected final function setProtocolName (string $protocolName) { + protected final function setProtocolName (string $protocolName): void { $this->protocolName = $protocolName; } diff --git a/application/hub/classes/tags/package/class_PackageTags.php b/application/hub/classes/tags/package/class_PackageTags.php index 954b3be6e..b82d7438e 100644 --- a/application/hub/classes/tags/package/class_PackageTags.php +++ b/application/hub/classes/tags/package/class_PackageTags.php @@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Tag\Package; use Org\Shipsimu\Hub\Factory\Handler\Protocol\ProtocolHandlerFactory; use Org\Shipsimu\Hub\Factory\Registry\Object\ObjectTypeRegistryFactory; 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; use Org\Shipsimu\Hub\Node\Tagging\InvalidTagException; @@ -73,7 +74,7 @@ class PackageTags extends BaseTag implements Tagable { * * @return $tagsInstance An instance of a Tagable class */ - public static final function createPackageTags () { + public static final function createPackageTags (): Tagable { // Get new instance $tagsInstance = new PackageTags(); @@ -87,7 +88,7 @@ class PackageTags extends BaseTag implements Tagable { * * @return void */ - private function initObjectRegistry () { + private function initObjectRegistry (): void { // Get the application instance /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: Initializing object registry - CALLED!'); $applicationInstance = ApplicationHelper::getSelfInstance(); @@ -114,7 +115,7 @@ class PackageTags extends BaseTag implements Tagable { * @param $packageInstance An instance of a DeliverablePackage class * @return void */ - private function extractTagsFromPackageInstance (DeliverablePackage $packageInstance) { + private function extractTagsFromPackageInstance (DeliverablePackage $packageInstance): void { // Debug message /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); //* PRINTR-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('PACKAGE-TAGS: packageInstance' . print_r($packageInstance, TRUE)); @@ -140,7 +141,7 @@ class PackageTags extends BaseTag implements Tagable { * @return void * @throws InvalidTagException If a provided tag from the package data is invalid */ - private function verifyAllTags (DeliverablePackage $packageInstance) { + private function verifyAllTags (DeliverablePackage $packageInstance): void { // Get the registry /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $objectRegistryInstance = ObjectTypeRegistryFactory::createObjectTypeRegistryInstance(); @@ -179,7 +180,7 @@ class PackageTags extends BaseTag implements Tagable { * @param $packageInstance An instance of a DeliverablePackage class * @return $lastProtocol An instance of the last used HandleableProtocol class */ - public function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance) { + public function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance): HandleableProtocol { // Extract the tags /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $this->extractTagsFromPackageInstance($packageInstance); @@ -199,7 +200,7 @@ class PackageTags extends BaseTag implements Tagable { * @param $listenerInstance A Listenable instance * @return $accepts Whether it is accepted */ - public function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance) { + public function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance): bool { // Extract the tags /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('PACKAGE-TAGS: packageInstance=%s - CALLED!', $packageInstance->__toString())); $this->extractTagsFromPackageInstance($packageInstance); diff --git a/application/hub/classes/template/xml/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/classes/template/xml/objects/class_XmlObjectRegistryTemplateEngine.php index 7e7744b73..aa1b9e04d 100644 --- a/application/hub/classes/template/xml/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/classes/template/xml/objects/class_XmlObjectRegistryTemplateEngine.php @@ -83,7 +83,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * @throws BasePathReadProtectedException If $templateBasePath is * read-protected */ - public static final function createXmlObjectRegistryTemplateEngine () { + public static final function createXmlObjectRegistryTemplateEngine (): CompileableXmlTemplate { // Get a new instance $templateInstance = new XmlObjectRegistryTemplateEngine(); @@ -101,7 +101,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * @param $characters Characters to handle * @return void */ - public function characterHandler ($resource, string $characters) { + public function characterHandler ($resource, string $characters): void { // Trim all spaces away //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('XML-OBJECT-REGISTRY-TEMPLATE-ENGINE: resource[%s]=%s,characters[%s]=%s - CALLED!', gettype($resource), $resource, gettype($characters), $characters)); $characters = trim($characters); @@ -132,7 +132,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return $fqfn Full-qualified file name of the menu cache */ - public function getObjectRegistryCacheFqfn () { + public function getObjectRegistryCacheFqfn (): string { DebugMiddleware::getSelfInstance()->partialStub('Please implement this method.'); } @@ -141,7 +141,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectRegistry () { + protected function startObjectRegistry (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', 'object-registry'); } @@ -151,7 +151,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectList () { + protected function startObjectList (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', 'object-list'); } @@ -161,7 +161,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectListEntry () { + protected function startObjectListEntry (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', 'object-list-entry'); } @@ -171,7 +171,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectName () { + protected function startObjectName (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_NAME); } @@ -181,7 +181,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectRecipientLimitation () { + protected function startObjectRecipientLimitation (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_LIMITATION); } @@ -191,7 +191,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectMaxSpread () { + protected function startObjectMaxSpread (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_MAX_SPREAD); } @@ -201,7 +201,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectProtocol () { + protected function startObjectProtocol (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_PROTOCOL); } @@ -211,7 +211,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function startObjectRecipientType () { + protected function startObjectRecipientType (): void { // Push the node name on the stacker $this->getStackInstance()->pushNamed('node_object_registry', self::OBJECT_TYPE_DATA_RECIPIENT_TYPE); } @@ -221,7 +221,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectRecipientType () { + protected function finishObjectRecipientType (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -231,7 +231,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectProtocol () { + protected function finishObjectProtocol (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -241,7 +241,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectMaxSpread () { + protected function finishObjectMaxSpread (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -251,7 +251,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectRecipientLimitation () { + protected function finishObjectRecipientLimitation (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -261,7 +261,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectName () { + protected function finishObjectName (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -271,7 +271,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectListEntry () { + protected function finishObjectListEntry (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -281,7 +281,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectList () { + protected function finishObjectList (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } @@ -291,7 +291,7 @@ class XmlObjectRegistryTemplateEngine extends BaseXmlTemplateEngine implements C * * @return void */ - protected function finishObjectRegistry () { + protected function finishObjectRegistry (): void { // Pop the last entry $this->getStackInstance()->popNamed('node_object_registry'); } diff --git a/application/hub/exceptions/socket/class_NoSocketRegisteredException.php b/application/hub/exceptions/socket/class_NoSocketRegisteredException.php index d338b41ac..123f5d0c3 100644 --- a/application/hub/exceptions/socket/class_NoSocketRegisteredException.php +++ b/application/hub/exceptions/socket/class_NoSocketRegisteredException.php @@ -38,7 +38,7 @@ class NoSocketRegisteredException extends AbstractSocketException { * @param $code Error code * @return void */ - public function __construct (HandleableProtocol $protocolInstance, $code) { + public function __construct (HandleableProtocol $protocolInstance, int $code) { // Construct the message $message = sprintf('[%s:] Requested socket is not yet registered.', $protocolInstance->__toString() diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index f6754ece3..9e2a470e9 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -60,19 +60,10 @@ interface StorableSocket extends FrameworkInterface { const SOCKET_PROTOCOL_TCP = 'tcp'; const SOCKET_PROTOCOL_UDP = 'udp'; - /** - * Connection type 'incoming' - */ + // Connection types + const CONNECTION_TYPE_INVALID = 'invalid'; const CONNECTION_TYPE_INCOMING = 'incoming'; - - /** - * Connection type 'outgoing' - */ const CONNECTION_TYPE_OUTGOING = 'outgoing'; - - /** - * Connection type 'server' - */ const CONNECTION_TYPE_SERVER = 'server'; // Exception codes @@ -85,7 +76,7 @@ interface StorableSocket extends FrameworkInterface { * @throws InvalidSocketException If stored socket is invalid * @throws NullPointerException If listener instance is not given */ - function bindSocketToFile (); + function bindSocketToFile (): bool; /** * Tries to bind to attached listener's address and port @@ -94,7 +85,7 @@ interface StorableSocket extends FrameworkInterface { * @throws InvalidSocketException If stored socket is invalid * @throws NullPointerException If listener instance is not given */ - function bindSocketToListener (); + function bindSocketToListener (): bool; /** * Tries to listen on the socket @@ -102,7 +93,7 @@ interface StorableSocket extends FrameworkInterface { * @return $result Result from listening on socket * @throws InvalidSocketException If stored socket is invalid */ - function listenToSocket (); + function listenToSocket (): bool; /** * Tries to set non-blocking I/O on stored socket @@ -110,7 +101,7 @@ interface StorableSocket extends FrameworkInterface { * @return $result Result of changing to non-blocking I/O * @throws InvalidSocketException If stored socket is invalid */ - function enableSocketNonBlocking (); + function enableSocketNonBlocking (): bool; /** * Tries to enable option "reuse address" @@ -118,7 +109,7 @@ interface StorableSocket extends FrameworkInterface { * @return void * @throws InvalidSocketException If stored socket is invalid */ - function enableSocketReuseAddress (); + function enableSocketReuseAddress (): bool; /** * Determines socket's "peer name", mostly address and port number. @@ -128,36 +119,36 @@ interface StorableSocket extends FrameworkInterface { * @return $result Result from asking for peer address * @throws InvalidSocketException If stored socket is invalid */ - function determineSocketPeerName (string &$peerAddress, int &$peerPort); + function determineSocketPeerName (string &$peerAddress, int &$peerPort): bool; /** * Calls socket_select() on stored socket resource * - * @return $socketInstance An instance of a StorableSocket class + * @return $socketInstance An instance of a StorableSocket class or NULL if no new socket was detected * @throws InvalidSocketException If stored socket is invalid */ - function acceptNewIncomingSocket (); + function acceptNewIncomingSocket (): ?StorableSocket; /** * Tries to identify the socket peer by calling socket_getpeer() * * @return $result Whether the peer has been identified */ - function identifySocketPeer (); + function identifySocketPeer (): bool; /** * Tries to set socket timeout option * * @return $result Whether the option has been set */ - function setSocketTimeoutOptions (); + function setSocketTimeoutOptions (): bool; /** * Tries to enable out-of-band (OOB) data * * @return $result Whether OOB has been enabled */ - function enableSocketOutOfBandData (); + function enableSocketOutOfBandData (): bool; /** * Connects to socket recipient (supplied in package data array @@ -165,7 +156,7 @@ interface StorableSocket extends FrameworkInterface { * @return $result Result from calling socket_connect() * @throws InvalidSocketException If stored socket is invalid */ - function connectToSocketRecipient (); + function connectToSocketRecipient (): bool; /** * Writes given buffer array to socket by calling socket_write(). The sent @@ -180,14 +171,14 @@ interface StorableSocket extends FrameworkInterface { * @return $result Result of calling socket_write() * @throws InvalidSocketException If stored socket is invalid */ - function writeBufferToSocketByArray (array &$socketBuffer, int &$sentBytes); + function writeBufferToSocketByArray (array &$socketBuffer, int &$sentBytes): bool; /** * Getter for socket procotol field * * @return $socketProtocol Socket protocol (e.g. 'tcp' for TCP/IPv4, 'file' for Uni* file sockets) */ - function getSocketProtocol (); + function getSocketProtocol (): string; /** * Getter for socket recipient UNL @@ -196,7 +187,7 @@ interface StorableSocket extends FrameworkInterface { * @throws LogicException If 'recipient' array element is not found * @throws InvalidSocketException If stored socket is invalid */ - function getSocketRecipientUnl (); + function getSocketRecipientUnl (): string; /** * Getter for socket recipient's address part @@ -204,7 +195,7 @@ interface StorableSocket extends FrameworkInterface { * @return $recipientAddress Recipient's address part * @throws InvalidSocketException If stored socket is invalid */ - function getSocketRecipientAddress (); + function getSocketRecipientAddress (): string; /** * Getter for socket recipient's port part @@ -212,7 +203,7 @@ interface StorableSocket extends FrameworkInterface { * @return $recipientPort Recipient's port part * @throws InvalidSocketException If stored socket is invalid */ - function getSocketRecipientPort (); + function getSocketRecipientPort (): int; /** * Checks whether the given Universal Node Locator matches with the one from package data @@ -220,7 +211,7 @@ interface StorableSocket extends FrameworkInterface { * @param $unl A Universal Node Locator * @return $matches Whether $address matches with the one from package data */ - function ifAddressMatches (string $unl); + function ifAddressMatches (string $unl): bool; /** * Checks whether the given socket matches with stored @@ -228,7 +219,7 @@ interface StorableSocket extends FrameworkInterface { * @param $socketResource An instance of a Socket class * @return $matches Whether given socket matches */ - function ifSocketResourceMatches (Socket $socketResource); + function ifSocketResourceMatches (Socket $socketResource): bool; /** * Shuts down a given socket resource. This method does only ease calling @@ -236,7 +227,7 @@ interface StorableSocket extends FrameworkInterface { * * @return void */ - function shutdownSocket (); + function shutdownSocket (): void; /** * Half-shuts down a given socket resource. This method does only ease calling @@ -244,14 +235,14 @@ interface StorableSocket extends FrameworkInterface { * * @return void */ - function halfShutdownSocket (); + function halfShutdownSocket (): void; /** * Validates stored stocket * * @return $isValidSocket Whether the stored socket is valid */ - function isValidSocket (); + function isValidSocket (): bool; /** * Getter for last socket error @@ -259,7 +250,7 @@ interface StorableSocket extends FrameworkInterface { * @return $errorCode Last socket error * @throws InvalidSocketException If stored socket is invalid */ - function getLastSocketErrorCode (); + function getLastSocketErrorCode (): int; /** * Getter for last socket error message @@ -267,14 +258,14 @@ interface StorableSocket extends FrameworkInterface { * @return $errorMessage Last socket error message * @throws InvalidSocketException If stored socket is invalid */ - function getLastSocketErrorMessage (); + function getLastSocketErrorMessage (): string; /** * Translates last socket error code into a human-readable form * * @return $codeName Code name to used e.g. with some_$codeName_socket_error_class or so */ - function translateLastSocketErrorCodeToName (); + function translateLastSocketErrorCodeToName (): string; /** * Handles socket error for given socket resource and peer data. This method @@ -288,7 +279,7 @@ interface StorableSocket extends FrameworkInterface { * @throws InvalidSocketException If the stored socket resource is no socket resource * @throws NoSocketErrorDetectedException If socket_last_error() gives zero back */ - function handleSocketError (string $method, int $line); + function handleSocketError (string $method, int $line): void; /** * Do the shutdown sequence for this connection helper @@ -297,7 +288,7 @@ interface StorableSocket extends FrameworkInterface { * @throws SocketShutdownException If the current socket could not be shut down * @throws BaseMethodCallException If this method is possibly called twice */ - function doShutdown (); + function doShutdown (): void; /** * Checks whether the given connection type is valid @@ -305,7 +296,7 @@ interface StorableSocket extends FrameworkInterface { * @param $connectionType Type of connection, can be 'incoming', 'outgoing' or 'server' * @return $isValid Whether the provided connection type is valid */ - function isValidConnectionType (string $connectionType); + function isValidConnectionType (string $connectionType): bool; /** * Clears last socket error @@ -314,7 +305,7 @@ interface StorableSocket extends FrameworkInterface { * @throws InvalidSocketException If stored socket is invalid * @throws BadMethodCallException If no socket error was reported but method called */ - function clearLastSocketError (); + function clearLastSocketError (): void; /** * Registers whether helper or listener instance found in given info @@ -323,7 +314,7 @@ interface StorableSocket extends FrameworkInterface { * @param $infoInstance An instance of a ShareableInfo class * @return void */ - function registerInfoInstance (ShareableInfo $infoInstance); + function registerInfoInstance (ShareableInfo $infoInstance): void; /** * Reads (binary) data from socket instance @@ -331,14 +322,14 @@ interface StorableSocket extends FrameworkInterface { * @return $rawData Raw data being read * @throws InvalidSocketException If the stored socket is not valid */ - function readDataFromSocket (); + function readDataFromSocket (): mixed; /** * Getter for socket file instance * * @return $socketFile An instance of a SplFileInfo class */ - public function getSocketFile (); + function getSocketFile (): SplFileInfo; /** * Setter for socket file instance @@ -346,13 +337,13 @@ interface StorableSocket extends FrameworkInterface { * @param $socketFile An instance of a SplFileInfo class * @return void */ - public function setSocketFile (SplFileInfo $socketFile); + function setSocketFile (SplFileInfo $socketFile): void; /** * Getter for socket type * * @return $socketFile Stocket type */ - public function getSocketType (); + function getSocketType (): string; } diff --git a/application/hub/interfaces/database/frontend/node_dht/class_NodeDhtFrontend.php b/application/hub/interfaces/database/frontend/node_dht/class_NodeDhtFrontend.php index c1b1263d6..d0829cc62 100644 --- a/application/hub/interfaces/database/frontend/node_dht/class_NodeDhtFrontend.php +++ b/application/hub/interfaces/database/frontend/node_dht/class_NodeDhtFrontend.php @@ -11,6 +11,7 @@ use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; use Org\Mxchange\CoreFramework\Criteria\Local\LocalSearchCriteria; use Org\Mxchange\CoreFramework\Database\Frontend\DatabaseFrontend; use Org\Mxchange\CoreFramework\Handler\DataSet\HandleableDataSet; +use Org\Mxchange\CoreFramework\Result\Search\SearchableResult; /** * An interface for distributed hash tables for nodes @@ -40,7 +41,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * * @return $unpublishedEntriesInstance Result instance */ - function getUnpublishedEntriesInstance (); + function getUnpublishedEntriesInstance (): SearchableResult; /** * Checks whether the local (*this*) node is registered in the DHT by @@ -48,14 +49,14 @@ interface NodeDhtFrontend extends DatabaseFrontend { * * @return $isRegistered Whether *this* node is registered in the DHT */ - function isLocalNodeRegistered (); + function isLocalNodeRegistered (): bool; /** * Registeres the local (*this*) node with its data in the DHT. * * @return void */ - function registerLocalNode (); + function registerLocalNode (): void; /** * Updates local (*this*) node's data in DHT, this is but not limited to the @@ -63,7 +64,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * * @return void */ - function updateLocalNode (); + function updateLocalNode (): void; /** * Finds a node locally by given session id @@ -72,7 +73,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @return $resultInstance An instance of a SearchableResult class * @throws InvalidArgumentException If parameter $sessionId is not valid */ - function findNodeLocalBySessionId (string $sessionId); + function findNodeLocalBySessionId (string $sessionId): SearchableResult; /** * Finds a node locally by given UNL instance @@ -80,7 +81,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $locatorInstance An instance of a LocateableNode class * @return $resultInstance An instance of a SearchableResult class */ - function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance); + function findNodeLocalByLocatorInstance (LocateableNode $locatorInstance): SearchableResult; /** * Registeres a node by given message data. @@ -89,7 +90,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $handlerInstance An instance of a HandleableDataSet class * @return void */ - function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance); + function registerNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance): void; /** * Updates an existing entry in node list @@ -99,7 +100,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $searchInstance An instance of LocalSearchCriteria class * @return void */ - function updateNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance); + function updateNodeByMessageInstance (DeliverableMessage $messageInstance, HandleableDataSet $handlerInstance, LocalSearchCriteria $searchInstance): void; /** * Determines whether the given node data is already inserted in the DHT @@ -107,7 +108,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $nodeData An array with valid node data * @return $isRegistered Whether the given node data is already inserted */ - function isNodeRegistered (array $nodeData); + function isNodeRegistered (array $nodeData): bool; /** * Registers a node with given data in the DHT. If the node is already @@ -117,7 +118,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @return void * @throws NodeAlreadyRegisteredException If the node is already registered */ - function registerNode (array $nodeData); + function registerNode (array $nodeData): void; /** * Updates a node's entry in the DHT with given data. This will enrich or @@ -128,7 +129,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @return void * @throws NodeDataMissingException If the node's data is missing */ - function updateNode (array $nodeData); + function updateNode (array $nodeData): void; /** * Checks whether there are unpublished entries @@ -136,7 +137,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @return $hasUnpublished Whether there are unpublished entries * @todo Add minimum/maximum age limitations */ - function hasUnpublishedEntries (); + function hasUnpublishedEntries (): bool; /** * Initializes publication of DHT entries. This does only prepare @@ -146,7 +147,7 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @return void * @todo Add timestamp to dataset instance */ - function initEntryPublication (); + function initEntryPublication (): void; /** * Removes non-public data from given array. @@ -154,15 +155,15 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $data An array with possible non-public data that needs to be removed. * @return $data A cleaned up array with only public data. */ - function removeNonPublicDataFromArray(array $data); + function removeNonPublicDataFromArray(array $data): array; /** * Find recipients for given package data and exclude the sender * * @param $packageInstance An instance of a DeliverablePackage class - * @return $recipients An indexed array with DHT recipients + * @return $resultInstance An instance of a SearchableResult class */ - function getResultFromExcludedSender (DeliverablePackage $packageInstance); + function getResultFromExcludedSender (DeliverablePackage $packageInstance): SearchableResult; /** * Find recopients by given key/value pair. First look for the key and if it @@ -172,13 +173,13 @@ interface NodeDhtFrontend extends DatabaseFrontend { * @param $value Value to compare if key matches * @return $recipients An indexed array with DHT recipients */ - function getResultFromKeyValue (string $key, $value); + function getResultFromKeyValue (string $key, mixed $value): array; /** * Enable DHT bootstrap request acceptance for local node * * @return void */ - function enableAcceptDhtBootstrap (); + function enableAcceptDhtBootstrap (): void; } diff --git a/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php b/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php index 63863296d..9b750f05c 100644 --- a/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php +++ b/application/hub/interfaces/discovery/recipient/socket/class_DiscoverableSocket.php @@ -3,8 +3,10 @@ namespace Org\Shipsimu\Hub\Discovery\Socket; // Import application-specific stuff +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Discovery\Recipient\DiscoverableRecipient; use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; +use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; /** @@ -40,7 +42,7 @@ interface DiscoverableSocket extends DiscoverableRecipient { * @throws NoListGroupException If the procol group is not found in peer list * @throws NullPointerException If listenerInstance is NULL */ - function discoverSocket (DeliverablePackage $packageInstance, string $connectionType); + function discoverSocket (DeliverablePackage $packageInstance, string $connectionType): StorableSocket; /** * Tries to dicover the right listener instance @@ -49,6 +51,6 @@ interface DiscoverableSocket extends DiscoverableRecipient { * @param $packageInstance An instance of a DeliverablePackage class * @return $listenerInstance An instance of a Listenable instance or null */ - function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance); + function discoverListenerInstance (HandleableProtocol $protocolInstance, DeliverablePackage $packageInstance): Listenable; } diff --git a/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php b/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php index 7faea30cd..5b446fe50 100644 --- a/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php +++ b/application/hub/interfaces/handler/protocol/class_HandleableProtocol.php @@ -37,14 +37,14 @@ interface HandleableProtocol extends Handleable, HubInterface { * * @return $port The port number */ - function getPort (); + function getPort (): int; /** * Getter for protocol name * * @return $protocol Name of used protocol */ - function getProtocolName (); + function getProtocolName (): string; /** * Default implementation for returning address part, may not be suitable @@ -52,7 +52,7 @@ interface HandleableProtocol extends Handleable, HubInterface { * * @return $address Address part for the UNL */ - function getAddressPart (); + function getAddressPart (): string; /** * Validates given 'recipient' if it is a valid UNL. This means that the UNL @@ -61,7 +61,7 @@ interface HandleableProtocol extends Handleable, HubInterface { * @param $packageInstance Valid raw package data * @return $isValid Whether the UNL can be validated */ - function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance); + function isValidUniversalNodeLocatorByPackageInstance (DeliverablePackage $packageInstance): bool; /** * If the found UNL (address) matches own external or internal address @@ -69,6 +69,6 @@ interface HandleableProtocol extends Handleable, HubInterface { * @param $unl UNL to test * @return $ifMatches Whether the found UNL matches own addresss */ - function isOwnAddress (string $unl); + function isOwnAddress (string $unl): bool; } diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index ff8994952..d9c938b29 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -62,13 +62,13 @@ interface ConnectionHelper extends HubHelper { * @param $socketInstance A StorableSocket instance * @return void */ - function setSocketInstance (StorableSocket $socketInstance); + function setSocketInstance (StorableSocket $socketInstance): void; /** * Getter for socket instance * * @return $socketInstance An instance of a StorableSocket class */ - function getSocketInstance (); + function getSocketInstance (): StorableSocket; } diff --git a/application/hub/interfaces/listener/class_Listenable.php b/application/hub/interfaces/listener/class_Listenable.php index dc5a123ff..f3e3bf005 100644 --- a/application/hub/interfaces/listener/class_Listenable.php +++ b/application/hub/interfaces/listener/class_Listenable.php @@ -6,6 +6,7 @@ namespace Org\Shipsimu\Hub\Listener; use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; +use Org\Shipsimu\Hub\Pool\Peer\PoolablePeer; /** * An interface for listeners @@ -35,14 +36,14 @@ interface Listenable extends HubInterface { * * @return void */ - function initListener(); + function initListener(): void; /** * "Listens" for incoming network packages * * @return void */ - function doListen(); + function doListen(): void; /** * Checks whether the listener would accept the given package data array @@ -50,7 +51,7 @@ interface Listenable extends HubInterface { * @param $packageInstance An instance of a DeliverablePackage class * @return $accepts Whether this listener does accept */ - function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance); + function ifListenerAcceptsPackageData (DeliverablePackage $packageInstance): bool; /** * Monitors incoming raw data from the handler and transfers it to the @@ -58,28 +59,28 @@ interface Listenable extends HubInterface { * * @return void */ - function monitorIncomingRawData (); + function monitorIncomingRawData (): void; /** * Getter for listen address * * @return $listenAddress The address this listener should listen on */ - function getListenAddress (); + function getListenAddress (): string; /** * Getter for listen port * * @return $listenPort The port this listener should listen on */ - function getListenPort (); + function getListenPort (): int; /** * Getter for peer pool instance * * @return $poolInstance The peer pool instance we shall set */ - function getPoolInstance (); + function getPoolInstance (): PoolablePeer; /** * Setter for socket instance @@ -87,13 +88,13 @@ interface Listenable extends HubInterface { * @param $socketInstance A StorableSocket instance * @return void */ - function setSocketInstance (StorableSocket $socketInstance); + function setSocketInstance (StorableSocket $socketInstance): void; /** * Getter for socket instance * * @return $socketInstance An instance of a StorableSocket class */ - function getSocketInstance (); + function getSocketInstance (): StorableSocket; } diff --git a/application/hub/interfaces/pool/peer/class_PoolablePeer.php b/application/hub/interfaces/pool/peer/class_PoolablePeer.php index 5488d3e5f..95ad82959 100644 --- a/application/hub/interfaces/pool/peer/class_PoolablePeer.php +++ b/application/hub/interfaces/pool/peer/class_PoolablePeer.php @@ -61,6 +61,6 @@ interface PoolablePeer extends Poolable, SocketTag { * @return $sockets An array with sockets of given type * @throws InvalidConnectionTypeException If the found connection type is not valid */ - function getSocketsByConnectionType (string $connectionType); + function getSocketsByConnectionType (string $connectionType): array; } diff --git a/application/hub/interfaces/registry/socket/class_RegisterableSocket.php b/application/hub/interfaces/registry/socket/class_RegisterableSocket.php index a76ee2a08..f2f51f33a 100644 --- a/application/hub/interfaces/registry/socket/class_RegisterableSocket.php +++ b/application/hub/interfaces/registry/socket/class_RegisterableSocket.php @@ -42,7 +42,7 @@ interface RegisterableSocket extends Registerable { * @param $socketInstance An instance of a StorableSocket class * @return $isRegistered Whether the given socket resource is registered */ - function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance); + function isSocketRegistered (ShareableInfo $infoInstance, StorableSocket $socketInstance): bool; /** * Registeres given socket for listener or throws an exception if it is already registered @@ -52,7 +52,7 @@ interface RegisterableSocket extends Registerable { * @return void * @throws SocketAlreadyRegisteredException If the given socket is already registered */ - function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance); + function registerSocketInstance (ShareableInfo $infoInstance, StorableSocket $socketInstance): void; /** * Getter for given listener's socket resource @@ -69,7 +69,7 @@ interface RegisterableSocket extends Registerable { * @param $packageInstance An instance of a DeliverablePackage class * @return $infoInstance An instance of a ShareableInfo class */ - function determineInfoInstanceByPackageInstance (DeliverablePackage $packageInstance); + function determineInfoInstanceByPackageInstance (DeliverablePackage $packageInstance): ShareableInfo; /** * Checks whether a socket of a connection type 'incoming' is registered. @@ -77,6 +77,6 @@ interface RegisterableSocket extends Registerable { * @param $listenerInstance An instance of a Listenable class * @return $isRegistered Whether such a socket is registered */ - function isIncomingSocketRegistered (Listenable $listenerInstance); + function isIncomingSocketRegistered (Listenable $listenerInstance): bool; } diff --git a/application/hub/interfaces/shareable/info/class_ShareableInfo.php b/application/hub/interfaces/shareable/info/class_ShareableInfo.php index 78930ca55..e0437b49d 100644 --- a/application/hub/interfaces/shareable/info/class_ShareableInfo.php +++ b/application/hub/interfaces/shareable/info/class_ShareableInfo.php @@ -72,13 +72,13 @@ interface ShareableInfo extends HubInterface { * @param $socketInstance A StorableSocket instance * @return void */ - function setSocketInstance (StorableSocket $socketInstance); + function setSocketInstance (StorableSocket $socketInstance): void; /** * Getter for socket instance * * @return $socketInstance An instance of a StorableSocket class */ - function getSocketInstance (); + function getSocketInstance (): StorableSocket; } diff --git a/application/hub/interfaces/socket/class_SocketTag.php b/application/hub/interfaces/socket/class_SocketTag.php index adec943d3..6fc81faaa 100644 --- a/application/hub/interfaces/socket/class_SocketTag.php +++ b/application/hub/interfaces/socket/class_SocketTag.php @@ -3,6 +3,7 @@ namespace Org\Shipsimu\Hub\Tag\Socket; // Import application-specific stuff +use Org\Shipsimu\Hub\Container\Socket\StorableSocket; use Org\Shipsimu\Hub\Generic\HubInterface; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; @@ -37,6 +38,6 @@ interface SocketTag extends HubInterface { * @return $socketInstance An instance of a StorableSocket class * @throws InvalidConnectionTypeException If the provided connection type is not valid */ - function getSocketFromPackageInstance (DeliverablePackage $packageInstance, string $connectionType = NULL); + function getSocketFromPackageInstance (DeliverablePackage $packageInstance, string $connectionType = NULL): ?StorableSocket; } diff --git a/application/hub/interfaces/tags/class_Tagable.php b/application/hub/interfaces/tags/class_Tagable.php index d35bfafe9..f58e6d996 100644 --- a/application/hub/interfaces/tags/class_Tagable.php +++ b/application/hub/interfaces/tags/class_Tagable.php @@ -4,6 +4,7 @@ namespace Org\Shipsimu\Hub\Tag; // Import application-specific stuff use Org\Shipsimu\Hub\Generic\HubInterface; +use Org\Shipsimu\Hub\Handler\Protocol\HandleableProtocol; use Org\Shipsimu\Hub\Listener\Listenable; use Org\Shipsimu\Hub\Network\Package\DeliverablePackage; @@ -42,7 +43,7 @@ interface Tagable extends HubInterface { * @param $packageInstance An instance of a DeliverablePackage class * @return $protocolInstance An instance of a HandleableProtocol class */ - function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance); + function chooseProtocolFromPackageInstance (DeliverablePackage $packageInstance): HandleableProtocol; /** * Checks whether the given package data is accepted by the listener @@ -51,6 +52,6 @@ interface Tagable extends HubInterface { * @param $listenerInstance A Listenable instance * @return $accepts Whether it is accepted */ - function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance); + function ifPackageDataIsAcceptedByListener (DeliverablePackage $packageInstance, Listenable $listenerInstance): bool; } diff --git a/application/hub/traits/container/socket/class_StorableSocketTrait.php b/application/hub/traits/container/socket/class_StorableSocketTrait.php index a2c81c577..f4be47419 100644 --- a/application/hub/traits/container/socket/class_StorableSocketTrait.php +++ b/application/hub/traits/container/socket/class_StorableSocketTrait.php @@ -39,7 +39,7 @@ trait StorableSocketTrait { * @param $socketInstance A StorableSocket instance * @return void */ - public final function setSocketInstance (StorableSocket $socketInstance) { + public final function setSocketInstance (StorableSocket $socketInstance): void { $this->socketInstance = $socketInstance; } @@ -48,8 +48,17 @@ trait StorableSocketTrait { * * @return $socketInstance An instance of a StorableSocket class */ - public final function getSocketInstance () { + public final function getSocketInstance (): StorableSocket { return $this->socketInstance; } + /** + * Checks whether a socket instance is set + * + * @return $isset Whether a socket instance is set + */ + public final function isSocketInstanceSet (): bool { + return ($this->socketInstance instanceof StorableSocket); + } + } diff --git a/core b/core index 7c9c09a00..f66175754 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 7c9c09a0065013ed20f8361e87ad6ceda7896cb9 +Subproject commit f661757540897e6a0ee26231ddba8de4835fdd04 -- 2.39.5