From 5334882c200176bf3d9d187d360f2a97afb99e12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 25 Oct 2020 13:27:11 +0100 Subject: [PATCH] Continue: - removed all deprecated SOCKET_ARRAY_INDEX_* constants with proper setter invocations, still most are not implemented yet - needed to make setListerInstance() public MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../hub/classes/class_BaseHubSystem.php | 2 +- .../container/class_BaseHubContainer.php | 3 +- .../frontend/class_BaseHubDatabaseWrapper.php | 2 +- .../node/class_NodeObjectFactory.php | 10 ++++ .../factories/socket/class_SocketFactory.php | 50 +++++++++---------- .../classes/handler/class_BaseHubHandler.php | 2 +- .../package/class_NetworkPackageHandler.php | 18 ++++--- .../listener/class_BaseListenerDecorator.php | 2 +- .../container/socket/class_StorableSocket.php | 6 --- 9 files changed, 53 insertions(+), 42 deletions(-) diff --git a/application/hub/classes/class_BaseHubSystem.php b/application/hub/classes/class_BaseHubSystem.php index 92e0ac5ba..89f5aa2e5 100644 --- a/application/hub/classes/class_BaseHubSystem.php +++ b/application/hub/classes/class_BaseHubSystem.php @@ -378,7 +378,7 @@ abstract class BaseHubSystem extends BaseFrameworkSystem implements HubInterface * @param $listenerInstance A Listenable instance * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { + public final function setListenerInstance (Listenable $listenerInstance) { $this->listenerInstance = $listenerInstance; } diff --git a/application/hub/classes/container/class_BaseHubContainer.php b/application/hub/classes/container/class_BaseHubContainer.php index 220c1b4ea..284d82d64 100644 --- a/application/hub/classes/container/class_BaseHubContainer.php +++ b/application/hub/classes/container/class_BaseHubContainer.php @@ -70,6 +70,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { */ protected function __construct ($className) { // Call parent constructor + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('HUB-CONTAINER: className=%s - CONSTRUCTED!', $className)); parent::__construct($className); } @@ -240,7 +241,7 @@ abstract class BaseHubContainer extends BaseContainer implements HubInterface { * @param $listenerInstance A Listenable instance * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { + public final function setListenerInstance (Listenable $listenerInstance) { $this->listenerInstance = $listenerInstance; } diff --git a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php index ab09bca9c..3aa5e7ce0 100644 --- a/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php +++ b/application/hub/classes/database/frontend/class_BaseHubDatabaseWrapper.php @@ -240,7 +240,7 @@ abstract class BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements Hub * @param $listenerInstance A Listenable instance * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { + public final function setListenerInstance (Listenable $listenerInstance) { $this->listenerInstance = $listenerInstance; } diff --git a/application/hub/classes/factories/node/class_NodeObjectFactory.php b/application/hub/classes/factories/node/class_NodeObjectFactory.php index f7f2d45dc..3b9529acf 100644 --- a/application/hub/classes/factories/node/class_NodeObjectFactory.php +++ b/application/hub/classes/factories/node/class_NodeObjectFactory.php @@ -51,20 +51,26 @@ class NodeObjectFactory extends ObjectFactory { */ public static final function createNodeInstance (Requestable $requestInstance = NULL, Responseable $responseInstance = NULL) { // Get new factory instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: requestInstance[]=%s,responseInstance[]=%s - CALLED!', gettype($requestInstance), gettype($responseInstance))); $factoryInstance = new NodeObjectFactory(); // If there is no handler? if (GenericRegistry::getRegistry()->instanceExists('node')) { // Get handler from registry + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: Getting node instance from registry ...'); + $nodeInstance = GenericRegistry::getRegistry()->getInstance('node'); } elseif (($requestInstance instanceof Requestable) && ($responseInstance instanceof Responseable)) { // The default node-mode is from our configuration + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NODE-FACTORY: requestInstance and responseInstance are both set.'); $nodeMode = $factoryInstance->getConfigInstance()->getConfigEntry('node_default_mode'); // Is the node 'mode' parameter set? + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from CONFIG', $nodeMode)); if ($requestInstance->isRequestElementSet('mode')) { // Then use this which overrides the config entry temporarily $nodeMode = $requestInstance->getRequestElement('mode'); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeMode=%s - from REQUEST', $nodeMode)); } else { // Set it for easier re-usage $requestInstance->setRequestElement('mode', $nodeMode); @@ -78,15 +84,18 @@ class NodeObjectFactory extends ObjectFactory { ); // Get the node instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Loading class with className=%s ...', $className)); $nodeInstance = ObjectFactory::createObjectByName($className); // Get a registry $applicationInstance = GenericRegistry::getRegistry()->getInstance('application'); // Add node-specific filters + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Registering node-specific filters, responseInstance[]=%s', gettype($responseInstance))); $nodeInstance->addExtraFilters($applicationInstance->getControllerInstance(), $responseInstance); // Add it to the registry + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: Adding nodeInstance=%s to registry ...', $nodeInstance->__toString())); GenericRegistry::getRegistry()->addInstance('node', $nodeInstance); } else { // Throw an exception here @@ -94,6 +103,7 @@ class NodeObjectFactory extends ObjectFactory { } // Return the instance + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('NODE-FACTORY: nodeInstance=%s - EXIT!', $nodeInstance->__toString())); return $nodeInstance; } diff --git a/application/hub/classes/factories/socket/class_SocketFactory.php b/application/hub/classes/factories/socket/class_SocketFactory.php index e33598ae4..c41de7545 100644 --- a/application/hub/classes/factories/socket/class_SocketFactory.php +++ b/application/hub/classes/factories/socket/class_SocketFactory.php @@ -209,19 +209,23 @@ class SocketFactory extends ObjectFactory { */ public static final function createTcpOutgoingSocketFromPackageInstance (DeliverablePackage $packageInstance) { // Trace message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString())); + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: packageInstance=%s - CALLED!', $packageInstance->__toString())); // Create a socket instance $socketResource = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // Debug message - /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SOCKET-FACTORY: Created socket[' . gettype($socketResource) . ']=' . $socketResource . ' ...'); - - // Add socket type 'outgoing' to package data - $packageData[StorableSocket::SOCKET_ARRAY_INDEX_TYPE] = StorableSocket::CONNECTION_TYPE_OUTGOING; + /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: Created socketResource[%s]=%s ...', gettype($socketResource), $socketResource)); // Construct container class, this won't be reached if an exception is thrown - $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array($socketResource, StorableSocket::SOCKET_PROTOCOL_TCP, $packageData)); + $socketInstance = ObjectFactory::createObjectByConfiguredName('socket_container_class', array( + $socketResource, + StorableSocket::SOCKET_PROTOCOL_TCP, + $packageInstance, + )); + + // Set socket type to outgoing + $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_OUTGOING); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { @@ -291,10 +295,8 @@ class SocketFactory extends ObjectFactory { // Set listener instance and type $socketInstance->setListenerInstance($listenerInstance); $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER); - /* - StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(), - StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(), - */ + $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress()); + $socketInstance->setSocketListenPort($listenerInstance->getListenPort()); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { @@ -374,10 +376,8 @@ class SocketFactory extends ObjectFactory { // Set listener instance and socket type $socketInstance->setListenerInstance($listenerInstance); $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_SERVER); - /* - StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => $listenerInstance->getListenAddress(), - StorableSocket::SOCKET_ARRAY_INDEX_PORT => $listenerInstance->getListenPort(), - */ + $socketInstance->setSocketListenAddress($listenerInstance->getListenAddress()); + $socketInstance->setSocketListenPort($listenerInstance->getListenPort()); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { @@ -479,10 +479,8 @@ class SocketFactory extends ObjectFactory { // Try to accept a new (incoming) socket from current listener instance $acceptedSocketInstance = $current[Poolable::SOCKET_ARRAY_INSTANCE]->acceptNewIncomingSocket(); - // Trace message - //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance))); - // Return found socket instance + //* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: acceptedSocketInstance[]=%s - EXIT!', gettype($acceptedSocketInstance))); return $acceptedSocketInstance; } @@ -494,15 +492,17 @@ class SocketFactory extends ObjectFactory { * @return $socketInstance An instance of a StorableSocket class */ public static final function createIncomingSocketInstance ($socketResource, $socketProtocol) { - // Fake package data array (must be set later on) - $packageData = array( - StorableSocket::SOCKET_ARRAY_INDEX_ADDRESS => 'invalid', - StorableSocket::SOCKET_ARRAY_INDEX_PORT => '0', - StorableSocket::SOCKET_ARRAY_INDEX_TYPE => StorableSocket::CONNECTION_TYPE_INCOMING, - ); - // Create socket instance - $socketInstance = self::createObjectByConfiguredName('socket_container_class', array($socketResource, $socketProtocol, $packageData, NULL)); + /* NOISY-DEBUG */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('SOCKET-FACTORY: socketResource[%s]=%s,socketProtocol=%s - CALLED!', gettype($socketResource), $socketResource, $socketProtocol)); + $socketInstance = self::createObjectByConfiguredName('socket_container_class', array( + $socketResource, + $socketProtocol, + )); + + // Set all socket data + $socketInstance->setSocketType(StorableSocket::CONNECTION_TYPE_INCOMING); + $socketInstance->setSocketAddress('invalid'); + $socketInstance->setSocketPort('0'); // Is the socket resource valid? if (!$socketInstance->isValidSocket()) { diff --git a/application/hub/classes/handler/class_BaseHubHandler.php b/application/hub/classes/handler/class_BaseHubHandler.php index aa464b1d2..34f371448 100644 --- a/application/hub/classes/handler/class_BaseHubHandler.php +++ b/application/hub/classes/handler/class_BaseHubHandler.php @@ -242,7 +242,7 @@ abstract class BaseHubHandler extends BaseHandler implements Handleable, HubInte * @param $listenerInstance A Listenable instance * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { + public final function setListenerInstance (Listenable $listenerInstance) { $this->listenerInstance = $listenerInstance; } diff --git a/application/hub/classes/handler/package/class_NetworkPackageHandler.php b/application/hub/classes/handler/package/class_NetworkPackageHandler.php index 08d00692f..d1789a9d3 100644 --- a/application/hub/classes/handler/package/class_NetworkPackageHandler.php +++ b/application/hub/classes/handler/package/class_NetworkPackageHandler.php @@ -438,21 +438,24 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei * @return $hash Hash for given package content */ private function getHashFromContent ($content) { + // Get node instance + $nodeInstance = NodeObjectFactory::createNodeInstance(); + // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); // Create the hash // @TODO md5() is very weak, but it needs to be fast $hash = md5( $content . self::PACKAGE_CHECKSUM_SEPARATOR . - $this->getSessionId() . + $nodeInstance->getSessionId() . self::PACKAGE_CHECKSUM_SEPARATOR . $this->getCompressorInstance()->getCompressorExtension() ); // Debug message - //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $this->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); + //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('NETWORK-PACKAGE: content[md5]=' . md5($content) . ',sender=' . $nodeInstance->getSessionId() . ',hash=' . $hash . ',compressor=' . $this->getCompressorInstance()->getCompressorExtension()); // And return it return $hash; @@ -829,18 +832,21 @@ class NetworkPackageHandler extends BaseHubHandler implements Deliverable, Recei // Make sure required data is there assert(!empty($content)); - assert($this->getSessionId() != ''); + assert($nodeInstance->getSessionId() != ''); // Init package instance $packageInstance = PackageDataFactory::createPackageDataInstance(); + // Get node instance + $nodeInstance = NodeObjectFactory::createNodeInstance(); + // Set all data - $packageInstance->setSenderAddress($this->getSessionId()); + $packageInstance->setSenderAddress($nodeInstance->getSessionId()); $packageInstance->setSenderPort('0'); $packageInstance->setRecipientType($helperInstance->getRecipientType()); $packageInstance->setPackageContent($packageContent); $packageInstance->setStatus(self::PACKAGE_STATUS_NEW); - $packageInstance->setContentHash($this->generatePackageHash($content, $this->getSessionId())); + $packageInstance->setContentHash($this->generatePackageHash($content, $nodeInstance->getSessionId())); $packageInstance->setPrivateKeyHash($this->getPrivateKeyHash()); // Now prepare the temporary array and push it on the 'undeclared' stack diff --git a/application/hub/classes/listener/class_BaseListenerDecorator.php b/application/hub/classes/listener/class_BaseListenerDecorator.php index 6dd4b9f7e..a7f5f87f2 100644 --- a/application/hub/classes/listener/class_BaseListenerDecorator.php +++ b/application/hub/classes/listener/class_BaseListenerDecorator.php @@ -309,7 +309,7 @@ abstract class BaseListenerDecorator extends BaseDecorator implements Visitable * @param $listenerInstance A Listenable instance * @return void */ - protected final function setListenerInstance (Listenable $listenerInstance) { + public final function setListenerInstance (Listenable $listenerInstance) { $this->listenerInstance = $listenerInstance; } diff --git a/application/hub/interfaces/container/socket/class_StorableSocket.php b/application/hub/interfaces/container/socket/class_StorableSocket.php index 1f234ddf2..c67c53a5c 100644 --- a/application/hub/interfaces/container/socket/class_StorableSocket.php +++ b/application/hub/interfaces/container/socket/class_StorableSocket.php @@ -50,12 +50,6 @@ interface StorableSocket extends FrameworkInterface { const SOCKET_ERROR_OPERATION_NOT_SUPPORTED = 'operation_not_supported'; // 'Operation not supported' const SOCKET_CONNECTED = 'connected'; // Nothing errorous happens, socket is connected - // Socket data array indexes - // @deprecated Use a class instead of asociative array - const SOCKET_ARRAY_INDEX_ADDRESS = 'socket_address'; - const SOCKET_ARRAY_INDEX_PORT = 'socket_port'; - const SOCKET_ARRAY_INDEX_TYPE = 'socket_type'; - // Socket protocols const SOCKET_PROTOCOL_INVALID = 'invalid'; const SOCKET_PROTOCOL_FILE = 'file'; -- 2.39.5