Added peer states and lookup table classes/interfaces:
authorRoland Häder <roland@mxchange.org>
Fri, 28 May 2010 02:33:36 +0000 (02:33 +0000)
committerRoland Häder <roland@mxchange.org>
Fri, 28 May 2010 02:33:36 +0000 (02:33 +0000)
- Added new PeerStateable interface for peer states
- Added new Lookupable interface for lookup tables
- Added new PeerStateFactory class for generating peer states
- Added new PeerStateLookupTable class for looking up peer states
- Added new NewConnectionPeerState class for new peer connections

21 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/lookup/.htaccess [new file with mode: 0644]
application/hub/interfaces/lookup/class_Lookupable.php [new file with mode: 0644]
application/hub/interfaces/states/class_
application/hub/interfaces/states/peer/.htaccess [new file with mode: 0644]
application/hub/interfaces/states/peer/class_PeerStateable.php [new file with mode: 0644]
application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php [new file with mode: 0644]
application/hub/main/factories/states/class_StateFactory.php
application/hub/main/factories/states/peer/.htaccess [new file with mode: 0644]
application/hub/main/factories/states/peer/class_PeerStateFactory.php [new file with mode: 0644]
application/hub/main/lookup/.htaccess [new file with mode: 0644]
application/hub/main/lookup/class_ [new file with mode: 0644]
application/hub/main/lookup/class_BaseLookupTable.php [new file with mode: 0644]
application/hub/main/lookup/peer/.htaccess [new file with mode: 0644]
application/hub/main/lookup/peer/class_PeerStateLookupTable.php [new file with mode: 0644]
application/hub/main/resolver/state/network/class_NetworkStateResolver.php
application/hub/main/states/peer/class_ [new file with mode: 0644]
application/hub/main/states/peer/new/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/new/class_NewConnectionPeerState.php [new file with mode: 0644]
db/peer_states/.htaccess [new file with mode: 0644]

index 269bdaf923619a0f5b2a7f7407857013c0b09870..61dd4b367deb9dc889fa3d187cf17174cbf5c8c5 100644 (file)
@@ -34,6 +34,7 @@ application/hub/interfaces/listener/.htaccess -text
 application/hub/interfaces/listener/class_Listenable.php -text
 application/hub/interfaces/lists/.htaccess -text
 application/hub/interfaces/lists/class_Listable.php -text
+application/hub/interfaces/lookup/.htaccess -text
 application/hub/interfaces/nodes/.htaccess -text
 application/hub/interfaces/nodes/class_NodeHelper.php -text
 application/hub/interfaces/package/.htaccess -text
@@ -59,6 +60,7 @@ application/hub/interfaces/states/hub/.htaccess -text
 application/hub/interfaces/states/hub/class_HubStateable.php -text
 application/hub/interfaces/states/node/.htaccess -text
 application/hub/interfaces/states/node/class_NodeStateable.php -text
+application/hub/interfaces/states/peer/.htaccess -text
 application/hub/interfaces/tags/.htaccess -text
 application/hub/interfaces/tasks/.htaccess -text
 application/hub/interfaces/tasks/class_Taskable.php -text
@@ -120,6 +122,7 @@ application/hub/main/factories/lists/.htaccess -text
 application/hub/main/factories/package/.htaccess -text
 application/hub/main/factories/states/.htaccess -text
 application/hub/main/factories/states/class_StateFactory.php -text
+application/hub/main/factories/states/peer/.htaccess -text
 application/hub/main/factories/tags/.htaccess -text
 application/hub/main/filter/.htaccess -text
 application/hub/main/filter/activation/.htaccess -text
@@ -223,6 +226,9 @@ application/hub/main/lists/query/local/class_LocalQueryList.php -text
 application/hub/main/lists/recipient/.htaccess -text
 application/hub/main/lists/tasks/.htaccess -text
 application/hub/main/lists/tasks/class_TaskList.php -text
+application/hub/main/lookup/.htaccess -text
+application/hub/main/lookup/class_ -text
+application/hub/main/lookup/peer/.htaccess -text
 application/hub/main/nodes/.htaccess -text
 application/hub/main/nodes/boot/.htaccess -text
 application/hub/main/nodes/boot/class_HubBootNode.php -text
@@ -284,7 +290,9 @@ application/hub/main/states/node/init/class_NodeInitState.php -text
 application/hub/main/states/node/virgin/.htaccess -text
 application/hub/main/states/node/virgin/class_NodeVirginState.php -text
 application/hub/main/states/peer/.htaccess -text
+application/hub/main/states/peer/class_ -text
 application/hub/main/states/peer/class_BasePeerState.php -text
+application/hub/main/states/peer/new/.htaccess -text
 application/hub/main/tags/.htaccess -text
 application/hub/main/tags/class_ -text
 application/hub/main/tags/package/.htaccess -text
@@ -335,6 +343,7 @@ db/.htaccess -text
 db/news/.htaccess -text
 db/node_data/.htaccess -text
 db/node_list/.htaccess -text
+db/peer_states/.htaccess -text
 docs/COPYING -text
 docs/COPYING.documents -text
 docs/COPYING.software -text
index 70ff10389513224832e74138467d8b6d8d658e50..c7fec7a33b54efe42a9342aaa6db110d1851cbed 100644 (file)
@@ -51,6 +51,9 @@ $cfg->setConfigEntry('node_info_db_wrapper_class', 'NodeInformationDatabaseWrapp
 // CFG: NODE-LIST-DB-WRAPPER-CLASS
 $cfg->setConfigEntry('node_list_db_wrapper_class', 'NodeListDatabaseWrapper');
 
+// CFG: PEER-LOOKUP-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('peer_lookup_db_wrapper_class', 'PeerLookupDatabaseWrapper');
+
 // CFG: WEB-CONTENT-TYPE
 $cfg->setConfigEntry('web_content_type', '');
 
@@ -411,5 +414,11 @@ $cfg->setConfigEntry('tcp_connect_retry_max', 10);
 // CFG: UDP-CONNECT-RETRY-MAX
 $cfg->setConfigEntry('udp_connect_retry_max', 10);
 
+// CFG: PEER-STATE-LOOKUP-TABLE-CLASS
+$cfg->setConfigEntry('peer_state_lookup_table_class', 'PeerStateLookupTable');
+
+// CFG: PEER-STATE-CHECKED-PACKAGE-CLASS
+$cfg->setConfigEntry('peer_state_checked_package_class', 'NewConnectionPeerState');
+
 // [EOF]
 ?>
diff --git a/application/hub/interfaces/lookup/.htaccess b/application/hub/interfaces/lookup/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/lookup/class_Lookupable.php b/application/hub/interfaces/lookup/class_Lookupable.php
new file mode 100644 (file)
index 0000000..ccaf19c
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for lookup tables
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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/>.
+ */
+interface Lookupable extends FrameworkInterface {
+}
+
+// [EOF]
+?>
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..fa55693582e5f55bc66f1a61c2a764f2e2452c21 100644 (file)
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for ??? states
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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/>.
+ */
+interface ???Stateable extends Stateable {
+}
+
+// [EOF]
+?>
diff --git a/application/hub/interfaces/states/peer/.htaccess b/application/hub/interfaces/states/peer/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/states/peer/class_PeerStateable.php b/application/hub/interfaces/states/peer/class_PeerStateable.php
new file mode 100644 (file)
index 0000000..c2b6ac2
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for Peer states
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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/>.
+ */
+interface PeerStateable extends Stateable {
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php
new file mode 100644 (file)
index 0000000..1352626
--- /dev/null
@@ -0,0 +1,92 @@
+<?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, 2010 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 {
+       // Constants for database table names
+       const DB_TABLE_PEER_LOOKUP = 'peer_states';
+
+       // Constants for database column names
+       const DB_COLUMN_PEER_IP    = 'peer_ip';
+
+       /**
+        * 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 final static function createPeerLookupDatabaseWrapper () {
+               // Get a new instance
+               $wrapperInstance = new PeerLookupDatabaseWrapper();
+
+               // 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) {
+               // Get a search criteria instance
+               $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+               // Add 'sender' as the peer's IP (this must already be looked up!)
+               $searchInstance->addCriteria(self::DB_COLUMN_PEER_IP, $packageData['sender']);
+               $searchInstance->setLimit(1);
+
+               // Count the query
+               $entries = $this->doSelectCountByCriteria($searchInstance);
+
+               // Is it there?
+               $isNewPeer = ($entries === 0);
+
+               // Return the result
+               return $isNewPeer;
+       }
+}
+
+// [EOF]
+?>
index f39e0cbf3017c58e57c69df72fa68c444fef7ca7..876e1d0f42c3651b7437e14e31acbbc567abb1c2 100644 (file)
@@ -40,7 +40,7 @@ class StateFactory extends ObjectFactory {
         * @param       $nodeInstance   A NodeHelper class instance
         * @return      $stateInstance  A Stateable class instance
         */
-       public static final function createStateInstanceByName($stateName, NodeHelper $nodeInstance) {
+       public static final function createStateInstanceByName ($stateName, NodeHelper $nodeInstance) {
                // Then construct the class' configuraton entry
                $className = 'node_' . $stateName . '_state_class';
 
diff --git a/application/hub/main/factories/states/peer/.htaccess b/application/hub/main/factories/states/peer/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/factories/states/peer/class_PeerStateFactory.php b/application/hub/main/factories/states/peer/class_PeerStateFactory.php
new file mode 100644 (file)
index 0000000..d7edad9
--- /dev/null
@@ -0,0 +1,92 @@
+<?php
+/**
+ * A factory class for peer states
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PeerStateFactory extends ObjectFactory {
+       /**
+        * Static lookup table instance
+        */
+       private static $tableInstance = null;
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates a peer state instance based on errorCode if no entry is found in the lookup table
+        * for the peer given in $packageData 'sender' element or it changes the state if it differs
+        * from current state.
+        *
+        * @param       $errorCode              The last error code
+        * @param       $packageData    Raw package data
+        * @return      $stateInstance  A Stateable class instance
+        */
+       public static final function createPeerStateInstanceByErrorCode ($errorCode, array $packageData) {
+               // So first we need our lookup table
+               $tableInstance = self::getTableInstance();
+
+               // Do we have an entry?
+               if ($tableInstance->isSenderNewPeer($packageData)) {
+                       // Is a new peer so create the state instance based on error code, first we need a config entry
+                       $configEntry = 'peer_state_' . $errorCode . '_class';
+
+                       // Then get it
+                       $stateInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+
+                       // And register it with the lookup table
+                       $tableInstance->registerPeerState($stateInstance, $packageData);
+               } else {
+                       // It is a known peer, so we need to check if the state has changed
+                       die(__METHOD__ . ': Lookup!' . "\n");
+               }
+
+               // For any purposes, return the state instance
+               die(__METHOD__."\n");
+               return $stateInstance;
+       }
+
+       /**
+        * Singleton getter for lookup table instances, kept public if we need this
+        * table somewhere else.
+        *
+        * @return      $tableInstance  An instance of a lookup table
+        */
+       public final static function getTableInstance () {
+               // Is the instance null?
+               if (is_null(self::$tableInstance)) {
+                       // Get a new one
+                       self::$tableInstance = ObjectFactory::createObjectByConfiguredName('peer_state_lookup_table_class');
+               } // END - if
+
+               // Return it
+               return self::$tableInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/lookup/.htaccess b/application/hub/main/lookup/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/lookup/class_ b/application/hub/main/lookup/class_
new file mode 100644 (file)
index 0000000..f54be04
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A ??? lookup table class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 ???LookupTable extends BaseLookupTable implements Lookupable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $tableInstance  An instance of a Lookupable class
+        */
+       public final static function create???LookupTable () {
+               // Get new instance
+               $tableInstance = new ???LookupTable();
+
+               // Return the prepared instance
+               return $tableInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/lookup/class_BaseLookupTable.php b/application/hub/main/lookup/class_BaseLookupTable.php
new file mode 100644 (file)
index 0000000..07318c8
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general LookupTable class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 BaseLookupTable extends BaseHubSystem {
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/lookup/peer/.htaccess b/application/hub/main/lookup/peer/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/lookup/peer/class_PeerStateLookupTable.php b/application/hub/main/lookup/peer/class_PeerStateLookupTable.php
new file mode 100644 (file)
index 0000000..35095ad
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+/**
+ * A Peer lookup table class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 PeerStateLookupTable extends BaseLookupTable implements Lookupable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $tableInstance  An instance of a Lookupable class
+        */
+       public final static function createPeerLookupTable () {
+               // Get new instance
+               $tableInstance = new PeerLookupTable();
+
+               // Get a database wrapper instance
+               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('peer_state_lookup_db_wrapper_class');
+
+               // Set it for later re-use
+               $tableInstance->setWrapperInstance($wrapperInstance);
+
+               // Return the prepared instance
+               return $tableInstance;
+       }
+}
+
+// [EOF]
+?>
index cd314f033554c3bd60236274a3812fbded55cc37..203a871495723c7041483cfac290977cb519a29a 100644 (file)
@@ -86,9 +86,8 @@ class NetworkStateResolver extends BaseStateResolver implements StateResolver {
                        $errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
                } // END - if
 
-               // @TODO We need to somehow detect the state/status of the remote peer and still maintain good speed.
-               // @TODO So maybe some pre-instancing of classes might help here to speedup this I/O intensive process.
-               $this->partialStub('errorCode=' . $errorCode . ',packageData[] = ' . gettype($packageData) . '(' . count($packageData) . ')');
+               // Create a state instance based on $errorCode. This factory does the hard work for us
+               $stateInstance = PeerStateFactory::createPeerStateInstanceByErrorCode($errorCode, $packageData);
 
                // Return the prepared instance
                return $stateInstance;
diff --git a/application/hub/main/states/peer/class_ b/application/hub/main/states/peer/class_
new file mode 100644 (file)
index 0000000..3edf26d
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A ??? peer state class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 ???PeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function create???PeerState () {
+               // Get new instance
+               $stateInstance = new ???PeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/states/peer/new/.htaccess b/application/hub/main/states/peer/new/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/states/peer/new/class_NewConnectionPeerState.php b/application/hub/main/states/peer/new/class_NewConnectionPeerState.php
new file mode 100644 (file)
index 0000000..2616460
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A NewConnection peer state class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 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 NewConnectionPeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function createNewConnectionPeerState () {
+               // Get new instance
+               $stateInstance = new NewConnectionPeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/db/peer_states/.htaccess b/db/peer_states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all