]> git.mxchange.org Git - hub.git/commitdiff
Hub project continued:
authorRoland Häder <roland@mxchange.org>
Wed, 31 Aug 2011 20:15:13 +0000 (20:15 +0000)
committerRoland Häder <roland@mxchange.org>
Wed, 31 Aug 2011 20:15:13 +0000 (20:15 +0000)
- Prepared the code for HTTP requests (wait for it what it will become!)
- Added a lot peer/node states
- Added db/node_states/ directory
- Directory 'db/peer_states/ does now ignore *.serialized files
- Handling of DNAT/MASQUERADE combination which results in self_connect task
  in a 'connection refused' state. This is normal with DNAT/MASQUERADE networks
- Rewritten/improved/completed a lot parts, yet not all is working, I cannot
  remember all (to long ago)
- TODOs.txt updated
- NEWS/README a little updated

84 files changed:
.gitattributes
.gitignore
application/hub/class_ApplicationHelper.php
application/hub/config.php
application/hub/exceptions.php
application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php
application/hub/exceptions/state/class_InvalidStateException.php
application/hub/interfaces/helper/connections/class_ConnectionHelper.php
application/hub/interfaces/helper/messages/class_MessageHelper.php
application/hub/interfaces/lookup/node_states/.htaccess [new file with mode: 0644]
application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php [new file with mode: 0644]
application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php
application/hub/interfaces/package/class_Deliverable.php
application/hub/interfaces/package/fragmenter/class_Fragmentable.php
application/hub/main/class_BaseHubSystem.php
application/hub/main/connectors/query/local/class_LocalQueryConnector.php
application/hub/main/controller/http/.htaccess [new file with mode: 0644]
application/hub/main/cruncher/class_BaseHubCruncher.php
application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php
application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php
application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php
application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
application/hub/main/discovery/socket/class_PackageSocketDiscovery.php
application/hub/main/factories/socket/class_SocketFactory.php
application/hub/main/factories/states/node/class_NodeStateFactory.php
application/hub/main/factories/states/peer/class_PeerStateFactory.php
application/hub/main/handler/network/class_BaseRawDataHandler.php
application/hub/main/handler/tasks/class_TaskHandler.php
application/hub/main/helper/connection/class_BaseConnectionHelper.php
application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php
application/hub/main/iterator/hub/class_HubPingIterator.php
application/hub/main/iterator/network/class_NetworkListenIterator.php
application/hub/main/iterator/pool/class_DefaultIterator.php
application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php
application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php
application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php
application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php
application/hub/main/listener/class_BaseListener.php
application/hub/main/lookup/class_
application/hub/main/lookup/class_BaseLookupTable.php
application/hub/main/lookup/peer/class_NodeStateLookupTable.php
application/hub/main/nodes/class_BaseHubNode.php
application/hub/main/package/class_NetworkPackage.php
application/hub/main/package/fragmenter/class_PackageFragmenter.php
application/hub/main/pools/class_BasePool.php
application/hub/main/pools/peer/class_DefaultPeerPool.php
application/hub/main/producer/class_BaseProducer.php
application/hub/main/registry/objects/class_ObjectTypeRegistry.php
application/hub/main/registry/socket/class_SocketRegistry.php
application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php
application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php
application/hub/main/resolver/controller/http/.htaccess [new file with mode: 0644]
application/hub/main/resolver/state/class_BaseStateResolver.php
application/hub/main/resolver/state/network/class_NetworkStateResolver.php
application/hub/main/resolver/state/peer/.htaccess [new file with mode: 0644]
application/hub/main/resolver/state/peer/class_PeerStateResolver.php [new file with mode: 0644]
application/hub/main/states/cruncher/init/class_CruncherInitState.php
application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php
application/hub/main/states/node/active/class_NodeActiveState.php
application/hub/main/states/node/announced/class_NodeAnnouncedState.php
application/hub/main/states/node/init/class_NodeInitState.php
application/hub/main/states/node/virgin/class_NodeVirginState.php
application/hub/main/states/peer/class_
application/hub/main/states/peer/class_BasePeerState.php
application/hub/main/states/peer/connected/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/connected/class_ConnectedPeerState.php [new file with mode: 0644]
application/hub/main/states/peer/errors/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php [new file with mode: 0644]
application/hub/main/states/peer/init/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/init/class_InitPeerState.php [new file with mode: 0644]
application/hub/main/states/peer/new/class_NewConnectionNodeState.php
application/hub/main/states/peer/transport_endpoint/.htaccess [new file with mode: 0644]
application/hub/main/states/peer/transport_endpoint/class_TransportEndpointGonePeerState.php [new file with mode: 0644]
application/hub/main/statistics/.htaccess [new file with mode: 0644]
application/hub/main/statistics/connection/.htaccess [new file with mode: 0644]
application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php [new file with mode: 0644]
application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php
application/hub/main/tools/class_HubTools.php
application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php
db/node_states/.htaccess [new file with mode: 0644]
docs/NEWS
docs/README
docs/TODOs.txt
index.php

index dc18b2b64aec7b5be2c2e84edbe1e124b7f0e702..6c28d77d0f18318815b0fb69425966b1685d64a0 100644 (file)
@@ -59,6 +59,8 @@ application/hub/interfaces/lists/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/lists/class_Listable.php svneol=native#text/plain
 application/hub/interfaces/lookup/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/lookup/class_Lookupable.php svneol=native#text/plain
+application/hub/interfaces/lookup/node_states/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php svneol=native#text/plain
 application/hub/interfaces/lookup/peer_states/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php svneol=native#text/plain
 application/hub/interfaces/messages/.htaccess svneol=native#text/plain
@@ -159,6 +161,7 @@ application/hub/main/controller/console/.htaccess -text svneol=unset#text/plain
 application/hub/main/controller/console/class_HubConsoleChatController.php svneol=native#text/plain
 application/hub/main/controller/console/class_HubConsoleCruncherController.php svneol=native#text/plain
 application/hub/main/controller/console/class_HubConsoleDefaultNewsController.php svneol=native#text/plain
+application/hub/main/controller/http/.htaccess -text svneol=unset#text/plain
 application/hub/main/cruncher/.htaccess svneol=native#text/plain
 application/hub/main/cruncher/class_BaseHubCruncher.php svneol=native#text/plain
 application/hub/main/cruncher/mcrypt/.htaccess svneol=native#text/plain
@@ -431,10 +434,13 @@ application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.ph
 application/hub/main/resolver/controller/.htaccess -text svneol=unset#text/plain
 application/hub/main/resolver/controller/console/.htaccess -text svneol=unset#text/plain
 application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php svneol=native#text/plain
+application/hub/main/resolver/controller/http/.htaccess -text svneol=unset#text/plain
 application/hub/main/resolver/state/.htaccess -text svneol=unset#text/plain
 application/hub/main/resolver/state/class_BaseStateResolver.php svneol=native#text/plain
 application/hub/main/resolver/state/network/.htaccess -text svneol=unset#text/plain
 application/hub/main/resolver/state/network/class_NetworkStateResolver.php svneol=native#text/plain
+application/hub/main/resolver/state/peer/.htaccess -text svneol=unset#text/plain
+application/hub/main/resolver/state/peer/class_PeerStateResolver.php svneol=native#text/plain
 application/hub/main/source/.htaccess svneol=native#text/plain
 application/hub/main/source/class_BaseSource.php svneol=native#text/plain
 application/hub/main/source/units/.htaccess svneol=native#text/plain
@@ -465,9 +471,19 @@ application/hub/main/states/node/virgin/class_NodeVirginState.php svneol=native#
 application/hub/main/states/peer/.htaccess -text svneol=unset#text/plain
 application/hub/main/states/peer/class_ svneol=native#text/plain
 application/hub/main/states/peer/class_BasePeerState.php svneol=native#text/plain
+application/hub/main/states/peer/connected/.htaccess -text svneol=unset#text/plain
+application/hub/main/states/peer/connected/class_ConnectedPeerState.php svneol=native#text/plain
+application/hub/main/states/peer/errors/.htaccess -text svneol=unset#text/plain
+application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php svneol=native#text/plain
+application/hub/main/states/peer/init/.htaccess -text svneol=unset#text/plain
+application/hub/main/states/peer/init/class_InitPeerState.php svneol=native#text/plain
 application/hub/main/states/peer/new/.htaccess -text svneol=unset#text/plain
 application/hub/main/states/peer/new/class_NewConnectionNodeState.php svneol=native#text/plain
 application/hub/main/states/peer/new/class_NewConnectionPeerState.php svneol=native#text/plain
+application/hub/main/states/peer/transport_endpoint/.htaccess -text svneol=unset#text/plain
+application/hub/main/states/peer/transport_endpoint/class_TransportEndpointGonePeerState.php svneol=native#text/plain
+application/hub/main/statistics/.htaccess -text svneol=unset#text/plain
+application/hub/main/statistics/connection/.htaccess -text svneol=unset#text/plain
 application/hub/main/streams/.htaccess svneol=native#text/plain
 application/hub/main/streams/package/.htaccess svneol=native#text/plain
 application/hub/main/streams/package/input/.htaccess svneol=native#text/plain
@@ -553,6 +569,7 @@ 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
+db/node_states/.htaccess -text svneol=unset#text/plain
 db/peer_states/.htaccess -text svneol=unset#text/plain
 docs/COPYING -text
 docs/COPYING.documents -text
index 69cb1981e120d9225729a48f4558aed4cc0b9c12..0b7f63a199bfab4009091fa75e59a9d991b458b3 100644 (file)
@@ -3,5 +3,7 @@
 /.settings
 application/hub/config-local.php
 db/node_data/*.serialized
+db/node_states/*.serialized
+db/peer_states/*.serialized
 docs/warn.log
 /nbproject
index 3241281311f883936fa77bf8b4080e1f9d758040..dafd73e5569607a93db8f9344c167386b7c8864c 100644 (file)
@@ -57,7 +57,7 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
        /**
         * An instance of this class
         */
-       private static $thisInstance = null;
+       private static $thisInstance = NULL;
 
        /**
         * Private constructor
@@ -152,25 +152,19 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica
                // Set this application in registry
                Registry::getRegistry()->addInstance('app', $this);
 
+               // Default response is console
+               $response = $this->getResponseTypeFromSystem();
+               $responseType = $this->getResponseTypeFromSystem();
+
                // Create a new request object
-               $requestInstance = ObjectFactory::createObjectByName('ConsoleRequest');
+               $requestInstance = ObjectFactory::createObjectByName($this->convertToClassName($response) . 'Request');
 
                // Remember request instance here
                $this->setRequestInstance($requestInstance);
 
-               // Default response is console
-               $response = 'console';
-               $responseType = 'console';
-
-               // Do we have a 'client' parameter set?
-               if ($requestInstance->isRequestElementSet('client')) {
-                       // Extend the response type
-                       $responseType = 'client_' . $responseType;
-               } // END - if
-
                // Do we have another response?
                if ($requestInstance->isRequestElementSet('request')) {
-                       // Then use it, this does override above 'client'!
+                       // Then use it
                        $response = strtolower($requestInstance->getRequestElement('request'));
                        $responseType = $response;
                } // END - if
index 1a32e2c97185cad0ae12730be5ad62d6c14bc26c..fa0a3ed2d7272965da0755df40ccd68f1497efb6 100644 (file)
@@ -51,8 +51,8 @@ $cfg->setConfigEntry('node_info_db_wrapper_class', 'NodeInformationDatabaseWrapp
 // CFG: NODE-LIST-DB-WRAPPER-CLASS
 $cfg->setConfigEntry('node_list_db_wrapper_class', 'NodeListDatabaseWrapper');
 
-// CFG: NODE-LOOKUP-DB-WRAPPER-CLASS
-$cfg->setConfigEntry('node_state_lookup_db_wrapper_class', 'NodeStateLookupDatabaseWrapper');
+// CFG: PEER-LOOKUP-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'PeerStateLookupDatabaseWrapper');
 
 // CFG: WEB-CONTENT-TYPE
 $cfg->setConfigEntry('web_content_type', '');
@@ -501,9 +501,6 @@ $cfg->setConfigEntry('tcp_connect_retry_max', 10);
 // CFG: UDP-CONNECT-RETRY-MAX
 $cfg->setConfigEntry('udp_connect_retry_max', 10);
 
-// CFG: NODE-STATE-LOOKUP-TABLE-CLASS
-$cfg->setConfigEntry('node_state_lookup_table_class', 'NodeStateLookupTable');
-
 // CFG: NODE-STATE-CHECKED-PACKAGE-CLASS
 $cfg->setConfigEntry('node_state_checked_package_class', 'NewConnectionNodeState');
 
@@ -526,7 +523,23 @@ $cfg->setConfigEntry('node_raw_data_output_stream_class', 'RawDataOutputStream')
 $cfg->setConfigEntry('node_raw_data_input_stream_class', 'RawDataInputStream');
 
 ///////////////////////////////////////////////////////////////////////////////
-//                        Cruncher Configuration
+//                              Peer states
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: PEER-INIT-STATE-CLASS
+$cfg->setConfigEntry('peer_init_state_class', 'InitPeerState');
+
+// CFG: PEER-CONNECTED-STATE-CLASS
+$cfg->setConfigEntry('peer_connected_state_class', 'ConnectedPeerState');
+
+// CFG: PEER-CONNECTION-REFUSED-STATE-CLASS
+$cfg->setConfigEntry('peer_connection_refused_state_class', 'ConnectionRefusedPeerState');
+
+// CFG: PEER-TRANSPORT-ENDPOINT-STATE-CLASS
+$cfg->setConfigEntry('peer_transport_endpoint_state_class', 'TransportEndpointGonePeerState');
+
+///////////////////////////////////////////////////////////////////////////////
+//                        Cruncher configuration
 ///////////////////////////////////////////////////////////////////////////////
 
 // CFG: CRUNCHER-DEFAULT-MODE (can be only 'mcrypt' at the moment)
@@ -689,5 +702,18 @@ $cfg->setConfigEntry('chat_bootstrap_generic_activation_filter', 'ChatBootstrapG
 // CFG: CHAT-SHUTDOWN-FILTER
 $cfg->setConfigEntry('chat_shutdown_filter', 'ChatShutdownFilter');
 
+///////////////////////////////////////////////////////////////////////////////
+//                            HTTP Configuration
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: DEFAULT-WEB-COMMAND
+$cfg->setConfigEntry('default_web_command', 'home');
+
+// CFG: WEB-CMD-HOME-RESOLVER-CLASS
+$cfg->setConfigEntry('web_cmd_home_resolver_class', 'WebCommandResolver');
+
+// CFG: NEWS-HOME-LIMIT
+$cfg->setConfigEntry('news_home_limit', 10);
+
 // [EOF]
 ?>
index fa54a9a20888b0f939267fee430402d4316588ce..f219040e6fdb52844ec8e15c0c8c1844df06da30 100644 (file)
@@ -21,7 +21,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// The hub's own exception handler
+// The node's own exception handler
 function hub_exception_handler ($exceptionInstance) {
        // Is it an object and a valid instance?
        if ((is_object($exceptionInstance)) && ($exceptionInstance instanceof FrameworkException)) {
index c33c9db2c16c9532662026bb55fc4cd78ee0bc8e..d2501012b958c773e7e55a65fa1db661b833c93e 100644 (file)
@@ -34,7 +34,7 @@ class PeerAlreadyRegisteredException extends FrameworkException {
                $message = sprintf("[%s:%d] Sender %s is already registered.",
                        $messageArray[0]->__toString(),
                        $this->getLine(),
-                       $messageArray[NetworkPackage::INDEX_PACKAGE_SENDER]
+                       $messageArray[NetworkPackage::PACKAGE_DATA_SENDER]
                );
 
                // Call parent exception constructor
index b89d74f6c634452d5afac5c15f06a54e910cb300..6d3e1be2bfa7323395dbb73c37fe99f79c5b7cdb 100644 (file)
@@ -32,7 +32,7 @@ class InvalidStateException extends FrameworkException {
        public function __construct (Stateable $stateInstance, $code) {
                // Construct the message
                $message = sprintf("[%s:%d] Unexpected state detected.",
-                       $nodeSateInstance->__toString(),
+                       $stateInstance->__toString(),
                        $this->getLine()
                );
 
index 947899c80d67adbf918c460aab03bc7eeb2446cb..6447bdb2518a87cc1e8dc4bda1b2f7909e95d493 100644 (file)
@@ -7,6 +7,7 @@
  * @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
+ * @todo               Please find another name for this interface
  *
  * 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
@@ -31,13 +32,6 @@ interface ConnectionHelper extends Helper {
         */
        function sendRawPackageData (array $packageData);
 
-       /**
-        * Checks wether the connect retry is exhausted
-        *
-        * @return      $isExhaused             Wether connect retry is exchausted
-        */
-       function isConnectRetryExhausted ();
-
        /**
         * Do the shutdown sequence for this connection helper
         *
index 2f2364b4cdd5ee8f0ae0c5a9c509d368cf058198..212a927a0ff20b6271a666cc9327df80f58db8ba 100644 (file)
@@ -7,6 +7,7 @@
  * @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
+ * @todo               Please find another name for this interface
  *
  * 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
diff --git a/application/hub/interfaces/lookup/node_states/.htaccess b/application/hub/interfaces/lookup/node_states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php b/application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php
new file mode 100644 (file)
index 0000000..62d63e6
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for node-state lookup tables
+ *
+ * @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/>.
+ */
+interface LookupableNodeState extends Lookupable {
+}
+
+// [EOF]
+?>
index aadff2e5353949958173b5fcf3c48fe6188b8fc3..e530c1c766897f91e69850d2caba838606081dc1 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * An interface for peer-state lookup tables
+ * An interface for peer-state lookup table wrappers
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
index 48ea7beb77662c2df66dbc7aad3517292044cab7..2c6803843fd4d3ce2463349b2d125ddab5fe5c9a 100644 (file)
@@ -26,11 +26,11 @@ interface Deliverable extends FrameworkInterface {
         * "Enqueues" raw content into this delivery class by reading the raw content
         * from given template instance and pushing it on the 'undeclared' stack.
         *
-        * @param       $helperInstance         An instance of a BaseHubHelper class
+        * @param       $helperInstance         An instance of a HelpableHub class
         * @param       $nodeInstance           An instance of a NodeHelper class
         * @return      void
         */
-       function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance, NodeHelper $nodeInstance);
+       function enqueueRawDataFromTemplate (HelpableHub $helperInstance, NodeHelper $nodeInstance);
 
        /**
         * Checks wether a package has been enqueued for delivery.
index 5a3ebe80d54633187bf96c9e05bb66ff933f808a..d91767c0a730f2b196bb14393608bd314785cf9f 100644 (file)
@@ -28,11 +28,11 @@ interface Fragmentable extends FrameworkInterface {
         * to all chunks and prepends a final hashsum chunk. It will return the
         * final hash for faster processing of packages.
         *
-        * @param       $packageData                    Raw package data array
-        * @param       $connectionInstance             A helper instance for connections
-        * @return      $finalHash                              Final hash for faster processing
+        * @param       $packageData            Raw package data array
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      $finalHash                      Final hash for faster processing
         */
-       function fragmentPackageArray (array $packageData, BaseConnectionHelper $connectionInstance);
+       function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance);
 
        /**
         * This method gets the next chunk from the internal FIFO which should be
index 824353d673b3fd8aa462d9944e259b2302209a18..14ec46a9d9ba5dfdbecb783d1b4bb668ca828545 100644 (file)
@@ -30,37 +30,37 @@ class BaseHubSystem extends BaseFrameworkSystem {
        /**
         * An instance of a node
         */
-       private $nodeInstance = null;
+       private $nodeInstance = NULL;
 
        /**
         * An instance of a cruncher
         */
-       private $cruncherInstance = null;
+       private $cruncherInstance = NULL;
 
        /**
         * Listener instance
         */
-       private $listenerInstance = null;
+       private $listenerInstance = NULL;
 
        /**
         * A network package handler instance
         */
-       private $packageInstance = null;
+       private $packageInstance = NULL;
 
        /**
         * A Receivable instance
         */
-       private $receiverInstance = null;
+       private $receiverInstance = NULL;
 
        /**
         * State instance
         */
-       private $stateInstance = null;
+       private $stateInstance = NULL;
 
        /**
         * Listener pool instance
         */
-       private $listenerPoolInstance = null;
+       private $listenerPoolInstance = NULL;
 
        /**
         * Protected constructor
@@ -215,7 +215,7 @@ class BaseHubSystem extends BaseFrameworkSystem {
         */
        public function shutdownSocket ($socketResource) {
                // Debug message
-               $this->debugOutput('Shutting down socket ' . $socketResource . ' ...');
+               $this->debugOutput('HUB-SYSTEM: Shutting down socket resource ' . $socketResource . ' with state ' . $this->getPrintableState() . ' ...');
 
                // Set socket resource
                $this->setSocketResource($socketResource);
index 94a5c9ac1ff389a92c3fec13a775635d24ac103c..e2ff589448a7c80ce28e4d6bda933c159762fc23 100644 (file)
@@ -26,7 +26,7 @@ class LocalQueryConnector extends BaseQueryConnector implements Connectable, Vis
        /**
         * The query class instance
         */
-       private $queryInstance = null;
+       private $queryInstance = NULL;
 
        /**
         * Protected constructor
diff --git a/application/hub/main/controller/http/.htaccess b/application/hub/main/controller/http/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
index 39471d34dca5da6286f48f774c76a96d2714c8ed..d45ca163292f9f9301320d63acd938e4d4e9f6fb 100644 (file)
@@ -35,7 +35,7 @@ abstract class BaseHubCruncher extends BaseHubSystem implements Updateable {
        /**
         * All buffer queue instances (a FIFO)
         */
-       private $bufferInstance = null;
+       private $bufferInstance = NULL;
 
        /**
         * Protected constructor
index 262ced5de572457a089264460c16c29317c9c25f..e008420d2156f7f447f1d48a6fe1bc7f647b4261 100644 (file)
@@ -29,6 +29,9 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl
        const DB_COLUMN_NODE_SESSION_ID = 'node_session_id';
        const DB_COLUMN_NODE_IP_PORT    = 'node_ipport';
 
+       // Other constants
+       const INVALID_IP_PORT = 'invalid:invalid';
+
        /**
         * Protected constructor
         *
@@ -72,7 +75,7 @@ class NodeListDatabaseWrapper extends BaseDatabaseWrapper implements Registerabl
         */
        public function resolveIpPortBySessionId ($sessionId) {
                // Set invalid ip:port combination
-               $recipient = 'invalid:invalid';
+               $recipient = self::INVALID_IP_PORT;
 
                // Now get a search criteria instance
                $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
index 1e4b174cea65205ce19e092494b69b11dd7d5ea0..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,172 +1,3 @@
 <?php
-/**
- * A database wrapper for node 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 NodeStateLookupDatabaseWrapper extends BaseDatabaseWrapper {
-       // Exception constants
-       const EXCEPTION_NODE_ALREADY_REGISTERED = 0x300;
-
-       // Constants for database table names
-       const DB_TABLE_NODE_LOOKUP = 'node_states';
-
-       // Constants for database column names
-       const DB_COLUMN_NODE_IP         = 'node_ip';
-       const DB_COLUMN_NODE_PORT       = 'node_port';
-       const DB_COLUMN_NODE_SESSION_ID = 'node_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 createNodeStateLookupDatabaseWrapper () {
-               // Get a new instance
-               $wrapperInstance = new NodeStateLookupDatabaseWrapper();
-
-               // Set (primary!) table name
-               $wrapperInstance->setTableName(self::DB_TABLE_NODE_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 node
-        *
-        * @param       $packageData    Raw package data
-        * @return      $isNewPeer              Wether 'sender' is a new node to this node
-        */
-       public function isSenderNewPeer (array $packageData) {
-               // Is always new node by default
-               $isNewPeer = true;
-
-               // Is the package valid?
-               if (!isset($packageData[NetworkPackage::INDEX_PACKAGE_SENDER])) {
-                       // Invalid package found, please report this
-                       die(__METHOD__ . ': 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 node's IP address
-                       $searchInstance->addCriteria(self::DB_COLUMN_NODE_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 node 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 node is already registered
-        * @throws      InvalidSocketException  If the socket resource was invalid
-        */
-       public function registerPeerByPackageData (array $packageData, $socketResource) {
-               // Make sure only new nodes 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_NODE_ALREADY_REGISTERED);
-               } // END - if
-
-               // Generate a dataset instance
-               $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class', array(self::DB_TABLE_NODE_LOOKUP));
-
-               // Session ids must be unique
-               $dataSetInstance->setUniqueKey(self::DB_COLUMN_NODE_SESSION_ID);
-
-               // Add session id
-               $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_SESSION_ID, $packageData[NetworkPackage::INDEX_PACKAGE_SENDER]);
-
-               // Get node name
-               if (!socket_getnodename($socketResource, $nodeName, $nodePort)) {
-                       // 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_NODE_IP  , $nodeName);
-               $dataSetInstance->addCriteria(self::DB_COLUMN_NODE_PORT, $nodePort);
-
-               // "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 node name
-               if (!socket_getnodename($socketResource, $nodeName, $nodePort)) {
-                       // 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
 ?>
index f551ef47b7591c74e7b59193e56a1fa6505a87ab..450609e1ed24a29f6350a5eacb175024669e662c 100644 (file)
@@ -1,3 +1,191 @@
 <?php
-// @DEPRECATED
+/**
+ * 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 implements LookupablePeerState {
+       // 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';
+       const DB_COLUMN_SOCKET_ERROR_CODE = 'socket_error_code';
+       const DB_COLUMN_SOCKET_ERROR_MSG  = 'socket_error_msg';
+
+       /**
+        * 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 peer
+        */
+       public function isSenderNewPeer (array $packageData) {
+               //* DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: ' . __FUNCTION__ . ' called with packageData()=' . count($packageData) . ' - ENTERED!');
+               // Is always new peer by default
+               $isNewPeer = true;
+
+               // Is the package valid?
+               if (!isset($packageData[NetworkPackage::PACKAGE_DATA_SENDER])) {
+                       // Invalid package found, please report this
+                       die(__METHOD__ . ': packageData=' . print_r($packageData, true));
+               } // END - if
+
+               // Resolve session id > IP:port
+               //* DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: sender=' . $packageData[NetworkPackage::PACKAGE_DATA_SENDER] . ' - resolving ...');
+               $ipPort = HubTools::resolveSessionId($packageData[NetworkPackage::PACKAGE_DATA_SENDER]);
+               //* DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: ipPort=' . $ipPort);
+
+               // Is it not invalid:invalid?
+               if ($ipPort != NodeListDatabaseWrapper::INVALID_IP_PORT) {
+                       // 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?
+                       //* DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: entries=' . $entries);
+                       $isNewPeer = ($entries === 0);
+               } // END - if
+
+               // Return the result
+               //* DEBUG: */ $this->debugOutput('DATABASE-WRAPPER: isNewPeer=' . intval($isNewPeer) . ' - EXIT!');
+               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
+        */
+       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::PACKAGE_DATA_SENDER]);
+
+               // Get peer name
+               if (!@socket_getpeername($socketResource, $peerName, $peerPort)) {
+                       // Get last error
+                       $lastError = socket_last_error($socketResource);
+
+                       // ... and cleartext message from it and put both into criteria
+                       $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $lastError);
+                       $dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_MSG , socket_strerror($lastError));
+               } // 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);
+       }
+
+       /**
+        * Registers the given peer state and raw package data
+        *
+        * @param       $stateInstance  A PeerStateable class instance
+        * @param       $packageData    Valid package data array
+        * @return      void
+        * @todo        Unfinished area
+        */
+       public function registerPeerState (PeerStateable $stateInstance, array $packageData) {
+               $this->debugBackTrace('stateInstance=' . $stateInstance->__toString() . ' - UNFINISHED AREA!');
+       }
+
+       /**
+        * 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]
 ?>
index 5e504daa09fc10af0e830b78451025831674e1c9..d7a5c0e4c760e155aab02c1f47fe17b08545d438 100644 (file)
@@ -87,7 +87,7 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
                                $listInstance->addEntry('ip_port', $ipPort);
                                break;
 
-                       // This may be a direct recipient (hub's session id)
+                       // This may be a direct recipient (node's session id)
                        default:
                                $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
                                break;
index 790b5ed508053ffde342a93a75d9016be82b2193..024e45a5a5a38d1a99fe85870e73828fbe80f10b 100644 (file)
@@ -63,7 +63,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                $poolInstance = Registry::getRegistry()->getInstance('node')->getListenerPoolInstance();
 
                // Init listener instance
-               $listenerInstance = null;
+               $listenerInstance = NULL;
 
                /*
                 * Now we need to choose again. It is wether we are speaking with a hub
@@ -87,7 +87,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
         * matching socket resource for that protocol.
         *
         * @param       $packageData            Raw package data array
-        * @return      $socketResource         A valid socket resource
+        * @return      $socketResource         A valid socket resource or FALSE if an error occured
         * @throws      NoListGroupException    If the procol group is not found in peer list
         */
        public function discoverSocket (array $packageData) {
@@ -99,7 +99,7 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
 
                // If there is no listener who wants to have that package, we simply drop it here
                if (is_null($listenerInstance)) {
-                       // @TODO We may need some locking here
+                       // @TODO We may need some logging here
                        // Abort with no resource
                        return false;
                } // END - if
@@ -113,11 +113,28 @@ class PackageSocketDiscovery extends BaseHubDiscovery implements DiscoverableSoc
                $socketResource = $listenerInstance->getPoolInstance()->getSocketFromPackageData($packageData);
 
                // Is it false, the recipient isn't known to us and we have no connection to it
-               if (!is_resource($socketResource)) {
-                       // Create a new socket resource
-                       $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
+               if ((!is_resource($socketResource)) || (socket_last_error($socketResource) > 0)) {
+                       // Try to create a new socket resource
+                       try {
+                               // Possibly noisy debug message
+                               /* NOISY-DEBUG: */ $this->debugOutput('SOCKET-DISCOVERY: Trying to establish a ' . strtoupper($protocolName) . ' connection to ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ' ...');
+
+                               // Get a socket resource from our factory (if succeeded)
+                               $socketResource = SocketFactory::createSocketFromPackageData($packageData, $protocolName);
+
+                               // This succeeded, so change the state to 'CONNECTED'
+                       } catch (SocketConnectionException $e) {
+                               // The connection fails of being established, so log it away
+                               $this->debugOutput('SOCKET-DISCOVERY: ' . $e->__toString() . ',message=' . $e->getMessage());
+                       }
                } // END - if
 
+               // Get the helper instance from registry
+               $helperInstance = Registry::getRegistry()->getInstance('connection');
+
+               // Resolve the peer's state (but ignore return value)
+               PeerStateResolver::resolveStateByPackage($helperInstance, $packageData, $socketResource);
+
                // And return it
                return $socketResource;
        }
index 60447820664f7f8d45d8bfdb03df5ddefe4235f9..53b748b82275382931cfc28ece2ab2901d546c12 100644 (file)
@@ -41,11 +41,29 @@ class SocketFactory extends BaseHubHelper {
         * @return      $socketResource         Socket resource
         */
        public static function createSocketFromPackageData (array $packageData, $protocolName) {
-               // Construct configuration entry for object factory
-               $configEntry = $protocolName . '_connection_helper_class';
+               // Construct registry key
+               $registryKey = 'socket_' . $protocolName . '_' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT];
 
-               // And call the static method
-               $socketResource = call_user_func(FrameworkConfiguration::getInstance()->getConfigEntry($configEntry) . '::createConnectionFromPackageData', $packageData);
+               // Is the key there?
+               if (Registry::getRegistry()->instanceExists($registryKey)) {
+                       // Get container instance
+                       $containerInstance = Registry::getRegistry()->getInstance($registryKey);
+
+                       // Get socket back
+                       $socketResource = $containerInstance->getSocketResource();
+               } else {
+                       // Construct configuration entry for object factory and get it
+                       $className = FrameworkConfiguration::getInstance()->getConfigEntry($protocolName . '_connection_helper_class');
+
+                       // And call the static method
+                       $socketResource = call_user_func($className . '::createConnectionFromPackageData', $packageData);
+
+                       // Construct container class, this won't be reached if an exception is thrown
+                       $containerInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, NULL, $packageData));
+
+                       // Register it with the registry
+                       Registry::getRegistry()->addInstance($registryKey, $containerInstance);
+               }
 
                // Return the resource
                return $socketResource;
index d1e8f42c8dfb296811ca80b46968d9cc67b981c5..db351b678dcf0b6153fcb6ad663106a1678c7f7f 100644 (file)
@@ -47,6 +47,9 @@ class NodeStateFactory extends ObjectFactory {
                // Get a class from that configuration entry
                $stateInstance = self::createObjectByConfiguredName($className, array($nodeInstance));
 
+               // Debug message
+               $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
                // Once we have that state, set it in the node instance
                $nodeInstance->setStateInstance($stateInstance);
 
index 5cbcc9a2ebb4d2c9e96f214040b2c5d1eaa08bc9..34951fc65abd5911c85dba872063d369c988a382 100644 (file)
@@ -25,7 +25,7 @@ class PeerStateFactory extends ObjectFactory {
        /**
         * Static lookup table instance
         */
-       private static $tableInstance = null;
+       private static $tableInstance = NULL;
 
        /**
         * Protected constructor
@@ -37,27 +37,53 @@ class PeerStateFactory extends ObjectFactory {
                parent::__construct(__CLASS__);
        }
 
+       /**
+        * Singleton getter for lookup table instances, kept public if we need this
+        * table somewhere else.
+        *
+        * @return      $tableInstance  An instance of a lookup table
+        */
+       public static final function getTableInstance () {
+               // Is the instance null?
+               if (is_null(self::$tableInstance)) {
+                       // Get a new one
+                       self::$tableInstance = self::createObjectByConfiguredName('peer_state_lookup_db_wrapper_class');
+               } // END - if
+
+               // Return it
+               return self::$tableInstance;
+       }
+
        /**
         * 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       $helperInstance         An instance of a ConnectionHelper class
         * @param       $packageData            Raw package data
         * @param       $socketResource         A valid socket resource
+        * @param       $errorCode                      The last error code
         * @return      $stateInstance          A Stateable class instance
         */
-       public static final function createPeerStateInstanceByErrorCode ($errorCode, array $packageData, $socketResource) {
+       public static final function createPeerStateInstanceBySocketStatusCode (ConnectionHelper $helperInstance, array $packageData, $socketResource, $errorCode) {
                // So first we need our lookup table
                $tableInstance = self::getTableInstance();
 
                // Purge old entries
-               $tableInstance->purgeOldEntriesBySocketResource($socketResource);
+               try {
+                       $tableInstance->purgeOldEntriesBySocketResource($socketResource);
+               } catch (InvalidSocketException $e) {
+                       // Just log all errors
+                       $tableInstance->debugOutput('PEER-STATE-FACTORY: Purging of old entries failed. Message from exception: ' . $e->getMessage());
+               }
 
                // Do we have an entry?
                if ($tableInstance->isSenderNewPeer($packageData)) {
+                       // Debug output
+                       $tableInstance->debugOutput('PEER-STATE-FACTORY: errorCode=' . $errorCode);
+
                        // Is a new peer so create the state instance based on error code, first we need a config entry
-                       $configEntry = 'peer_state_' . $errorCode . '_class';
+                       $configEntry = 'peer_' . $errorCode . '_state_class';
 
                        // Register the new peer with its session id
                        $tableInstance->registerPeerByPackageData($packageData, $socketResource);
@@ -69,28 +95,42 @@ class PeerStateFactory extends ObjectFactory {
                        $tableInstance->registerPeerState($stateInstance, $packageData);
                } else {
                        // It is a known peer, so we need to check if the state has changed
-                       die(__METHOD__ . ': Lookup!' . "\n");
+                       $this->debugBackTrace(__METHOD__ . ': Lookup!' . "\n");
                }
 
+               // Debug message
+               $stateInstance->debugOutput('PEER-STATE[' . __LINE__ . ']: Has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+               // Set the state in the helper
+               $helperInstance->setStateInstance($stateInstance);
+
                // For any purposes, return the state instance
                return $stateInstance;
        }
 
        /**
-        * Singleton getter for lookup table instances, kept public if we need this
-        * table somewhere else.
+        * Creates an instance of a configurable peer state and sets it in the
+        * given peer instance.
         *
-        * @return      $tableInstance  An instance of a lookup table
+        * @param       $stateName                      Name of the state
+        * @param       $helperInstance         A ConnectionHelper class instance
+        * @return      $stateInstance          A Stateable class instance
         */
-       public static final function getTableInstance () {
-               // Is the instance null?
-               if (is_null(self::$tableInstance)) {
-                       // Get a new one
-                       self::$tableInstance = self::createObjectByConfiguredName('node_state_lookup_table_class');
-               } // END - if
+       public static final function createPeerStateInstanceByName ($stateName, ConnectionHelper $helperInstance) {
+               // Then construct the class' configuraton entry
+               $className = 'peer_' . $stateName . '_state_class';
 
-               // Return it
-               return self::$tableInstance;
+               // Get a class from that configuration entry
+               $stateInstance = self::createObjectByConfiguredName($className, array($helperInstance));
+
+               // Debug message
+               $stateInstance->debugOutput('PEER-STATE[' . __LINE__ . ']: Has changed from ' . $helperInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
+
+               // Once we have that state, set it in the peer instance
+               $helperInstance->setStateInstance($stateInstance);
+
+               // For any purposes, return the state instance
+               return $stateInstance;
        }
 }
 
index ef57908233ec8e4edb25391812467cd19f3933d1..8bea9a8ed2f6c59a17140ffe48d0734db0ec21ef 100644 (file)
@@ -30,6 +30,8 @@ class BaseRawDataHandler extends BaseHandler {
        const SOCKET_ERROR_INVALID_BASE64_MODULO  = 'base64_modulo';      // Length is not modulo 4
        const SOCKET_ERROR_INVALID_BASE64_MESSAGE = 'base64_message';     // Raw data is not Base64-encoded
        const SOCKET_ERROR_UNHANDLED              = 'unhandled_package';  // Unhandled raw data (not bad)
+       const SOCKET_ERROR_CONNECTION_REFUSED     = 'connection_refused'; // The name says it: connection refused
+       const SOCKET_CONNECTED                    = 'connected';          // Nothing errorous happens, socket is connected
 
        // - Package errors
        const PACKAGE_ERROR_INVALID_DATA       = 'invalid_data';    // Invalid data in package found
@@ -147,7 +149,7 @@ class BaseRawDataHandler extends BaseHandler {
 
                // Does it match?
                // @TODO Numeric or alpha-numeric index?
-               $matches = ($ownAddress === $packageData[NetworkPackage::INDEX_PACKAGE_RECIPIENT]);
+               $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
 
                // Return result
                return $matches;
index 02fd4b7c55a3570b27c526a013c64363d43cfa19..b9502d91e2debd90482a206d6a970fba853b106e 100644 (file)
@@ -28,7 +28,7 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
        /**
         * Visitor instance for all tasks while they are active
         */
-       private $visitorInstance = null;
+       private $visitorInstance = NULL;
 
        /**
         * Protected constructor
@@ -296,7 +296,6 @@ class TaskHandler extends BaseHandler implements Registerable, HandleableTask {
                        $this->getIteratorInstance()->next();
                } // END - while
 
-
                // Debug message
                $this->debugOutput('TASK-HANDLER: Shutdown of all tasks completed.');
 
index f6c4debedf037350e8790360bd59b28f7ac60141..5a2d92443ff57a945d136057cc1a8c2b746d3df5 100644 (file)
@@ -47,11 +47,6 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
         */
        private $diff = 0;
 
-       /**
-        * Connect retries for this connection
-        */
-       private $retryCount = 0;
-
        /**
         * Wether this connection is shutted down
         */
@@ -85,63 +80,51 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
 
                // And add it to this connection helper
                $this->setOutputStreamInstance($streamInstance);
-       }
 
-       /**
-        * Getter for port number to satify ProtocolHandler
-        *
-        * @return      $port   The port number
-        */
-       public final function getPort () {
-               return $this->port;
+               // Init state which sets the state to 'init'
+               $this->initState();
        }
 
        /**
-        * Setter for port number to satify ProtocolHandler
+        * Getter for real class name
         *
-        * @param       $port   The port number
-        * @return      void
+        * @return      $class  Name of this class
         */
-       protected final function setPort ($port) {
-               $this->port = $port;
-       }
+       public function __toString () {
+               // Class name representation
+               $class = self::getConnectionClassName($this->getAddress(), $this->getPort(), parent::__toString());
 
-       /**
-        * Getter for protocol
-        *
-        * @return      $protocol       Used protocol
-        */
-       public final function getProtocol () {
-               return $this->protocol;
+               // Return it
+               return $class;
        }
 
        /**
-        * Setter for protocol
+        * Static "getter" for this connection class' name
         *
-        * @param       $protocol       Used protocol
-        * @return      void
+        * @param       $address        IP address
+        * @param       $port           Port number
+        * @param       $className      Original class name
+        * @return      $class          Expanded class name
         */
-       protected final function setProtocol ($protocol) {
-               $this->protocol = $protocol;
-       }
+       public static function getConnectionClassName ($address, $port, $className) {
+               // Construct it
+               $class = $address . ':' . $port . ':' . $className;
 
-       /**
-        * Getter for IP address
-        *
-        * @return      $address        The IP address
-        */
-       public final function getAddress () {
-               return $this->address;
+               // ... and return it
+               return $class;
        }
 
        /**
-        * Setter for IP address
+        * Initializes the peer's state which sets it to 'init'
         *
-        * @param       $address        The IP address
         * @return      void
         */
-       protected final function setAddress ($address) {
-               $this->address = $address;
+       private function initState() {
+               /*
+                * Get the state factory and create the initial state, we don't need
+                * the state instance here
+                */
+               PeerStateFactory::createPeerStateInstanceByName('init', $this);
        }
 
        /**
@@ -193,6 +176,63 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                }
        }
 
+       /**
+        * Getter for port number to satify ProtocolHandler
+        *
+        * @return      $port   The port number
+        */
+       public final function getPort () {
+               return $this->port;
+       }
+
+       /**
+        * Setter for port number to satify ProtocolHandler
+        *
+        * @param       $port   The port number
+        * @return      void
+        */
+       protected final function setPort ($port) {
+               $this->port = $port;
+       }
+
+       /**
+        * Getter for protocol
+        *
+        * @return      $protocol       Used protocol
+        */
+       public final function getProtocol () {
+               return $this->protocol;
+       }
+
+       /**
+        * Setter for protocol
+        *
+        * @param       $protocol       Used protocol
+        * @return      void
+        */
+       protected final function setProtocol ($protocol) {
+               $this->protocol = $protocol;
+       }
+
+       /**
+        * Getter for IP address
+        *
+        * @return      $address        The IP address
+        */
+       public final function getAddress () {
+               return $this->address;
+       }
+
+       /**
+        * Setter for IP address
+        *
+        * @param       $address        The IP address
+        * @return      void
+        */
+       protected final function setAddress ($address) {
+               $this->address = $address;
+       }
+
        /**
         * "Accept" a visitor by simply calling it back
         *
@@ -212,6 +252,9 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
         * @throws      InvalidSocketException  If we got a problem with this socket
         */
        public function sendRawPackageData (array $packageData) {
+               // The helper's state must be 'connected'
+               $this->getStateInstance()->validatePeerStateConnected();
+
                // Cache buffer length
                $bufferSize = $this->getConfigInstance()->getConfigEntry($this->getProtocol() . '_buffer_length');
 
@@ -294,50 +337,13 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
                return $totalSentBytes;
        }
 
-       /**
-        * Getter for real class name
-        *
-        * @return      $class  Name of this class
-        */
-       public function __toString () {
-               // Class name representation
-               $class = $this->getAddress() . ':' . $this->getPort() . ':' . parent::__toString();
-
-               // Return it
-               return $class;
-       }
-
-       /**
-        * Checks wether the connect retry is exhausted
-        *
-        * @return      $isExhaused             Wether connect retry is exchausted
-        */
-       public final function isConnectRetryExhausted () {
-               // Construct config entry
-               $configEntry = $this->getProtocol() . '_connect_retry_max';
-
-               // Check it out
-               $isExhausted = ($this->retryCount >=  $this->getConfigInstance()->getConfigEntry($configEntry));
-
-               // Return it
-               return $isExhausted;
-       }
-
-       /**
-        * Increases the connect retry count
-        *
-        * @return      void
-        */
-       public final function increaseConnectRetry () {
-               $this->retryCount++;
-       }
-
        /**
         * Marks this connection as shutted down
         *
         * @return      void
         */
-       protected final function markConnectionShutdown () {
+       protected final function markConnectionShuttedDown () {
+               /* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: ' . $this->__toString() . ' has been marked as shutted down');
                $this->shuttedDown = true;
        }
 
@@ -347,6 +353,7 @@ class BaseConnectionHelper extends BaseHubHelper implements Registerable, Protoc
         * @return      $shuttedDown    Wether this connection is shutted down
         */
        public final function isShuttedDown () {
+               /* NOISY-DEBUG: */ $this->debugOutput('CONNECTION: ' . $this->__toString() . ',shuttedDown=' . intval($this->shuttedDown));
                return $this->shuttedDown;
        }
 }
index 02e9707fd191bc36012437c3f7ccd73991f6fae7..5f41295c8e4efb25142ff9210f693393feee1ac0 100644 (file)
@@ -41,7 +41,9 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
         *
         * @param       $packageData            Raw package data
         * @return      $socketResource         Socket resource
-        * @throws      InvalidSocketException  If the socket is invalid
+        * @throws      SocketCreationException         If the socket could not be created
+        * @throws      SocketOptionException           If a socket option could not be set
+        * @throws      SocketConnectionException       If a connection could not be opened
         */
        public static function createConnectionFromPackageData (array $packageData) {
                // Create an instance
@@ -53,7 +55,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                // Is the socket resource valid?
                if (!is_resource($socketResource)) {
                        // Something bad happened
-                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), 0, 'invalid'), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new SocketCreationException(array($helperInstance, gettype($socketResource), 0, 'invalid'), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
                } // END - if
 
                // Get socket error code for verification
@@ -61,8 +63,11 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
 
                // Check if there was an error else
                if ($socketError > 0) {
+                       // Shutdown this socket
+                       $helperInstance->shutdownSocket($socketResource);
+
                        // Then throw again
-                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new SocketCreationException(array($helperInstance, gettype($socketResource), $socketError, socket_strerror($socketError)), BaseListener::EXCEPTION_SOCKET_CREATION_FAILED);
                } // END - if
 
                // Set the option to reuse the port
@@ -77,7 +82,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                        $helperInstance->shutdownSocket($socketResource);
 
                        // And throw again
-                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new SocketOptionException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
                // Set the resource
@@ -107,7 +112,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                                $helperInstance->shutdownSocket($socketResource);
 
                                // Throw it again
-                               throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                               throw new SocketConnectionException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                        } else {
                                // Debug output
                                $helperInstance->debugOutput('CONNECTION: Operation is in progress, this usual for non-blocking connections.');
@@ -126,9 +131,12 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                        $helperInstance->shutdownSocket($socketResource);
 
                        // And throw again
-                       throw new InvalidSocketException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
+                       throw new SocketOptionException(array($helperInstance, gettype($socketResource), $socketError, $errorMessage), BaseListener::EXCEPTION_INVALID_SOCKET);
                } // END - if
 
+               // We have a connection, so change the state
+               PeerStateFactory::createPeerStateInstanceByName('connected', $this);
+
                // Okay, that should be it. So return it...
                return $socketResource;
        }
@@ -141,6 +149,9 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
         * @todo        We may want to implement a filter for ease notification of other objects like our pool
         */
        public function doShutdown () {
+               // Debug message
+               $this->debugOutput('HELPER: Shutting down socket resource ' . $this->getSocketResource());
+
                // Clear any previous errors
                socket_clear_error($this->getSocketResource());
 
@@ -154,7 +165,7 @@ class TcpConnectionHelper extends BaseConnectionHelper implements ConnectionHelp
                } // END - if
 
                // Mark this connection as shutted down
-               $this->markConnectionShutdown();
+               $this->markConnectionShuttedDown();
        }
 }
 
index 206bf5f826ed05c71a73e184708553c5260bdc78..ea605265eb521f1c88063b7441c01179e7a2f7b9 100644 (file)
@@ -52,7 +52,7 @@ class HubPingIterator extends BaseIterator implements Iterator {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                $this->partialStub('Please implement this method.');
 
@@ -67,7 +67,7 @@ class HubPingIterator extends BaseIterator implements Iterator {
         */
        public function key () {
                // Default is null
-               $key = null;
+               $key = NULL;
 
                $this->partialStub('Please implement this method.');
 
index e451c0a8004d4f5ddcf8089066e03e9c0887ac38..00e031a6626274b0ed35367fc3660059e8b20735 100644 (file)
@@ -64,7 +64,7 @@ class NetworkListenIterator extends BaseIterator implements Iterator {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index 1551b0a75a2f30891e9e4f31349dc732eacccb17..52744883713d1d282f8a4dbaf6db25f3572e1483 100644 (file)
@@ -62,7 +62,7 @@ class DefaultIterator extends BaseIterator implements Iterator {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index f64651024faa2cf898c0017c24f28e39c819a31c..0f27de5099cca50d25e762c4674d3b88b8922450 100644 (file)
@@ -64,7 +64,7 @@ class HandlerPoolIterator extends BaseIterator implements Iterator {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index 72a2c2d866a7a37ab7fab0d6b0a52dee1f5238b9..c58ba6247d60f93f1bd6d8edf1ef91b34ce8ba19 100644 (file)
@@ -64,7 +64,7 @@ class MonitorPoolIterator extends BaseIterator implements Iterator, Registerable
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index e1081bb1ae278746b5f20f57bc331dc5a43ba92e..7001854bf2a1db061554cb5c5fdafddb5337fb5a 100644 (file)
@@ -62,7 +62,7 @@ class ShutdownPoolIterator extends BaseIterator implements Iterator {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index f82dbf3eaa64eeb906b2c7def1cc732311b57d1f..60ea2d0e2afdeca1af901e25efc3badb231e6980 100644 (file)
@@ -64,7 +64,7 @@ class TaskPoolIterator extends BaseIterator implements Iterator, Registerable {
         */
        public function current () {
                // Default is null
-               $current = null;
+               $current = NULL;
 
                // Is the entry valid?
                if (!$this->valid()) {
index b81ffd2027d98f28c52c1a78a443f4fb2b481cad..c367b30d4037605371ef0d13e770f40858823fa8 100644 (file)
@@ -25,6 +25,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
        // Exception code constants
        const EXCEPTION_INVALID_SOCKET            = 0xa00;
        const EXCEPTION_SOCKET_ALREADY_REGISTERED = 0xa01;
+       const EXCEPTION_SOCKET_CREATION_FAILED    = 0xa02;
 
        /**
         * Used protocol (Default: invalid, which is indeed invalid...)
@@ -49,7 +50,7 @@ class BaseListener extends BaseHubSystem implements Visitable {
        /**
         * A peer pool instance
         */
-       private $poolInstance = null;
+       private $poolInstance = NULL;
 
        /**
         * Protected constructor
index 3646b7f85aa08ced770f538ae24020abfaf38e5c..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,50 +1,3 @@
 <?php
-/**
- * A ??? lookup table 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/>.
- */
-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]
+// @DEPRECATED
 ?>
index fe32094f711a85908af7c3f903c3f506dc0796e4..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,38 +1,3 @@
 <?php
-/**
- * A general LookupTable 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/>.
- */
-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]
+// @DEPRECATED
 ?>
index 89ff7128436c9070b77c201eb4c91c9886efe059..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,104 +1,3 @@
 <?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 - 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 NodeStateLookupTable extends BaseLookupTable implements LookupablePeerState {
-       /**
-        * 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 static final function createNodeStateLookupTable () {
-               // Get new instance
-               $tableInstance = new NodeStateLookupTable();
-
-               // Get a database wrapper instance
-               $wrapperInstance = ObjectFactory::createObjectByConfiguredName('node_state_lookup_db_wrapper_class');
-
-               // Set it for later re-use
-               $tableInstance->setWrapperInstance($wrapperInstance);
-
-               // Return the prepared instance
-               return $tableInstance;
-       }
-
-       /**
-        * 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 our wrapper instance and ask for it
-               $isNewPeer = $this->getWrapperInstance()->isSenderNewPeer($packageData);
-
-               // Return it
-               return $isNewPeer;
-       }
-
-       /**
-        * Registers a peer with given package data. We use the session id from it
-        *
-        * @param       $packageData            Valid raw package data
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        */
-       public function registerPeerByPackageData (array $packageData, $socketResource) {
-               // Just handle it over
-               $this->getWrapperInstance()->registerPeerByPackageData($packageData, $socketResource);
-       }
-
-       /**
-        * Registers the given peer state and raw package data
-        *
-        * @param       $stateInstance  A PeerStateable class instance
-        * @param       $packageData    Valid package data array
-        * @return      void
-        */
-       public function registerPeerState (PeerStateable $stateInstance, array $packageData) {
-               die(__METHOD__."\n");
-       }
-
-       /**
-        * Purges old entries of given socket resource. We use the IP address from that resource.
-        *
-        * @param       $socketResource         A valid socket resource
-        * @return      void
-        */
-       public function purgeOldEntriesBySocketResource ($socketResource) {
-               // Just handle it over
-               $this->getWrapperInstance()->purgeOldEntriesBySocketResource($socketResource);
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
index fbe8f50dfc2e250c39f2c9731e1bf1b56788c65a..5bfc26f7d4b44c721d3088df622005b1be437ea6 100644 (file)
@@ -41,12 +41,12 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
        /**
         * Query connector instance
         */
-       private $queryConnectorInstance = null;
+       private $queryConnectorInstance = NULL;
 
        /**
         * Queue connector instance
         */
-       private $queueConnectorInstance = null;
+       private $queueConnectorInstance = NULL;
 
        /**
         * Wether this node is anncounced (KEEP ON false!)
@@ -79,8 +79,10 @@ class BaseHubNode extends BaseHubSystem implements Updateable {
         * @return      void
         */
        private function initState() {
-               // Get the state factory and create the initial state, we don't need
-               // the state instance here
+               /*
+                * Get the state factory and create the initial state, we don't need
+                * the state instance here
+                */
                NodeStateFactory::createNodeStateInstanceByName('init', $this);
        }
 
index 576aae790a67026b7569a5c671dfdca2168d534c..4cfe47c87222bcbb30c726aba63e56be51c1b4bb 100644 (file)
@@ -74,8 +74,8 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
        /**
         * Named array elements for package data
         */
-       const PACKAGE_DATA_RECIPIENT = 'recipient';
        const PACKAGE_DATA_SENDER    = 'sender';
+       const PACKAGE_DATA_RECIPIENT = 'recipient';
        const PACKAGE_DATA_CONTENT   = 'content';
 
        /**
@@ -204,14 +204,14 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
         * "Getter" for hash from given content and helper instance
         *
         * @param       $content        Raw package content
-        * @param       $helperInstance         An instance of a BaseHubHelper class
+        * @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, BaseHubHelper $helperInstance, NodeHelper $nodeInstance) {
+       private function getHashFromContent ($content, HelpableHub $helperInstance, NodeHelper $nodeInstance) {
                // Create the hash
-               // @TODO crc32 is not very strong, but it needs to be fast
+               // @TODO crc32() is not very strong, but it needs to be fast
                $hash = crc32(
                        $content .
                        self::PACKAGE_CHECKSUM_SEPERATOR .
@@ -298,18 +298,21 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
                // Now discover the right protocol
                $socketResource = $discoveryInstance->discoverSocket($packageData);
 
+               // Get the listener from registry
+               $helperInstance = Registry::getRegistry()->getInstance('connection');
+
                // We have to put this socket in our registry, so get an instance
                $registryInstance = SocketRegistry::createSocketRegistry();
 
-               // Get the listener from registry
-               $connectionInstance = Registry::getRegistry()->getInstance('connection');
-
                // Is it not there?
-               if (!$registryInstance->isSocketRegistered($connectionInstance, $socketResource)) {
+               if ((is_resource($socketResource)) && (!$registryInstance->isSocketRegistered($helperInstance, $socketResource))) {
                        // Then register it
-                       $registryInstance->registerSocket($connectionInstance, $socketResource, $packageData);
+                       $registryInstance->registerSocket($helperInstance, $socketResource, $packageData);
                } // END - if
 
+               // Make sure the connection is up
+               $helperInstance->getStateInstance()->validatePeerStateConnected();
+
                // We enqueue it again, but now in the out-going queue
                $this->getStackerInstance()->pushNamed(self::STACKER_NAME_OUTGOING, $packageData);
        }
@@ -321,18 +324,21 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
         * @return      void
         */
        private function sendOutgoingRawPackageData (array $packageData) {
+               // Init sent bytes
+               $sentBytes = 0;
+
                // Get the right connection instance
-               $connectionInstance = SocketRegistry::createSocketRegistry()->getHandlerInstanceFromPackageData($packageData);
+               $helperInstance = SocketRegistry::createSocketRegistry()->getHandlerInstanceFromPackageData($packageData);
 
                // Is this connection still alive?
-               if ($connectionInstance->isShuttedDown()) {
+               if ($helperInstance->isShuttedDown()) {
                        // This connection is shutting down
                        // @TODO We may want to do somthing more here?
                        return;
                } // END - if
 
-               // Sent it away (we catch exceptions one method above)
-               $sentBytes = $connectionInstance->sendRawPackageData($packageData);
+               // Sent out package data
+               $sentBytes = $helperInstance->sendRawPackageData($packageData);
 
                // Remember unsent raw bytes in back-buffer, if any
                $this->storeUnsentBytesInBackBuffer($packageData, $sentBytes);
@@ -342,11 +348,11 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
         * "Enqueues" raw content into this delivery class by reading the raw content
         * from given template instance and pushing it on the 'undeclared' stack.
         *
-        * @param       $helperInstance         An instance of a  BaseHubHelper class
+        * @param       $helperInstance         An instance of a HelpableHub class
         * @param       $nodeInstance           An instance of a NodeHelper class
         * @return      void
         */
-       public function enqueueRawDataFromTemplate (BaseHubHelper $helperInstance, NodeHelper $nodeInstance) {
+       public function enqueueRawDataFromTemplate (HelpableHub $helperInstance, NodeHelper $nodeInstance) {
                // Get the raw content ...
                $content = $helperInstance->getTemplateInstance()->getRawTemplateData();
 
@@ -459,11 +465,16 @@ class NetworkPackage extends BaseFrameworkSystem implements Deliverable, Receiva
                // Get the package again
                $packageData = $this->getStackerInstance()->getNamed(self::STACKER_NAME_DECLARED);
 
-               // And send it
-               $this->deliverRawPackageData($packageData);
+               try {
+                       // And try to send it
+                       $this->deliverRawPackageData($packageData);
 
-               // And remove it finally
-               $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED);
+                       // And remove it finally
+                       $this->getStackerInstance()->popNamed(self::STACKER_NAME_DECLARED);
+               } catch (InvalidStateException $e) {
+                       // The state is not excepected (shall be 'connected')
+                       $this->debugOutput('PACKAGE: Unexpected state detected. message=' . $e->getMessage());
+               }
        }
 
        /**
index 2fb1f3b65d1e65e6d22479be9e5fe32cb4d51368..453c0b148636499afefe0b7ed86ae43403120245 100644 (file)
@@ -351,11 +351,11 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                        $this->chunkHashes[$finalHash][] = $chunkHash;
 
                        // Prepend the hash to the chunk
-                       $chunk =
+                       $chunk = (
                                $chunkHash . self::CHUNK_DATA_HASH_SEPERATOR .
                                $this->getNextHexSerialNumber() . self::CHUNK_DATA_HASH_SEPERATOR .
                                $chunk . self::CHUNK_SEPERATOR
-                       ;
+                       );
 
                        // Make sure the chunk is not larger than a TCP package can hold
                        assert(strlen($chunk) <= NetworkPackage::TCP_PACKAGE_SIZE);
@@ -420,12 +420,12 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
         * to all chunks and prepends a chunk with all hashes only in it. It will
         * return the final hash for faster processing of packages.
         *
-        * @param       $packageData                    Raw package data array
-        * @param       $connectionInstance             A helper instance for connections
-        * @return      $finalHash                              Final hash for faster processing
-        * @todo        $connectionInstance is unused
+        * @param       $packageData            Raw package data array
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      $finalHash                      Final hash for faster processing
+        * @todo        $helperInstance is unused
         */
-       public function fragmentPackageArray (array $packageData, BaseConnectionHelper $connectionInstance) {
+       public function fragmentPackageArray (array $packageData, ConnectionHelper $helperInstance) {
                // Is this package already fragmented?
                if (!$this->isPackageProcessed($packageData)) {
                        // First we need to "implode" the array
@@ -474,7 +474,7 @@ class PackageFragmenter extends BaseFrameworkSystem implements Fragmentable, Reg
                        // This may happen when the final hash is true
                        if ($finalHash === true) {
                                // Set current to null
-                               $current = null;
+                               $current = NULL;
                        } else {
                                // Throw the exception
                                throw $e;
index 2e6c5c8955163af171e06a0cb0569d26bd9b2aed..0e58c98ba267fc1a14bd4b214ddb2f823d857de7 100644 (file)
@@ -25,7 +25,7 @@ class BasePool extends BaseHubSystem implements Visitable {
        /**
         * A list of pool entries
         */
-       private $poolEntriesInstance = null;
+       private $poolEntriesInstance = NULL;
 
        /**
         * Protected constructor
index 11c91f508acec4546df495e269ecf4d0781f2bd2..42ca9668e7c105a6250f14137cd7191a1d1ad850 100644 (file)
@@ -54,6 +54,7 @@ class DefaultPeerPool extends BasePool implements PoolablePeer {
         *
         * @param       $socketResource         A valid socket resource
         * @return      void
+        * @throws      InvalidSocketException  If the given socket has an error
         */
        private function validateSocket ($socketResource) {
                // Is it a valid resource?
index 5ef91a4df71a724cf8cebbddbbef2ffac0deacb5..e69b83f7fe86c641f85938db29d3bff0ed774527 100644 (file)
@@ -25,12 +25,12 @@ abstract class BaseProducer extends BaseFrameworkSystem {
        /**
         * Outgoing work-queue
         */
-       private $outgoingQueueInstance = null;
+       private $outgoingQueueInstance = NULL;
 
        /**
         * Incoming raw data/items queue
         */
-       private $incomingQueueInstance = null;
+       private $incomingQueueInstance = NULL;
 
        /**
         * Protected constructor
index 8e75ea519c720afa90710623eefece347051dc09..1cadcc63fc3ae623a0e5d2d099bbcf2d08db3940 100644 (file)
@@ -25,7 +25,7 @@ class ObjectTypeRegistry extends BaseRegistry implements Register {
        /**
         * Instance of this class
         */
-       private static $registryInstance = null;
+       private static $registryInstance = NULL;
 
        /**
         * Protected constructor
index 8094736739ccb88eede444aa74f5b6626d444bcc..a8aa3330ff41ef56951ab99606f995f612a74d87 100644 (file)
@@ -28,7 +28,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
        /**
         * Instance of this class
         */
-       private static $registryInstance = null;
+       private static $registryInstance = NULL;
 
        /**
         * Protected constructor
@@ -172,6 +172,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                $socketInstance = ObjectFactory::CreateObjectByConfiguredName('socket_container_class', array($socketResource, $protocolInstance, $packageData));
 
                // We have a sub-registry, the socket key and the socket, now we need to put all together
+               /* DEBUG: */ $this->debugOutput('SOCKET-REGISTRY: socketKey=' . $socketKey . ',socketResource=' . $socketResource);
                $registryInstance->addInstance($socketKey, $socketInstance);
        }
 
@@ -213,7 +214,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
         */
        public function getHandlerInstanceFromPackageData (array $packageData) {
                // Init protocol instance
-               $protocolInstance = null;
+               $protocolInstance = NULL;
 
                // Get all keys and check them
                foreach ($this->getInstanceRegistry() as $key=>$registryInstance) {
@@ -221,7 +222,7 @@ class SocketRegistry extends BaseRegistry implements Register, RegisterableSocke
                        foreach ($registryInstance->getInstanceRegistry() as $subKey=>$containerInstance) {
                                // This is a SocketContainer instance, so does the recipient match?
                                if ($containerInstance->ifAddressMatches($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT])) {
-                                       // Found one, so get the protocol instance and abort
+                                       // Found one, so get the protocol instance and abort any further search
                                        $protocolInstance = $containerInstance->getProtocolInstance();
                                        break;
                                } // END - if
index d5aba0faefe490d724f90658ffb51edcb3e7ee85..898897a361d147c4fd397b576d01016ab772aaff 100644 (file)
@@ -78,7 +78,7 @@ class HubConsoleCommandResolver extends BaseCommandResolver implements CommandRe
        public function resolveCommandByRequest (Requestable $requestInstance) {
                // Init variables
                $commandName = '';
-               $commandInstance = null;
+               $commandInstance = NULL;
 
                // This goes fine so let's resolve the command
                $commandName = $requestInstance->getRequestElement('command');
@@ -117,7 +117,7 @@ class HubConsoleCommandResolver extends BaseCommandResolver implements CommandRe
         */
        public function resolveCommand ($commandName) {
                // Initiate the instance variable
-               $commandInstance = null;
+               $commandInstance = NULL;
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_console_command');
@@ -145,7 +145,7 @@ class HubConsoleCommandResolver extends BaseCommandResolver implements CommandRe
         */
        private function loadCommand ($commandName) {
                // Init command instance
-               $commandInstance = null;
+               $commandInstance = NULL;
 
                // Create class name
                $className = 'HubConsole' . $this->convertToClassName($commandName) . 'Command';
index 0eaadb7071ed2ed962e7be9b5b63e64605c0918f..bc649c6143f4dd4630730c23cd6b9b87cb1c95d1 100644 (file)
@@ -78,7 +78,7 @@ class HubConsoleControllerResolver extends BaseControllerResolver implements Con
        public function resolveController () {
                // Init variables
                $controllerName = '';
-               $controllerInstance = null;
+               $controllerInstance = NULL;
 
                // Get the command name 
                $controllerName = $this->getControllerName();
diff --git a/application/hub/main/resolver/controller/http/.htaccess b/application/hub/main/resolver/controller/http/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
index 98736b3d4c52f71964fc69908f7c877c0608a3a1..ac05a5556cfc343ac4a09eaaab6689a690f8281f 100644 (file)
@@ -93,7 +93,7 @@ class BaseStateResolver extends BaseResolver {
         */
        protected function loadState ($stateName) {
                // Init state instance
-               $stateInstance = null;
+               $stateInstance = NULL;
 
                // Create state class name
                $className = $this->getStatePrefix() . '' . $this->convertToClassName($stateName) . 'State';
@@ -147,9 +147,9 @@ class BaseStateResolver extends BaseResolver {
                        if (class_exists($this->getClassName())) {
                                // This class does exist. :-)
                                $isValid = true;
-                       } elseif ($this->getClassName() != $this->statePrefix.'DefaultNewsState') {
+                       } elseif ($this->getClassName() != $this->statePrefix . 'DefaultState') {
                                // Set default state
-                               $this->setClassName($this->statePrefix . 'DefaultNewsState');
+                               $this->setClassName($this->statePrefix . 'DefaultState');
                        } else {
                                // All is tried, give it up here
                                throw new DefaultStateException($this, self::EXCEPTION_DEFAULT_STATE_GONE);
index 9b592b6f8ed311f99963c090a4afd24bf98fc4e8..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,99 +1,3 @@
 <?php
-/**
- * A resolver for resolving states locally
- *
- * @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 NetworkStateResolver extends BaseStateResolver implements StateResolver {
-       /**
-        * Last successfull resolved state (name)
-        */
-       private $lastStateName = '';
-
-       /**
-        * Last successfull resolved state (instance)
-        */
-       private $lastStateInstance = null;
-
-       /**
-        * Protected constructor
-        *
-        * @return      void
-        */
-       protected function __construct () {
-               // Call parent constructor
-               parent::__construct(__CLASS__);
-
-               // Set prefix to 'Network'
-               $this->setStatePrefix('Network');
-       }
-
-       /**
-        * Creates an instance of a resolver class with a given state
-        *
-        * @return      $resolverInstance       The prepared state resolver instance
-        */
-       public static final function createNetworkStateResolver () {
-               // Create the new instance
-               $resolverInstance = new NetworkStateResolver();
-
-               // Return the prepared instance
-               return $resolverInstance;
-       }
-
-       /**
-        * Returns an state instance for a given package class
-        *
-        * @param       $packageInstance        An instance of a package class
-        * @param       $packageData            Raw package data
-        * @param       $socketResource         A valid socket resource
-        * @return      $stateInstance          An instance of the resolved state
-        * @todo        ~30% done
-        */
-       public function resolveStateByPackage (Networkable $packageInstance, array $packageData, $socketResource) {
-               // Init state instance
-               $stateInstance = null;
-
-               // Get error code
-               $errorCode = $packageInstance->getErrorCode();
-
-               // Is the code a number, then we have to change it
-               if (($errorCode == 134) || ($errorCode == 107)) {
-                       // Transport endpoint not connected, should be handled else!
-                       // @TODO On some systems it is 134, on some 107?
-                       $errorCode = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
-               } elseif (is_int($errorCode)) {
-                       // Unhandled error code detected, so first debug it because we may want to handle it like the others
-                       $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
-
-                       // Change it only in this class
-                       $errorCode = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
-               } // END - if
-
-               // Create a state instance based on $errorCode. This factory does the hard work for us
-               $stateInstance = PeerStateFactory::createPeerStateInstanceByErrorCode($errorCode, $packageData, $socketResource);
-
-               // Return the prepared instance
-               return $stateInstance;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/resolver/state/peer/.htaccess b/application/hub/main/resolver/state/peer/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/resolver/state/peer/class_PeerStateResolver.php b/application/hub/main/resolver/state/peer/class_PeerStateResolver.php
new file mode 100644 (file)
index 0000000..077a5bc
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+/**
+ * A resolver for resolving peer states locally
+ *
+ * @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 PeerStateResolver extends BaseStateResolver implements StateResolver {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set prefix to 'Peer'
+               $this->setStatePrefix('Peer');
+       }
+
+       /**
+        * Creates an instance of a resolver class with a given state
+        *
+        * @return      $resolverInstance       The prepared state resolver instance
+        */
+       public static final function createPeerStateResolver () {
+               // Create the new instance
+               $resolverInstance = new PeerStateResolver();
+
+               // Return the prepared instance
+               return $resolverInstance;
+       }
+
+       /**
+        * Returns an state instance for a given raw package data and socket resource
+        *
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @param       $packageData            Raw package data
+        * @param       $socketResource         A valid socket resource
+        * @return      $stateInstance          An instance of the resolved state
+        * @todo        ~30% done
+        */
+       public static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, $socketResource) {
+               // Get temporary resolver instance
+               $resolverInstance = self::createPeerStateResolver();
+
+               // Init state instance
+               $stateInstance = NULL;
+
+               // Is the socket resource valid?
+               if (!is_resource($socketResource)) {
+                       // No, so get socket resource from helper
+                       $socketResource = $helperInstance->getSocketResource();
+               } // END - if
+
+               // Get error code from it
+               $errorCode = socket_last_error($socketResource);
+
+               // Is the code a number, then we have to change it
+               if (($errorCode == 134) || ($errorCode == 107)) {
+                       // Transport endpoint not connected, should be handled else!
+                       // @TODO On some systems it is 134, on some 107?
+                       $errorCode = BaseRawDataHandler::SOCKET_ERROR_TRANSPORT_ENDPOINT;
+               } elseif ($errorCode == 111) {
+                       // Error 'connection refused'
+                       $errorCode = BaseRawDataHandler::SOCKET_ERROR_CONNECTION_REFUSED;
+               } elseif ($errorCode > 0) {
+                       // Unhandled error code detected, so first debug it because we may want to handle it like the others
+                       $resolverInstance->debugOutput('[' . __METHOD__ . ':' . __LINE__ . '] UNKNOWN ERROR CODE = ' . $errorCode, ', MESSAGE = ' . socket_strerror($errorCode));
+
+                       // Change it only in this class
+                       $errorCode = BaseRawDataHandler::SOCKET_ERROR_UNKNOWN;
+               } else {
+                       // Nothing bad happend
+                       $errorCode = BaseRawDataHandler::SOCKET_CONNECTED;
+               }
+
+               // Create a state instance based on $errorCode. This factory does the hard work for us
+               $stateInstance = PeerStateFactory::createPeerStateInstanceBySocketStatusCode($helperInstance, $packageData, $socketResource, $errorCode);
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
index 1caf37c580dd4c3e61e395c5498ce4c1d2809702..749ae73f6e54290e1262d8e03e871927d74a5b46 100644 (file)
@@ -45,9 +45,6 @@ class CruncherInitState extends BaseCruncherState implements Stateable {
                // Get new instance
                $stateInstance = new CruncherInitState();
 
-               // Debug message
-               $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Set the cruncher instance
                $stateInstance->setCruncherInstance($cruncherInstance);
 
index 6f567f4afc3a990553498cfd46c0341e9ef3ed58..ebc9489010dcdeab0b74a985444e7f5f522c210c 100644 (file)
@@ -45,9 +45,6 @@ class CruncherVirginState extends BaseCruncherState implements Stateable {
                // Get new instance
                $stateInstance = new CruncherVirginState();
 
-               // Debug message
-               $stateInstance->debugOutput('CRUNCHER-STATE: Has changed from ' . $cruncherInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Set the cruncher instance
                $stateInstance->setCruncherInstance($cruncherInstance);
 
index 9822dfaa855decf2f0da6073f0577d504f194f60..86fd1b889c618468b9a7c3418ce55e0f8661a590 100644 (file)
@@ -45,9 +45,6 @@ class NodeActiveState extends BaseNodeState implements Stateable {
                // Get new instance
                $stateInstance = new NodeActiveState();
 
-               // Debug message
-               $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Enable isActive flag in node instance
                $nodeInstance->enableIsActive();
 
index 30b080f920c2d929ddaa550516d577dec6ee551c..001d7258fdc0b07d391b3f905269d188dca4323a 100644 (file)
@@ -45,9 +45,6 @@ class NodeAnnouncedState extends BaseNodeState implements Stateable {
                // Get new instance
                $stateInstance = new NodeAnnouncedState();
 
-               // Debug message
-               $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Set the node instance
                $stateInstance->setNodeInstance($nodeInstance);
 
index 473204dce5ca556440f1613e2d0d2c9e00fc2914..d46ee8eb36634634ed618515fc2486b81f29a1c1 100644 (file)
@@ -45,9 +45,6 @@ class NodeInitState extends BaseNodeState implements Stateable {
                // Get new instance
                $stateInstance = new NodeInitState();
 
-               // Debug message
-               $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Set the node instance
                $stateInstance->setNodeInstance($nodeInstance);
 
index 61e2395553ecc683b357fb3ad022632e6f2d80ac..bf37f53417dadc04f27844942a3c0927a8580d65 100644 (file)
@@ -45,9 +45,6 @@ class NodeVirginState extends BaseNodeState implements Stateable {
                // Get new instance
                $stateInstance = new NodeVirginState();
 
-               // Debug message
-               $stateInstance->debugOutput('NODE-STATE: Has changed from ' . $nodeInstance->getPrintableState() . ' to ' . $stateInstance->getStateName() . '.');
-
                // Set the node instance
                $stateInstance->setNodeInstance($nodeInstance);
 
index edb7029d723a7c652e7608ab895cb34b7b00e9fa..83be3f3e3b94fc1d3f09dfeb79fbd51dd7e3a375 100644 (file)
@@ -30,6 +30,9 @@ class ???PeerState extends BasePeerState implements PeerStateable {
        protected function __construct () {
                // Call parent constructor
                parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('!!!');
        }
 
        /**
index 7b6b3814dca16753014261f5bc4732c0d6329826..b5d9bc4012fa40539badd544a7567631dac9e5f4 100644 (file)
@@ -32,6 +32,31 @@ class BasePeerState extends BaseState {
                // Call parent constructor
                parent::__construct($className);
        }
+
+       /**
+        * Validates wether the state is 'connected' or throws an exception if
+        * it is every other state.
+        *
+        * @return      void
+        * @throws      InvalidStateException   If the state is not 'connected'
+        */
+       public function validatePeerStateConnected () {
+               // Just compare it...
+               if (!$this->isPeerStateConnected()) {
+                       // Throw the exception
+                       throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE);
+               } // END - if
+       }
+
+       /**
+        * Checks wether the peer's state is 'connected'
+        *
+        * @return      $isConnected                    Wether the state is 'connected'
+        */
+       public function isPeerStateConnected () {
+               // Just compare it...
+               return ($this instanceof ConnectedPeerState);
+       }
 }
 
 // [EOF]
diff --git a/application/hub/main/states/peer/connected/.htaccess b/application/hub/main/states/peer/connected/.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/connected/class_ConnectedPeerState.php b/application/hub/main/states/peer/connected/class_ConnectedPeerState.php
new file mode 100644 (file)
index 0000000..62479e4
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A Connected peer state 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/>.
+ */
+class ConnectedPeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function createConnectedPeerState () {
+               // Get new instance
+               $stateInstance = new ConnectedPeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/states/peer/errors/.htaccess b/application/hub/main/states/peer/errors/.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/errors/class_ConnectionRefusedPeerState.php b/application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php
new file mode 100644 (file)
index 0000000..60ad54c
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A ConnectionRefused peer state 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/>.
+ */
+class ConnectionRefusedPeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('connection_refused');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function createConnectionRefusedPeerState () {
+               // Get new instance
+               $stateInstance = new ConnectionRefusedPeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/states/peer/init/.htaccess b/application/hub/main/states/peer/init/.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/init/class_InitPeerState.php b/application/hub/main/states/peer/init/class_InitPeerState.php
new file mode 100644 (file)
index 0000000..b06940d
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A Init peer state 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/>.
+ */
+class InitPeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('init');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function createInitPeerState () {
+               // Get new instance
+               $stateInstance = new InitPeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
index b6270bff5daa10ea7afab5908264ef4d28f32421..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,50 +1,3 @@
 <?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 - 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 NewConnectionNodeState 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 static final function createNewConnectionNodeState () {
-               // Get new instance
-               $stateInstance = new NewConnectionNodeState();
-
-               // Return the prepared instance
-               return $stateInstance;
-       }
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/main/states/peer/transport_endpoint/.htaccess b/application/hub/main/states/peer/transport_endpoint/.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/transport_endpoint/class_TransportEndpointGonePeerState.php b/application/hub/main/states/peer/transport_endpoint/class_TransportEndpointGonePeerState.php
new file mode 100644 (file)
index 0000000..ee17be8
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * A TransportEndpointGone peer state 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/>.
+ */
+class TransportEndpointGonePeerState extends BasePeerState implements PeerStateable {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+
+               // Set state name
+               $this->setStateName('transport_endpoint');
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $stateInstance  An instance of a PeerStateable class
+        */
+       public final static function createTransportEndpointGonePeerState () {
+               // Get new instance
+               $stateInstance = new TransportEndpointGonePeerState();
+
+               // Return the prepared instance
+               return $stateInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/statistics/.htaccess b/application/hub/main/statistics/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/statistics/connection/.htaccess b/application/hub/main/statistics/connection/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php
new file mode 100644 (file)
index 0000000..42fd5c1
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+/**
+ * A helper class for maintaining connection statistics, no instance is
+ * required to use this class.
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.org
+ * @todo               Find an interface for hub helper
+ *
+ * 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 ConnectionStatisticsHelper extends BaseHubSystem {
+       /**
+        * Statistics array
+        */
+       private static $connectionStatistics = array(
+               // Statistics for TCP connections
+               'tcp' => array(
+                       // Tried connection attempts
+                       'retry_count' => array(),
+               ),
+               // Statistics for UDP connections
+               'udp' => array(
+                       'retry_count' => array(),
+               )
+       );
+
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Checks wether the retry count has reached a configured limit for given
+        * connection.
+        *
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      $isExhausted            Wether the retry count has been reached
+        */
+       public static function isConnectRetryExhausted (ConnectionHelper $helperInstance) {
+               //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
+               // Construct config entry
+               $configEntry = $helperInstance->getProtocol() . '_connect_retry_max';
+
+               // Check it out
+               $isExhausted = (
+                       (
+                               isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])
+                       ) && (
+                               self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] >= $helperInstance->getConfigInstance()->getConfigEntry($configEntry)
+                       )
+               );
+
+               // Return it
+               //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ',isExhausted=' . intval($isExhausted) . ' - EXIT!');
+               return $isExhausted;
+       }
+
+       /**
+        * Increaes connect-retry count for given connection
+        *
+        * @param       $helperInstance         An instance of a ConnectionHelper class
+        * @return      void
+        */
+       public static function increaseConnectRetry (ConnectionHelper $helperInstance) {
+               //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - ENTERED!');
+               // Is the counter there
+               if (!isset(self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'])) {
+                       // First attempt
+                       //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - FIRST!');
+                       self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count'] = 1;
+               } else {
+                       // Next attempt
+                       //* DEBUG: */ $helperInstance->debugOutput(__METHOD__ . ':helperInstance=' . $helperInstance->__toString() . ' - INCREMENT!');
+                       self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['retry_count']++;
+               }
+
+               // Create/update 'last_update' for later purging
+               self::$connectionStatistics[$helperInstance->getProtocol()][$helperInstance->__toString()]['last_update'] = time();
+       }
+}
+
+// [EOF]
+?>
index c6afa7cc88f1f0e684241a7af2175f02e2c7d439..0c65ed65fdd56b92f2a26d90a9cc55e6e6497de2 100644 (file)
@@ -26,7 +26,7 @@ class XmlObjectRegistryTemplateEngine extends BaseTemplateEngine implements Comp
        /**
         * Instance for the object registry
         */
-       private $objectRegistryInstance = null;
+       private $objectRegistryInstance = NULL;
 
        /**
         * Main nodes in the XML tree
index 60fd33ca75a2ae72458fb9b2e0610c1333a555a8..4d8227f2f80799908c20fcda9da453cf1936d780 100644 (file)
@@ -39,7 +39,7 @@ class HubTools extends BaseFrameworkSystem {
        /**
         * Self instance
         */
-       private static $selfInstance = null;
+       private static $selfInstance = NULL;
 
        /**
         * Protected constructor
@@ -136,7 +136,7 @@ class HubTools extends BaseFrameworkSystem {
                        } // END - if
                } elseif (preg_match('/([a-f0-9]{' . $selfInstance->getSessionIdLength() . '})/', $sessionId)) {
                        // Debug message
-                       $selfInstance->debugOutput('HUB-TOOLS: Using internal resolver.');
+                       $selfInstance->debugOutput('HUB-TOOLS: Using internal session id resolver.');
 
                        // Resolve session id into a ip:port combination
                        $recipient = $selfInstance->resolveIpPortBySessionId($sessionId);
index 04d9d85e5ccd7ebf266a0db2d0b389eb38aee318..69354167f37821217acf540a1e4d26e5c069df38 100644 (file)
@@ -52,17 +52,17 @@ class ShutdownSocketVisitor extends BaseVisitor implements Visitor {
         * "Visit" method to do the actual request. Here we want to shutdown the
         * attached socket.
         *
-        * @param       $helperInstance         A BaseConnectionHelper instance
+        * @param       $helperInstance         A ConnectionHelper instance
         * @return      void
         */
-       public function visitConnectionHelper (BaseConnectionHelper $helperInstance) {
+       public function visitConnectionHelper (ConnectionHelper $helperInstance) {
                // Do we have reached the retry count?
-               if ($helperInstance->isConnectRetryExhausted()) {
+               if (ConnectionStatisticsHelper::isConnectRetryExhausted($helperInstance)) {
                        // Shutdown the connection
                        $helperInstance->doShutdown();
                } else {
                        // We can still move on and retry the connection attempt
-                       $helperInstance->increaseConnectRetry();
+                       ConnectionStatisticsHelper::increaseConnectRetry($helperInstance);
                }
        }
 }
diff --git a/db/node_states/.htaccess b/db/node_states/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
index 7339625fe69791df43521365d92c4ed2841f18bb..72dabad3baf32e60d612e7d0e6cbc93a8391b1eb 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -21,7 +21,7 @@ NEWS / ChangeLog
 [2009-04-30]
 ------------
 - Detection of own IP address fixed (but might still be rewritten)
-- Boot-node code moved from NaseHubNode class to its own class (cleanup)
+- Boot-node code moved from BaseHubNode class to its own class (cleanup)
 - FileNotFoundException in ConsoleTools was caught without any console
   ouput which is not recommended.
 - README updated to reflect changes in some revisions ago
index ec1451369abbfb0aa02fb81895636f32e334dbd5..2a3b921a93ef481e6b9a944d8a2355cca7c0bd0d 100644 (file)
@@ -53,7 +53,7 @@ just 'hey, my code runs' code.
 This software is simply called "hub". This has a simple reason that this is,
 first, the "working title" for it. And second, I have found no better name than
 "Generic Object Sharing Hub" for this. I would not shortcut it to "Gosh" or
-"GNU Gosh" or such other title, because the word "gosh" is english and
+"GNU Gosh" or such other title, because the word "gosh" is English and
 completely misleading.
 
 So if you have a really good ("selling") name, please send it to me:
index 0c067a8666811a15a4de5c63fca37f1903410a6a..34b9ca90336bc1cfbf5a2137ceb797f8382c7ef0 100644 (file)
@@ -1,8 +1,13 @@
 ### WARNING: THIS FILE IS AUTO-GENERATED BY ./todo-builder.sh ###
 ### DO NOT EDIT THIS FILE. ###
+./application/hub/interfaces/chat/class_Chatter.php:10: * @todo                We need to find a better name for this interface
 ./application/hub/interfaces/cruncher/class_CruncherHelper.php:10: * @todo             We need to find a better name for this interface
-./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:44:  * @todo        We may want to implement a filter for ease notification of other objects like our pool
+./application/hub/interfaces/helper/connections/class_ConnectionHelper.php:10: * @todo         Please find another name for this interface
+./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/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?
 ./application/hub/main/commands/console/class_HubConsoleCruncherCommand.php:58:         * @todo        Try to create a CruncherActivationTask or so
 ./application/hub/main/commands/console/class_HubConsoleMainCommand.php:114:    * @todo        Should we add some more filters?
 ./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:108:         * @todo        Implement this method
 ./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:138:         * @todo        0% done
 ./application/hub/main/cruncher/mcrypt/class_HubMcryptCruncher.php:98:         // @TODO Implement this method
-./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102:                  // @TODO We may need some locking here
+./application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php:165:    * @todo        Unfinished area
+./application/hub/main/discovery/socket/class_PackageSocketDiscovery.php:102:                  // @TODO We may need some logging here
 ./application/hub/main/factories/socket/class_SocketFactory.php:10: * @todo            Find an interface for hub helper
+./application/hub/main/filter/bootstrap/chat/class_ChatBootstrapGenericActivationFilter.php:54:         * @todo        Maybe we want to do somthing more here?
 ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapBufferQueueInitializerFilter.php:54:    * @todo        0% done
 ./application/hub/main/filter/bootstrap/cruncher/class_CruncherBootstrapGenericActivationFilter.php:54:         * @todo        Maybe we want to do somthing more here?
+./application/hub/main/filter/chat/class_ChatInitializationFilter.php:54:       * @todo        0% done
+./application/hub/main/filter/chat/class_ChatPhpRequirementsFilter.php:55:      * @todo        Add more test and try to add an extra message to the thrown exception
+./application/hub/main/filter/chat/class_ChatWelcomeTeaserFilter.php:55:        * @todo        Handle over the $responseInstance to outputConsoleTeaser()
 ./application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php:54:       * @todo        0% done
 ./application/hub/main/filter/cruncher/class_CruncherInitializationFilter.php:87:                      // @TODO Can we rewrite this to app_die() ?
 ./application/hub/main/filter/cruncher/class_CruncherPhpRequirementsFilter.php:55:      * @todo        Add more test and try to add an extra message to the thrown exception
-./application/hub/main/filter/cruncher/class_CruncherWelcomeTeaserFilter.php:55:        * @todo        Handle over the $responseInstance to outputCruncherTeaser()
+./application/hub/main/filter/cruncher/class_CruncherWelcomeTeaserFilter.php:55:        * @todo        Handle over the $responseInstance to outputConsoleTeaser()
 ./application/hub/main/filter/node/class_NodeInitializationFilter.php:54:       * @todo        0% done
 ./application/hub/main/filter/node/class_NodeInitializationFilter.php:87:                      // @TODO Can we rewrite this to app_die() ?
 ./application/hub/main/filter/node/class_NodePhpRequirementsFilter.php:55:      * @todo        Add more test and try to add an extra message to the thrown exception
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownDeinitQueuesFilter.php:55:        * @todo        0% done
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownFlushNodeListFilter.php:55:       * @todo        0% done
 ./application/hub/main/filter/shutdown/node/class_NodeShutdownTaskHandlerFilter.php:55:         * @todo        0% done
+./application/hub/main/filter/task/chat/class_ChatTaskHandlerInitializerFilter.php:55:  * @todo        5% done
 ./application/hub/main/filter/task/cruncher/class_CruncherTaskHandlerInitializerFilter.php:55:  * @todo        5% done
 ./application/hub/main/filter/task/node/class_NodeTaskHandlerInitializerFilter.php:55:  * @todo        Maybe some more tasks needs to be added?
-./application/hub/main/handler/network/class_BaseRawDataHandler.php:142:        * @todo        This method will be moved to a better place
-./application/hub/main/handler/network/class_BaseRawDataHandler.php:149:               // @TODO Numeric or alpha-numeric index?
+./application/hub/main/handler/network/class_BaseRawDataHandler.php:144:        * @todo        This method will be moved to a better place
+./application/hub/main/handler/network/class_BaseRawDataHandler.php:151:               // @TODO Numeric or alpha-numeric index?
 ./application/hub/main/handler/network/udp/class_UdpRawDataHandler.php:58:      * @todo        0%
 ./application/hub/main/handler/tasks/class_TaskHandler.php:140:                // @TODO Messurement can be added around this call
 ./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:10: * @todo         Find an interface for hub helper
-./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:141:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
+./application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php:149:         * @todo        We may want to implement a filter for ease notification of other objects like our pool
 ./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:10: * @todo         Find an interface for hub helper
 ./application/hub/main/helper/connection/udp/class_UdpConnectionHelper.php:54:  * @todo        We may want to implement a filter for ease notification of other objects like our pool
 ./application/hub/main/helper/hub/announcement/class_HubDescriptorHelper.php:10: * @todo               Find an interface for hub helper
@@ -61,9 +72,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:382:         * @todo        Try to make this method more generic so we can move it in BaseFrameworkSystem
-./application/hub/main/nodes/class_BaseHubNode.php:422:         * @todo        Change the first if() block to check for a specific state
-./application/hub/main/nodes/class_BaseHubNode.php:595:                // @TODO Add some criteria, e.g. if the node is active or so
+./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/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
 ./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:210:    * @todo        $helperInstance is unused
-./application/hub/main/package/class_NetworkPackage.php:214:           // @TODO crc32 is not very strong, but it needs to be fast
+./application/hub/main/package/class_NetworkPackage.php:214:           // @TODO crc32() is not very strong, but it needs to be fast
 ./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:330:                   // @TODO We may want to do somthing more here?
-./application/hub/main/package/class_NetworkPackage.php:429:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:455:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:548:                   // @TODO Add some logging here
-./application/hub/main/package/class_NetworkPackage.php:626:           // @TODO Add some content here
-./application/hub/main/package/fragmenter/class_PackageFragmenter.php:426:      * @todo        $connectionInstance is unused
-./application/hub/main/pools/peer/class_DefaultPeerPool.php:148:                       // @TODO Check for IP
+./application/hub/main/package/class_NetworkPackage.php:336:                   // @TODO We may want to do somthing more here?
+./application/hub/main/package/class_NetworkPackage.php:435:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:461:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:559:                   // @TODO Add some logging here
+./application/hub/main/package/class_NetworkPackage.php:637:           // @TODO Add some content here
+./application/hub/main/package/fragmenter/class_PackageFragmenter.php:426:      * @todo        $helperInstance is unused
+./application/hub/main/pools/peer/class_DefaultPeerPool.php:149:                       // @TODO Check for IP
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:106:                       // @TODO Do something with it
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:62:         * @todo        Find something for init phase of this key producer
 ./application/hub/main/producer/cruncher/keys/class_CruncherKeyProducer.php:72:         * @todo        ~30% done
 ./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:79:      * @todo        ~60% done
 ./application/hub/main/producer/cruncher/work_units/class_CruncherTestUnitProducer.php:99:                     // @TODO Unfinished work here
-./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:68:        * @todo        ~30% done
-./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:80:                       // @TODO On some systems it is 134, on some 107?
-./application/hub/main/states/node/init/class_NodeInitState.php:63:     * @todo        We might want to move some calls to this method to fill it with life
+./application/hub/main/resolver/state/peer/class_PeerStateResolver.php:58:      * @todo        ~30% done
+./application/hub/main/resolver/state/peer/class_PeerStateResolver.php:79:                     // @TODO On some systems it is 134, on some 107?
+./application/hub/main/states/node/init/class_NodeInitState.php:60:     * @todo        We might want to move some calls to this method to fill it with life
+./application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php:11: * @todo          Find an interface for hub helper
 ./application/hub/main/streams/raw_data/input/class_RawDataInputStream.php:57:  * @todo        Do we need to do something more here?
 ./application/hub/main/streams/raw_data/output/class_RawDataOutputStream.php:53:        * @todo        Do we need to do something more here?
 ./application/hub/main/tasks/cruncher/class_CruncherKeyProducerTask.php:53:     * @todo        Maybe visit some sub-objects
 ./inc/classes/main/controller/web/class_WebStatusController.php:10: * @todo            This controller shall still provide some headlines for sidebars
 ./inc/classes/main/criteria/search/class_SearchCriteria.php:126:        * @todo        Find a nice casting here. (int) allows until and including 32766.
 ./inc/classes/main/criteria/search/class_SearchCriteria.php:94:         * @todo        Find a nice casting here. (int) allows until and including 32766.
-./inc/classes/main/database/databases/class_LocalFileDatabase.php:360:  * @todo        Do some checks on the database directory and files here
+./inc/classes/main/database/databases/class_LocalFileDatabase.php:331:  * @todo        Do some checks on the database directory and files here
 ./inc/classes/main/decorator/template/class_XmlRewriterTemplateDecorator.php:426:       * @todo        Find something useful with this!
 ./inc/classes/main/discovery/payment/class_LocalPaymentDiscovery.php:82:        * @todo        0% done
 ./inc/classes/main/filter/change/class_EmailChangeFilter.php:54:        * @todo        Implement email change of the user here. HINT: Use the User class!
 ./inc/classes/main/output/class_ConsoleOutput.php:56:          // @TODO Need to rewrite this to $requestInstance->addHeader()
 ./inc/classes/main/parser/xml/class_XmlParser.php:76:                  // @TODO We need to find a fallback solution here
 ./inc/classes/main/points/class_UserPoints.php:100:     * @todo        Finish loading part of points
-./inc/classes/main/request/console/class_ConsoleRequest.php:115:               // @TODO There are no cookies on console
-./inc/classes/main/request/console/class_ConsoleRequest.php:55:         * @todo        Needs to be implemented
+./inc/classes/main/request/console/class_ConsoleRequest.php:106:               // @TODO Can't this be 'CONSOLE' ?
 ./inc/classes/main/request/web/class_HttpRequest.php:10: * @todo               Move out the cookie part to a seperate class, e.g. Cookie
 ./inc/classes/main/response/http/class_HttpResponse.php:77:     * @todo        Encryption of cookie data not yet supported.
 ./inc/classes/main/response/http/class_HttpResponse.php:78:     * @todo        Why are these parameters conflicting?
 ./application/hub/main/database/wrapper/class_NodeInformationDatabaseWrapper.php:2:// @DEPRECATED
 ./application/hub/main/database/wrapper/class_NodeListDatabaseWrapper.php:2:// @DEPRECATED
 ./application/hub/main/database/wrapper/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED
-./application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php:2:// @DEPRECATED
+./application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php:2:// @DEPRECATED
 ./application/hub/main/factories/states/class_StateFactory.php:2:// @DEPRECATED
 ./application/hub/main/filter/activation/class_HubActivationSelfAnnouncementFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/bootstrap/class_HubBootstrapAquireHubIdFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/shutdown/class_HubShutdownListenerPoolFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/shutdown/class_HubShutdownNodeFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/shutdown/class_HubShutdownTaskHandlerFilter.php:2:// @DEPRECATED
+./application/hub/main/filter/shutdown/cruncher/class_CruncherShutdownCruncherFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/task/class_CruncherTaskHandlerInitializerFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/task/class_HubTaskHandlerInitializerFilter.php:2:// @DEPRECATED
 ./application/hub/main/filter/task/class_TaskHandlerInitializerFilter.php:2:// @DEPRECATED
 ./application/hub/main/iterator/producer/class_TestUnitKeyProducerIterator.php:2:// @DEPRECATED
 ./application/hub/main/listener/tcp/decorators/class_PeerTcpListenerDecorator.php:2:// @DEPRECATED
 ./application/hub/main/listener/udp/decorators/class_PeerUdpListenerDecorator.php:2:// @DEPRECATED
+./application/hub/main/lookup/class_BaseLookupTable.php:2:// @DEPRECATED
+./application/hub/main/lookup/peer/class_NodeStateLookupTable.php:2:// @DEPRECATED
 ./application/hub/main/lookup/peer/class_PeerStateLookupTable.php:2:// @DEPRECATED
 ./application/hub/main/nodes/class_BaseHubNode.php:53:  * @deprecated
+./application/hub/main/resolver/state/network/class_NetworkStateResolver.php:2:// @DEPRECATED
+./application/hub/main/states/peer/new/class_NewConnectionNodeState.php:2:// @DEPRECATED
 ./application/hub/main/states/peer/new/class_NewConnectionPeerState.php:2:// @DEPRECATED
 ./application/hub/main/streams/package/input/class_PackageInputStream.php:2:// @DEPRECATED
 ./application/hub/main/streams/package/output/class_PackageOutputStream.php:2:// @DEPRECATED
index 3950334e917c67e0b9c65eaa558bae402cfd9677..c0af3b26dc44f8d2d09ddce97b5ac927124c79c2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -88,7 +88,7 @@ final class ApplicationEntryPoint {
                $languageInstance = LanguageSystem::getInstance();
 
                // Initialize template instance here to avoid warnings in IDE
-               $templateInstance = null;
+               $templateInstance = NULL;
 
                // Get response instance
                $responseInstance = ApplicationHelper::getInstance()->getResponseInstance();
@@ -130,7 +130,7 @@ final class ApplicationEntryPoint {
                        } // END - foreach
 
                        // Init application instance
-                       $applicationInstance = null;
+                       $applicationInstance = NULL;
 
                        // Is the class there?
                        if (class_exists('ApplicationHelper')) {