]> git.mxchange.org Git - hub.git/commitdiff
Added missing exceptions + updated some text + renamed (still unimplemented) method.
authorRoland 'Quix0r' Haeder <roland@mxchange.org>
Thu, 20 Feb 2014 22:01:46 +0000 (23:01 +0100)
committerRoland 'Quix0r' Haeder <roland@mxchange.org>
Thu, 20 Feb 2014 22:01:46 +0000 (23:01 +0100)
Signed-off-by: Roland 'Quix0r' Haeder <roland@mxchange.org>
application/hub/exceptions/dht/.htaccess [new file with mode: 0644]
application/hub/exceptions/dht/class_DhtBootstrapNotAcceptedException.php [new file with mode: 0644]
application/hub/exceptions/dht/class_NoDhtBootstrapAttemptedException.php [new file with mode: 0644]
application/hub/main/handler/message-types/dht/class_NodeMessageDhtBootstrapHandler.php

diff --git a/application/hub/exceptions/dht/.htaccess b/application/hub/exceptions/dht/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..d44b29a
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * This exception is thrown when a DHT bootstrap request from other nodes was
+ * received but this node doesn't accept such requests.
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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 (file)
index 0000000..32b2946
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * This exception is thrown when an DHT bootstrap answer comes but this node
+ * didn't send out such request.
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 5b99b1116577f3022db4eb91db15b67fb48cc192..7804a8817b71945932676cba2be320d35f9407cc 100644 (file)
@@ -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