From 81c90916f7a908c77f8844dff5adc6fae3aed422 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 31 Aug 2011 20:15:13 +0000 Subject: [PATCH] Hub project continued: - 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 --- .gitattributes | 17 ++ .gitignore | 2 + application/hub/class_ApplicationHelper.php | 20 +- application/hub/config.php | 38 +++- application/hub/exceptions.php | 2 +- .../class_PeerAlreadyRegisteredException.php | 2 +- .../state/class_InvalidStateException.php | 2 +- .../connections/class_ConnectionHelper.php | 8 +- .../helper/messages/class_MessageHelper.php | 1 + .../interfaces/lookup/node_states/.htaccess | 1 + .../node_states/class_LookupableNodeState.php | 28 +++ .../peer_states/class_LookupablePeerState.php | 2 +- .../interfaces/package/class_Deliverable.php | 4 +- .../package/fragmenter/class_Fragmentable.php | 8 +- application/hub/main/class_BaseHubSystem.php | 16 +- .../query/local/class_LocalQueryConnector.php | 2 +- .../hub/main/controller/http/.htaccess | 1 + .../main/cruncher/class_BaseHubCruncher.php | 2 +- .../node/class_NodeListDatabaseWrapper.php | 5 +- .../class_NodeStateLookupDatabaseWrapper.php | 171 +--------------- .../class_PeerStateLookupDatabaseWrapper.php | 190 +++++++++++++++++- .../class_PackageRecipientDiscovery.php | 2 +- .../socket/class_PackageSocketDiscovery.php | 29 ++- .../factories/socket/class_SocketFactory.php | 26 ++- .../states/node/class_NodeStateFactory.php | 3 + .../states/peer/class_PeerStateFactory.php | 74 +++++-- .../network/class_BaseRawDataHandler.php | 4 +- .../main/handler/tasks/class_TaskHandler.php | 3 +- .../connection/class_BaseConnectionHelper.php | 171 ++++++++-------- .../tcp/class_TcpConnectionHelper.php | 25 ++- .../iterator/hub/class_HubPingIterator.php | 4 +- .../network/class_NetworkListenIterator.php | 2 +- .../iterator/pool/class_DefaultIterator.php | 2 +- .../handler/class_HandlerPoolIterator.php | 2 +- .../monitor/class_MonitorPoolIterator.php | 2 +- .../shutdown/class_ShutdownPoolIterator.php | 2 +- .../pool/tasks/class_TaskPoolIterator.php | 2 +- .../hub/main/listener/class_BaseListener.php | 3 +- application/hub/main/lookup/class_ | 49 +---- .../hub/main/lookup/class_BaseLookupTable.php | 37 +--- .../peer/class_NodeStateLookupTable.php | 103 +--------- .../hub/main/nodes/class_BaseHubNode.php | 10 +- .../hub/main/package/class_NetworkPackage.php | 49 +++-- .../fragmenter/class_PackageFragmenter.php | 16 +- application/hub/main/pools/class_BasePool.php | 2 +- .../main/pools/peer/class_DefaultPeerPool.php | 1 + .../hub/main/producer/class_BaseProducer.php | 4 +- .../objects/class_ObjectTypeRegistry.php | 2 +- .../registry/socket/class_SocketRegistry.php | 7 +- .../class_HubConsoleCommandResolver.php | 6 +- .../class_HubConsoleControllerResolver.php | 2 +- .../main/resolver/controller/http/.htaccess | 1 + .../state/class_BaseStateResolver.php | 6 +- .../network/class_NetworkStateResolver.php | 98 +-------- .../hub/main/resolver/state/peer/.htaccess | 1 + .../state/peer/class_PeerStateResolver.php | 104 ++++++++++ .../cruncher/init/class_CruncherInitState.php | 3 - .../virgin/class_CruncherVirginState.php | 3 - .../node/active/class_NodeActiveState.php | 3 - .../announced/class_NodeAnnouncedState.php | 3 - .../states/node/init/class_NodeInitState.php | 3 - .../node/virgin/class_NodeVirginState.php | 3 - application/hub/main/states/peer/class_ | 3 + .../main/states/peer/class_BasePeerState.php | 25 +++ .../hub/main/states/peer/connected/.htaccess | 1 + .../connected/class_ConnectedPeerState.php | 53 +++++ .../hub/main/states/peer/errors/.htaccess | 1 + .../class_ConnectionRefusedPeerState.php | 53 +++++ .../hub/main/states/peer/init/.htaccess | 1 + .../states/peer/init/class_InitPeerState.php | 53 +++++ .../peer/new/class_NewConnectionNodeState.php | 49 +---- .../states/peer/transport_endpoint/.htaccess | 1 + .../class_TransportEndpointGonePeerState.php | 53 +++++ application/hub/main/statistics/.htaccess | 1 + .../hub/main/statistics/connection/.htaccess | 1 + .../class_ConnectionStatisticsHelper.php | 102 ++++++++++ .../class_XmlObjectRegistryTemplateEngine.php | 2 +- application/hub/main/tools/class_HubTools.php | 4 +- .../socket/class_ShutdownSocketVisitor.php | 8 +- db/node_states/.htaccess | 1 + docs/NEWS | 2 +- docs/README | 2 +- docs/TODOs.txt | 64 +++--- index.php | 4 +- 84 files changed, 1102 insertions(+), 776 deletions(-) create mode 100644 application/hub/interfaces/lookup/node_states/.htaccess create mode 100644 application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php create mode 100644 application/hub/main/controller/http/.htaccess create mode 100644 application/hub/main/resolver/controller/http/.htaccess create mode 100644 application/hub/main/resolver/state/peer/.htaccess create mode 100644 application/hub/main/resolver/state/peer/class_PeerStateResolver.php create mode 100644 application/hub/main/states/peer/connected/.htaccess create mode 100644 application/hub/main/states/peer/connected/class_ConnectedPeerState.php create mode 100644 application/hub/main/states/peer/errors/.htaccess create mode 100644 application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php create mode 100644 application/hub/main/states/peer/init/.htaccess create mode 100644 application/hub/main/states/peer/init/class_InitPeerState.php create mode 100644 application/hub/main/states/peer/transport_endpoint/.htaccess create mode 100644 application/hub/main/states/peer/transport_endpoint/class_TransportEndpointGonePeerState.php create mode 100644 application/hub/main/statistics/.htaccess create mode 100644 application/hub/main/statistics/connection/.htaccess create mode 100644 application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php create mode 100644 db/node_states/.htaccess diff --git a/.gitattributes b/.gitattributes index dc18b2b64..6c28d77d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore index 69cb1981e..0b7f63a19 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/application/hub/class_ApplicationHelper.php b/application/hub/class_ApplicationHelper.php index 324128131..dafd73e55 100644 --- a/application/hub/class_ApplicationHelper.php +++ b/application/hub/class_ApplicationHelper.php @@ -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 diff --git a/application/hub/config.php b/application/hub/config.php index 1a32e2c97..fa0a3ed2d 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -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] ?> diff --git a/application/hub/exceptions.php b/application/hub/exceptions.php index fa54a9a20..f219040e6 100644 --- a/application/hub/exceptions.php +++ b/application/hub/exceptions.php @@ -21,7 +21,7 @@ * along with this program. If not, see . */ -// 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)) { diff --git a/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php b/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php index c33c9db2c..d2501012b 100644 --- a/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php +++ b/application/hub/exceptions/peer/class_PeerAlreadyRegisteredException.php @@ -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 diff --git a/application/hub/exceptions/state/class_InvalidStateException.php b/application/hub/exceptions/state/class_InvalidStateException.php index b89d74f6c..6d3e1be2b 100644 --- a/application/hub/exceptions/state/class_InvalidStateException.php +++ b/application/hub/exceptions/state/class_InvalidStateException.php @@ -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() ); diff --git a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php index 947899c80..6447bdb25 100644 --- a/application/hub/interfaces/helper/connections/class_ConnectionHelper.php +++ b/application/hub/interfaces/helper/connections/class_ConnectionHelper.php @@ -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 * diff --git a/application/hub/interfaces/helper/messages/class_MessageHelper.php b/application/hub/interfaces/helper/messages/class_MessageHelper.php index 2f2364b4c..212a927a0 100644 --- a/application/hub/interfaces/helper/messages/class_MessageHelper.php +++ b/application/hub/interfaces/helper/messages/class_MessageHelper.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/interfaces/lookup/node_states/.htaccess @@ -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 index 000000000..62d63e663 --- /dev/null +++ b/application/hub/interfaces/lookup/node_states/class_LookupableNodeState.php @@ -0,0 +1,28 @@ + + * @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 . + */ +interface LookupableNodeState extends Lookupable { +} + +// [EOF] +?> diff --git a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php index aadff2e53..e530c1c76 100644 --- a/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php +++ b/application/hub/interfaces/lookup/peer_states/class_LookupablePeerState.php @@ -1,6 +1,6 @@ * @version 0.0.0 diff --git a/application/hub/interfaces/package/class_Deliverable.php b/application/hub/interfaces/package/class_Deliverable.php index 48ea7beb7..2c6803843 100644 --- a/application/hub/interfaces/package/class_Deliverable.php +++ b/application/hub/interfaces/package/class_Deliverable.php @@ -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. diff --git a/application/hub/interfaces/package/fragmenter/class_Fragmentable.php b/application/hub/interfaces/package/fragmenter/class_Fragmentable.php index 5a3ebe80d..d91767c0a 100644 --- a/application/hub/interfaces/package/fragmenter/class_Fragmentable.php +++ b/application/hub/interfaces/package/fragmenter/class_Fragmentable.php @@ -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 diff --git a/application/hub/main/class_BaseHubSystem.php b/application/hub/main/class_BaseHubSystem.php index 824353d67..14ec46a9d 100644 --- a/application/hub/main/class_BaseHubSystem.php +++ b/application/hub/main/class_BaseHubSystem.php @@ -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); diff --git a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php index 94a5c9ac1..e2ff58944 100644 --- a/application/hub/main/connectors/query/local/class_LocalQueryConnector.php +++ b/application/hub/main/connectors/query/local/class_LocalQueryConnector.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/controller/http/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/cruncher/class_BaseHubCruncher.php b/application/hub/main/cruncher/class_BaseHubCruncher.php index 39471d34d..d45ca1632 100644 --- a/application/hub/main/cruncher/class_BaseHubCruncher.php +++ b/application/hub/main/cruncher/class_BaseHubCruncher.php @@ -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 diff --git a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php index 262ced5de..e008420d2 100644 --- a/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeListDatabaseWrapper.php @@ -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'); diff --git a/application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php index 1e4b174ce..f551ef47b 100644 --- a/application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_NodeStateLookupDatabaseWrapper.php @@ -1,172 +1,3 @@ - * @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 . - */ -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 ?> diff --git a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php index f551ef47b..450609e1e 100644 --- a/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/states/class_PeerStateLookupDatabaseWrapper.php @@ -1,3 +1,191 @@ + * @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 . + */ +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] ?> diff --git a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php index 5e504daa0..d7a5c0e4c 100644 --- a/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php +++ b/application/hub/main/discovery/package/class_PackageRecipientDiscovery.php @@ -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; diff --git a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php index 790b5ed50..024e45a5a 100644 --- a/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php +++ b/application/hub/main/discovery/socket/class_PackageSocketDiscovery.php @@ -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; } diff --git a/application/hub/main/factories/socket/class_SocketFactory.php b/application/hub/main/factories/socket/class_SocketFactory.php index 604478206..53b748b82 100644 --- a/application/hub/main/factories/socket/class_SocketFactory.php +++ b/application/hub/main/factories/socket/class_SocketFactory.php @@ -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; diff --git a/application/hub/main/factories/states/node/class_NodeStateFactory.php b/application/hub/main/factories/states/node/class_NodeStateFactory.php index d1e8f42c8..db351b678 100644 --- a/application/hub/main/factories/states/node/class_NodeStateFactory.php +++ b/application/hub/main/factories/states/node/class_NodeStateFactory.php @@ -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); diff --git a/application/hub/main/factories/states/peer/class_PeerStateFactory.php b/application/hub/main/factories/states/peer/class_PeerStateFactory.php index 5cbcc9a2e..34951fc65 100644 --- a/application/hub/main/factories/states/peer/class_PeerStateFactory.php +++ b/application/hub/main/factories/states/peer/class_PeerStateFactory.php @@ -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; } } diff --git a/application/hub/main/handler/network/class_BaseRawDataHandler.php b/application/hub/main/handler/network/class_BaseRawDataHandler.php index ef5790823..8bea9a8ed 100644 --- a/application/hub/main/handler/network/class_BaseRawDataHandler.php +++ b/application/hub/main/handler/network/class_BaseRawDataHandler.php @@ -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; diff --git a/application/hub/main/handler/tasks/class_TaskHandler.php b/application/hub/main/handler/tasks/class_TaskHandler.php index 02fd4b7c5..b9502d91e 100644 --- a/application/hub/main/handler/tasks/class_TaskHandler.php +++ b/application/hub/main/handler/tasks/class_TaskHandler.php @@ -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.'); diff --git a/application/hub/main/helper/connection/class_BaseConnectionHelper.php b/application/hub/main/helper/connection/class_BaseConnectionHelper.php index f6c4debed..5a2d92443 100644 --- a/application/hub/main/helper/connection/class_BaseConnectionHelper.php +++ b/application/hub/main/helper/connection/class_BaseConnectionHelper.php @@ -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; } } diff --git a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php index 02e9707fd..5f41295c8 100644 --- a/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php +++ b/application/hub/main/helper/connection/tcp/class_TcpConnectionHelper.php @@ -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(); } } diff --git a/application/hub/main/iterator/hub/class_HubPingIterator.php b/application/hub/main/iterator/hub/class_HubPingIterator.php index 206bf5f82..ea605265e 100644 --- a/application/hub/main/iterator/hub/class_HubPingIterator.php +++ b/application/hub/main/iterator/hub/class_HubPingIterator.php @@ -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.'); diff --git a/application/hub/main/iterator/network/class_NetworkListenIterator.php b/application/hub/main/iterator/network/class_NetworkListenIterator.php index e451c0a80..00e031a66 100644 --- a/application/hub/main/iterator/network/class_NetworkListenIterator.php +++ b/application/hub/main/iterator/network/class_NetworkListenIterator.php @@ -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()) { diff --git a/application/hub/main/iterator/pool/class_DefaultIterator.php b/application/hub/main/iterator/pool/class_DefaultIterator.php index 1551b0a75..527448837 100644 --- a/application/hub/main/iterator/pool/class_DefaultIterator.php +++ b/application/hub/main/iterator/pool/class_DefaultIterator.php @@ -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()) { diff --git a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php index f64651024..0f27de509 100644 --- a/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php +++ b/application/hub/main/iterator/pool/handler/class_HandlerPoolIterator.php @@ -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()) { diff --git a/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php b/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php index 72a2c2d86..c58ba6247 100644 --- a/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php +++ b/application/hub/main/iterator/pool/monitor/class_MonitorPoolIterator.php @@ -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()) { diff --git a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php index e1081bb1a..7001854bf 100644 --- a/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php +++ b/application/hub/main/iterator/pool/shutdown/class_ShutdownPoolIterator.php @@ -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()) { diff --git a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php index f82dbf3ea..60ea2d0e2 100644 --- a/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php +++ b/application/hub/main/iterator/pool/tasks/class_TaskPoolIterator.php @@ -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()) { diff --git a/application/hub/main/listener/class_BaseListener.php b/application/hub/main/listener/class_BaseListener.php index b81ffd202..c367b30d4 100644 --- a/application/hub/main/listener/class_BaseListener.php +++ b/application/hub/main/listener/class_BaseListener.php @@ -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 diff --git a/application/hub/main/lookup/class_ b/application/hub/main/lookup/class_ index 3646b7f85..f551ef47b 100644 --- a/application/hub/main/lookup/class_ +++ b/application/hub/main/lookup/class_ @@ -1,50 +1,3 @@ - * @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 . - */ -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 ?> diff --git a/application/hub/main/lookup/class_BaseLookupTable.php b/application/hub/main/lookup/class_BaseLookupTable.php index fe32094f7..f551ef47b 100644 --- a/application/hub/main/lookup/class_BaseLookupTable.php +++ b/application/hub/main/lookup/class_BaseLookupTable.php @@ -1,38 +1,3 @@ - * @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 . - */ -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 ?> diff --git a/application/hub/main/lookup/peer/class_NodeStateLookupTable.php b/application/hub/main/lookup/peer/class_NodeStateLookupTable.php index 89ff71284..f551ef47b 100644 --- a/application/hub/main/lookup/peer/class_NodeStateLookupTable.php +++ b/application/hub/main/lookup/peer/class_NodeStateLookupTable.php @@ -1,104 +1,3 @@ - * @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 . - */ -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 ?> diff --git a/application/hub/main/nodes/class_BaseHubNode.php b/application/hub/main/nodes/class_BaseHubNode.php index fbe8f50df..5bfc26f7d 100644 --- a/application/hub/main/nodes/class_BaseHubNode.php +++ b/application/hub/main/nodes/class_BaseHubNode.php @@ -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); } diff --git a/application/hub/main/package/class_NetworkPackage.php b/application/hub/main/package/class_NetworkPackage.php index 576aae790..4cfe47c87 100644 --- a/application/hub/main/package/class_NetworkPackage.php +++ b/application/hub/main/package/class_NetworkPackage.php @@ -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()); + } } /** diff --git a/application/hub/main/package/fragmenter/class_PackageFragmenter.php b/application/hub/main/package/fragmenter/class_PackageFragmenter.php index 2fb1f3b65..453c0b148 100644 --- a/application/hub/main/package/fragmenter/class_PackageFragmenter.php +++ b/application/hub/main/package/fragmenter/class_PackageFragmenter.php @@ -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; diff --git a/application/hub/main/pools/class_BasePool.php b/application/hub/main/pools/class_BasePool.php index 2e6c5c895..0e58c98ba 100644 --- a/application/hub/main/pools/class_BasePool.php +++ b/application/hub/main/pools/class_BasePool.php @@ -25,7 +25,7 @@ class BasePool extends BaseHubSystem implements Visitable { /** * A list of pool entries */ - private $poolEntriesInstance = null; + private $poolEntriesInstance = NULL; /** * Protected constructor diff --git a/application/hub/main/pools/peer/class_DefaultPeerPool.php b/application/hub/main/pools/peer/class_DefaultPeerPool.php index 11c91f508..42ca9668e 100644 --- a/application/hub/main/pools/peer/class_DefaultPeerPool.php +++ b/application/hub/main/pools/peer/class_DefaultPeerPool.php @@ -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? diff --git a/application/hub/main/producer/class_BaseProducer.php b/application/hub/main/producer/class_BaseProducer.php index 5ef91a4df..e69b83f7f 100644 --- a/application/hub/main/producer/class_BaseProducer.php +++ b/application/hub/main/producer/class_BaseProducer.php @@ -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 diff --git a/application/hub/main/registry/objects/class_ObjectTypeRegistry.php b/application/hub/main/registry/objects/class_ObjectTypeRegistry.php index 8e75ea519..1cadcc63f 100644 --- a/application/hub/main/registry/objects/class_ObjectTypeRegistry.php +++ b/application/hub/main/registry/objects/class_ObjectTypeRegistry.php @@ -25,7 +25,7 @@ class ObjectTypeRegistry extends BaseRegistry implements Register { /** * Instance of this class */ - private static $registryInstance = null; + private static $registryInstance = NULL; /** * Protected constructor diff --git a/application/hub/main/registry/socket/class_SocketRegistry.php b/application/hub/main/registry/socket/class_SocketRegistry.php index 809473673..a8aa3330f 100644 --- a/application/hub/main/registry/socket/class_SocketRegistry.php +++ b/application/hub/main/registry/socket/class_SocketRegistry.php @@ -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 diff --git a/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php b/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php index d5aba0fae..898897a36 100644 --- a/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php +++ b/application/hub/main/resolver/command/console/class_HubConsoleCommandResolver.php @@ -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'; diff --git a/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php b/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php index 0eaadb707..bc649c614 100644 --- a/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php +++ b/application/hub/main/resolver/controller/console/class_HubConsoleControllerResolver.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/controller/http/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/main/resolver/state/class_BaseStateResolver.php b/application/hub/main/resolver/state/class_BaseStateResolver.php index 98736b3d4..ac05a5556 100644 --- a/application/hub/main/resolver/state/class_BaseStateResolver.php +++ b/application/hub/main/resolver/state/class_BaseStateResolver.php @@ -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); diff --git a/application/hub/main/resolver/state/network/class_NetworkStateResolver.php b/application/hub/main/resolver/state/network/class_NetworkStateResolver.php index 9b592b6f8..f551ef47b 100644 --- a/application/hub/main/resolver/state/network/class_NetworkStateResolver.php +++ b/application/hub/main/resolver/state/network/class_NetworkStateResolver.php @@ -1,99 +1,3 @@ - * @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 . - */ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/resolver/state/peer/.htaccess @@ -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 index 000000000..077a5bcf2 --- /dev/null +++ b/application/hub/main/resolver/state/peer/class_PeerStateResolver.php @@ -0,0 +1,104 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/states/cruncher/init/class_CruncherInitState.php b/application/hub/main/states/cruncher/init/class_CruncherInitState.php index 1caf37c58..749ae73f6 100644 --- a/application/hub/main/states/cruncher/init/class_CruncherInitState.php +++ b/application/hub/main/states/cruncher/init/class_CruncherInitState.php @@ -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); diff --git a/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php b/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php index 6f567f4af..ebc948901 100644 --- a/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php +++ b/application/hub/main/states/cruncher/virgin/class_CruncherVirginState.php @@ -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); diff --git a/application/hub/main/states/node/active/class_NodeActiveState.php b/application/hub/main/states/node/active/class_NodeActiveState.php index 9822dfaa8..86fd1b889 100644 --- a/application/hub/main/states/node/active/class_NodeActiveState.php +++ b/application/hub/main/states/node/active/class_NodeActiveState.php @@ -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(); diff --git a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php index 30b080f92..001d7258f 100644 --- a/application/hub/main/states/node/announced/class_NodeAnnouncedState.php +++ b/application/hub/main/states/node/announced/class_NodeAnnouncedState.php @@ -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); diff --git a/application/hub/main/states/node/init/class_NodeInitState.php b/application/hub/main/states/node/init/class_NodeInitState.php index 473204dce..d46ee8eb3 100644 --- a/application/hub/main/states/node/init/class_NodeInitState.php +++ b/application/hub/main/states/node/init/class_NodeInitState.php @@ -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); diff --git a/application/hub/main/states/node/virgin/class_NodeVirginState.php b/application/hub/main/states/node/virgin/class_NodeVirginState.php index 61e239555..bf37f5341 100644 --- a/application/hub/main/states/node/virgin/class_NodeVirginState.php +++ b/application/hub/main/states/node/virgin/class_NodeVirginState.php @@ -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); diff --git a/application/hub/main/states/peer/class_ b/application/hub/main/states/peer/class_ index edb7029d7..83be3f3e3 100644 --- a/application/hub/main/states/peer/class_ +++ b/application/hub/main/states/peer/class_ @@ -30,6 +30,9 @@ class ???PeerState extends BasePeerState implements PeerStateable { protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); + + // Set state name + $this->setStateName('!!!'); } /** diff --git a/application/hub/main/states/peer/class_BasePeerState.php b/application/hub/main/states/peer/class_BasePeerState.php index 7b6b3814d..b5d9bc401 100644 --- a/application/hub/main/states/peer/class_BasePeerState.php +++ b/application/hub/main/states/peer/class_BasePeerState.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/peer/connected/.htaccess @@ -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 index 000000000..62479e41f --- /dev/null +++ b/application/hub/main/states/peer/connected/class_ConnectedPeerState.php @@ -0,0 +1,53 @@ + + * @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 . + */ +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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/peer/errors/.htaccess @@ -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 index 000000000..60ad54cfe --- /dev/null +++ b/application/hub/main/states/peer/errors/class_ConnectionRefusedPeerState.php @@ -0,0 +1,53 @@ + + * @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 . + */ +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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/peer/init/.htaccess @@ -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 index 000000000..b06940dc7 --- /dev/null +++ b/application/hub/main/states/peer/init/class_InitPeerState.php @@ -0,0 +1,53 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/states/peer/new/class_NewConnectionNodeState.php b/application/hub/main/states/peer/new/class_NewConnectionNodeState.php index b6270bff5..f551ef47b 100644 --- a/application/hub/main/states/peer/new/class_NewConnectionNodeState.php +++ b/application/hub/main/states/peer/new/class_NewConnectionNodeState.php @@ -1,50 +1,3 @@ - * @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 . - */ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/states/peer/transport_endpoint/.htaccess @@ -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 index 000000000..ee17be818 --- /dev/null +++ b/application/hub/main/states/peer/transport_endpoint/class_TransportEndpointGonePeerState.php @@ -0,0 +1,53 @@ + + * @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 . + */ +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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/statistics/.htaccess @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/main/statistics/connection/.htaccess @@ -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 index 000000000..42fd5c1da --- /dev/null +++ b/application/hub/main/statistics/connection/class_ConnectionStatisticsHelper.php @@ -0,0 +1,102 @@ + + * @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 . + */ +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] +?> diff --git a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php index c6afa7cc8..0c65ed65f 100644 --- a/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php +++ b/application/hub/main/template/objects/class_XmlObjectRegistryTemplateEngine.php @@ -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 diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 60fd33ca7..4d8227f2f 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -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); diff --git a/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php b/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php index 04d9d85e5..69354167f 100644 --- a/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php +++ b/application/hub/main/visitor/socket/class_ShutdownSocketVisitor.php @@ -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 index 000000000..3a4288278 --- /dev/null +++ b/db/node_states/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/docs/NEWS b/docs/NEWS index 7339625fe..72dabad3b 100644 --- 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 diff --git a/docs/README b/docs/README index ec1451369..2a3b921a9 100644 --- a/docs/README +++ b/docs/README @@ -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: diff --git a/docs/TODOs.txt b/docs/TODOs.txt index 0c067a866..34b9ca903 100644 --- a/docs/TODOs.txt +++ b/docs/TODOs.txt @@ -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? @@ -14,14 +19,19 @@ ./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 @@ -29,14 +39,15 @@ ./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 @@ -74,23 +85,24 @@ ./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 @@ -141,7 +153,7 @@ ./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! @@ -174,8 +186,7 @@ ./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? @@ -226,7 +237,7 @@ ./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 @@ -244,6 +255,7 @@ ./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 @@ -254,8 +266,12 @@ ./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 diff --git a/index.php b/index.php index 3950334e9..c0af3b26d 100644 --- 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')) { -- 2.39.5