]> git.mxchange.org Git - hub.git/commitdiff
Added parameter 'key' to encryption methods to allow own keys
authorRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2011 09:08:34 +0000 (09:08 +0000)
committerRoland Häder <roland@mxchange.org>
Tue, 29 Mar 2011 09:08:34 +0000 (09:08 +0000)
19 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/nodes/class_NodeHelper.php
application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php
application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php
application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php
application/hub/main/database/wrapper/cruncher/.htaccess [new file with mode: 0644]
application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/database/wrapper/node/.htaccess [new file with mode: 0644]
application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/database/wrapper/states/.htaccess [new file with mode: 0644]
application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/producer/cruncher/class_BaseUnitProducer.php [new file with mode: 0644]
application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php
application/hub/main/template/producer/test_units/class_XmlCruncherTestUnitTemplateEngine.php
application/hub/templates/xml/cruncher/producer/test_unit.xml
application/hub/templates/xml/cruncher/producer/work_unit.xml
db/cruncher_units/.htaccess [new file with mode: 0644]

index 925aaa560751e6657b580ad8075118644b24d2fb..aff797b2c56f12f561c205ab049945dde1235f67 100644 (file)
@@ -153,6 +153,13 @@ application/hub/main/database/wrapper/.htaccess -text svneol=unset#text/plain
 application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php -text svneol=unset#text/plain
 application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php -text svneol=unset#text/plain
 application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php svneol=native#text/plain
+application/hub/main/database/wrapper/cruncher/.htaccess svneol=native#text/plain
+application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php svneol=native#text/plain
+application/hub/main/database/wrapper/node/.htaccess svneol=native#text/plain
+application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php svneol=native#text/plain
+application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php svneol=native#text/plain
+application/hub/main/database/wrapper/states/.htaccess svneol=native#text/plain
+application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php svneol=native#text/plain
 application/hub/main/decorators/.htaccess -text svneol=unset#text/plain
 application/hub/main/decorators/class_BaseDecorator.php -text
 application/hub/main/discovery/.htaccess -text svneol=unset#text/plain
@@ -358,6 +365,7 @@ application/hub/main/producer/.htaccess svneol=native#text/plain
 application/hub/main/producer/class_ -text
 application/hub/main/producer/class_BaseProducer.php svneol=native#text/plain
 application/hub/main/producer/cruncher/.htaccess svneol=native#text/plain
+application/hub/main/producer/cruncher/class_BaseUnitProducer.php svneol=native#text/plain
 application/hub/main/producer/cruncher/work_units/.htaccess svneol=native#text/plain
 application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php svneol=native#text/plain
 application/hub/main/queries/.htaccess -text svneol=unset#text/plain
@@ -482,6 +490,7 @@ application/hub/templates/xml/self_connect/.htaccess -text svneol=unset#text/pla
 application/hub/templates/xml/self_connect/self_connect.xml -text svneol=unset#text/plain
 /clear-cache.sh -text
 db/.htaccess -text svneol=unset#text/plain
+db/cruncher_units/.htaccess svneol=native#text/plain
 db/news/.htaccess -text svneol=unset#text/plain
 db/node_data/.htaccess -text svneol=unset#text/plain
 db/node_list/.htaccess -text svneol=unset#text/plain
index 3b18d1b8ed2011ce878d882825d1ddd49a473c57..198cf29ef67226291dfc7f261645f5343f939f99 100644 (file)
@@ -558,5 +558,17 @@ $cfg->setConfigEntry('cruncher_test_unit_template_type', 'xml/cruncher/producer'
 // CFG: STACKER-CRUNCHER-TEST-UNIT-MAX-SIZE
 $cfg->setConfigEntry('stacker_cruncher_test_unit_max_size', 20);
 
+// CFG: CRUNCHER-TEST-UNIT-MAX-COUNT
+$cfg->setConfigEntry('cruncher_test_unit_max_count', 1000);
+
+// CFG: CRUNCHER-UNIT-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('cruncher_unit_db_wrapper_class', 'CruncherUnitDatabaseWrapper');
+
+// CFG: CRUNCHER-RANDOM-SECRET-MESSAGE-LENGTH
+$cfg->setConfigEntry('cruncher_random_secret_message_length', 100);
+
+// CFG: CRUNCHER-RANDOM-SECRET-KEY-LENGTH
+$cfg->setConfigEntry('cruncher_random_secret_key_length', 8);
+
 // [EOF]
 ?>
index dc96ab30a5d7458c020c394e23a03565fbf298c4..c917a8490b07cb474875a500462121a9c31e6332 100644 (file)
@@ -122,6 +122,15 @@ interface NodeHelper extends FrameworkInterface {
         * @return      $addressPort            A address:port combination for this node
         */
        function getAddressPort (Networkable $handlerInstance);
+
+       /**
+        * Adds hub data elements to a given dataset instance
+        *
+        * @param       $criteriaInstance       An instance of a storeable criteria
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      void
+        */
+       function addElementsToDataSet (StoreableCriteria $criteriaInstance, Requestable $requestInstance);
 }
 
 // [EOF]
index 52dc0ff1361cd6447fd5d57e4089e528ea03307a..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,115 +1,3 @@
 <?php
-/**
- * A database wrapper for node informations
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
- */
-class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper {
-       // Constants for database table names
-       const DB_TABLE_NODE_INFORMATION = 'node_data';
-
-       // Constants for database column names
-       const DB_COLUMN_NODE_NR    = 'node_nr';
-       const DB_COLUMN_NODE_ID    = 'node_id';
-       const DB_COLUMN_SESSION_ID = 'session_id';
-       const DB_COLUMN_NODE_TYPE  = 'node_type';
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this database wrapper by a provided user class
-        *
-        * @return      $wrapperInstance        An instance of the created wrapper class
-        */
-       public static final function createNodeInformationDatabaseWrapper () {
-               // Get a new instance
-               $wrapperInstance = new NodeInformationDatabaseWrapper();
-
-               // Set (primary!) table name
-               $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
-
-               // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Getter for index key
-        *
-        * @return      $indexKey       Index key
-        */
-       public final function getIndexKey () {
-               return $this->getDatabaseInstance()->getIndexKey();
-       }
-
-       /**
-        * 'Registers' a new node id along with data provided in the node instance.
-        * This may sound confusing but avoids double code very nicely...
-        *
-        * @param       $nodeInstance           A node instance
-        * @param       $requestInstance        An instance of a Requestable class
-        * @return      void
-        */
-       public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
-               // Get a dataset instance
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
-
-               // Set the primary key
-               $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
-               // Add registration elements to the dataset
-               $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
-
-               // "Insert" this request instance completely into the database
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
-       }
-
-       /**
-        * 'Registers' a new session id along with data provided in the node instance.
-        * This may sound confusing but avoids double code very nicely...
-        *
-        * @param       $nodeInstance           A node instance
-        * @param       $requestInstance        An instance of a Requestable class
-        * @return      void
-        */
-       public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
-               // Get a dataset instance
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
-
-               // Set the primary key
-               $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
-
-               // Add registration elements to the dataset
-               $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
-
-               // "Insert" this request instance completely into the database
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
index 262ced5de572457a089264460c16c29317c9c25f..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,102 +1,3 @@
 <?php
-/**
- * A database wrapper for node list
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
- */
-class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable {
-       // Table names
-       const DB_TABLE_NODE_LIST = 'node_list';
-
-       // Constants for column name
-       const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
-       const DB_COLUMN_NODE_IP_PORT    = 'node_ipport';
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this database wrapper by a provided user class
-        *
-        * @return      $wrapperInstance        An instance of the created wrapper class
-        */
-       public static final function createNodeListDatabaseWrapper () {
-               // Get a new instance
-               $wrapperInstance = new NodeListDatabaseWrapper();
-
-               // Set (primary!) table name
-               $wrapperInstance->setTableName(self::DB_TABLE_NODE_LIST);
-
-               // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Getter for index key
-        *
-        * @return      $indexKey       Index key
-        */
-       public final function getIndexKey () {
-               return $this->getDatabaseInstance()->getIndexKey();
-       }
-
-       /**
-        * Resolves a session id into an ip:port combination
-        *
-        * @param       $sessionId      A valid session id
-        * @return      $recipient      Recipient as ip:port combination
-        */
-       public function resolveIpPortBySessionId ($sessionId) {
-               // Set invalid ip:port combination
-               $recipient = 'invalid:invalid';
-
-               // Now get a search criteria instance
-               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
-               // Search for the node number zero which is hard-coded the default
-               $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, 1);
-               $searchInstance->setLimit(1);
-
-               // Get a result back
-               $resultInstance = $this->doSelectByCriteria($searchInstance);
-
-               // Is it valid?
-               if ($resultInstance->next()) {
-                       // Save the result instance in this class
-                       $this->setResultInstance($resultInstance);
-
-                       // Get the node id from result and set it
-                       $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT);
-               } // END - if
-
-               // Return result
-               return $recipient;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
index 86d4528671a9732f4c7d7428c81737950c2f8e89..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,172 +1,3 @@
 <?php
-/**
- * A database wrapper for peer state lookups
- *
- * @author             Roland Haeder <webmaster@ship-simu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
- */
-class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper {
-       // Exception constants
-       const EXCEPTION_PEER_ALREADY_REGISTERED = 0x300;
-
-       // Constants for database table names
-       const DB_TABLE_PEER_LOOKUP = 'peer_states';
-
-       // Constants for database column names
-       const DB_COLUMN_PEER_IP         = 'peer_ip';
-       const DB_COLUMN_PEER_PORT       = 'peer_port';
-       const DB_COLUMN_PEER_SESSION_ID = 'peer_session_id';
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-       }
-
-       /**
-        * Creates an instance of this database wrapper by a provided user class
-        *
-        * @return      $wrapperInstance        An instance of the created wrapper class
-        */
-       public static final function createPeerStateLookupDatabaseWrapper () {
-               // Get a new instance
-               $wrapperInstance = new PeerStateLookupDatabaseWrapper();
-
-               // Set (primary!) table name
-               $wrapperInstance->setTableName(self::DB_TABLE_PEER_LOOKUP);
-
-               // Return the instance
-               return $wrapperInstance;
-       }
-
-       /**
-        * Getter for index key
-        *
-        * @return      $indexKey       Index key
-        */
-       public final function getIndexKey () {
-               return $this->getDatabaseInstance()->getIndexKey();
-       }
-
-       /**
-        * Checks wether given 'sender' is a new peer
-        *
-        * @param       $packageData    Raw package data
-        * @return      $isNewPeer              Wether 'sender' is a new peer to this node
-        */
-       public function isSenderNewPeer (array $packageData) {
-               // Is always new peer by default
-               $isNewPeer = true;
-
-               // Is the package valid?
-               if (!isset($packageData[NetworkPackage::INDEX_PACKAGE_SENDER])) {
-                       // Invalid package found, please report this
-                       die('packageData='.print_r($packageData, true));
-               } // END - if
-
-               // Remove session id > IP:port
-               $ipPort = HubTools::resolveSessionId($packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
-
-               // Is it not invalid:invalid?
-               if ($ipPort != 'invalid:invalid') {
-                       // Get a search criteria instance
-                       $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
-
-                       // Add 'sender' as the peer's IP address
-                       $searchInstance->addCriteria(self::DB_COLUMN_PEER_IP, $ipPort);
-                       $searchInstance->setLimit(1);
-
-                       // Count the query
-                       $entries = $this->doSelectCountByCriteria($searchInstance);
-
-                       // Is it there?
-                       $isNewPeer = ($entries === 0);
-               } // END - if
-
-               // Return the result
-               return $isNewPeer;
-       }
-
-       /**
-        * Registers a new peer with given package data. We use the session id from it.
-        *
-        * @param       $packageData            Raw package data
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        * @throws      PeerAlreadyRegisteredException  If a peer is already registered
-        * @throws      InvalidSocketException  If the socket resource was invalid
-        */
-       public function registerPeerByPackageData (array $packageData, $socketResource) {
-               // Make sure only new peers can be registered with package data
-               if (!$this->isSenderNewPeer($packageData)) {
-                       // Throw an exception because this should normally not happen
-                       throw new PeerAlreadyRegisteredException(array($this, $packageData), self::EXCEPTION_PEER_ALREADY_REGISTERED);
-               } // END - if
-
-               // Generate a dataset instance
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
-
-               // Session ids must be unique
-               $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
-
-               // Add session id
-               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
-
-               // Get peer name
-               if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
-                       // Get last error
-                       $lastError = socket_last_error($socketResource);
-
-                       // Doesn't work!
-                       throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
-               } // END - if
-
-               // Add ip address and port
-               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP  , $peerName);
-               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $peerPort);
-
-               // "Insert" the data set
-               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
-       }
-
-       /**
-        * Purges old entries of given socket resource. We use the IP address from that resource.
-        *
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        * @throws      InvalidSocketException  If the socket resource was invalid
-        */
-       public function purgeOldEntriesBySocketResource ($socketResource) {
-               // Get peer name
-               if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
-                       // Get last error
-                       $lastError = socket_last_error($socketResource);
-
-                       // Doesn't work!
-                       throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
-               } // END - if
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/database/wrapper/cruncher/.htaccess b/application/hub/main/database/wrapper/cruncher/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php b/application/hub/main/database/wrapper/cruncher/class_CruncherUnitDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..07a5773
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * A database wrapper for cruncher work/test units
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
+ */
+class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper {
+       // Constants for database table names
+       const DB_TABLE_CRUNCHER_UNITS = 'cruncher_units';
+
+       // Constants for database column names
+       const DB_COLUMN_UNIT_TYPE   = 'unit_type';
+       const DB_COLUMN_UNIT_STATUS = 'unit_status';
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this database wrapper by a provided user class
+        *
+        * @return      $wrapperInstance        An instance of the created wrapper class
+        */
+       public static final function createCruncherUnitDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new CruncherUnitDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_CRUNCHER_UNITS);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Getter for index key
+        *
+        * @return      $indexKey       Index key
+        */
+       public final function getIndexKey () {
+               return $this->getDatabaseInstance()->getIndexKey();
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/database/wrapper/node/.htaccess b/application/hub/main/database/wrapper/node/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeInformationDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..52dc0ff
--- /dev/null
@@ -0,0 +1,115 @@
+<?php
+/**
+ * A database wrapper for node informations
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
+ */
+class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper {
+       // Constants for database table names
+       const DB_TABLE_NODE_INFORMATION = 'node_data';
+
+       // Constants for database column names
+       const DB_COLUMN_NODE_NR    = 'node_nr';
+       const DB_COLUMN_NODE_ID    = 'node_id';
+       const DB_COLUMN_SESSION_ID = 'session_id';
+       const DB_COLUMN_NODE_TYPE  = 'node_type';
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this database wrapper by a provided user class
+        *
+        * @return      $wrapperInstance        An instance of the created wrapper class
+        */
+       public static final function createNodeInformationDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new NodeInformationDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_NODE_INFORMATION);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Getter for index key
+        *
+        * @return      $indexKey       Index key
+        */
+       public final function getIndexKey () {
+               return $this->getDatabaseInstance()->getIndexKey();
+       }
+
+       /**
+        * 'Registers' a new node id along with data provided in the node instance.
+        * This may sound confusing but avoids double code very nicely...
+        *
+        * @param       $nodeInstance           A node instance
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      void
+        */
+       public function registerNodeId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
+               // Get a dataset instance
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+               // Add registration elements to the dataset
+               $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+               // "Insert" this request instance completely into the database
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * 'Registers' a new session id along with data provided in the node instance.
+        * This may sound confusing but avoids double code very nicely...
+        *
+        * @param       $nodeInstance           A node instance
+        * @param       $requestInstance        An instance of a Requestable class
+        * @return      void
+        */
+       public function registerSessionId (BaseHubNode $nodeInstance, Requestable $requestInstance) {
+               // Get a dataset instance
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_INFORMATION));
+
+               // Set the primary key
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_ID);
+
+               // Add registration elements to the dataset
+               $nodeInstance->addElementsToDataSet($dataSetInstance, $requestInstance);
+
+               // "Insert" this request instance completely into the database
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..262ced5
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * A database wrapper for node list
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
+ */
+class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerable {
+       // Table names
+       const DB_TABLE_NODE_LIST = 'node_list';
+
+       // Constants for column name
+       const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
+       const DB_COLUMN_NODE_IP_PORT    = 'node_ipport';
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this database wrapper by a provided user class
+        *
+        * @return      $wrapperInstance        An instance of the created wrapper class
+        */
+       public static final function createNodeListDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new NodeListDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_NODE_LIST);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Getter for index key
+        *
+        * @return      $indexKey       Index key
+        */
+       public final function getIndexKey () {
+               return $this->getDatabaseInstance()->getIndexKey();
+       }
+
+       /**
+        * Resolves a session id into an ip:port combination
+        *
+        * @param       $sessionId      A valid session id
+        * @return      $recipient      Recipient as ip:port combination
+        */
+       public function resolveIpPortBySessionId ($sessionId) {
+               // Set invalid ip:port combination
+               $recipient = 'invalid:invalid';
+
+               // Now get a search criteria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Search for the node number zero which is hard-coded the default
+               $searchInstance->addCriteria(NodeListDatabaseWrapper::DB_COLUMN_NODE_SESSION_ID, 1);
+               $searchInstance->setLimit(1);
+
+               // Get a result back
+               $resultInstance = $this->doSelectByCriteria($searchInstance);
+
+               // Is it valid?
+               if ($resultInstance->next()) {
+                       // Save the result instance in this class
+                       $this->setResultInstance($resultInstance);
+
+                       // Get the node id from result and set it
+                       $recipient = $this->getField(NodeListDatabaseWrapper::DB_COLUMN_NODE_IP_PORT);
+               } // END - if
+
+               // Return result
+               return $recipient;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/database/wrapper/states/.htaccess b/application/hub/main/database/wrapper/states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..86d4528
--- /dev/null
@@ -0,0 +1,172 @@
+<?php
+/**
+ * A database wrapper for peer state lookups
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
+ */
+class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper {
+       // Exception constants
+       const EXCEPTION_PEER_ALREADY_REGISTERED = 0x300;
+
+       // Constants for database table names
+       const DB_TABLE_PEER_LOOKUP = 'peer_states';
+
+       // Constants for database column names
+       const DB_COLUMN_PEER_IP         = 'peer_ip';
+       const DB_COLUMN_PEER_PORT       = 'peer_port';
+       const DB_COLUMN_PEER_SESSION_ID = 'peer_session_id';
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this database wrapper by a provided user class
+        *
+        * @return      $wrapperInstance        An instance of the created wrapper class
+        */
+       public static final function createPeerStateLookupDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new PeerStateLookupDatabaseWrapper();
+
+               // Set (primary!) table name
+               $wrapperInstance->setTableName(self::DB_TABLE_PEER_LOOKUP);
+
+               // Return the instance
+               return $wrapperInstance;
+       }
+
+       /**
+        * Getter for index key
+        *
+        * @return      $indexKey       Index key
+        */
+       public final function getIndexKey () {
+               return $this->getDatabaseInstance()->getIndexKey();
+       }
+
+       /**
+        * Checks wether given 'sender' is a new peer
+        *
+        * @param       $packageData    Raw package data
+        * @return      $isNewPeer              Wether 'sender' is a new peer to this node
+        */
+       public function isSenderNewPeer (array $packageData) {
+               // Is always new peer by default
+               $isNewPeer = true;
+
+               // Is the package valid?
+               if (!isset($packageData[NetworkPackage::INDEX_PACKAGE_SENDER])) {
+                       // Invalid package found, please report this
+                       die('packageData='.print_r($packageData, true));
+               } // END - if
+
+               // Remove session id > IP:port
+               $ipPort = HubTools::resolveSessionId($packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
+
+               // Is it not invalid:invalid?
+               if ($ipPort != 'invalid:invalid') {
+                       // Get a search criteria instance
+                       $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+                       // Add 'sender' as the peer's IP address
+                       $searchInstance->addCriteria(self::DB_COLUMN_PEER_IP, $ipPort);
+                       $searchInstance->setLimit(1);
+
+                       // Count the query
+                       $entries = $this->doSelectCountByCriteria($searchInstance);
+
+                       // Is it there?
+                       $isNewPeer = ($entries === 0);
+               } // END - if
+
+               // Return the result
+               return $isNewPeer;
+       }
+
+       /**
+        * Registers a new peer with given package data. We use the session id from it.
+        *
+        * @param       $packageData            Raw package data
+        * @param       $socketResource         A valid socket resource
+        * @return      void
+        * @throws      PeerAlreadyRegisteredException  If a peer is already registered
+        * @throws      InvalidSocketException  If the socket resource was invalid
+        */
+       public function registerPeerByPackageData (array $packageData, $socketResource) {
+               // Make sure only new peers can be registered with package data
+               if (!$this->isSenderNewPeer($packageData)) {
+                       // Throw an exception because this should normally not happen
+                       throw new PeerAlreadyRegisteredException(array($this, $packageData), self::EXCEPTION_PEER_ALREADY_REGISTERED);
+               } // END - if
+
+               // Generate a dataset instance
+               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_PEER_LOOKUP));
+
+               // Session ids must be unique
+               $dataSetInstance->setUniqueKey(self::DB_COLUMN_PEER_SESSION_ID);
+
+               // Add session id
+               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_SESSION_ID, $packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
+
+               // Get peer name
+               if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
+                       // Get last error
+                       $lastError = socket_last_error($socketResource);
+
+                       // Doesn't work!
+                       throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+
+               // Add ip address and port
+               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_IP  , $peerName);
+               $dataSetInstance->addCriteria(self::DB_COLUMN_PEER_PORT, $peerPort);
+
+               // "Insert" the data set
+               $this->getDatabaseInstance()->queryInsertDataSet($dataSetInstance);
+       }
+
+       /**
+        * Purges old entries of given socket resource. We use the IP address from that resource.
+        *
+        * @param       $socketResource         A valid socket resource
+        * @return      void
+        * @throws      InvalidSocketException  If the socket resource was invalid
+        */
+       public function purgeOldEntriesBySocketResource ($socketResource) {
+               // Get peer name
+               if (!socket_getpeername($socketResource, $peerName, $peerPort)) {
+                       // Get last error
+                       $lastError = socket_last_error($socketResource);
+
+                       // Doesn't work!
+                       throw new InvalidSocketException(array($this, gettype($socketResource), $lastError, socket_strerror($lastError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+               } // END - if
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/producer/cruncher/class_BaseUnitProducer.php b/application/hub/main/producer/cruncher/class_BaseUnitProducer.php
new file mode 100644 (file)
index 0000000..328334f
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+/**
+ * A general Producer class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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 <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseUnitProducer extends BaseProducer {
+       /**
+        * Work/test unit status
+        */
+       const UNIT_STATUS_AVAILABLE = 'available'; // Available for crunching
+       const UNIT_STATUS_PENDING   = 'pending';   // Is being crunched at the moment
+       const UNIT_STATUS_DONE      = 'done';      // Is already crunched/finished
+
+       /**
+        * Work or test unit?
+        */
+       const UNIT_TYPE_TEST_UNIT = 'test_unit';
+       const UNIT_TYPE_TEST_WORK = 'work_unit';
+
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+}
+
+// [EOF]
+?>
index d12697a24b8264f2362e0c8eb1da6226234d0a7d..efd3109ce59683d3b60370478bd22c53cdd56cd8 100644 (file)
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
-class CruncherTestUnitProducer extends BaseProducer implements UnitProducer, Registerable {
+class CruncherTestUnitProducer extends BaseUnitProducer implements UnitProducer, Registerable {
        /**
         * Protected constructor
         *
@@ -69,10 +69,45 @@ class CruncherTestUnitProducer extends BaseProducer implements UnitProducer, Reg
         * Produces some test units and pushes them onto the queue
         *
         * @return      void
-        * @todo        0% done
+        * @todo        ~30% done
         */
        public function produceUnits () {
-               $this->partialStub('Please implement this method.');
+               // First get a database wrapper because we want to permanently store test units
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('cruncher_unit_db_wrapper_class');
+
+               // Now get a search instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add criteria for looking up already created and available test units
+               $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_TYPE, BaseUnitProducer::UNIT_TYPE_TEST_UNIT);
+               $searchInstance->addCriteria(CruncherUnitDatabaseWrapper::DB_COLUMN_UNIT_STATUS, BaseUnitProducer::UNIT_STATUS_AVAILABLE);
+               $searchInstance->setLimit($this->getConfigInstance()->getConfigEntry('cruncher_test_unit_max_count'));
+
+               // Search for our units
+               $resultInstance = $wrapperInstance->doSelectByCriteria($searchInstance);
+
+               // Do we have some entries?
+               if ($resultInstance->next()) {
+                       // Entries found
+                       // @TODO Unfinished work here
+                       $this->debugInstance();
+               } else {
+                       // No entries found, so generate some. First we need a very secret message (a random string) ...
+                       $rngInstance = ObjectFactory::createObjectByConfiguredName('rng_class');
+                       $secretMessage = base64_encode($rngInstance->randomString($this->getConfigInstance()->getConfigEntry('cruncher_random_secret_message_length')));
+
+                       // Second, we need a secret key
+                       $secretKey = $rngInstance->randomString($this->getConfigInstance()->getConfigEntry('cruncher_random_secret_key_length'));
+
+                       // Now encrypt the message with our key and a good (strong) cipher
+                       $cryptoInstance = ObjectFactory::createObjectByConfiguredName('crypto_class');
+                       $encryptedMessage = base64_encode($cryptoInstance->encryptString($secretMessage, $secretKey));
+
+                       // Make sure the secret key and message are removed from memory
+                       unset($secretKey);
+                       unset($secretMessage);
+                       die($encryptedMessage);
+               }
        }
 }
 
index 3fadf06bc9d01d648057bba4c478bfbc179b0f33..968220f63fc34d6039b91c8166c07c3c049cd38d 100644 (file)
@@ -36,10 +36,12 @@ class XmlCruncherTestUnitTemplateEngine extends BaseTemplateEngine implements Co
        private $subNodes = array(
                'meta-data',
                'global-project-identifier',
+               'test-unit-created',
                'cipher',
                'cipher-function',
                'cipher-name',
                'unprocessed-data',
+               'encrypted-message',
                'cruncher-key-list',
                'cruncher-key',
                'key-id',
@@ -303,6 +305,26 @@ class XmlCruncherTestUnitTemplateEngine extends BaseTemplateEngine implements Co
                $this->getStackerInstance()->popNamed('cruncher_test_unit');
        }
 
+       /**
+        * Starts the test-unit-created
+        *
+        * @return      void
+        */
+       private function startTestUnitCreated () {
+               // Push the node name on the stacker
+               $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'test-unit-created');
+       }
+
+       /**
+        * Finishes the test-unit-created
+        *
+        * @return      void
+        */
+       private function finishTestUnitCreated () {
+               // Pop the last entry
+               $this->getStackerInstance()->popNamed('cruncher_test_unit');
+       }
+
        /**
         * Starts the cipher
         *
@@ -383,6 +405,26 @@ class XmlCruncherTestUnitTemplateEngine extends BaseTemplateEngine implements Co
                $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'unprocessed-data');
        }
 
+       /**
+        * Starts the encrypted-message
+        *
+        * @return      void
+        */
+       private function startEncryptedMessage () {
+               // Push the node name on the stacker
+               $this->getStackerInstance()->pushNamed('cruncher_test_unit', 'encrypted-message');
+       }
+
+       /**
+        * Finishes the encrypted-message
+        *
+        * @return      void
+        */
+       private function finishEncryptedMessage () {
+               // Pop the last entry
+               $this->getStackerInstance()->popNamed('cruncher_test_unit');
+       }
+
        /**
         * Starts the cruncher-key-list
         *
index 1efe031bd58ec603441be8ea01fd977177a5728c..16c3a35e05c9402f1b6ac7592b94ecebb23c1fbc 100644 (file)
@@ -41,13 +41,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        <cipher-function>{?cipher_function?}</cipher-function>
                        <cipher-name>{?cipher_name?}</cipher-name>
                </cipher>
+               <!--
+               Timestamp in the format YYYY-mm-dd HH:ii:ss when this test unit has been
+               created.
+               //-->
+               <test-unit-created>{?test_unit_created</test-unit-created>
        </meta-data>
        <!--
        The data the cruncher shall process for this test unit.
        //-->
        <unprocessed-data>
                <!--
-               Because this is a WU for crunchers, there is always a key list.
+               Our encrypted, secret message, no need to distribute it (because the key producer will validate it)
+               //-->
+               <encrypted-message><![CDATA[{?encrypted_message?}]]></encrypted-message>
+               <!--
+               Because this is a test unit for crunchers, there is always a key list.
                //-->
                <cruncher-key-list key-count="{?key_count?}">
                        <!-- A single key to crunch. //-->
index cbe8611a471b847b1b585ee8ef326dbaba85a764..956095913732804732da22fddafef8cb07ebd404 100644 (file)
@@ -42,6 +42,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
                        <cipher-name>{?cipher_name?}</cipher-name>
                </cipher>
                <!--
+               Timestamp in the format YYYY-mm-dd HH:ii:ss when this test unit has been
+               created.
+               //-->
+               <test-unit-created>{?test_unit_created</test-unit-created>
+               <!--
                The node's hub-id. This is required to verify the GPI.
                //-->
                <hub-id>{?hub_id?}</hub-id>
diff --git a/db/cruncher_units/.htaccess b/db/cruncher_units/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all