]> git.mxchange.org Git - hub.git/commitdiff
Very basic implementation for adding "discovered" DHT recipients as package recipients.
authorRoland Haeder <roland@mxchange.org>
Sat, 15 Feb 2014 21:51:00 +0000 (22:51 +0100)
committerRoland Haeder <roland@mxchange.org>
Sat, 15 Feb 2014 21:51:00 +0000 (22:51 +0100)
Signed-off-by: Roland Haeder <roland@mxchange.org>
application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php
application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php
application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php
application/hub/main/recipient/dht/class_DhtRecipient.php

index a51fc2cb18258e5fa6139dd5111f39e23654cfb7..4e540ac9b4bf827bfd94a5a01df3a2fcbd42afcc 100644 (file)
@@ -40,6 +40,7 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem
        const DB_COLUMN_ACCEPTED_OBJECTS   = 'accepted_object_types';
        const DB_COLUMN_NODE_LIST          = 'node_list';
        const DB_COLUMN_PUBLICATION_STATUS = 'publication_status';
+       const DB_COLUMN_ANSWER_STATUS      = 'answer_status';
 
        // Publication status'
        const PUBLICATION_STATUS_PENDING = 'PENDING';
index 2521fd74e6f22a8f4379fc98818f959a1a944400..de82989db9f55e4690ce46b12bac6a23dc495ebc 100644 (file)
@@ -161,7 +161,7 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl
                $statusCode = $this->getTranslatedStatusFromLastException();
 
                // Set it in configuration (temporarily)
-               $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode);
+               $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
        }
 
        /**
@@ -184,8 +184,8 @@ class NodeMessageAnnouncementHandler extends BaseMessageHandler implements Handl
                        $this->getConfigInstance()->unsetConfigEntry($configKey);
                } // END - foreach
 
-               // Remove 'answer_status' as well
-               $this->getConfigInstance()->unsetConfigEntry('answer_status');
+               // Remove NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS as well
+               $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
        }
 }
 
index c19d4803e76bcb7b49c0e6a81e8dcd3a3582a7c8..d8239a34327724ee57ba1c677bad646ad781ac21 100644 (file)
@@ -149,7 +149,7 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha
                $statusCode = $this->getTranslatedStatusFromLastException();
 
                // Set it in configuration (temporarily)
-               $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode);
+               $this->getConfigInstance()->setConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS, $statusCode);
        }
 
        /**
@@ -167,7 +167,7 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha
                } // END - foreach
 
                // Remove answer status/node list as well
-               $this->getConfigInstance()->unsetConfigEntry('answer_status');
+               $this->getConfigInstance()->unsetConfigEntry(NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_ANSWER_STATUS);
                $this->getConfigInstance()->unsetConfigEntry('node_list');
        }
 }
index 58266fd07ce816e9c76452d6715131385bea7065..256fbb9a2cc0dcef52fedefc632ded867c5f7b2b 100644 (file)
@@ -56,7 +56,6 @@ class DhtRecipient extends BaseRecipient implements Recipient {
         * @param       $packageData    Valid package data array
         * @return      void
         * @throws      FrameworkException      Could throw different exceptions depending on implementation
-        * @todo        30% done
         */
        public function resolveRecipient ($recipient, Listable $listInstance, array $packageData) {
                // Make sure the recipient is valid
@@ -69,7 +68,18 @@ class DhtRecipient extends BaseRecipient implements Recipient {
                // "Discover" recipients by given package data
                $recipients = $discoverInstance->resolveRecipientsByPackageData($packageData);
 
-               $this->partialStub('Please implement this method. recipient=' . $recipient . ',recipients=' . print_r($recipients, TRUE));
+               // Now "walk" through all elements and add them to the list
+               foreach ($recipients as $recipient) {
+                       // These array elements must exist for this loop:
+                       assert(isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP]));
+                       assert(isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]));
+
+                       // Put ip and port both together
+                       $ipPort = $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP] . ':' . $recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT];
+
+                       // Add it to the list
+                       $listInstance->addEntry('ip_port', $ipPort);
+               } // END - foreach
        }
 }