From e1749e8c86c960720ee70adb757294eecefda48e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 27 Apr 2012 20:16:46 +0000 Subject: [PATCH] Some refacturings: - Moved [g|s]et[Node|Session]Id() from BaseHubNode to BaseHubSystem - This allows $nodeInstance to be removed from some method signatures - Debug line added (which will be noisy, I know) - TODOs.txt updated --- .../interfaces/package/class_Deliverable.php | 3 +- application/hub/main/class_BaseHubSystem.php | 40 +++++++++++++++++++ .../class_HubDescriptorHelper.php | 2 +- .../connection/class_HubSelfConnectHelper.php | 2 +- .../hub/main/nodes/class_BaseHubNode.php | 40 ------------------- .../hub/main/package/class_NetworkPackage.php | 13 +++--- docs/TODOs.txt | 21 +++++----- 7 files changed, 59 insertions(+), 62 deletions(-) diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index d38f4504c..517b2bb5e 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -27,10 +27,9 @@ interface Deliverable extends FrameworkInterface { * from given template instance and pushing it on the 'undeclared' stack. * * @param $helperInstance An instance of a HelpableHub class - * @param $nodeInstance An instance of a NodeHelper class * @return void */ - function enqueueRawDataFromTemplate (HelpableHub $helperInstance, NodeHelper $nodeInstance); + function enqueueRawDataFromTemplate (HelpableHub $helperInstance); /** * Checks whether a package has been enqueued for delivery. diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index b6431b158..414be86c6 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -282,6 +282,46 @@ class BaseHubSystem extends BaseFrameworkSystem { return $this->assemblerInstance; } + /** + * Setter for node id + * + * @param $nodeId Our new node id + * @return void + */ + private final function setNodeId ($nodeId) { + // Set it config now + $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId); + } + + /** + * Getter for node id + * + * @return $nodeId Current node id + */ + private final function getNodeId () { + // Get it from config + return $this->getConfigInstance()->getConfigEntry('node_id'); + } + + /** + * Setter for session id + * + * @param $sessionId Our new session id + * @return void + */ + private final function setSessionId ($sessionId) { + $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId); + } + + /** + * Getter for session id + * + * @return $sessionId Current session id + */ + public final function getSessionId () { + return $this->getConfigInstance()->getConfigEntry('session_id'); + } + /** * Constructs a callable method name from given socket error code. If the * method is not found, a generic one is used. diff --git a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php index 7f4bf97b7..d87de3c5e 100644 --- a/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php +++ b/application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php @@ -98,7 +98,7 @@ class HubDescriptorHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, $nodeInstance); + $packageInstance->enqueueRawDataFromTemplate($this); } /** diff --git a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php index 26761f19f..26609fd8f 100644 --- a/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php +++ b/application/hub/main/helper/hub/connection/class_HubSelfConnectHelper.php @@ -93,7 +93,7 @@ class HubSelfConnectHelper extends BaseHubHelper implements HelpableHub { $packageInstance = NetworkPackageFactory::createNetworkPackageInstance(); // Next, feed the content in. The network package class is a pipe-through class. - $packageInstance->enqueueRawDataFromTemplate($this, $nodeInstance); + $packageInstance->enqueueRawDataFromTemplate($this); } /** diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index 07974fad4..bbd63bf6a 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -86,46 +86,6 @@ class BaseHubNode extends BaseHubSystem implements Updateable { NodeStateFactory::createNodeStateInstanceByName('init', $this); } - /** - * Setter for node id - * - * @param $nodeId Our new node id - * @return void - */ - private final function setNodeId ($nodeId) { - // Set it config now - $this->getConfigInstance()->setConfigEntry('node_id', (string) $nodeId); - } - - /** - * Getter for node id - * - * @return $nodeId Current node id - */ - private final function getNodeId () { - // Get it from config - return $this->getConfigInstance()->getConfigEntry('node_id'); - } - - /** - * Setter for session id - * - * @param $sessionId Our new session id - * @return void - */ - private final function setSessionId ($sessionId) { - $this->getConfigInstance()->setConfigEntry('session_id', (string) $sessionId); - } - - /** - * Getter for session id - * - * @return $sessionId Current session id - */ - public final function getSessionId () { - return $this->getConfigInstance()->getConfigEntry('session_id'); - } - /** * Setter for query instance * diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 1fb432da5..3549f0d73 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -250,15 +250,14 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * @param $helperInstance An instance of a HelpableHub class * @param $nodeInstance An instance of a NodeHelper class * @return $hash Hash for given package content - * @todo $helperInstance is unused */ - private function getHashFromContent ($content, HelpableHub $helperInstance, NodeHelper $nodeInstance) { + private function getHashFromContent ($content) { // Create the hash // @TODO crc32() is very weak, but it needs to be fast $hash = crc32( $content . self::PACKAGE_CHECKSUM_SEPARATOR . - $nodeInstance->getSessionId() . + $this->getSessionId() . self::PACKAGE_CHECKSUM_SEPARATOR . $this->getCompressorInstance()->getCompressorExtension() ); @@ -473,10 +472,9 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * from given template instance and pushing it on the 'undeclared' stack. * * @param $helperInstance An instance of a HelpableHub class - * @param $nodeInstance An instance of a NodeHelper class * @return void */ - public function enqueueRawDataFromTemplate (HelpableHub $helperInstance, NodeHelper $nodeInstance) { + public function enqueueRawDataFromTemplate (HelpableHub $helperInstance) { // Get the raw content ... $content = $helperInstance->getTemplateInstance()->getRawTemplateData(); @@ -498,7 +496,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R // - separator self::PACKAGE_MASK_SEPARATOR, // 4.) Checksum - $this->getHashFromContent($content, $helperInstance, $nodeInstance) + $this->getHashFromContent($content) ); // Now prepare the temporary array and push it on the 'undeclared' stack @@ -507,7 +505,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R self::PACKAGE_DATA_RECIPIENT => $helperInstance->getRecipientType(), self::PACKAGE_DATA_CONTENT => $content, self::PACKAGE_DATA_STATUS => self::PACKAGE_STATUS_NEW, - self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($content, $nodeInstance->getSessionId()) + self::PACKAGE_DATA_SIGNATURE => $this->generatePackageSignature($content, $this->getSessionId()) )); } @@ -715,6 +713,7 @@ class NetworkPackage extends BaseHubSystem implements Deliverable, Receivable, R * Also make sure the error code is SOCKET_ERROR_UNHANDLED because we * only want to handle unhandled packages here. */ + /* NOISY-DEBUG: */ $this->debugOutput('NETWORK-PACKAGE: errorCode=' . $decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE]); assert($decodedData[BaseRawDataHandler::PACKAGE_ERROR_CODE] == BaseRawDataHandler::SOCKET_ERROR_UNHANDLED); // Remove the last chunk SEPARATOR (because it is being added and we don't need it) diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 8a6252233..ee4879dd8 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -6,7 +6,7 @@ ./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:38: * @todo We may want to implement a filter for ease notification of other objects like our pool ./application/hub/interfaces/helper/messages/class_MessageHelper.php:10: * @todo Please find another name for this interface ./application/hub/interfaces/nodes/class_NodeHelper.php:10: * @todo We need to find a better name for this interface -./application/hub/main/class_BaseHubSystem.php:400: // @TODO On some systems it is 134, on some 107? +./application/hub/main/class_BaseHubSystem.php:440: // @TODO On some systems it is 134, on some 107? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:107: * @todo Should we add some more filters? ./application/hub/main/commands/console/class_HubConsoleChatCommand.php:58: * @todo Try to create a ChatActivationTask or so ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:107: * @todo Should we add some more filters? @@ -75,9 +75,9 @@ ./application/hub/main/nodes/boot/class_HubBootNode.php:119: // @TODO Add some filters here ./application/hub/main/nodes/boot/class_HubBootNode.php:58: * @todo add some more special bootstrap things for this boot node ./application/hub/main/nodes/boot/class_HubBootNode.php:99: * @todo Unfinished method -./application/hub/main/nodes/class_BaseHubNode.php:384: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem -./application/hub/main/nodes/class_BaseHubNode.php:424: * @todo Change the first if() block to check for a specific state -./application/hub/main/nodes/class_BaseHubNode.php:597: // @TODO Add some criteria, e.g. if the node is active or so +./application/hub/main/nodes/class_BaseHubNode.php:344: * @todo Try to make this method more generic so we can move it in BaseFrameworkSystem +./application/hub/main/nodes/class_BaseHubNode.php:384: * @todo Change the first if() block to check for a specific state +./application/hub/main/nodes/class_BaseHubNode.php:557: // @TODO Add some criteria, e.g. if the node is active or so ./application/hub/main/nodes/list/class_HubListNode.php:58: * @todo Implement more bootstrap steps ./application/hub/main/nodes/list/class_HubListNode.php:68: * @todo Unfinished method ./application/hub/main/nodes/list/class_HubListNode.php:91: // @TODO Add some filters here @@ -88,13 +88,12 @@ ./application/hub/main/nodes/regular/class_HubRegularNode.php:68: * @todo Unfinished method ./application/hub/main/nodes/regular/class_HubRegularNode.php:91: // @TODO Add some filters here ./application/hub/main/package/class_NetworkPackage.php:23: * @todo Needs to add functionality for handling the object's type -./application/hub/main/package/class_NetworkPackage.php:248: * @todo $helperInstance is unused -./application/hub/main/package/class_NetworkPackage.php:252: // @TODO crc32() is very weak, but it needs to be fast -./application/hub/main/package/class_NetworkPackage.php:434: // @TODO We may want to do somthing more here? -./application/hub/main/package/class_NetworkPackage.php:562: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:692: // @TODO Add some logging here -./application/hub/main/package/class_NetworkPackage.php:812: // @TODO Add some content here -./application/hub/main/package/class_NetworkPackage.php:851: * @todo This may be enchanced for outgoing packages? +./application/hub/main/package/class_NetworkPackage.php:256: // @TODO crc32() is very weak, but it needs to be fast +./application/hub/main/package/class_NetworkPackage.php:438: // @TODO We may want to do somthing more here? +./application/hub/main/package/class_NetworkPackage.php:565: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:695: // @TODO Add some logging here +./application/hub/main/package/class_NetworkPackage.php:816: // @TODO Add some content here +./application/hub/main/package/class_NetworkPackage.php:855: * @todo This may be enchanced for outgoing packages? ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:275: * @todo Implement a way to send non-announcement packages with extra-salt ./application/hub/main/package/fragmenter/class_PackageFragmenter.php:427: * @todo $helperInstance is unused ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106: // @TODO Do something with it -- 2.39.5