From: Roland 'Quix0r' Haeder Date: Thu, 20 Feb 2014 22:01:46 +0000 (+0100) Subject: Added missing exceptions + updated some text + renamed (still unimplemented) method. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9b62346fe8256eed19e4b85f4cdd73cc69628c01;p=hub.git Added missing exceptions + updated some text + renamed (still unimplemented) method. Signed-off-by: Roland 'Quix0r' Haeder --- diff --git a/application/hub/exceptions/dht/.htaccess b/application/hub/exceptions/dht/.htaccess new file mode 100644 index 000000000..3a4288278 --- /dev/null +++ b/application/hub/exceptions/dht/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php new file mode 100644 index 000000000..d44b29a25 --- /dev/null +++ b/application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php @@ -0,0 +1,53 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 . + */ +class DhtBootstrapNotAcceptedException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageArray, $code) { + // Construct the message + $message = sprintf('[%s:%d] This node (%s) is not accepting DHT bootstrap requests, but got one from session-id=%s,ip=%s/%s,listen port=%s,status=%s,mode=%s', + $messageArray[0]->__toString(), + $this->getLine(), + $messageArray[1]->__toString(), + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID], + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_IP], + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_IP], + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT], + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS], + $messageArray[2][XmlDhtBootstrapTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_MODE] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/application/hub/exceptions/dht/class_NoDhtBootstrapAttemptedException.php b/application/hub/exceptions/dht/class_NoDhtBootstrapAttemptedException.php new file mode 100644 index 000000000..32b294678 --- /dev/null +++ b/application/hub/exceptions/dht/class_NoDhtBootstrapAttemptedException.php @@ -0,0 +1,52 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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 . + */ +class NoDhtBootstrapAttemptedException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $messageArray Error message array + * @param $code Error code + * @return void + */ + public function __construct (array $messageArray, $code) { + // Construct the message + $message = sprintf('[%s:%d] This node (%s) has not attempted to bootstrap its DHT, but got an answer from session-id=%s,ip=%s/%s,listen port=%s,status=%s.', + $messageArray[0]->__toString(), + $this->getLine(), + $messageArray[1]->__toString(), + $messageArray[2][XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_SESSION_ID], + $messageArray[2][XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_EXTERNAL_IP], + $messageArray[2][XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_INTERNAL_IP], + $messageArray[2][XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_LISTEN_PORT], + $messageArray[2][XmlDhtBootstrapAnswerTemplateEngine::DHT_BOOTSTRAP_DATA_NODE_STATUS] + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php index 5b99b1116..7804a8817 100644 --- a/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php +++ b/application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php @@ -32,7 +32,7 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl parent::__construct(__CLASS__); // Set handler name - $this->setHandlerName('message_announcement'); + $this->setHandlerName('message_dht_bootstrap'); // Init message data array $this->messageDataElements = array( @@ -85,22 +85,21 @@ class NodeMessageDhtBootstrapHandler extends BaseMessageHandler implements Handl * @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 announcements + * @throws DhtBootstrapNotAcceptedException If this node does not accept DHT bootstrap requests */ public function handleMessageData (array $messageData, Receivable $packageInstance) { // Get node instance $nodeInstance = Registry::getRegistry()->getInstance('node'); - // Is this node accepting announcements? - if (!$nodeInstance->isAcceptingDhtBootstraps()) { + // Is this node accepting DHT bootstrap requests? + if (!$nodeInstance->isAcceptingDhtBootstrap()) { /* - * This node is not accepting announcements, then someone wants to - * announce his node to a non-bootstrap and non-master node. + * This node is not accepting DHT bootstrap requests. */ throw new DhtBootstrapNotAcceptedException(array($this, $nodeInstance, $messageData), self::EXCEPTION_DHT_BOOTSTRAP_NOT_ACCEPTED); } // END - if - // Register the announcing node with this node + // Register the DHT bootstrap requesting node with this node $this->registerNodeByMessageData($messageData); // Prepare answer message to be delivered back to the other node