]> git.mxchange.org Git - hub.git/commitdiff
Introduced Recipient implentation classes:
authorRoland Häder <roland@mxchange.org>
Mon, 18 Feb 2013 05:49:14 +0000 (05:49 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 18 Feb 2013 05:49:14 +0000 (05:49 +0000)
- DirectRecipient: A direct session id that needs solving into an ip:port
  combination
- DhtRecipient: A virtual recipient that will cause querying the local DHT
  data for possible recipients (unfinished)
- SelfRecipient: A virtual recipient, yet direct one, as this will be resolved
  into *this* own node's session id
- UpperRecipient A virtual recipient for all boot, master and list node's
  session ids
- Internal TODO for above closed (and nicely solved)

18 files changed:
.gitattributes
application/hub/config.php
application/hub/interfaces/queues/class_Queueable.php
application/hub/interfaces/recipient/.htaccess [new file with mode: 0644]
application/hub/interfaces/recipient/class_Recipient.php [new file with mode: 0644]
application/hub/main/discovery/package/class_PackageRecipientDiscovery.php
application/hub/main/recipient/.htaccess [new file with mode: 0644]
application/hub/main/recipient/class_ [new file with mode: 0644]
application/hub/main/recipient/class_BaseRecipient.php [new file with mode: 0644]
application/hub/main/recipient/dht/.htaccess [new file with mode: 0644]
application/hub/main/recipient/dht/class_DhtRecipient.php [new file with mode: 0644]
application/hub/main/recipient/direct/.htaccess [new file with mode: 0644]
application/hub/main/recipient/direct/class_DirectRecipient.php [new file with mode: 0644]
application/hub/main/recipient/self/.htaccess [new file with mode: 0644]
application/hub/main/recipient/self/class_SelfRecipient.php [new file with mode: 0644]
application/hub/main/recipient/upper/.htaccess [new file with mode: 0644]
application/hub/main/recipient/upper/class_UpperRecipient.php [new file with mode: 0644]
application/hub/main/states/dht/class_BaseDhtState.php

index c3652a7fdb15edd665c7c00738e5fa8de7affb7d..e366d7bf87b2448acdffecc6a897bd8425ba1578 100644 (file)
@@ -127,6 +127,8 @@ application/hub/interfaces/query/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/query/class_Queryable.php svneol=native#text/plain
 application/hub/interfaces/queues/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/queues/class_Queueable.php svneol=native#text/plain
+application/hub/interfaces/recipient/.htaccess -text svneol=unset#text/plain
+application/hub/interfaces/recipient/class_Recipient.php svneol=native#text/plain
 application/hub/interfaces/socket/.htaccess -text svneol=unset#text/plain
 application/hub/interfaces/socket/class_SocketTag.php svneol=native#text/plain
 application/hub/interfaces/source/.htaccess svneol=native#text/plain
@@ -543,6 +545,16 @@ application/hub/main/queues/class_ svneol=native#text/plain
 application/hub/main/queues/class_BaseQueue.php svneol=native#text/plain
 application/hub/main/queues/peer/.htaccess -text svneol=unset#text/plain
 application/hub/main/queues/peer/class_LocalPeerQueue.php svneol=native#text/plain
+application/hub/main/recipient/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/class_ svneol=native#text/plain
+application/hub/main/recipient/dht/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/dht/class_DhtRecipient.php svneol=native#text/plain
+application/hub/main/recipient/direct/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/direct/class_DirectRecipient.php svneol=native#text/plain
+application/hub/main/recipient/self/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/self/class_SelfRecipient.php svneol=native#text/plain
+application/hub/main/recipient/upper/.htaccess -text svneol=unset#text/plain
+application/hub/main/recipient/upper/class_UpperRecipient.php svneol=native#text/plain
 application/hub/main/registry/.htaccess -text svneol=unset#text/plain
 application/hub/main/registry/connection/.htaccess -text svneol=unset#text/plain
 application/hub/main/registry/connection/class_ConnectionRegistry.php svneol=native#text/plain
index 6f88c44399693f2bf34375aa214f0ac4bfabeb0d..ce328572f65bcfde07198823527fb55a6c11eb54 100644 (file)
@@ -802,6 +802,22 @@ $cfg->setConfigEntry('announcement_answer_status_okay_handler_class', 'Announcem
 // CFG: REQUEST-NODE-LIST-ANSWER-STATUS-OKAY-HANDLER-CLASS
 $cfg->setConfigEntry('request_node_list_answer_status_okay_handler_class', 'RequestNodeListAnswerOkayHandler');
 
+///////////////////////////////////////////////////////////////////////////////
+//                          Recipient resolver
+///////////////////////////////////////////////////////////////////////////////
+
+// CFG: DIRECT-RECIPIENT-CLASS
+$cfg->setConfigEntry('direct_recipient_class', 'DirectRecipient');
+
+// CFG: DHT-RECIPIENT-CLASS
+$cfg->setConfigEntry('dht_recipient_class', 'DhtRecipient');
+
+// CFG: SELF-RECIPIENT-CLASS
+$cfg->setConfigEntry('self_recipient_class', 'SelfRecipient');
+
+// CFG: UPPER-RECIPIENT-CLASS
+$cfg->setConfigEntry('upper_recipient_class', 'UpperRecipient');
+
 ///////////////////////////////////////////////////////////////////////////////
 //                        Cruncher configuration
 ///////////////////////////////////////////////////////////////////////////////
index 3064de590b45db728229ec5131d8b74d915489dc..f551ef47b7591c74e7b59193e56a1fa6505a87ab 100644 (file)
@@ -1,28 +1,3 @@
 <?php
-/**
- * An interface for queues
- *
- * @author             Roland Haeder <webmaster@ship-simu.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.ship-simu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-interface Queueable extends FrameworkInterface {
-}
-
-// [EOF]
+// @DEPRECATED
 ?>
diff --git a/application/hub/interfaces/recipient/.htaccess b/application/hub/interfaces/recipient/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/interfaces/recipient/class_Recipient.php b/application/hub/interfaces/recipient/class_Recipient.php
new file mode 100644 (file)
index 0000000..96e7796
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * An interface for recipients
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.ship-simu.org
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Recipient extends FrameworkInterface {
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        */
+       function resolveRecipient ($recipient, Listable $listInstance);
+}
+
+// [EOF]
+?>
index 6bd982d83f09c8bb33a4930b8974dc469c2a6eb4..5567d36ed280b68c6afa7794e2f4c7aa38f5bc76 100644 (file)
@@ -57,75 +57,28 @@ class PackageRecipientDiscovery extends BaseHubDiscovery implements Discoverable
         *
         * @param       $packageData    Raw package data array
         * @return      void
-        * @todo        Find a better way than this switch/case/default thing
         */
        public function discoverRecipients (array $packageData) {
-               // We do some rudimentary checks but this might be a bit ugly
-               switch ($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) {
-                       case NetworkPackage::NETWORK_TARGET_UPPER_NODES: // All upper hubs, these are currently the bootstrap nodes and later on prepended list-nodes
-                               // Get all bootstrap nodes
-                               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
-                                       // Is maximum reached?
-                                       if ($this->getListInstance()->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
-                                               // Debug message
-                                               /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
-
-                                               // Then stop adding more
-                                               break;
-                                       } // END - if
-
-                                       // Debug message
-                                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('DISCOVERY: Adding node ' . $ipPort . ' as recipient.');
-
-                                       // Add the entry
-                                       $this->getListInstance()->addEntry('ip_port', $ipPort);
-                               } // END - foreach
-                               break;
-
-                       case NetworkPackage::NETWORK_TARGET_SELF: // The target 'self' is always the external IP address!
-                               // Determine own port
-                               $port = $this->getConfigInstance()->getConfigEntry('node_listen_port');
-
-                               // Determine IP or 'external_ip' if set
-                               $ip = HubTools::determineOwnExternalIp();
-
-                               // Is it not empty?
-                               if (!empty($ip)) {
-                                       // Add it to the list
-                                       $this->getListInstance()->addEntry('ip_port', $ip . ':' . $port);
-                               } // END - if
-                               break;
-
-                       case NetworkPackage::NETWORK_TARGET_DHT: // The target 'dht' is a list from local DHT query
-                               $this->partialStub('DHT recipient unimplemented: packageData=' . print_r($packageData, true));
-                               break;
-
-                       default: // This may be a direct recipient (node's session id)
-                               /*
-                                * Try to solve it, if an exception comes back, it is not a
-                                * session-id, nor IP:port and not a hostname:port combination.
-                                */
-                               try {
-                                       // "Explode" all recipients
-                                       $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]);
-
-                                       // Is maximum reached?
-                                       assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
-
-                                       // Try it on all
-                                       foreach ($recipients as $recipient) {
-                                               // Try to sole a single recipient
-                                               $ipPort = HubTools::resolveSessionId($recipient);
-
-                                               // Add it as recipient
-                                               $this->getListInstance()->addEntry('ip_port', $ipPort);
-                                       } // END - foreach
-                               } catch (FrameworkException $e) {
-                                       // Didn't work, pleace add more code
-                                       $this->partialStub('Please add code handling recipients ' . $packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT] . ',packageData=' . print_r($packageData, true) . ',exception=' . $e->__toString() . ',message=' . $e->getMessage());
-                               }
-                               break;
-               } // END - switch
+               // First try out the direct recipient (session id)
+               try {
+                       // Get instance (should not break)
+                       $recipientInstance = ObjectFactory::createObjectByConfiguredName('direct_recipient_class');
+
+                       // Try to solve it
+                       $recipientInstance->resolveRecipient($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT], $this->getListInstance());
+               } catch (FrameworkException $e) {
+                       // Didn't work, so try the non-generic, depending recipient field itself (this may fail)
+                       try {
+                               // Try to find the right class
+                               $recipientInstance = ObjectFactory::createObjectByConfiguredName(strtolower($packageData[NetworkPackage::PACKAGE_DATA_RECIPIENT]) . '_recipient_class');
+
+                               // And try to solve again
+                               $recipientInstance->resolveRecipient('', $this->getListInstance());
+                       } catch (FrameworkException $e) {
+                               // Could not find class, what ever failed
+                               $this->debugInstance($e->getMessage());
+                       }
+               }
        }
 
        /**
diff --git a/application/hub/main/recipient/.htaccess b/application/hub/main/recipient/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/recipient/class_ b/application/hub/main/recipient/class_
new file mode 100644 (file)
index 0000000..7669560
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A ??? recipient
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 ???Recipient extends BaseRecipient implements Recipient {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $recipientInstance              An instance of a Recipient class
+        */
+       public final static function create???Recipient () {
+               // Get new instance
+               $recipientInstance = new ???Recipient();
+
+               // Return the prepared instance
+               return $recipientInstance;
+       }
+
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        * @todo        0% done
+        */
+       public function resolveRecipient ($recipient, Listable $listInstance) {
+               $this->partialStub('Please implement this method. recipient=' . $recipient);
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/recipient/class_BaseRecipient.php b/application/hub/main/recipient/class_BaseRecipient.php
new file mode 100644 (file)
index 0000000..f6a7a05
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general Recipient class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 BaseRecipient extends BaseHubSystem {
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/recipient/dht/.htaccess b/application/hub/main/recipient/dht/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php
new file mode 100644 (file)
index 0000000..328de54
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/**
+ * A DHT recipient
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 DhtRecipient extends BaseRecipient implements Recipient {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $recipientInstance              An instance of a Recipient class
+        */
+       public final static function createDhtRecipient () {
+               // Get new instance
+               $recipientInstance = new DhtRecipient();
+
+               // Return the prepared instance
+               return $recipientInstance;
+       }
+
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        * @todo        0% done
+        */
+       public function resolveRecipient ($recipient, Listable $listInstance) {
+               $this->partialStub('Please implement this method. recipient=' . $recipient);
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/recipient/direct/.htaccess b/application/hub/main/recipient/direct/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/recipient/direct/class_DirectRecipient.php b/application/hub/main/recipient/direct/class_DirectRecipient.php
new file mode 100644 (file)
index 0000000..e3be9d8
--- /dev/null
@@ -0,0 +1,76 @@
+<?php
+/**
+ * A Direct recipient
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 DirectRecipient extends BaseRecipient implements Recipient {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $recipientInstance              An instance of a Recipient class
+        */
+       public final static function createDirectRecipient () {
+               // Get new instance
+               $recipientInstance = new DirectRecipient();
+
+               // Return the prepared instance
+               return $recipientInstance;
+       }
+
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        */
+       public function resolveRecipient ($recipient, Listable $listInstance = NULL) {
+               // "Explode" all recipients
+               $recipients = explode(NetworkPackage::PACKAGE_RECIPIENT_SEPARATOR, $recipient);
+
+               // Is maximum reached?
+               assert(count($recipients) <= $this->getConfigInstance()->getConfigEntry('package_recipient_max_count'));
+
+               // Try it on all
+               foreach ($recipients as $recipient) {
+                       // Try to sole a single recipient
+                       $ipPort = HubTools::resolveSessionId($recipient);
+
+                       // Add it as recipient
+                       $listInstance->addEntry('ip_port', $ipPort);
+               } // END - foreach
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/recipient/self/.htaccess b/application/hub/main/recipient/self/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/recipient/self/class_SelfRecipient.php b/application/hub/main/recipient/self/class_SelfRecipient.php
new file mode 100644 (file)
index 0000000..5839a2f
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+/**
+ * A Self recipient
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 SelfRecipient extends BaseRecipient implements Recipient {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $recipientInstance              An instance of a Recipient class
+        */
+       public final static function createSelfRecipient () {
+               // Get new instance
+               $recipientInstance = new SelfRecipient();
+
+               // Return the prepared instance
+               return $recipientInstance;
+       }
+
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        */
+       public function resolveRecipient ($recipient, Listable $listInstance) {
+               // Determine own port
+               $port = $this->getConfigInstance()->getConfigEntry('node_listen_port');
+
+               // Determine IP or 'external_ip' if set
+               $ip = HubTools::determineOwnExternalIp();
+
+               // Is it not empty?
+               if (!empty($ip)) {
+                       // Add it to the list
+                       $listInstance->addEntry('ip_port', $ip . ':' . $port);
+               } // END - if
+       }
+}
+
+// [EOF]
+?>
diff --git a/application/hub/main/recipient/upper/.htaccess b/application/hub/main/recipient/upper/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/application/hub/main/recipient/upper/class_UpperRecipient.php b/application/hub/main/recipient/upper/class_UpperRecipient.php
new file mode 100644 (file)
index 0000000..e0cc719
--- /dev/null
@@ -0,0 +1,79 @@
+<?php
+/**
+ * A Upper recipient
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.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.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 UpperRecipient extends BaseRecipient implements Recipient {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this class
+        *
+        * @return      $recipientInstance              An instance of a Recipient class
+        */
+       public final static function createUpperRecipient () {
+               // Get new instance
+               $recipientInstance = new UpperRecipient();
+
+               // Return the prepared instance
+               return $recipientInstance;
+       }
+
+       /**
+        * Tries to resolve given recipient into session ids or ip:port combination
+        * depending on implementation (hint: Template Method Pattern)
+        *
+        * @param       $recipient              Recipient to resolve (e.g. could be a virtual recipient or direct session id)
+        * @param       $listInstance   An instance of a Listable class
+        * @return      $resolved               Resolved recipient or VOID if only the set list has been filled
+        * @throws      FrameworkException      Could throw different exceptions back depending on implementation
+        */
+       public function resolveRecipient ($recipient, Listable $listInstance) {
+               // Get all bootstrap nodes
+               foreach (explode(BaseHubSystem::BOOTSTRAP_NODES_SEPARATOR, $this->getConfigInstance()->getConfigEntry('hub_bootstrap_nodes')) as $ipPort) {
+                       // Is maximum reached?
+                       if ($listInstance->count() == $this->getConfigInstance()->getConfigEntry('package_recipient_max_count')) {
+                               // Debug message
+                               /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Going to abort at maximum of ' . $this->getConfigInstance()->getConfigEntry('package_recipient_max_count') . ' recipients!');
+
+                               // Then stop adding more
+                               break;
+                       } // END - if
+
+                       // Debug message
+                       /* DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput('RECIPIENT-RESOLVER: Adding node ' . $ipPort . ' as recipient.');
+
+                       // Add the entry
+                       $listInstance->addEntry('ip_port', $ipPort);
+               } // END - foreach
+       }
+}
+
+// [EOF]
+?>
index e70151cbe6df5265f3ba2e6859b50a5ea2b1d40e..8a1223acfa1eda16bea775ca0063f6a4c8382488 100644 (file)
@@ -32,6 +32,21 @@ class BaseDhtState extends BaseState {
                // Call parent constructor
                parent::__construct($className);
        }
+
+       /**
+        * Validates whether the DHT state is 'init' or throws an exception if it
+        * is every other state.
+        *
+        * @return      void
+        * @throws      InvalidStateException   If the state is not 'active'
+        */
+       public function validateDhtStateIsInitialized () {
+               // Just compare it...
+               if (!$this instanceof DhtInitState) {
+                       // Throw the exception
+                       throw new InvalidStateException($this, self::EXCEPTION_INVALID_STATE);
+               } // END - if
+       }
 }
 
 // [EOF]