application/hub/interfaces/listener/class_Listenable.php -text
application/hub/interfaces/lists/.htaccess -text
application/hub/interfaces/lists/class_Listable.php -text
+application/hub/interfaces/lookup/.htaccess -text
application/hub/interfaces/nodes/.htaccess -text
application/hub/interfaces/nodes/class_NodeHelper.php -text
application/hub/interfaces/package/.htaccess -text
application/hub/interfaces/states/hub/class_HubStateable.php -text
application/hub/interfaces/states/node/.htaccess -text
application/hub/interfaces/states/node/class_NodeStateable.php -text
+application/hub/interfaces/states/peer/.htaccess -text
application/hub/interfaces/tags/.htaccess -text
application/hub/interfaces/tasks/.htaccess -text
application/hub/interfaces/tasks/class_Taskable.php -text
application/hub/main/factories/package/.htaccess -text
application/hub/main/factories/states/.htaccess -text
application/hub/main/factories/states/class_StateFactory.php -text
+application/hub/main/factories/states/peer/.htaccess -text
application/hub/main/factories/tags/.htaccess -text
application/hub/main/filter/.htaccess -text
application/hub/main/filter/activation/.htaccess -text
application/hub/main/lists/recipient/.htaccess -text
application/hub/main/lists/tasks/.htaccess -text
application/hub/main/lists/tasks/class_TaskList.php -text
+application/hub/main/lookup/.htaccess -text
+application/hub/main/lookup/class_ -text
+application/hub/main/lookup/peer/.htaccess -text
application/hub/main/nodes/.htaccess -text
application/hub/main/nodes/boot/.htaccess -text
application/hub/main/nodes/boot/class_HubBootNode.php -text
application/hub/main/states/node/virgin/.htaccess -text
application/hub/main/states/node/virgin/class_NodeVirginState.php -text
application/hub/main/states/peer/.htaccess -text
+application/hub/main/states/peer/class_ -text
application/hub/main/states/peer/class_BasePeerState.php -text
+application/hub/main/states/peer/new/.htaccess -text
application/hub/main/tags/.htaccess -text
application/hub/main/tags/class_ -text
application/hub/main/tags/package/.htaccess -text
db/news/.htaccess -text
db/node_data/.htaccess -text
db/node_list/.htaccess -text
+db/peer_states/.htaccess -text
docs/COPYING -text
docs/COPYING.documents -text
docs/COPYING.software -text
// CFG: NODE-LIST-DB-WRAPPER-CLASS
$cfg->setConfigEntry('node_list_db_wrapper_class', 'NodeListDatabaseWrapper');
+// CFG: PEER-LOOKUP-DB-WRAPPER-CLASS
+$cfg->setConfigEntry('peer_lookup_db_wrapper_class', 'PeerLookupDatabaseWrapper');
+
// CFG: WEB-CONTENT-TYPE
$cfg->setConfigEntry('web_content_type', '');
// CFG: UDP-CONNECT-RETRY-MAX
$cfg->setConfigEntry('udp_connect_retry_max', 10);
+// CFG: PEER-STATE-LOOKUP-TABLE-CLASS
+$cfg->setConfigEntry('peer_state_lookup_table_class', 'PeerStateLookupTable');
+
+// CFG: PEER-STATE-CHECKED-PACKAGE-CLASS
+$cfg->setConfigEntry('peer_state_checked_package_class', 'NewConnectionPeerState');
+
// [EOF]
?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for lookup tables
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Lookupable extends FrameworkInterface {
+}
+
+// [EOF]
+?>
+<?php
+/**
+ * An interface for ??? states
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface ???Stateable extends Stateable {
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * An interface for Peer states
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface PeerStateable extends Stateable {
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A database wrapper for peer state lookups
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper {
+ // Constants for database table names
+ const DB_TABLE_PEER_LOOKUP = 'peer_states';
+
+ // Constants for database column names
+ const DB_COLUMN_PEER_IP = 'peer_ip';
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this database wrapper by a provided user class
+ *
+ * @return $wrapperInstance An instance of the created wrapper class
+ */
+ public final static function createPeerLookupDatabaseWrapper () {
+ // Get a new instance
+ $wrapperInstance = new PeerLookupDatabaseWrapper();
+
+ // Set (primary!) table name
+ $wrapperInstance->setTableName(self::DB_TABLE_PEER_LOOKUP);
+
+ // Return the instance
+ return $wrapperInstance;
+ }
+
+ /**
+ * Getter for index key
+ *
+ * @return $indexKey Index key
+ */
+ public final function getIndexKey () {
+ return $this->getDatabaseInstance()->getIndexKey();
+ }
+
+ /**
+ * Checks wether given 'sender' is a new peer
+ *
+ * @param $packageData Raw package data
+ * @return $isNewPeer Wether 'sender' is a new peer to this node
+ */
+ public function isSenderNewPeer (array $packageData) {
+ // Get a search criteria instance
+ $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class');
+
+ // Add 'sender' as the peer's IP (this must already be looked up!)
+ $searchInstance->addCriteria(self::DB_COLUMN_PEER_IP, $packageData['sender']);
+ $searchInstance->setLimit(1);
+
+ // Count the query
+ $entries = $this->doSelectCountByCriteria($searchInstance);
+
+ // Is it there?
+ $isNewPeer = ($entries === 0);
+
+ // Return the result
+ return $isNewPeer;
+ }
+}
+
+// [EOF]
+?>
* @param $nodeInstance A NodeHelper class instance
* @return $stateInstance A Stateable class instance
*/
- public static final function createStateInstanceByName($stateName, NodeHelper $nodeInstance) {
+ public static final function createStateInstanceByName ($stateName, NodeHelper $nodeInstance) {
// Then construct the class' configuraton entry
$className = 'node_' . $stateName . '_state_class';
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A factory class for peer states
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PeerStateFactory extends ObjectFactory {
+ /**
+ * Static lookup table instance
+ */
+ private static $tableInstance = null;
+
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates a peer state instance based on errorCode if no entry is found in the lookup table
+ * for the peer given in $packageData 'sender' element or it changes the state if it differs
+ * from current state.
+ *
+ * @param $errorCode The last error code
+ * @param $packageData Raw package data
+ * @return $stateInstance A Stateable class instance
+ */
+ public static final function createPeerStateInstanceByErrorCode ($errorCode, array $packageData) {
+ // So first we need our lookup table
+ $tableInstance = self::getTableInstance();
+
+ // Do we have an entry?
+ if ($tableInstance->isSenderNewPeer($packageData)) {
+ // Is a new peer so create the state instance based on error code, first we need a config entry
+ $configEntry = 'peer_state_' . $errorCode . '_class';
+
+ // Then get it
+ $stateInstance = ObjectFactory::createObjectByConfiguredName($configEntry);
+
+ // And register it with the lookup table
+ $tableInstance->registerPeerState($stateInstance, $packageData);
+ } else {
+ // It is a known peer, so we need to check if the state has changed
+ die(__METHOD__ . ': Lookup!' . "\n");
+ }
+
+ // For any purposes, return the state instance
+ die(__METHOD__."\n");
+ return $stateInstance;
+ }
+
+ /**
+ * Singleton getter for lookup table instances, kept public if we need this
+ * table somewhere else.
+ *
+ * @return $tableInstance An instance of a lookup table
+ */
+ public final static function getTableInstance () {
+ // Is the instance null?
+ if (is_null(self::$tableInstance)) {
+ // Get a new one
+ self::$tableInstance = ObjectFactory::createObjectByConfiguredName('peer_state_lookup_table_class');
+ } // END - if
+
+ // Return it
+ return self::$tableInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A ??? lookup table class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class ???LookupTable extends BaseLookupTable implements Lookupable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $tableInstance An instance of a Lookupable class
+ */
+ public final static function create???LookupTable () {
+ // Get new instance
+ $tableInstance = new ???LookupTable();
+
+ // Return the prepared instance
+ return $tableInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general LookupTable class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class BaseLookupTable extends BaseHubSystem {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A Peer lookup table class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class PeerStateLookupTable extends BaseLookupTable implements Lookupable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $tableInstance An instance of a Lookupable class
+ */
+ public final static function createPeerLookupTable () {
+ // Get new instance
+ $tableInstance = new PeerLookupTable();
+
+ // Get a database wrapper instance
+ $wrapperInstance = ObjectFactory::createObjectByConfiguredName('peer_state_lookup_db_wrapper_class');
+
+ // Set it for later re-use
+ $tableInstance->setWrapperInstance($wrapperInstance);
+
+ // Return the prepared instance
+ return $tableInstance;
+ }
+}
+
+// [EOF]
+?>
$errorCode = BaseNetworkPackageHandler::SOCKET_ERROR_UNKNOWN;
} // END - if
- // @TODO We need to somehow detect the state/status of the remote peer and still maintain good speed.
- // @TODO So maybe some pre-instancing of classes might help here to speedup this I/O intensive process.
- $this->partialStub('errorCode=' . $errorCode . ',packageData[] = ' . gettype($packageData) . '(' . count($packageData) . ')');
+ // Create a state instance based on $errorCode. This factory does the hard work for us
+ $stateInstance = PeerStateFactory::createPeerStateInstanceByErrorCode($errorCode, $packageData);
// Return the prepared instance
return $stateInstance;
--- /dev/null
+<?php
+/**
+ * A ??? peer state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class ???PeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function create???PeerState () {
+ // Get new instance
+ $stateInstance = new ???PeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+/**
+ * A NewConnection peer state class
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+class NewConnectionPeerState extends BasePeerState implements PeerStateable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $stateInstance An instance of a PeerStateable class
+ */
+ public final static function createNewConnectionPeerState () {
+ // Get new instance
+ $stateInstance = new NewConnectionPeerState();
+
+ // Return the prepared instance
+ return $stateInstance;
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all