- method renamed to getConnectionClassNameFromSocket() which now only accepts a StorableSocket class
- resolveStateByPackage() now accepts StorableSocket instead of socket resource
- also extend HubInterface
- introduced BaseHubHandler to implement HubInterface (or what is missing + protected setter/getter)
- introduced BaseHubDatabaseWrapper to implement HubInterface
- more debug messages
- other stuff improved
- imported (Base|Peer)StateResolver
- imported StorableSocket
- imported (Lookupable)PeerState
- imported PeerStateable
- created new namespaces
- moved classes around
Signed-off-by: Roland Häder <roland@mxchange.org>
use Hub\Information\ShareableInfo;
use Hub\Listener\BaseListener;
use Hub\Listener\Listenable;
+use Hub\Locator\Node\LocateableNode;
use Hub\Network\Deliver\Deliverable;
use Hub\Network\Package\Assembler\Assembler;
use Hub\Network\Package\Fragment\Fragmentable;
*/
private $socketInstance = NULL;
+ /**
+ * An instance of a LocateableNode class
+ */
+ private $universalNodeLocatorInstance = NULL;
+
/**
* Name of used protocol
*/
return $this->socketInstance;
}
+ /**
+ * Setter for UNL instance
+ *
+ * @para $unlInstance An instance of a LocateableNode class
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ // Set new UNL data array
+ $this->universalNodeLocatorInstance = $unlInstance;
+ }
+
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ */
+ public final function getUniversalNodeLocatorInstance () {
+ // Return UNL data array
+ return $this->universalNodeLocatorInstance;
+ }
+
}
* @throws InvalidSocketException If stored socket is invalid
*/
public function connectToSocketRecipient () {
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: CALLED!', strtoupper($this->getSocketProtocol())));
+
// Should be valid socket
if (!$this->isValidSocket()) {
// Throw exception
// Try to connect to it
$result = socket_connect($this->getSocketResource(), $unlInstance->getUnlAddress(), $unlInstance->getUnlPort());
+ // Trace message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput(sprintf('%s-SOCKET: result=%d - EXIT!', strtoupper($this->getSocketProtocol()), intval($result)));
+
// Return result
return $result;
}
*
* @return void
* @throws SocketShutdownException If the current socket could not be shut down
- * @throws BaseMethodCallException If this method is possibly called twice
+ * @throws BadMethodCallException If this method is possibly called twice
* @todo We may want to implement a filter for ease notification of other objects like our pool
* @todo rewrite this!
*/
// Should be valid socket
if (!$this->isValidSocket()) {
// Throw exception
- throw new BaseMethodCallException(sprintf('[%s:%d]: Shutdown on invalid socket. Maybe called already?', __METHOD__, __LINE__), self::EXCEPTION_INVALID_SOCKET);
+ throw new BadMethodCallException(sprintf('[%s:%d]: Shutdown on invalid socket. Maybe called already?', __METHOD__, __LINE__), self::EXCEPTION_INVALID_SOCKET);
} // END - if
// Debug message
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Database\Frontend;
+
+// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Generic\HubInterface;
+use Hub\Information\ShareableInfo;
+use Hub\Locator\Node\LocateableNode;
+use Hub\Pool\Poolable;
+
+// Import framework stuff
+use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
+
+/**
+ * A database wrapper for cruncher work/test units
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2011 - 2014 Cruncher Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 BaseHubDatabaseWrapper extends BaseDatabaseWrapper implements HubInterface {
+
+ /**
+ * Listener pool instance
+ */
+ private $listenerPoolInstance = NULL;
+
+ /**
+ * Info instance
+ */
+ private $infoInstance = NULL;
+
+ /**
+ * A StorableSocket instance
+ */
+ private $socketInstance = NULL;
+
+ /**
+ * An instance of a LocateableNode class
+ */
+ private $universalNodeLocatorInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Checks whether start/end marker are set
+ *
+ * @param $data Data to be checked
+ * @return $isset Whether start/end marker are set
+ */
+ public final function ifStartEndMarkersSet ($data) {
+ // Determine it
+ $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+ // ... and return it
+ return $isset;
+ }
+
+ /**
+ * Setter for listener pool instance
+ *
+ * @param $listenerPoolInstance The new listener pool instance
+ * @return void
+ */
+ protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) {
+ $this->listenerPoolInstance = $listenerPoolInstance;
+ }
+
+ /**
+ * Getter for listener pool instance
+ *
+ * @return $listenerPoolInstance Our current listener pool instance
+ */
+ public final function getListenerPoolInstance () {
+ return $this->listenerPoolInstance;
+ }
+
+ /**
+ * Setter for info instance
+ *
+ * @param $infoInstance A ShareableInfo instance
+ * @return void
+ */
+ protected final function setInfoInstance (ShareableInfo $infoInstance) {
+ $this->infoInstance = $infoInstance;
+ }
+
+ /**
+ * Getter for info instance
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final function getInfoInstance () {
+ return $this->infoInstance;
+ }
+
+ /**
+ * Setter for socket instance
+ *
+ * @param $socketInstance A StorableSocket instance
+ * @return void
+ */
+ public final function setSocketInstance (StorableSocket $socketInstance) {
+ $this->socketInstance = $socketInstance;
+ }
+
+ /**
+ * Getter for socket instance
+ *
+ * @return $socketInstance An instance of a StorableSocket class
+ */
+ public final function getSocketInstance () {
+ return $this->socketInstance;
+ }
+
+ /**
+ * Setter for UNL instance
+ *
+ * @para $unlInstance An instance of a LocateableNode class
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ // Set new UNL data array
+ $this->universalNodeLocatorInstance = $unlInstance;
+ }
+
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ */
+ public final function getUniversalNodeLocatorInstance () {
+ // Return UNL data array
+ return $this->universalNodeLocatorInstance;
+ }
+
+ /**
+ * Setter for node id
+ *
+ * @param $nodeId The new node id
+ * @return void
+ */
+ protected final function setNodeId ($nodeId) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for node id
+ *
+ * @return $nodeId Current node id
+ */
+ public final function getNodeId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key
+ *
+ * @param $privateKey The new private key
+ * @return void
+ */
+ protected final function setPrivateKey ($privateKey) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key
+ *
+ * @return $privateKey Current private key
+ */
+ public final function getPrivateKey () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key hash
+ *
+ * @param $privateKeyHash The new private key hash
+ * @return void
+ */
+ protected final function setPrivateKeyHash ($privateKeyHash) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key hash
+ *
+ * @return $privateKeyHash Current private key hash
+ */
+ public final function getPrivateKeyHash () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for session id
+ *
+ * @return $sessionId Current session id
+ */
+ public final function getSessionId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+}
// Own namespace
namespace Hub\Database\Frontend\Cruncher\Unit;
+// Import application-specific stuff
+use Hub\Database\Frontend\BaseHubDatabaseWrapper;
+
// Import framework stuff
-use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
use CoreFramework\Factory\ObjectFactory;
use CoreFramework\Registry\Registerable;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class CruncherUnitDatabaseWrapper extends BaseDatabaseWrapper implements UnitDatabaseWrapper, Registerable {
+class CruncherUnitDatabaseWrapper extends BaseHubDatabaseWrapper implements UnitDatabaseWrapper, Registerable {
// Constants for database table names
const DB_TABLE_CRUNCHER_UNITS = 'cruncher_units';
namespace Hub\Database\Frontend\Node\Dht;
// Import application-specific stuff
+use Hub\Database\Frontend\BaseHubDatabaseWrapper;
use Hub\Database\Frontend\Node\Information\NodeInformationDatabaseWrapper;
use Hub\Factory\Node\NodeObjectFactory;
use Hub\Network\Package\NetworkPackage;
use CoreFramework\Bootstrap\FrameworkBootstrap;
use CoreFramework\Criteria\Local\LocalSearchCriteria;
use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
use CoreFramework\Factory\ObjectFactory;
use CoreFramework\Handler\DataSet\HandleableDataSet;
use CoreFramework\Registry\Registerable;
* 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 NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implements NodeDhtWrapper, Registerable {
+class NodeDistributedHashTableDatabaseWrapper extends BaseHubDatabaseWrapper implements NodeDhtWrapper, Registerable {
/**
* "Cached" results for dabase for looking for unpublished entries
*/
namespace Hub\Database\Frontend\Node\Information;
// Import application-specific stuff
+use Hub\Database\Frontend\BaseHubDatabaseWrapper;
use Hub\Database\Frontend\Node\NodeInformationWrapper;
use Hub\Node\BaseHubNode;
use Hub\Helper\Node\NodeHelper;
// Import framework stuff
use CoreFramework\Bootstrap\FrameworkBootstrap;
use CoreFramework\Criteria\Local\LocalSearchCriteria;
-use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
use CoreFramework\Factory\ObjectFactory;
use CoreFramework\Registry\Registerable;
use CoreFramework\Request\Requestable;
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class NodeInformationDatabaseWrapper extends BaseDatabaseWrapper implements NodeInformationWrapper, Registerable {
+class NodeInformationDatabaseWrapper extends BaseHubDatabaseWrapper implements NodeInformationWrapper, Registerable {
// Constants for database table names
const DB_TABLE_NODE_INFORMATION = 'node_data';
namespace Hub\Database\Frontend\Node\PeerState;
// Import application-specific sutff
+use Hub\Container\Socket\StorableSocket;
+use Hub\Database\Frontend\BaseHubDatabaseWrapper;
use Hub\Helper\Connection\ConnectionHelper;
use Hub\Network\Package\NetworkPackage;
+use Hub\LookupTable\Lookupable;
+use Hub\State\Peer\Lookup\LookupablePeerState;
+use Hub\State\Peer\PeerStateable;
use Hub\Tools\HubTools;
// Import framework stuff
use CoreFramework\Criteria\Local\LocalSearchCriteria;
use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Database\Frontend\BaseDatabaseWrapper;
use CoreFramework\Factory\ObjectFactory;
/**
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class PeerStateLookupDatabaseWrapper extends BaseDatabaseWrapper implements LookupablePeerState {
+class PeerStateLookupDatabaseWrapper extends BaseHubDatabaseWrapper implements LookupablePeerState {
// Exception constants
const EXCEPTION_PEER_ALREADY_REGISTERED = 0x300;
* 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
+ * @param $socketResource An instance of a StorableSocket class
* @return void
* @throws PeerAlreadyRegisteredException If a peer is already registered
*/
- public function registerPeerByPackageData (array $packageData, $socketResource) {
+ public function registerPeerByPackageData (array $packageData, StorableSocket $socketInstance) {
// Make sure only new peers can be registered with package data
if (!$this->isSenderNewPeer($packageData)) {
// Throw an exception because this should normally not happen
$peerPort = '0';
// Get peer name
- if (!@socket_getpeername($socketResource, $peerAddress, $peerPort)) {
+ if (!@socket_getpeername($socketInstance, $peerAddress, $peerPort)) {
// Get last error
- $lastError = socket_last_error($socketResource);
+ $lastError = socket_last_error($socketInstance);
// ... and cleartext message from it and put both into criteria
$dataSetInstance->addCriteria(self::DB_COLUMN_SOCKET_ERROR_CODE, $lastError);
/**
* Purges old entries of given socket resource. We use the IP address from that resource.
*
- * @param $socketResource A valid socket resource
+ * @param $socketInstance An instance of a StorableSocket class
* @return void
* @throws InvalidSocketException If the socket resource was invalid
* @todo Unfinished area, please rewrite!
*/
- public function purgeOldEntriesBySocketResource ($socketResource) {
+ public function purgeOldEntriesBysocketInstance (StorableSocket $socketInstance) {
// Get peer name
- if (!@socket_getpeername($socketResource, $peerAddress, $peerPort)) {
+ if (!@socket_getpeername($socketInstance, $peerAddress, $peerPort)) {
// Get last error
- $lastError = socket_last_error($socketResource);
+ $lastError = socket_last_error($socketInstance);
// Doesn't work!
- throw new InvalidSocketException(array($this, $socketResource, $lastError, socket_strerror($lastError)), self::EXCEPTION_INVALID_SOCKET);
+ throw new InvalidSocketException(array($this, $socketInstance, $lastError, socket_strerror($lastError)), self::EXCEPTION_INVALID_SOCKET);
} // END - if
// Debug message
use Hub\Handler\Protocol\HandleableProtocol;
use Hub\Listener\Listenable;
use Hub\Network\Package\NetworkPackage;
+use Hub\Resolver\State\Peer\PeerStateResolver;
// Import framework stuff
use CoreFramework\Generic\NullPointerException;
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Announcement\Answer;
-
-// Import application-specific stuff
-use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Node\BaseHubNode;
-
-// Import framework stuff
-use CoreFramework\Registry\Registerable;
-use CoreFramework\Registry\Registry;
-
-/**
- * A AnnouncementAnswerOkay handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- );
-
- // Set handler name
- $this->setHandlerName('announcement_answer_okay');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeAnnouncementAnswerOkayHandler () {
- // Get new instance
- $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @todo Do some more here: Handle karma, et cetera?
- */
- public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
- /*
- * Query DHT and force update (which will throw an exception if the
- * node is not found).
- */
- DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
-
- // Get handler instance
- $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
-
- // Generate DHT bootstrap task
- $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
-
- // Register it as well
- $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
-
- // Get the node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Change state
- $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
-
- // Prepare next message
- $this->prepareNextMessage($messageData, $packageInstance);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * The following array is being handled over:
- *
- * my-external-address => 1.2.3.4
- * my-internal-address => 5.6.7.8
- * my-status => reachable
- * my-node-id => aaabbbcccdddeeefff123456789
- * my-session-id => aaabbbcccdddeeefff123456789
- * my-tcp-port => 9060
- * my-udp-port => 9060
- * answer-status => OKAY
- * message_type => announcement_answer
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Get an array of all accepted object types
- $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
-
- // Add missing (temporary) configuration 'accepted_object_types'
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration. For content of $messageData see method comment above.
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Remove temporay configuration
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A ??? handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ???Handler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('|||_answer_===');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function create???Handler () {
- // Get new instance
- $handlerInstance = new ???Handler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @return void
- */
- public function handleAnswerMessageData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-/**
- * A general answer-status handler. So called "answer-status handler" are
- * classes which handles a message field 'answer-status' which is, alongside
- * many other node-relevant data, the main part of the answer message. These
- * answer messages, by the way, are never sent unrequested. This, however,
- * sounds logical because the answer is a reply from a node that has responded
- * on a message.
- *
- * The answer-status field gives information back to the requesting node if the
- * receiving node could handle the message properly (all verfication steps are
- * passed, message type was understood, correct receiver, et cetera) and how
- * it handles it. Some messages may be rejected, e.g. when the requesting node
- * is blacklisted or its behavour has changed.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-abstract class BaseAnserStatusHandler extends BaseDataHandler {
- /**
- * 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
-// Own namespace
-namespace Hub\Handler\Answer\Okay\NodeList;
-
-// Import application-specific stuff
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Network\Receive\Receivable;
-
-// Import framework stuff
-use CoreFramework\Registry\Registerable;
-
-/**
- * A RequestNodeListAnswerOkay handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Init array
- $this->searchData = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
-
- // Set handler name
- $this->setHandlerName('request_node_list_answer_okay');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createRequestNodeListAnswerOkayHandler () {
- // Get new instance
- $handlerInstance = new RequestNodeListAnswerOkayHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles given message data array
- *
- * @param $messageData An array of message data
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NodeSessionIdVerficationException If the provided session id is not matching
- * @todo Do some more here: Handle karma, et cetera?
- */
- public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
- // Make sure node-list is found in array
- assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
-
- // Save node list
- $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
-
- // Make sure it is completely decoded
- assert(is_array($nodeList));
-
- // ... and remove it as it should not be included now
- unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
-
- // Write node list to DHT
- DhtObjectFactory::createDhtInstance('node')->insertNodeList($nodeList);
-
- /*
- * Query DHT and force update (which will throw an exception if the
- * node is not found).
- */
- DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
-
- // Prepare next message ("hello" message to all returned nodes)
- //$this->prepareNextMessage($messageData, $packageInstance);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * The following array is being handled over:
- *
- * session-id => aaabbbcccdddeeefff123456789
- * node-list => aabb:ccdd:eeff
- * answer-status => OKAY
- * message_type => request_node_list_answer
- *
- * @param $messageData An array with all message data
- * @return void
- * @todo 0% done
- */
- protected function initMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration. For content of $messageData see method comment above.
- *
- * @param $messageData An array with all message data
- * @return void
- * @todo 0% done
- */
- protected function removeMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
// Import application-specific stuff
use Hub\Factory\Fragmenter\FragmenterFactory;
+use Hub\Handler\BaseHubHandler;
use Hub\Network\Package\Fragment\PackageFragmenter;
// Import framework stuff
use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Handler\BaseHandler;
use CoreFramework\Registry\Registerable;
/**
* 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 ChunkHandler extends BaseHandler implements HandleableChunks, Registerable {
+class ChunkHandler extends BaseHubHandler implements HandleableChunks, Registerable {
/**
* Stacker for chunks with final EOP
*/
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler;
+
+// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Generic\HubInterface;
+use Hub\Information\ShareableInfo;
+use Hub\Locator\Node\LocateableNode;
+use Hub\Pool\Poolable;
+
+// Import framework stuff
+use CoreFramework\Handler\BaseHandler;
+use CoreFramework\Handler\Handleable;
+
+/**
+ * A general hub handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 BaseHubHandler extends BaseHandler implements Handleable, HubInterface {
+ /**
+ * Listener pool instance
+ */
+ private $listenerPoolInstance = NULL;
+
+ /**
+ * Info instance
+ */
+ private $infoInstance = NULL;
+
+ /**
+ * A StorableSocket instance
+ */
+ private $socketInstance = NULL;
+
+ /**
+ * An instance of a LocateableNode class
+ */
+ private $universalNodeLocatorInstance = NULL;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Checks whether start/end marker are set
+ *
+ * @param $data Data to be checked
+ * @return $isset Whether start/end marker are set
+ */
+ public final function ifStartEndMarkersSet ($data) {
+ // Determine it
+ $isset = ((substr($data, 0, strlen(BaseRawDataHandler::STREAM_START_MARKER)) == BaseRawDataHandler::STREAM_START_MARKER) && (substr($data, -1 * strlen(BaseRawDataHandler::STREAM_END_MARKER), strlen(BaseRawDataHandler::STREAM_END_MARKER)) == BaseRawDataHandler::STREAM_END_MARKER));
+
+ // ... and return it
+ return $isset;
+ }
+
+ /**
+ * Setter for listener pool instance
+ *
+ * @param $listenerPoolInstance The new listener pool instance
+ * @return void
+ */
+ protected final function setListenerPoolInstance (Poolable $listenerPoolInstance) {
+ $this->listenerPoolInstance = $listenerPoolInstance;
+ }
+
+ /**
+ * Getter for listener pool instance
+ *
+ * @return $listenerPoolInstance Our current listener pool instance
+ */
+ public final function getListenerPoolInstance () {
+ return $this->listenerPoolInstance;
+ }
+
+ /**
+ * Setter for info instance
+ *
+ * @param $infoInstance A ShareableInfo instance
+ * @return void
+ */
+ protected final function setInfoInstance (ShareableInfo $infoInstance) {
+ $this->infoInstance = $infoInstance;
+ }
+
+ /**
+ * Getter for info instance
+ *
+ * @return $infoInstance An instance of a ShareableInfo class
+ */
+ public final function getInfoInstance () {
+ return $this->infoInstance;
+ }
+
+ /**
+ * Setter for socket instance
+ *
+ * @param $socketInstance A StorableSocket instance
+ * @return void
+ */
+ public final function setSocketInstance (StorableSocket $socketInstance) {
+ $this->socketInstance = $socketInstance;
+ }
+
+ /**
+ * Getter for socket instance
+ *
+ * @return $socketInstance An instance of a StorableSocket class
+ */
+ public final function getSocketInstance () {
+ return $this->socketInstance;
+ }
+
+ /**
+ * Setter for UNL instance
+ *
+ * @para $unlInstance An instance of a LocateableNode class
+ * @return void
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ // Set new UNL data array
+ $this->universalNodeLocatorInstance = $unlInstance;
+ }
+
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ */
+ public final function getUniversalNodeLocatorInstance () {
+ // Return UNL data array
+ return $this->universalNodeLocatorInstance;
+ }
+
+ /**
+ * Setter for node id
+ *
+ * @param $nodeId The new node id
+ * @return void
+ */
+ protected final function setNodeId ($nodeId) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for node id
+ *
+ * @return $nodeId Current node id
+ */
+ public final function getNodeId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key
+ *
+ * @param $privateKey The new private key
+ * @return void
+ */
+ protected final function setPrivateKey ($privateKey) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key
+ *
+ * @return $privateKey Current private key
+ */
+ public final function getPrivateKey () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for private key hash
+ *
+ * @param $privateKeyHash The new private key hash
+ * @return void
+ */
+ protected final function setPrivateKeyHash ($privateKeyHash) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for private key hash
+ *
+ * @return $privateKeyHash Current private key hash
+ */
+ public final function getPrivateKeyHash () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for session id
+ *
+ * @return $sessionId Current session id
+ */
+ public final function getSessionId () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+}
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Announcement\Answer;
+
+// Import application-specific stuff
+use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Node\BaseHubNode;
+
+// Import framework stuff
+use CoreFramework\Registry\Registerable;
+use CoreFramework\Registry\Registry;
+
+/**
+ * A AnnouncementAnswerOkay handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeAnnouncementAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ );
+
+ // Set handler name
+ $this->setHandlerName('announcement_answer_okay');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeAnnouncementAnswerOkayHandler () {
+ // Get new instance
+ $handlerInstance = new NodeAnnouncementAnswerOkayHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @todo Do some more here: Handle karma, et cetera?
+ */
+ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
+ /*
+ * Query DHT and force update (which will throw an exception if the
+ * node is not found).
+ */
+ DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
+
+ // Get handler instance
+ $handlerInstance = Registry::getRegistry()->getInstance('task_handler');
+
+ // Generate DHT bootstrap task
+ $taskInstance = ObjectFactory::createObjectByConfiguredName('node_dht_late_bootstrap_task_class');
+
+ // Register it as well
+ $handlerInstance->registerTask('dht_late_bootstrap', $taskInstance);
+
+ // Get the node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Change state
+ $nodeInstance->getStateInstance()->nodeAnnouncementSuccessful();
+
+ // Prepare next message
+ $this->prepareNextMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * The following array is being handled over:
+ *
+ * my-external-address => 1.2.3.4
+ * my-internal-address => 5.6.7.8
+ * my-status => reachable
+ * my-node-id => aaabbbcccdddeeefff123456789
+ * my-session-id => aaabbbcccdddeeefff123456789
+ * my-tcp-port => 9060
+ * my-udp-port => 9060
+ * answer-status => OKAY
+ * message_type => announcement_answer
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Get an array of all accepted object types
+ $objectList = $nodeInstance->getListFromAcceptedObjectTypes();
+
+ // Add missing (temporary) configuration 'accepted_object_types'
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS, implode(BaseHubNode::OBJECT_LIST_SEPARATOR, $objectList));
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration. For content of $messageData see method comment above.
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Remove temporay configuration
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPTED_OBJECTS);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A ??? handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ???Handler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('|||_answer_===');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function create???Handler () {
+ // Get new instance
+ $handlerInstance = new ???Handler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @return void
+ */
+ public function handleAnswerMessageData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+/**
+ * A general answer-status handler. So called "answer-status handler" are
+ * classes which handles a message field 'answer-status' which is, alongside
+ * many other node-relevant data, the main part of the answer message. These
+ * answer messages, by the way, are never sent unrequested. This, however,
+ * sounds logical because the answer is a reply from a node that has responded
+ * on a message.
+ *
+ * The answer-status field gives information back to the requesting node if the
+ * receiving node could handle the message properly (all verfication steps are
+ * passed, message type was understood, correct receiver, et cetera) and how
+ * it handles it. Some messages may be rejected, e.g. when the requesting node
+ * is blacklisted or its behavour has changed.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseAnserStatusHandler extends BaseDataHandler {
+ /**
+ * 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
+// Own namespace
+namespace Hub\Handler\Answer\Okay\NodeList;
+
+// Import application-specific stuff
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Network\Receive\Receivable;
+
+// Import framework stuff
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A RequestNodeListAnswerOkay handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 RequestNodeListAnswerOkayHandler extends BaseAnserStatusHandler implements HandleableAnswerStatus, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Init array
+ $this->searchData = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+
+ // Set handler name
+ $this->setHandlerName('request_node_list_answer_okay');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createRequestNodeListAnswerOkayHandler () {
+ // Get new instance
+ $handlerInstance = new RequestNodeListAnswerOkayHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles given message data array
+ *
+ * @param $messageData An array of message data
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NodeSessionIdVerficationException If the provided session id is not matching
+ * @todo Do some more here: Handle karma, et cetera?
+ */
+ public function handleAnswerMessageData (array $messageData, Receivable $packageInstance) {
+ // Make sure node-list is found in array
+ assert(isset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
+
+ // Save node list
+ $nodeList = json_decode(base64_decode($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]));
+
+ // Make sure it is completely decoded
+ assert(is_array($nodeList));
+
+ // ... and remove it as it should not be included now
+ unset($messageData[XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST]);
+
+ // Write node list to DHT
+ DhtObjectFactory::createDhtInstance('node')->insertNodeList($nodeList);
+
+ /*
+ * Query DHT and force update (which will throw an exception if the
+ * node is not found).
+ */
+ DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this, TRUE);
+
+ // Prepare next message ("hello" message to all returned nodes)
+ //$this->prepareNextMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * The following array is being handled over:
+ *
+ * session-id => aaabbbcccdddeeefff123456789
+ * node-list => aabb:ccdd:eeff
+ * answer-status => OKAY
+ * message_type => request_node_list_answer
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @todo 0% done
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration. For content of $messageData see method comment above.
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @todo 0% done
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Network\;
+
+// Import application-specific stuff
+use Hub\Network\Networkable;
+
+/**
+ * A ??? network package handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 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 ???NetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('!!!');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public final static function create???NetworkPackageHandler () {
+ // Get new instance
+ $handlerInstance = new ???NetworkPackageHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes a package from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid resource identifier
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processResourcePackage ($resource) {
+ // Check the resource
+ if (!is_resource($resource)) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method.');
+ }
+
+}
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Data;
+
+// Import application-specific stuff
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Generic\HubInterface;
+use Hub\Handler\BaseHubHandler;
+use Hub\Network\Deliver\Deliverable;
+
+// Import framework stuff
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\FrameworkException;
+
+/**
+ * A general data Handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseDataHandler extends BaseHubHandler implements HubInterface {
+ /**
+ * Last exception instance from database layer or NULL (default)
+ */
+ private $lastException = NULL;
+
+ /**
+ * Array with search criteria elements
+ */
+ protected $searchData = array();
+
+ /**
+ * Array with all data XML nodes (which hold the actual data) and their values
+ */
+ protected $messageDataElements = array();
+
+ /**
+ * Array for translating message data elements (other node's data mostly)
+ * into configuration elements.
+ */
+ protected $messageToConfig = array();
+
+ /**
+ * Array for copying configuration entries
+ */
+ protected $configCopy = array();
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * Getter for search data array
+ *
+ * @return $searchData Search data array
+ */
+ public final function getSearchData () {
+ return $this->searchData;
+ }
+
+ /**
+ * Getter for last exception
+ *
+ * @return $lastException Last thrown exception
+ */
+ public final function getLastException () {
+ return $this->lastException;
+ }
+
+ /**
+ * Setter for last exception
+ *
+ * @param $lastException Last thrown exception
+ * @return void
+ */
+ public final function setLastException (FrameworkException $exceptionInstance = NULL) {
+ $this->lastException = $exceptionInstance;
+ }
+
+ /**
+ * Prepares a message as answer for given message data for delivery.
+ *
+ * @param $messageData An array with all message data
+ * @param $packageInstance An instance of a Deliverable instance
+ * @return void
+ */
+ protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
+
+ // Get a helper instance based on this handler's name
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Load descriptor XML
+ $helperInstance->loadDescriptorXml($nodeInstance);
+
+ /*
+ * Set missing (temporary) configuration data, mostly it needs to be
+ * copied from message data array.
+ */
+ $this->initMessageConfigurationData($messageData);
+
+ // Compile any configuration variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // Deliver the package
+ $helperInstance->sendPackage($nodeInstance);
+
+ /*
+ * Remove temporary configuration
+ */
+ $this->removeMessageConfigurationData($messageData);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Answer message has been prepared.');
+ }
+
+ /**
+ * Prepares the next message
+ *
+ * @param $messageData An array with all message data
+ * @param $packageInstance An instance of a Deliverable instance
+ * @return void
+ */
+ protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Going to send next message ...');
+
+ // Get a helper instance based on this handler's name
+ $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
+
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Load descriptor XML
+ $helperInstance->loadDescriptorXml($nodeInstance);
+
+ /*
+ * Set missing (temporary) configuration data, mostly it needs to be
+ * copied from message data array.
+ */
+ $this->initMessageConfigurationData($messageData);
+
+ // Compile any configuration variables
+ $helperInstance->getTemplateInstance()->compileConfigInVariables();
+
+ // Deliver the package
+ $helperInstance->sendPackage($nodeInstance);
+
+ /*
+ * Remove temporary configuration
+ */
+ $this->removeMessageConfigurationData($messageData);
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Next message has been prepared.');
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ abstract protected function initMessageConfigurationData (array $messageData);
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ abstract protected function removeMessageConfigurationData (array $messageData);
+
+}
--- /dev/null
+Deny from all
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Message\Announcement;
+
+// Import application-specific stuff
+use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Generic\BaseHubSystem;
+use Hub\Network\Receive\Receivable;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageAnnouncement handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => 'your_node_id',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash',
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageAnnouncementHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageAnnouncementHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws AnnouncementNotAcceptedException If this node does not accept announcements
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Is this node accepting announcements?
+ if (!$nodeInstance->isAcceptingAnnouncements()) {
+ /*
+ * This node is not accepting announcements, then someone wants to
+ * announce his node to a non-bootstrap and non-master node.
+ */
+ throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageData), BaseHubSystem::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Adding messageData[' . $key . ']=' . $messageData[$key] . ' ...');
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the translation array
+ foreach ($this->messageToConfig as $messageKey => $configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
+
+ // Set the element in configuration
+ $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to targetKey
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the translation array again
+ foreach ($this->messageToConfig as $dummy => $configKey) {
+ // Now unset this configuration entry (to save some memory)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Answer\Announcement;
+
+// Import application-specific stuff
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageAnnouncementAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id'
+ XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash'
+ */
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
+ XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageAnnouncementAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageAnnouncementAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoAnnouncementAttemptedException If this node has not attempted to announce itself
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Has this node attempted to announce itself?
+ if (!$nodeInstance->ifNodeIsAnnouncing()) {
+ /*
+ * This node has never announced itself, so it doesn't expect
+ * announcement answer messages.
+ */
+ throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Handle the answer status element
+ $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Answer\Node\DhtBootstrap;
+
+// Import application-specific stuff
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
+use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageDhtBootstrapAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_announcement_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ @TODO Why commented out?
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
+ */
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageDhtBootstrapAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageDhtBootstrapAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoDhtBootstrapAttemptedException If this DHT has not attempted to bootstrap
+ * @todo ~30% done
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get DHT instance
+ $dhtInstance = DhtObjectFactory::createDhtInstance('node');
+
+ // Has this DHT attempted to bootstrap?
+ if (!$dhtInstance->ifDhtIsBooting()) {
+ /*
+ * This DHT has never bootstrapped, so it doesn't expect
+ * announcement answer messages.
+ */
+ throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
+ } // END - if
+
+ // Unfinished
+ $this->partialStub('UNHANDLED: messageData=' . print_r($messageData, TRUE));
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Answer\Request\NodeList;
+
+// Import application-specific stuff
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageRequestNodeListAnswer handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_request_node_list_answer');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
+ BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ /*
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
+ */
+ );
+
+ // Init search data array
+ $this->searchData = array(
+ XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageRequestNodeListAnswerHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Has this node attempted to announce itself?
+ if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
+ /*
+ * This node has never announced itself, so it doesn't expect
+ * request-node-list answer messages.
+ */
+ throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Handle the answer status element
+ $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, TRUE));
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
+
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ /*
+ * Add it, but remove any 'my-' prefixes as they are not used in
+ * database layer.
+ */
+ $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Message\;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+
+/**
+ * A NodeMessage??? handler
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessage???Handler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_===');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ Xml???TemplateEngine::!!!_DATA_EXTERNAL_ADDRESS,
+ Xml???TemplateEngine::!!!_DATA_NODE_STATUS,
+ Xml???TemplateEngine::!!!_DATA_SESSION_ID,
+ Xml???TemplateEngine::!!!_DATA_LISTEN_PORT,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessage???Handler () {
+ // Get new instance
+ $handlerInstance = new NodeMessage???Handler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ $this->partialStub('Please implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Message;
+
+// Import hub-specific stuff
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Generic\BaseHubSystem;
+use Hub\Network\Receive\Receivable;
+
+// Import framework stuff
+use CoreFramework\Generic\FrameworkException;
+
+/**
+ * A general message handler, this class must be abstract to make the template
+ * method pattern working.
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+abstract class BaseMessageHandler extends BaseDataHandler {
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+ }
+
+ /**
+ * "Getter" for a translated last exception as a status code
+ *
+ * @return $statusCode Translated status code from last exception
+ */
+ protected function getTranslatedStatusFromLastException () {
+ // Default is all fine
+ $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
+
+ // Is the last exception not NULL?
+ if ($this->getLastException() instanceof FrameworkException) {
+ // "Determine" the right status code (may differ from exception to exception)
+ $this->debugInstance(sprintf('[%s:%d]: lastException=%s,message=%s is unfinished.', __METHOD__, __LINE__, $this->getLastException()->__toString(), $this->getLastException()->getMessage()));
+ } // END - if
+
+ // Return the status code
+ return $statusCode;
+ }
+
+ /**
+ * Registers an other node with this node by given message data. The
+ * following data must always be present:
+ *
+ * - session-id (for finding the node's record together with below data)
+ * - external-address (hostname or IP number)
+ * - listen-port (TCP/UDP listen port for inbound connections)
+ *
+ * @param $messageArray An array with all minimum message data
+ * @return void
+ */
+ protected function registerNodeByMessageData (array $messageData) {
+ // Check if searchData has entries
+ assert(count($this->getSearchData()) > 0);
+
+ // Let the DHT facade do the work
+ DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this);
+ }
+
+ /**
+ * Posty-handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
+ /*
+ * Feed hash to miner by handling over the whole array as also the
+ * sender and tags are needed.
+ */
+ $packageInstance->feedHashToMiner($messageData);
+ }
+
+}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Answer\Dht\Bootstrap;
+
+// Import application-specific stuff
+use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageDhtBootstrap handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_dht_bootstrap');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE,
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
+ );
+
+ // Init message-data->configuration translation array
+ $this->messageToConfig = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
+ XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
+ );
+
+ // Init array
+ $this->searchData = array(
+ XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageDhtBootstrapHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageDhtBootstrapHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws DhtBootstrapNotAcceptedException If this node does not accept DHT bootstrap requests
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Is this node accepting DHT bootstrap requests?
+ if (!NodeObjectFactory::createNodeInstance()->isAcceptingDhtBootstrap()) {
+ /*
+ * This node is not accepting DHT bootstrap requests.
+ */
+ throw new DhtBootstrapNotAcceptedException(array($this, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the DHT bootstrap requesting node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the translation array
+ foreach ($this->messageToConfig as $messageKey => $configKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
+
+ // Set the element in configuration
+ $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to target key
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+
+ /*
+ * Use the DHT instance to get a list of recipients. This means that all
+ * DHT nodes that accept bootstrap requests are read from the DHT
+ * database.
+ */
+ $nodeList = DhtObjectFactory::createDhtInstance('node')->findRecipientsByKey(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPT_BOOTSTRAP, 'Y');
+
+ // Make sure it is an array and has at least one entry
+ assert(is_array($nodeList));
+ assert(count($nodeList) > 0);
+
+ // Set it in configuration
+ $this->getConfigInstance()->setConfigEntry('dht_nodes', base64_encode(json_encode($nodeList)));
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the translation array again
+ foreach ($this->messageToConfig as $dummy => $configKey) {
+ // Now unset this configuration entry (to save some memory)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove temporary "special" values as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ $this->getConfigInstance()->unsetConfigEntry('dht_nodes');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Message\Request\NodeList;
+
+// Import application-specific stuff
+use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
+use Hub\Factory\Dht\DhtObjectFactory;
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+use Hub\Node\BaseHubNode;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageRequestNodeList handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageRequestNodeListHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_request_node_list');
+
+ // Init message data array
+ $this->messageDataElements = array(
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+ );
+
+ // Init config-copy array
+ $this->configCopy = array(
+ );
+
+ // Init search data array
+ $this->searchData = array(
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
+ );
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageRequestNodeListHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageRequestNodeListHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ * @throws RequestNotAcceptedException If this node does not accept this request
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Is this node accepting announcements?
+ if (!$nodeInstance->isAcceptingNodeListRequests()) {
+ /*
+ * This node is not accepting node list requests. Throw an
+ * exception to abort any further processing.
+ */
+ throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_REQUEST_NOT_ACCEPTED);
+ } // END - if
+
+ // Register the announcing node with this node
+ $this->registerNodeByMessageData($messageData);
+
+ // Prepare answer message to be delivered back to the other node
+ $this->prepareAnswerMessage($messageData, $packageInstance);
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Add all ements
+ foreach ($this->messageDataElements as $key) {
+ // Is it there?
+ assert(isset($messageData[$key]));
+
+ // Add it
+ $dataSetInstance->addCriteria($key, $messageData[$key]);
+ } // END - foreach
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: messageData=' . print_r($messageData, TRUE));
+
+ // "Walk" throught the config-copy array
+ foreach ($this->configCopy as $targetKey => $sourceKey) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
+
+ // Copy from source to targetKey
+ $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
+ } // END - foreach
+
+ // Query local DHT for nodes except given session id
+ $nodeList = DhtObjectFactory::createDhtInstance('node')->queryLocalNodeListExceptByMessageData(
+ $messageData,
+ $this,
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
+ XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
+ BaseHubNode::OBJECT_LIST_SEPARATOR
+ );
+
+ // Debug message
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Got a node list of ' . count($nodeList) . ' entry/-ies back.');
+
+ // Set it serialized in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(json_encode($nodeList)));
+
+ // Translate last exception into a status code
+ $statusCode = $this->getTranslatedStatusFromLastException();
+
+ // Set it in configuration (temporarily)
+ $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global
+ * configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // "Walk" throught the config-copy array again
+ foreach ($this->configCopy as $configKey => $dummy) {
+ // Now unset this configuration entry (to save some memory again)
+ $this->getConfigInstance()->unsetConfigEntry($configKey);
+ } // END - foreach
+
+ // Remove answer status/node list as well
+ $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
+ $this->getConfigInstance()->unsetConfigEntry('node_list');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Node\Message\SelfConnect;
+
+// Import application-specific stuff
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Network\Receive\Receivable;
+
+// Import framework stuff
+use CoreFramework\Criteria\Storing\StoreableCriteria;
+use CoreFramework\Generic\UnsupportedOperationException;
+use CoreFramework\Registry\Registerable;
+
+/**
+ * A NodeMessageSelfConnect handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('message_self_connect');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a HandleableMessage class
+ */
+ public final static function createNodeMessageSelfConnectHandler () {
+ // Get new instance
+ $handlerInstance = new NodeMessageSelfConnectHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Handles data array of the message
+ *
+ * @param $messageData An array with message data to handle
+ * @param $packageInstance An instance of a Receivable class
+ * @return void
+ */
+ public function handleMessageData (array $messageData, Receivable $packageInstance) {
+ // Get node instance
+ $nodeInstance = NodeObjectFactory::createNodeInstance();
+
+ // Are node id and session id the same?
+ if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
+ // Both are equal
+ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
+
+ // ... and change state
+ $nodeInstance->getStateInstance()->nodeHasSelfConnected();
+ } else {
+ // Something really horrible happened
+ // @TODO Throw an exception here instead of dying
+ $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE)));
+ }
+ }
+
+ /**
+ * Adds all required elements from given array into data set instance
+ *
+ * @param $dataSetInstance An instance of a StoreableCriteria class
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
+ // Add generic first
+ parent::addArrayToDataSet($dataSetInstance, $messageData);
+
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Initializes configuration data from given message data array
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function initMessageConfigurationData (array $messageData) {
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Removes configuration data with given message data array from global configuration
+ *
+ * @param $messageData An array with all message data
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected function removeMessageConfigurationData (array $messageData) {
+ // Please don't call this method!
+ throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+}
+
+// [EOF]
+?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Message\Announcement;
-
-// Import application-specific stuff
-use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Generic\BaseHubSystem;
-use Hub\Network\Receive\Receivable;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageAnnouncement handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageAnnouncementHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_MODE,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID => 'your_node_id',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash',
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
- );
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageAnnouncementHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageAnnouncementHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws AnnouncementNotAcceptedException If this node does not accept announcements
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Is this node accepting announcements?
- if (!$nodeInstance->isAcceptingAnnouncements()) {
- /*
- * This node is not accepting announcements, then someone wants to
- * announce his node to a non-bootstrap and non-master node.
- */
- throw new AnnouncementNotAcceptedException(array($this, $nodeInstance, $messageData), BaseHubSystem::EXCEPTION_ANNOUNCEMENT_NOT_ACCEPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Adding messageData[' . $key . ']=' . $messageData[$key] . ' ...');
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the translation array
- foreach ($this->messageToConfig as $messageKey => $configKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
-
- // Set the element in configuration
- $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
- } // END - foreach
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANNOUNCEMENT-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to targetKey
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the translation array again
- foreach ($this->messageToConfig as $dummy => $configKey) {
- // Now unset this configuration entry (to save some memory)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Answer\Announcement;
-
-// Import application-specific stuff
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Generic\UnsupportedOperationException;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageAnnouncementAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageAnnouncementAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'your_session_id'
- XmlAnnouncementTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'your_private_key_hash'
- */
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_NODE_STATUS => 'node_status',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID => 'session_id',
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_PRIVATE_KEY_HASH => 'private_key_hash',
- );
-
- // Init array
- $this->searchData = array(
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_SESSION_ID,
- XmlAnnouncementAnswerTemplateEngine::ANNOUNCEMENT_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageAnnouncementAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageAnnouncementAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoAnnouncementAttemptedException If this node has not attempted to announce itself
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Has this node attempted to announce itself?
- if (!$nodeInstance->ifNodeIsAnnouncing()) {
- /*
- * This node has never announced itself, so it doesn't expect
- * announcement answer messages.
- */
- throw new NoAnnouncementAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Handle the answer status element
- $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Answer\Node\DhtBootstrap;
-
-// Import application-specific stuff
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
-use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Generic\UnsupportedOperationException;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageDhtBootstrapAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageDhtBootstrapAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_announcement_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- @TODO Why commented out?
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
- */
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- );
-
- // Init array
- $this->searchData = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageDhtBootstrapAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageDhtBootstrapAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoDhtBootstrapAttemptedException If this DHT has not attempted to bootstrap
- * @todo ~30% done
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get DHT instance
- $dhtInstance = DhtObjectFactory::createDhtInstance('node');
-
- // Has this DHT attempted to bootstrap?
- if (!$dhtInstance->ifDhtIsBooting()) {
- /*
- * This DHT has never bootstrapped, so it doesn't expect
- * announcement answer messages.
- */
- throw new NoDhtBootstrapAttemptedException(array($this, $dhtInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ATTEMPTED);
- } // END - if
-
- // Unfinished
- $this->partialStub('UNHANDLED: messageData=' . print_r($messageData, TRUE));
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Answer\Request\NodeList;
-
-// Import application-specific stuff
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Template\Engine\Xml\Network\Answer\BaseXmlAnswerTemplateEngine;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Generic\UnsupportedOperationException;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageRequestNodeListAnswer handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageRequestNodeListAnswerHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_request_node_list_answer');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_NODE_LIST,
- BaseXmlAnswerTemplateEngine::ANSWER_STATUS,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- /*
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID => 'your_session_id'
- */
- );
-
- // Init search data array
- $this->searchData = array(
- XmlRequestNodeListAnswerTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageRequestNodeListAnswerHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageRequestNodeListAnswerHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws NoRequestNodeListAttemptedException If this node has not attempted to announce itself
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Has this node attempted to announce itself?
- if (!$nodeInstance->ifNodeHasAnnouncementCompleted()) {
- /*
- * This node has never announced itself, so it doesn't expect
- * request-node-list answer messages.
- */
- throw new NoRequestNodeListAttemptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_ANNOUNCEMENT_NOT_ATTEMPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Handle the answer status element
- $nodeInstance->handleAnswerStatusByMessageData($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData=' . print_r($messageData, TRUE));
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('ANSWER-HANDLER: messageData[' . $key . ']=' . $messageData[$key]);
-
- // Is it there?
- assert(isset($messageData[$key]));
-
- /*
- * Add it, but remove any 'my-' prefixes as they are not used in
- * database layer.
- */
- $dataSetInstance->addCriteria(str_replace('my-', '', $key), $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Message\;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-
-/**
- * A NodeMessage??? handler
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 NodeMessage???Handler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_===');
-
- // Init message data array
- $this->messageDataElements = array(
- Xml???TemplateEngine::!!!_DATA_EXTERNAL_ADDRESS,
- Xml???TemplateEngine::!!!_DATA_NODE_STATUS,
- Xml???TemplateEngine::!!!_DATA_SESSION_ID,
- Xml???TemplateEngine::!!!_DATA_LISTEN_PORT,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessage???Handler () {
- // Get new instance
- $handlerInstance = new NodeMessage???Handler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- $this->partialStub('Please implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Message;
-
-// Import hub-specific stuff
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Generic\BaseHubSystem;
-use Hub\Network\Receive\Receivable;
-
-// Import framework stuff
-use CoreFramework\Generic\FrameworkException;
-
-/**
- * A general message handler, this class must be abstract to make the template
- * method pattern working.
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-abstract class BaseMessageHandler extends BaseDataHandler {
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * "Getter" for a translated last exception as a status code
- *
- * @return $statusCode Translated status code from last exception
- */
- protected function getTranslatedStatusFromLastException () {
- // Default is all fine
- $statusCode = BaseHubSystem::MESSAGE_STATUS_CODE_OKAY;
-
- // Is the last exception not NULL?
- if ($this->getLastException() instanceof FrameworkException) {
- // "Determine" the right status code (may differ from exception to exception)
- $this->debugInstance(sprintf('[%s:%d]: lastException=%s,message=%s is unfinished.', __METHOD__, __LINE__, $this->getLastException()->__toString(), $this->getLastException()->getMessage()));
- } // END - if
-
- // Return the status code
- return $statusCode;
- }
-
- /**
- * Registers an other node with this node by given message data. The
- * following data must always be present:
- *
- * - session-id (for finding the node's record together with below data)
- * - external-address (hostname or IP number)
- * - listen-port (TCP/UDP listen port for inbound connections)
- *
- * @param $messageArray An array with all minimum message data
- * @return void
- */
- protected function registerNodeByMessageData (array $messageData) {
- // Check if searchData has entries
- assert(count($this->getSearchData()) > 0);
-
- // Let the DHT facade do the work
- DhtObjectFactory::createDhtInstance('node')->registerNodeByMessageData($messageData, $this);
- }
-
- /**
- * Posty-handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function postHandleMessageData (array $messageData, Receivable $packageInstance) {
- /*
- * Feed hash to miner by handling over the whole array as also the
- * sender and tags are needed.
- */
- $packageInstance->feedHashToMiner($messageData);
- }
-
-}
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Answer\Dht\Bootstrap;
-
-// Import application-specific stuff
-use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Template\Engine\Xml\Dht\Bootstrap\XmlDhtBootstrapTemplateEngine;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageDhtBootstrap handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_dht_bootstrap');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE,
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID,
- );
-
- // Init message-data->configuration translation array
- $this->messageToConfig = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'your_external_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'your_internal_address',
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'your_session_id'
- );
-
- // Init config-copy array
- $this->configCopy = array(
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS => 'external_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_ADDRESS => 'internal_address',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS => 'node_status',
- XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID => 'session_id',
- );
-
- // Init array
- $this->searchData = array(
- XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_ADDRESS,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageDhtBootstrapHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageDhtBootstrapHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws DhtBootstrapNotAcceptedException If this node does not accept DHT bootstrap requests
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Is this node accepting DHT bootstrap requests?
- if (!NodeObjectFactory::createNodeInstance()->isAcceptingDhtBootstrap()) {
- /*
- * This node is not accepting DHT bootstrap requests.
- */
- throw new DhtBootstrapNotAcceptedException(array($this, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED);
- } // END - if
-
- // Register the DHT bootstrap requesting node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the translation array
- foreach ($this->messageToConfig as $messageKey => $configKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Setting messageKey=' . $messageKey . ',configKey=' . $configKey . ':' . $messageData[$messageKey]);
-
- // Set the element in configuration
- $this->getConfigInstance()->setConfigEntry($configKey, $messageData[$messageKey]);
- } // END - foreach
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('DHT-BOOTSTRAP-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to target key
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
-
- /*
- * Use the DHT instance to get a list of recipients. This means that all
- * DHT nodes that accept bootstrap requests are read from the DHT
- * database.
- */
- $nodeList = DhtObjectFactory::createDhtInstance('node')->findRecipientsByKey(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ACCEPT_BOOTSTRAP, 'Y');
-
- // Make sure it is an array and has at least one entry
- assert(is_array($nodeList));
- assert(count($nodeList) > 0);
-
- // Set it in configuration
- $this->getConfigInstance()->setConfigEntry('dht_nodes', base64_encode(json_encode($nodeList)));
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the translation array again
- foreach ($this->messageToConfig as $dummy => $configKey) {
- // Now unset this configuration entry (to save some memory)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove temporary "special" values as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- $this->getConfigInstance()->unsetConfigEntry('dht_nodes');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Message\Request\NodeList;
-
-// Import application-specific stuff
-use Hub\Database\Frontend\Node\Dht\NodeDistributedHashTableDatabaseWrapper;
-use Hub\Factory\Dht\DhtObjectFactory;
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-use Hub\Node\BaseHubNode;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageRequestNodeList handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageRequestNodeListHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_request_node_list');
-
- // Init message data array
- $this->messageDataElements = array(
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
- );
-
- // Init config-copy array
- $this->configCopy = array(
- );
-
- // Init search data array
- $this->searchData = array(
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
- );
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageRequestNodeListHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageRequestNodeListHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- * @throws RequestNotAcceptedException If this node does not accept this request
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Is this node accepting announcements?
- if (!$nodeInstance->isAcceptingNodeListRequests()) {
- /*
- * This node is not accepting node list requests. Throw an
- * exception to abort any further processing.
- */
- throw new RequestNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_REQUEST_NOT_ACCEPTED);
- } // END - if
-
- // Register the announcing node with this node
- $this->registerNodeByMessageData($messageData);
-
- // Prepare answer message to be delivered back to the other node
- $this->prepareAnswerMessage($messageData, $packageInstance);
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Add all ements
- foreach ($this->messageDataElements as $key) {
- // Is it there?
- assert(isset($messageData[$key]));
-
- // Add it
- $dataSetInstance->addCriteria($key, $messageData[$key]);
- } // END - foreach
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: messageData=' . print_r($messageData, TRUE));
-
- // "Walk" throught the config-copy array
- foreach ($this->configCopy as $targetKey => $sourceKey) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Copying from sourceKey=' . $sourceKey . ' to targetKey=' . $targetKey . '...');
-
- // Copy from source to targetKey
- $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey));
- } // END - foreach
-
- // Query local DHT for nodes except given session id
- $nodeList = DhtObjectFactory::createDhtInstance('node')->queryLocalNodeListExceptByMessageData(
- $messageData,
- $this,
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID,
- XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES,
- BaseHubNode::OBJECT_LIST_SEPARATOR
- );
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('REQUEST-HANDLER: Got a node list of ' . count($nodeList) . ' entry/-ies back.');
-
- // Set it serialized in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(json_encode($nodeList)));
-
- // Translate last exception into a status code
- $statusCode = $this->getTranslatedStatusFromLastException();
-
- // Set it in configuration (temporarily)
- $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
- }
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // "Walk" throught the config-copy array again
- foreach ($this->configCopy as $configKey => $dummy) {
- // Now unset this configuration entry (to save some memory again)
- $this->getConfigInstance()->unsetConfigEntry($configKey);
- } // END - foreach
-
- // Remove answer status/node list as well
- $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
- $this->getConfigInstance()->unsetConfigEntry('node_list');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Node\Message\SelfConnect;
-
-// Import application-specific stuff
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Receive\Receivable;
-
-// Import framework stuff
-use CoreFramework\Criteria\Storing\StoreableCriteria;
-use CoreFramework\Generic\UnsupportedOperationException;
-use CoreFramework\Registry\Registerable;
-
-/**
- * A NodeMessageSelfConnect handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 NodeMessageSelfConnectHandler extends BaseMessageHandler implements HandleableMessage, Registerable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('message_self_connect');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a HandleableMessage class
- */
- public final static function createNodeMessageSelfConnectHandler () {
- // Get new instance
- $handlerInstance = new NodeMessageSelfConnectHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Handles data array of the message
- *
- * @param $messageData An array with message data to handle
- * @param $packageInstance An instance of a Receivable class
- * @return void
- */
- public function handleMessageData (array $messageData, Receivable $packageInstance) {
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Are node id and session id the same?
- if (($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_NODE_ID] == $nodeInstance->getNodeId()) && ($messageData[XmlSelfConnectTemplateEngine::SELF_CONNECT_DATA_SESSION_ID] == $nodeInstance->getSessionId())) {
- // Both are equal
- self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('SELF-CONNECT: Have connected to myself, both node and session id are equal!');
-
- // ... and change state
- $nodeInstance->getStateInstance()->nodeHasSelfConnected();
- } else {
- // Something really horrible happened
- // @TODO Throw an exception here instead of dying
- $this->debugInstance(sprintf('[%s:%d]: ids mismatching! messageData=%s', __METHOD__, __LINE__, print_r($messageData, TRUE)));
- }
- }
-
- /**
- * Adds all required elements from given array into data set instance
- *
- * @param $dataSetInstance An instance of a StoreableCriteria class
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- public function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData) {
- // Add generic first
- parent::addArrayToDataSet($dataSetInstance, $messageData);
-
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function initMessageConfigurationData (array $messageData) {
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-
- /**
- * Removes configuration data with given message data array from global configuration
- *
- * @param $messageData An array with all message data
- * @return void
- * @throws UnsupportedOperationException If this method is called
- */
- protected function removeMessageConfigurationData (array $messageData) {
- // Please don't call this method!
- throw new UnsupportedOperationException(array($this, __FUNCTION__), self::EXCEPTION_UNSPPORTED_OPERATION);
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Network\Socket\RawData;
-
-// Import application-specific stuff
-use Hub\Handler\Network\RawData\BaseRawDataHandler;
-use Hub\Network\Networkable;
-
-/**
- * A file-based socket raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 SocketRawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('socket');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createSocketRawDataHandler () {
- // Get new instance
- $handlerInstance = new SocketRawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the ???Listener class
- *
- * @param $resource A valid socket resource array
- * @return void
- */
- public function processRawDataFromResource (array $socketArray) {
- $this->partialStub('socketArray=' . print_r($socketArray, TRUE));
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-Deny from all
+++ /dev/null
-while (count($clients) > 0) {
- // create a copy, so $clients doesn't get modified by socket_select()
- $read = $clients;
-
- // get a list of all the clients that have data to be read from
- // if there are no clients with data, go to next iteration
- $left = @socket_select($read, $write = null, $except = null, 0, 150);
- if ($left < 1) {
- continue;
- }
-
- // check if there is a client trying to connect
- if (in_array($mainSocket, $read)) {
- // accept the client, and add him to the $clients array
- $new_sock = socket_accept($mainSocket);
- $clients[] = $new_sock;
-
- // send the client a welcome message
- socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
- "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
-
- socket_getpeername($new_sock, $ip);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
-
- // Notify all chatter
- if (count($clients) > 2) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket && $send_sock != $new_sock) {
- socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
- }
- }
- }
-
- // remove the listening socket from the clients-with-data array
- $key = array_search($mainSocket, $read);
- unset($read[$key]);
- }
-
- // loop through all the clients that have data to read from
- foreach ($read as $read_sock) {
- // Get client data
- socket_getpeername($read_sock, $ip);
-
- // read until newline or 1024 bytes
- // socket_read while show errors when the client is disconnected, so silence the error messages
- $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
-
- // check if the client is disconnected
- if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
-
- // remove client for $clients array
- $key = array_search($read_sock, $clients);
- unset($clients[$key]);
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
-
- // Notify all chatter
- if (count($clients) > 1) {
- foreach ($clients as $send_sock) {
- if ($send_sock != $mainSocket) {
- socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
- }
- }
- }
-
- // continue to the next client to read from, if any
- socket_write($read_sock, "Server: Good bye.\n");
- socket_shutdown($read_sock, 2);
- socket_close($read_sock);
- continue;
- } elseif (in_array(trim($data), $shutdown)) {
- // Is he allowed to shutdown?
- if (!in_array($ip, $masters)) {
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
- socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
- $data = "";
- continue;
- }
-
- // Close all connections a leave here
- foreach ($clients as $client) {
- // Send message to client
- if ($client !== $mainSocket && $client != $read_sock) {
- socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
- }
-
- // Quit him
- socket_shutdown($client, 2);
- socket_close($client);
- } // end foreach
-
- // Leave the loop
- $data = "";
- $clients = array();
- continue;
- }
-
- // trim off the trailing/beginning white spaces
- $data = trim($data);
-
- // Test for HTML codes
- $tags = strip_tags($data);
-
- // check if there is any data after trimming off the spaces
- if (!empty($data) && $tags == $data && count($clients) > 2) {
- // Send confirmation to "chatter"
- socket_write($read_sock, "\nServer: Message accepted.\n");
-
- // send this to all the clients in the $clients array (except the first one, which is a listening socket)
- foreach ($clients as $send_sock) {
-
- // if its the listening sock or the client that we got the message from, go to the next one in the list
- if ($send_sock == $mainSocket || $send_sock == $read_sock) {
- continue;
- } // END - if
-
- // write the message to the client -- add a newline character to the end of the message
- socket_write($send_sock, "{$ip}:{$data}\n");
-
- } // end of broadcast foreach
- } elseif ($tags != $data) {
- // HTML codes are not allowed
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
- socket_write($read_sock, "Server: HTML is forbidden!\n");
- } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
- // No one else will hear the "chatter"
- out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
- socket_write($read_sock, "Server: No one will hear you!\n");
- }
- } // end of reading foreach
-}
-
-// close the listening socket
-socket_close($mainSocket);
-
-?>
-// Own namespace
-namespace Hub\Listener\;
-
-// Import application-specific stuff
-use Hub\Helper\Node\NodeHelper;
-use Hub\Listener\BaseListener;
-use Hub\Listener\Listenable;
-
-// Import framework stuff
-use CoreFramework\Visitor\Visitable;
-
-<?php
-/**
- * A TCP ??? listener
- *
- * @author Roland Haeder <webmaster@ship-simu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ???Listener extends BaseListener implements Listenable, Visitable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
- }
-
- /**
- * Creates an instance of this class
- *
- * @param $nodeInstance A NodeHelper instance
- * @return $listenerInstance An instance a prepared listener class
- */
- public final static function create???Listener (NodeHelper $nodeInstance) {
- // Get new instance
- $listenerInstance = new ???Listener();
-
- // Set the application instance
- $listenerInstance->setNodeInstance($nodeInstance);
-
- // Return the prepared instance
- return $listenerInstance;
- }
-
- /**
- * Initializes the listener by setting up the required socket server
- *
- * @return void
- * @todo 0% done
- */
- public function initListener() {
- $this->partialStub('Need to implement this method.');
- }
-
- /**
- * "Listens" for incoming network packages
- *
- * @return void
- * @todo 0% done
- */
- public function doListen() {
- $this->partialStub('Need to implement this method.');
- }
-}
-
-// [EOF]
-?>
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Network\RawData\Tcp;
-
-// Import application-specific stuff
-use Hub\Handler\Network\RawData\BaseRawDataHandler;
-use Hub\Network\Networkable;
-use Hub\Pool\Poolable;
-
-/**
- * A TCP raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('tcp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createTcpRawDataHandler () {
- // Get new instance
- $handlerInstance = new TcpRawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
- *
- * @param $resource A valid socket resource array
- * @return void
- */
- public function processRawDataFromResource (array $socketArray) {
- // Check the resource
- if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Reset error code to unhandled
- $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
-
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
-
- /*
- * Read the raw data from socket. If you change PHP_BINARY_READ to
- * PHP_NORMAL_READ, this line will endless block. This script does only
- * provide simultanous threads, not real.
- */
- $rawData = socket_read($socketArray[Poolable::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
-
- // Get socket error code back
- $this->lastSocketError = socket_last_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
-
- // Debug output of read data length
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
- //* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData=' . $rawData);
-
- // Is it valid?
- if ($this->lastSocketError == 11) {
- // Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
-
- /*
- * Error code 11 (Resource temporary unavailable) can be safely
- * ignored on non-blocking sockets. The socket is currently not
- * sending any data.
- */
- socket_clear_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
-
- // Skip any further processing
- return;
- } elseif (($rawData === FALSE) || ($this->lastSocketError > 0)) {
- // Network error or connection lost
- $this->setErrorCode($this->lastSocketError);
- } elseif (empty($rawData)) {
- // The peer did send nothing to us which is now being ignored
- return;
- } else {
- /*
- * All is fine at this point. So it is okay to add the raw data to
- * the stacker. Here it doesn't matter if the raw data is a
- * well-formed BASE64-encoded message with start and markers. This
- * will be checked later on.
- */
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Adding ' . strlen($rawData) . ' bytes to stacker ...');
- $this->addRawDataToStacker($rawData);
- }
- }
-
-}
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Network\RawData\Udp;
-
-// Import application-specific stuff
-use Hub\Handler\Network\RawData\BaseRawDataHandler;
-use Hub\Network\Networkable;
-use Hub\Pool\Poolable;
-
-/**
- * A UDP raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('udp');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function createUdpRawDataHandler () {
- // Get new instance
- $handlerInstance = new UdpRawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for UDP
- * package handling and is implemented in the UdpListener class
- *
- * @param $socketArray A valid socket resource array
- * @return void
- * @throws InvalidResourceException If the given resource is invalid
- * @todo 0%
- */
- public function processRawDataFromResource (array $socketArray) {
- // Check the resource
- if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Implement processing here
- $this->partialStub('Please implement this method. resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRRAY_CONN_TYPE]);
- }
-}
-
-// [EOF]
-?>
namespace Hub\Handler\Protocol;
// Import application-specific sutff
+use Hub\Handler\BaseHubHandler;
use Hub\Handler\Protocol\HandleableProtocol;
-use Hub\Locator\Node\LocateableNode;
use Hub\Tools\HubTools;
-// Import framework stuff
-use CoreFramework\Handler\BaseHandler;
-
/**
* A general handler for protocols such as TCP, UDP and others.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-abstract class BaseProtocolHandler extends BaseHandler implements HandleableProtocol {
- /**
- * Whole UNL instance
- */
- private $universalNodeLocatorInstance = NULL;
-
+abstract class BaseProtocolHandler extends BaseHubHandler implements HandleableProtocol {
/**
* Name of used protocol
*/
parent::__construct($className);
}
- /**
- * Setter for UNL instance
- *
- * @para $unlInstance An instance of a LocateableNode class
- * @return void
- */
- protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
- // Set new UNL data array
- $this->universalNodeLocatorInstance = $unlInstance;
- }
-
/**
* Validates given UNL very basicly by given regular expression. You
* normally don't need/want to overwrite this method as this is a very basic
$this->protocolName = $protocolName;
}
- /**
- * Getter for UNL instance
- *
- * @return $unlData An instance of a LocateableNode class
- */
- public final function getUniversalNodeLocatorInstance () {
- // Return UNL data array
- return $this->universalNodeLocatorInstance;
- }
-
/**
* Default implementation for returning address part, may not be suitable
* for IPv4/IPv6 protocol handlers. So you have to overwrite (NOT CHANGE!) this method.
<?php
// Own namespace
-namespace Hub\Handler\Network\;
+namespace Hub\Handler\Network\RawData;
// Import application-specific stuff
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
use Hub\Network\Networkable;
/**
- * A ??? network package handler
+ * A !!! raw data handler
*
- * @author Roland Haeder <webmaster@ship-simu.org>
+ * @author Roland Haeder <webmaster@shipsimu.org>
* @version 0.0.0
* @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
- * @link http://www.ship-simu.org
+ * @link http://www.shipsimu.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
* 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 ???NetworkPackageHandler extends BaseNetworkPackageHandler implements Networkable {
+class ???RawDataHandler extends BaseRawDataHandler implements Networkable {
/**
* Protected constructor
*
parent::__construct(__CLASS__);
// Set handler name
- $this->setHandlerName('!!!');
+ $this->setHandlerName('|||');
}
/**
* Creates an instance of this class
*
- * @return $handlerInstance An instance of a Networkable class
+ * @return $handlerInstance An instance of a Networkable class
*/
- public final static function create???NetworkPackageHandler () {
+ public static final function create???RawDataHandler () {
// Get new instance
- $handlerInstance = new ???NetworkPackageHandler();
+ $handlerInstance = new ???RawDataHandler();
// Return the prepared instance
return $handlerInstance;
}
/**
- * Processes a package from given resource. This is mostly useful for TCP
- * package handling and is implemented in the TcpListener class
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the ???Listener class
*
- * @param $resource A valid resource identifier
+ * @param $resource A valid socket resource array
* @return void
- * @throws InvalidResourceException If the given resource is invalid
- * @todo 0%
*/
- public function processResourcePackage ($resource) {
- // Check the resource
- if (!is_resource($resource)) {
- // Throw an exception
- throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
- } // END - if
-
- // Implement processing here
- $this->partialStub('Please implement this method.');
+ public function processRawDataFromResource (array $socketArray) {
}
}
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Data;
-
-// Import application-specific stuff
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Deliver\Deliverable;
-
-// Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Generic\FrameworkException;
-use CoreFramework\Handler\BaseHandler;
-
-/**
- * A general data Handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-abstract class BaseDataHandler extends BaseHandler {
- /**
- * Last exception instance from database layer or NULL (default)
- */
- private $lastException = NULL;
-
- /**
- * Array with search criteria elements
- */
- protected $searchData = array();
-
- /**
- * Array with all data XML nodes (which hold the actual data) and their values
- */
- protected $messageDataElements = array();
-
- /**
- * Array for translating message data elements (other node's data mostly)
- * into configuration elements.
- */
- protected $messageToConfig = array();
-
- /**
- * Array for copying configuration entries
- */
- protected $configCopy = array();
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
- }
-
- /**
- * Getter for search data array
- *
- * @return $searchData Search data array
- */
- public final function getSearchData () {
- return $this->searchData;
- }
-
- /**
- * Getter for last exception
- *
- * @return $lastException Last thrown exception
- */
- public final function getLastException () {
- return $this->lastException;
- }
-
- /**
- * Setter for last exception
- *
- * @param $lastException Last thrown exception
- * @return void
- */
- public final function setLastException (FrameworkException $exceptionInstance = NULL) {
- $this->lastException = $exceptionInstance;
- }
-
- /**
- * Prepares a message as answer for given message data for delivery.
- *
- * @param $messageData An array with all message data
- * @param $packageInstance An instance of a Deliverable instance
- * @return void
- */
- protected function prepareAnswerMessage (array $messageData, Deliverable $packageInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Going to send an answer message for ' . $this->getHandlerName() . ' ...');
-
- // Get a helper instance based on this handler's name
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_answer_' . $this->getHandlerName() . '_helper_class', array($messageData));
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Load descriptor XML
- $helperInstance->loadDescriptorXml($nodeInstance);
-
- /*
- * Set missing (temporary) configuration data, mostly it needs to be
- * copied from message data array.
- */
- $this->initMessageConfigurationData($messageData);
-
- // Compile any configuration variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // Deliver the package
- $helperInstance->sendPackage($nodeInstance);
-
- /*
- * Remove temporary configuration
- */
- $this->removeMessageConfigurationData($messageData);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Answer message has been prepared.');
- }
-
- /**
- * Prepares the next message
- *
- * @param $messageData An array with all message data
- * @param $packageInstance An instance of a Deliverable instance
- * @return void
- */
- protected function prepareNextMessage (array $messageData, Deliverable $packageInstance) {
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Going to send next message ...');
-
- // Get a helper instance based on this handler's name
- $helperInstance = ObjectFactory::createObjectByConfiguredName('node_next_' . $this->getHandlerName() . '_helper_class', array($messageData));
-
- // Get node instance
- $nodeInstance = NodeObjectFactory::createNodeInstance();
-
- // Load descriptor XML
- $helperInstance->loadDescriptorXml($nodeInstance);
-
- /*
- * Set missing (temporary) configuration data, mostly it needs to be
- * copied from message data array.
- */
- $this->initMessageConfigurationData($messageData);
-
- // Compile any configuration variables
- $helperInstance->getTemplateInstance()->compileConfigInVariables();
-
- // Deliver the package
- $helperInstance->sendPackage($nodeInstance);
-
- /*
- * Remove temporary configuration
- */
- $this->removeMessageConfigurationData($messageData);
-
- // Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('MESSAGE-HANDLER: Next message has been prepared.');
- }
-
- /**
- * Initializes configuration data from given message data array
- *
- * @param $messageData An array with all message data
- * @return void
- */
- abstract protected function initMessageConfigurationData (array $messageData);
-
- /**
- * Removes configuration data with given message data array from global
- * configuration
- *
- * @param $messageData An array with all message data
- * @return void
- */
- abstract protected function removeMessageConfigurationData (array $messageData);
-
-}
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Network\RawData;
+
+// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
+use Hub\Factory\Node\NodeObjectFactory;
+use Hub\Generic\HubInterface;
+use Hub\Handler\BaseHubHandler;
+use Hub\Network\Package\NetworkPackage;
+
+// Import framework stuff
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\UnsupportedOperationException;
+
+/**
+ * A general Handler for raw data from sockets
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 BaseRawDataHandler extends BaseHubHandler implements HubInterface {
+ // - Package errors
+ const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
+ const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
+ const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
+ const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
+ const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
+
+ // Package data
+ const PACKAGE_RAW_DATA = 'raw_data';
+ const PACKAGE_ERROR_CODE = 'error_code';
+
+ // Start/end marker
+ const STREAM_START_MARKER = '[[S]]';
+ const STREAM_END_MARKER = '[[E]]';
+
+ /**
+ * Stacker for raw data
+ */
+ const STACKER_NAME_RAW_DATA = 'raw_data';
+
+ /**
+ * Error code from socket
+ */
+ private $errorCode = -1;
+
+ /**
+ * Protected constructor
+ *
+ * @param $className Name of the class
+ * @return void
+ */
+ protected function __construct ($className) {
+ // Call parent constructor
+ parent::__construct($className);
+
+ // Set error code to 'unknown'
+ $this->setErrorCode(StorableSocket::SOCKET_ERROR_UNKNOWN);
+
+ // Init stacker instance for processed raw data
+ $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
+
+ // Remember this in this package handler
+ $this->setStackInstance($stackInstance);
+
+ // Init stacker
+ $this->initStack();
+ }
+
+ /**
+ * Initializes the stacker for raw data
+ *
+ * @return void
+ */
+ protected function initStack () {
+ $this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
+ }
+
+ /**
+ * Adds given raw data to the raw data stacker
+ *
+ * @param $rawData raw data from the socket resource
+ * @return void
+ */
+ protected function addRawDataToStacker ($rawData) {
+ /*
+ * Add the deocoded data and error code to the stacker so other classes
+ * (e.g. NetworkPackage) can "pop" it from the stacker.
+ */
+ $this->getStackInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array(
+ self::PACKAGE_RAW_DATA => $rawData,
+ self::PACKAGE_ERROR_CODE => $this->getErrorCode()
+ ));
+ }
+
+ /**
+ * Checks whether raw data is pending for further processing.
+ *
+ * @return $isPending Whether raw data is pending
+ */
+ public function isRawDataPending () {
+ // Does the stacker have some entries (not empty)?
+ $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
+
+ // Return it
+ return $isPending;
+ }
+
+ /**
+ * "Getter" for next raw data from the stacker
+ *
+ * @return $rawData Raw data from the stacker
+ */
+ public function getNextRawData () {
+ // "Pop" the raw data from the stacker
+ $rawData = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
+
+ // And return it
+ return $rawData;
+ }
+
+ /**
+ * Checks whether the 'recipient' field matches our own an universal node
+ * locator.
+ *
+ * @param $packageData Raw package data
+ * @return $matches Whether it matches
+ * @todo This method will be moved to a better place
+ */
+ protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
+ // Construct own address first
+ $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
+
+ // Does it match?
+ $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
+
+ // Return result
+ return $matches;
+ }
+
+ /**
+ * Setter for error code
+ *
+ * @param $errorCode The error code we shall set
+ * @return void
+ */
+ public final function setErrorCode ($errorCode) {
+ $this->errorCode = $errorCode;
+ }
+
+ /**
+ * Getter for error code
+ *
+ * @return $errorCode The error code
+ */
+ public final function getErrorCode () {
+ return $this->errorCode;
+ }
+
+}
+++ /dev/null
-Deny from all
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Network\RawData;
-
-// Import application-specific stuff
-use Hub\Handler\Network\RawData\BaseRawDataHandler;
-use Hub\Network\Networkable;
-
-/**
- * A !!! raw data handler
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 ???RawDataHandler extends BaseRawDataHandler implements Networkable {
- /**
- * Protected constructor
- *
- * @return void
- */
- protected function __construct () {
- // Call parent constructor
- parent::__construct(__CLASS__);
-
- // Set handler name
- $this->setHandlerName('|||');
- }
-
- /**
- * Creates an instance of this class
- *
- * @return $handlerInstance An instance of a Networkable class
- */
- public static final function create???RawDataHandler () {
- // Get new instance
- $handlerInstance = new ???RawDataHandler();
-
- // Return the prepared instance
- return $handlerInstance;
- }
-
- /**
- * Processes raw data from given resource. This is mostly useful for TCP
- * package handling and is implemented in the ???Listener class
- *
- * @param $resource A valid socket resource array
- * @return void
- */
- public function processRawDataFromResource (array $socketArray) {
- }
-
-}
+++ /dev/null
-<?php
-// Own namespace
-namespace Hub\Handler\Network\RawData;
-
-// Import application-specific stuff
-use Hub\Container\Socket\StorableSocket;
-use Hub\Factory\Node\NodeObjectFactory;
-use Hub\Network\Package\NetworkPackage;
-
-// Import framework stuff
-use CoreFramework\Factory\ObjectFactory;
-use CoreFramework\Handler\BaseHandler;
-
-/**
- * A general Handler for raw data from sockets
- *
- * @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Hub Developer Team
- * @license GNU GPL 3.0 or any newer version
- * @link http://www.shipsimu.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 BaseRawDataHandler extends BaseHandler {
- // - Package errors
- const PACKAGE_ERROR_INVALID_DATA = 'invalid_data'; // Invalid data in package found
- const PACKAGE_ERROR_INCOMPLETE_DATA = 'incomplete_data'; // Incomplete data sent (e.g. field is missing)
- const PACKAGE_ERROR_INVALID_CONTENT = 'invalid_content'; // Content is invalid (e.g. not well-formed)
- const PACKAGE_ERROR_RECIPIENT_MISMATCH = 'recipient_error'; // Recipient is not us
- const PACKAGE_LEVEL_CHECK_OKAY = 'checked_package'; // Package is fine
-
- // Package data
- const PACKAGE_RAW_DATA = 'raw_data';
- const PACKAGE_ERROR_CODE = 'error_code';
-
- // Start/end marker
- const STREAM_START_MARKER = '[[S]]';
- const STREAM_END_MARKER = '[[E]]';
-
- /**
- * Stacker for raw data
- */
- const STACKER_NAME_RAW_DATA = 'raw_data';
-
- /**
- * Error code from socket
- */
- private $errorCode = -1;
-
- /**
- * Protected constructor
- *
- * @param $className Name of the class
- * @return void
- */
- protected function __construct ($className) {
- // Call parent constructor
- parent::__construct($className);
-
- // Set error code to 'unknown'
- $this->setErrorCode(StorableSocket::SOCKET_ERROR_UNKNOWN);
-
- // Init stacker instance for processed raw data
- $stackInstance = ObjectFactory::createObjectByConfiguredName('node_raw_data_stacker_class');
-
- // Remember this in this package handler
- $this->setStackInstance($stackInstance);
-
- // Init stacker
- $this->initStack();
- }
-
- /**
- * Initializes the stacker for raw data
- *
- * @return void
- */
- protected function initStack () {
- $this->getStackInstance()->initStack(self::STACKER_NAME_RAW_DATA);
- }
-
- /**
- * Adds given raw data to the raw data stacker
- *
- * @param $rawData raw data from the socket resource
- * @return void
- */
- protected function addRawDataToStacker ($rawData) {
- /*
- * Add the deocoded data and error code to the stacker so other classes
- * (e.g. NetworkPackage) can "pop" it from the stacker.
- */
- $this->getStackInstance()->pushNamed(self::STACKER_NAME_RAW_DATA, array(
- self::PACKAGE_RAW_DATA => $rawData,
- self::PACKAGE_ERROR_CODE => $this->getErrorCode()
- ));
- }
-
- /**
- * Checks whether raw data is pending for further processing.
- *
- * @return $isPending Whether raw data is pending
- */
- public function isRawDataPending () {
- // Does the stacker have some entries (not empty)?
- $isPending = (!$this->getStackInstance()->isStackEmpty(self::STACKER_NAME_RAW_DATA));
-
- // Return it
- return $isPending;
- }
-
- /**
- * "Getter" for next raw data from the stacker
- *
- * @return $rawData Raw data from the stacker
- */
- public function getNextRawData () {
- // "Pop" the raw data from the stacker
- $rawData = $this->getStackInstance()->popNamed(self::STACKER_NAME_RAW_DATA);
-
- // And return it
- return $rawData;
- }
-
- /**
- * Checks whether the 'recipient' field matches our own an universal node
- * locator.
- *
- * @param $packageData Raw package data
- * @return $matches Whether it matches
- * @todo This method will be moved to a better place
- */
- protected function ifRecipientMatchesOwnUniversalNodeLocator (array $packageData) {
- // Construct own address first
- $ownAddress = NodeObjectFactory::createNodeInstance()->determineUniversalNodeLocator();
-
- // Does it match?
- $matches = ($ownAddress === $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
- // Return result
- return $matches;
- }
-
- /**
- * Setter for error code
- *
- * @param $errorCode The error code we shall set
- * @return void
- */
- public final function setErrorCode ($errorCode) {
- $this->errorCode = $errorCode;
- }
-
- /**
- * Getter for error code
- *
- * @return $errorCode The error code
- */
- public final function getErrorCode () {
- return $this->errorCode;
- }
-
-}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Network\Socket\RawData;
+
+// Import application-specific stuff
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Network\Networkable;
+
+/**
+ * A file-based socket raw data handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 SocketRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('socket');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createSocketRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new SocketRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the ???Listener class
+ *
+ * @param $resource A valid socket resource array
+ * @return void
+ */
+ public function processRawDataFromResource (array $socketArray) {
+ $this->partialStub('socketArray=' . print_r($socketArray, TRUE));
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+Deny from all
--- /dev/null
+while (count($clients) > 0) {
+ // create a copy, so $clients doesn't get modified by socket_select()
+ $read = $clients;
+
+ // get a list of all the clients that have data to be read from
+ // if there are no clients with data, go to next iteration
+ $left = @socket_select($read, $write = null, $except = null, 0, 150);
+ if ($left < 1) {
+ continue;
+ }
+
+ // check if there is a client trying to connect
+ if (in_array($mainSocket, $read)) {
+ // accept the client, and add him to the $clients array
+ $new_sock = socket_accept($mainSocket);
+ $clients[] = $new_sock;
+
+ // send the client a welcome message
+ socket_write($new_sock, "No noobs, but I'll make an exception. :)\n".
+ "There are ".(count($clients) - 1)." client(s) connected to the server.\n");
+
+ socket_getpeername($new_sock, $ip);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:New client connected: {$ip}");
+
+ // Notify all chatter
+ if (count($clients) > 2) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket && $send_sock != $new_sock) {
+ socket_write($send_sock, "Server: Chatter has joined from {$ip}. There are now ".(count($clients) - 1)." clients.\n");
+ }
+ }
+ }
+
+ // remove the listening socket from the clients-with-data array
+ $key = array_search($mainSocket, $read);
+ unset($read[$key]);
+ }
+
+ // loop through all the clients that have data to read from
+ foreach ($read as $read_sock) {
+ // Get client data
+ socket_getpeername($read_sock, $ip);
+
+ // read until newline or 1024 bytes
+ // socket_read while show errors when the client is disconnected, so silence the error messages
+ $data = @socket_read($read_sock, 1024, PHP_NORMAL_READ);
+
+ // check if the client is disconnected
+ if (($data === FALSE) || (in_array(strtolower(trim($data)), $leaving))) {
+
+ // remove client for $clients array
+ $key = array_search($read_sock, $clients);
+ unset($clients[$key]);
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client from {$ip} disconnected. Left: ".(count($clients) - 1)."");
+
+ // Notify all chatter
+ if (count($clients) > 1) {
+ foreach ($clients as $send_sock) {
+ if ($send_sock != $mainSocket) {
+ socket_write($send_sock, "Server: Chatter from {$ip} has logged out. ".(count($clients) - 1)." client(s) left.\n");
+ }
+ }
+ }
+
+ // continue to the next client to read from, if any
+ socket_write($read_sock, "Server: Good bye.\n");
+ socket_shutdown($read_sock, 2);
+ socket_close($read_sock);
+ continue;
+ } elseif (in_array(trim($data), $shutdown)) {
+ // Is he allowed to shutdown?
+ if (!in_array($ip, $masters)) {
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has tried to shutdown the server!");
+ socket_write($read_sock, "Server: You are not allowed to shutdown the server!\n");
+ $data = "";
+ continue;
+ }
+
+ // Close all connections a leave here
+ foreach ($clients as $client) {
+ // Send message to client
+ if ($client !== $mainSocket && $client != $read_sock) {
+ socket_write($client, "Server: Shutting down! Thank you for joining us.\n");
+ }
+
+ // Quit him
+ socket_shutdown($client, 2);
+ socket_close($client);
+ } // end foreach
+
+ // Leave the loop
+ $data = "";
+ $clients = array();
+ continue;
+ }
+
+ // trim off the trailing/beginning white spaces
+ $data = trim($data);
+
+ // Test for HTML codes
+ $tags = strip_tags($data);
+
+ // check if there is any data after trimming off the spaces
+ if (!empty($data) && $tags == $data && count($clients) > 2) {
+ // Send confirmation to "chatter"
+ socket_write($read_sock, "\nServer: Message accepted.\n");
+
+ // send this to all the clients in the $clients array (except the first one, which is a listening socket)
+ foreach ($clients as $send_sock) {
+
+ // if its the listening sock or the client that we got the message from, go to the next one in the list
+ if ($send_sock == $mainSocket || $send_sock == $read_sock) {
+ continue;
+ } // END - if
+
+ // write the message to the client -- add a newline character to the end of the message
+ socket_write($send_sock, "{$ip}:{$data}\n");
+
+ } // end of broadcast foreach
+ } elseif ($tags != $data) {
+ // HTML codes are not allowed
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} has entered HTML code!");
+ socket_write($read_sock, "Server: HTML is forbidden!\n");
+ } elseif ((count($clients) == 2) && ($read_sock != $mainSocket)) {
+ // No one else will hear the "chatter"
+ out(__FILE__, __LINE__, '['.date('m/d/Y:H:i:s', time())."]:Client {$ip} speaks with himself.");
+ socket_write($read_sock, "Server: No one will hear you!\n");
+ }
+ } // end of reading foreach
+}
+
+// close the listening socket
+socket_close($mainSocket);
+
+?>
+// Own namespace
+namespace Hub\Listener\;
+
+// Import application-specific stuff
+use Hub\Helper\Node\NodeHelper;
+use Hub\Listener\BaseListener;
+use Hub\Listener\Listenable;
+
+// Import framework stuff
+use CoreFramework\Visitor\Visitable;
+
+<?php
+/**
+ * A TCP ??? listener
+ *
+ * @author Roland Haeder <webmaster@ship-simu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 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 ???Listener extends BaseListener implements Listenable, Visitable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @param $nodeInstance A NodeHelper instance
+ * @return $listenerInstance An instance a prepared listener class
+ */
+ public final static function create???Listener (NodeHelper $nodeInstance) {
+ // Get new instance
+ $listenerInstance = new ???Listener();
+
+ // Set the application instance
+ $listenerInstance->setNodeInstance($nodeInstance);
+
+ // Return the prepared instance
+ return $listenerInstance;
+ }
+
+ /**
+ * Initializes the listener by setting up the required socket server
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function initListener() {
+ $this->partialStub('Need to implement this method.');
+ }
+
+ /**
+ * "Listens" for incoming network packages
+ *
+ * @return void
+ * @todo 0% done
+ */
+ public function doListen() {
+ $this->partialStub('Need to implement this method.');
+ }
+}
+
+// [EOF]
+?>
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Network\RawData\Tcp;
+
+// Import application-specific stuff
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Network\Networkable;
+use Hub\Pool\Poolable;
+
+/**
+ * A TCP raw data handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 TcpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('tcp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createTcpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new TcpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for TCP
+ * package handling and is implemented in the TcpListener class
+ *
+ * @param $resource A valid socket resource array
+ * @return void
+ */
+ public function processRawDataFromResource (array $socketArray) {
+ // Check the resource
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Reset error code to unhandled
+ $this->setErrorCode(self::SOCKET_ERROR_UNHANDLED);
+
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Handling TCP package from resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRAY_CONN_TYPE] . ',last error=' . socket_strerror($this->lastSocketError));
+
+ /*
+ * Read the raw data from socket. If you change PHP_BINARY_READ to
+ * PHP_NORMAL_READ, this line will endless block. This script does only
+ * provide simultanous threads, not real.
+ */
+ $rawData = socket_read($socketArray[Poolable::SOCKET_ARRAY_INSTANCE], $this->getConfigInstance()->getConfigEntry('tcp_buffer_length'), PHP_BINARY_READ);
+
+ // Get socket error code back
+ $this->lastSocketError = socket_last_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+
+ // Debug output of read data length
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData[' . gettype($rawData) . ']=' . strlen($rawData) . ',MD5=' . md5($rawData) . ',resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',error=' . socket_strerror($this->lastSocketError));
+ //* NOISY-DEBUG: */ if ($rawData !== FALSE) self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: rawData=' . $rawData);
+
+ // Is it valid?
+ if ($this->lastSocketError == 11) {
+ // Debug message
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Ignoring error 11 (Resource temporary unavailable) from socket resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+
+ /*
+ * Error code 11 (Resource temporary unavailable) can be safely
+ * ignored on non-blocking sockets. The socket is currently not
+ * sending any data.
+ */
+ socket_clear_error($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]);
+
+ // Skip any further processing
+ return;
+ } elseif (($rawData === FALSE) || ($this->lastSocketError > 0)) {
+ // Network error or connection lost
+ $this->setErrorCode($this->lastSocketError);
+ } elseif (empty($rawData)) {
+ // The peer did send nothing to us which is now being ignored
+ return;
+ } else {
+ /*
+ * All is fine at this point. So it is okay to add the raw data to
+ * the stacker. Here it doesn't matter if the raw data is a
+ * well-formed BASE64-encoded message with start and markers. This
+ * will be checked later on.
+ */
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__, __LINE__)->debugOutput('TCP-HANDLER: Adding ' . strlen($rawData) . ' bytes to stacker ...');
+ $this->addRawDataToStacker($rawData);
+ }
+ }
+
+}
--- /dev/null
+Deny from all
--- /dev/null
+<?php
+// Own namespace
+namespace Hub\Handler\Network\RawData\Udp;
+
+// Import application-specific stuff
+use Hub\Handler\Network\RawData\BaseRawDataHandler;
+use Hub\Network\Networkable;
+use Hub\Pool\Poolable;
+
+/**
+ * A UDP raw data handler
+ *
+ * @author Roland Haeder <webmaster@shipsimu.org>
+ * @version 0.0.0
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
+ * @license GNU GPL 3.0 or any newer version
+ * @link http://www.shipsimu.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 UdpRawDataHandler extends BaseRawDataHandler implements Networkable {
+ /**
+ * Protected constructor
+ *
+ * @return void
+ */
+ protected function __construct () {
+ // Call parent constructor
+ parent::__construct(__CLASS__);
+
+ // Set handler name
+ $this->setHandlerName('udp');
+ }
+
+ /**
+ * Creates an instance of this class
+ *
+ * @return $handlerInstance An instance of a Networkable class
+ */
+ public static final function createUdpRawDataHandler () {
+ // Get new instance
+ $handlerInstance = new UdpRawDataHandler();
+
+ // Return the prepared instance
+ return $handlerInstance;
+ }
+
+ /**
+ * Processes raw data from given resource. This is mostly useful for UDP
+ * package handling and is implemented in the UdpListener class
+ *
+ * @param $socketArray A valid socket resource array
+ * @return void
+ * @throws InvalidResourceException If the given resource is invalid
+ * @todo 0%
+ */
+ public function processRawDataFromResource (array $socketArray) {
+ // Check the resource
+ if ((!isset($socketArray[Poolable::SOCKET_ARRAY_INSTANCE])) || (!is_resource($socketArray[Poolable::SOCKET_ARRAY_INSTANCE]))) {
+ // Throw an exception
+ throw new InvalidResourceException($this, self::EXCEPTION_INVALID_RESOURCE);
+ } // END - if
+
+ // Implement processing here
+ $this->partialStub('Please implement this method. resource=' . $socketArray[Poolable::SOCKET_ARRAY_INSTANCE] . ',type=' . $socketArray[Poolable::SOCKET_ARRRAY_CONN_TYPE]);
+ }
+}
+
+// [EOF]
+?>
namespace Hub\Helper\Connection;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Fragmenter\FragmenterFactory;
use Hub\Factory\Network\NetworkPackageFactory;
use Hub\Factory\State\Peer\PeerStateFactory;
*/
public final function __toString () {
// Class name representation
- $class = self::getConnectionClassName($this->getSocketInstance(), parent::__toString());
+ $class = self::getConnectionClassNameFromSocket($this->getSocketInstance(), parent::__toString());
// Return it
return $class;
/**
* Static "getter" for this connection class' name
*
- * @param $address IP address
- * @param $port Port number
- * @param $className Original class name
+ * @param $socketInstance An instance of a StorableSocket class
* @return $class Expanded class name
*/
- public static function getConnectionClassName ($address, $port, $className) {
+ public static function getConnectionClassNameFromSocket (StorableSocket $socketInstance) {
+ die(__METHOD__.':socketInstance='.print_r($socketInstance, TRUE));
// Construct it
$class = $address . ':' . $port . ':' . $className;
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\Network\NetworkPackageFactory;
use Hub\Listener\Listenable;
+use Hub\Locator\Node\LocateableNode;
use Hub\Network\Networkable;
// Import framework stuff
use CoreFramework\Generic\BaseDecorator;
+use CoreFramework\Generic\UnsupportedOperationException;
use CoreFramework\Visitor\Visitable;
use CoreFramework\Visitor\Visitor;
$this->protocolName = $protocolName;
}
+ /**
+ * Setter for UNL instance
+ *
+ * @para $unlInstance An instance of a LocateableNode class
+ * @return void
+ * @throws UnsupportedOperationException If this method is called
+ */
+ protected final function setUniversalNodeLocatorInstance (LocateableNode $unlInstance) {
+ throw new UnsupportedOperationException('This method should not be called.');
+ }
+
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlData An instance of a LocateableNode class
+ * @throws UnsupportedOperationException If this method is called
+ */
+ public final function getUniversalNodeLocatorInstance () {
+ throw new UnsupportedOperationException('This method should not be called.');
+ }
+
}
use Hub\Container\Socket\StorableSocket;
use Hub\Factory\State\Peer\PeerStateFactory;
use Hub\Helper\Connection\ConnectionHelper;
+use Hub\Resolver\State\BaseStateResolver;
+use Hub\Resolver\State\StateResolver;
// Import framework stuff
use CoreFramework\Socket\InvalidSocketException;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
// Return the prepared instance
return $stateInstance;
}
-}
-// [EOF]
-?>
+}
$cfg->setConfigEntry('node_dht_list_limit', 20);
// CFG: PEER-LOOKUP-DB-WRAPPER-CLASS
-$cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'PeerStateLookupDatabaseWrapper');
+$cfg->setConfigEntry('peer_state_lookup_db_wrapper_class', 'Hub\Database\Frontend\Node\PeerState\PeerStateLookupDatabaseWrapper');
// CFG: WEB-CONTENT-TYPE
$cfg->setConfigEntry('web_content_type', '');
*/
function getSocketInstance ();
+ /**
+ * Getter for UNL instance
+ *
+ * @return $unlInstance An instance of a LocateableNode class
+ */
+ function getUniversalNodeLocatorInstance ();
+
}
namespace Hub\AnswerStatus\Node;
// Import application-specific stuff
+use Hub\Generic\HubInterface;
use Hub\Network\Receive\Receivable;
// Import framework stuff
* 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 HandleableAnswerStatus extends HandleableDataSet {
+interface HandleableAnswerStatus extends HandleableDataSet, HubInterface {
/**
* Handles given message data array
*
* @return void
*/
function addArrayToDataSet (StoreableCriteria $dataSetInstance, array $messageData);
-}
-// [EOF]
-?>
+}
// Own namespace
namespace Hub\Handler\Network\RawData\Chunks;
+// Import application-specific stuff
+use Hub\Generic\HubInterface;
+
// Import framework stuff
use CoreFramework\Handler\Handleable;
* 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 HandleableChunks extends Handleable {
+interface HandleableChunks extends Handleable, HubInterface {
/**
* Adds all chunks if the last one verifies as a 'final chunk'.
*
* @return void
*/
function handledAssembledRawPackageData ();
-}
-// [EOF]
-?>
+}
namespace Hub\Handler\Message;
// Import application-specific stuff
+use Hub\Generic\HubInterface;
use Hub\Network\Receive\Receivable;
// Import framework stuff
* 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 HandleableMessage extends HandleableDataSet {
+interface HandleableMessage extends HandleableDataSet, HubInterface {
/**
* Handles data array of the message
*
* @return void
*/
function postHandleMessageData (array $messageData, Receivable $packageInstance);
-}
-// [EOF]
-?>
+}
// Own namespace
namespace Hub\Network;
+// Import application-specific stuff
+use Hub\Generic\HubInterface;
+
// Import framework stuff
use CoreFramework\Handler\DataSet\HandleableDataSet;
* 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 Networkable extends HandleableDataSet {
+interface Networkable extends HandleableDataSet, HubInterface {
/**
* Processes raw data from given resource. This is mostly useful for TCP
* package handling and is implemented in the TcpListener class
* @return $decodedData Raw data from the stacker
*/
function getNextRawData ();
-}
-// [EOF]
-?>
+}
// Own namespace
namespace Hub\Handler\Protocol;
+// Import application-specific stuff
+use Hub\Generic\HubInterface;
+
// Import framework stuff
use CoreFramework\Handler\Handleable;
* 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 HandleableProtocol extends Handleable {
- /**
- * Getter for UNL instance
- *
- * @return $unlInstance An instance of a LocateableNode class
- */
- function getUniversalNodeLocatorInstance ();
-
+interface HandleableProtocol extends Handleable, HubInterface {
/**
* Getter for port number to satify HandleableProtocol
*
namespace Hub\Helper\Connection;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Helper\HubHelper;
/**
/**
* Static "getter" for this connection class' name
*
- * @param $address IP address
- * @param $port Port number
- * @param $className Original class name
+ * @param $socketInstance An instance of a StorableSocket class
* @return $class Expanded class name
*/
- static function getConnectionClassName ($address, $port, $className);
+ static function getConnectionClassNameFromSocket (StorableSocket $socketInstance);
/**
* Getter for shuttedDown
<?php
+// Own namespace
+namespace Hub\State\Node\Lookup;
+
+// Import application-specific stuff
+use Hub\LookupTable\Lookupable;
+
/**
* An interface for node-state lookup tables
*
*/
interface LookupableNodeState extends Lookupable {
}
-
-// [EOF]
-?>
// Import application-specific stuff
use Hub\Container\Socket\StorableSocket;
use Hub\Helper\Connection\ConnectionHelper;
+use Hub\LookupTable\Lookupable;
+use Hub\State\Peer\PeerStateable;
// Import framework stuff
use CoreFramework\State\Stateable;
/**
* Purges old entries of given socket resource. We use the IP address from that resource.
*
- * @param $socketResource A valid socket resource
+ * @param $socketInstance An instance of a StorableSocket class
* @return void
*/
- function purgeOldEntriesBySocketResource ($socketResource);
+ function purgeOldEntriesBysocketInstance (StorableSocket $socketInstance);
/**
* Checks whether a given peer state (in helper instance) is same as stored
* @return $isSamePeerState Whether the peer's state is the same
*/
function isSamePeerState (ConnectionHelper $helperInstance, array $packageData);
-}
-// [EOF]
-?>
+}
namespace Hub\Resolver\State;
// Import application-specific stuff
+use Hub\Container\Socket\StorableSocket;
use Hub\Helper\Connection\ConnectionHelper;
// Import framework stuff
*
* @param $helperInstance An instance of a ConnectionHelper class
* @param $packageData Raw package data
- * @param $socketResource A valid socket resource
+ * @param $socketInstance An instance of a StorableSocket class
* @return $stateInstance An instance of the resolved state
*/
- static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, $socketResource);
+ static function resolveStateByPackage (ConnectionHelper $helperInstance, array $packageData, StorableSocket $socketInstance);
/**
* Checks whether the given state is valid
*/
interface PeerStateable extends Stateable {
}
-
-// [EOF]
-?>