From 4214610d2ae0800ccf3d593f10efa6ab11152d6a Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Sat, 15 Feb 2014 22:51:00 +0100 Subject: [PATCH] Very basic implementation for adding "discovered" DHT recipients as package recipients. Signed-off-by: Roland Haeder --- ...ass_NodeDistributedHashTableDatabaseWrapper.php | 1 + .../class_NodeMessageAnnouncementHandler.php | 6 +++--- .../class_NodeMessageRequestNodeListHandler.php | 4 ++-- .../hub/main/recipient/dht/class_DhtRecipient.php | 14 ++++++++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index a51fc2cb1..4e540ac9b 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -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'; diff --git a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php index 2521fd74e..de82989db 100644 --- a/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php +++ b/application/hub/main/handler/message-types/anouncement/class_NodeMessageAnnouncementHandler.php @@ -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); } } diff --git a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php index c19d4803e..d8239a343 100644 --- a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -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'); } } diff --git a/application/hub/main/recipient/dht/class_DhtRecipient.php b/application/hub/main/recipient/dht/class_DhtRecipient.php index 58266fd07..256fbb9a2 100644 --- a/application/hub/main/recipient/dht/class_DhtRecipient.php +++ b/application/hub/main/recipient/dht/class_DhtRecipient.php @@ -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 } } -- 2.39.5