From e8a52ce5ce49f0a5de5d73e855c9a9f9473bc826 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 13 Feb 2013 19:37:48 +0000 Subject: [PATCH] Renamed method: - Renamed method findNodeBySessionId() to findNodeLocalBySessionId() as it only searches in locally stored data and doesn't query other nodes - Added final (temporary) configuration entry 'node_list' which will be a BASE64-encoded and serialized array --- .../interfaces/distributable/class_Distributable.php | 4 ++-- .../hub/interfaces/wrapper/class_NodeDhtWrapper.php | 4 ++-- .../class_NodeDistributedHashTableDatabaseWrapper.php | 4 ++-- application/hub/main/dht/node/class_NodeDhtFacade.php | 6 +++--- .../class_NodeMessageRequestNodeListHandler.php | 10 ++++++---- application/hub/main/tools/class_HubTools.php | 2 +- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/application/hub/interfaces/distributable/class_Distributable.php b/application/hub/interfaces/distributable/class_Distributable.php index f62026546..c90430f91 100644 --- a/application/hub/interfaces/distributable/class_Distributable.php +++ b/application/hub/interfaces/distributable/class_Distributable.php @@ -30,12 +30,12 @@ interface Distributable extends FrameworkInterface { function initDht (); /** - * Finds a node by given session id + * Finds a node locally by given session id * * @param $sessionId Session id to lookup * @return $nodeData Node data array */ - function findNodeBySessionId ($sessionId); + function findNodeLocalBySessionId ($sessionId); /** * Registers an other node with this node by given message data. The diff --git a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php index 04ab69df9..622e864c8 100644 --- a/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php +++ b/application/hub/interfaces/wrapper/class_NodeDhtWrapper.php @@ -46,12 +46,12 @@ interface NodeDhtWrapper extends DatabaseWrapper { function updateLocalNode (); /** - * Finds a node by given session id + * Finds a node locally by given session id * * @param $sessionId Session id to lookup * @return $nodeData Node data array */ - function findNodeBySessionId ($sessionId); + function findNodeLocalBySessionId ($sessionId); } // [EOF] diff --git a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php index 2e8cd3a5a..45208a22e 100644 --- a/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php +++ b/application/hub/main/database/wrapper/node/class_NodeDistributedHashTableDatabaseWrapper.php @@ -180,12 +180,12 @@ class NodeDistributedHashTableDatabaseWrapper extends BaseDatabaseWrapper implem } /** - * Finds a node by given session id + * Finds a node locally by given session id * * @param $sessionId Session id to lookup * @return $nodeData Node data array */ - public function findNodeBySessionId ($sessionId) { + public function findNodeLocalBySessionId ($sessionId) { // Get search criteria $searchInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); diff --git a/application/hub/main/dht/node/class_NodeDhtFacade.php b/application/hub/main/dht/node/class_NodeDhtFacade.php index 6cd1846cf..49434e103 100644 --- a/application/hub/main/dht/node/class_NodeDhtFacade.php +++ b/application/hub/main/dht/node/class_NodeDhtFacade.php @@ -69,17 +69,17 @@ class NodeDhtFacade extends BaseDht implements Distributable, Registerable { } /** - * Finds a node by given session id + * Finds a node locally by given session id * * @param $sessionId Session id to lookup * @return $nodeData Node data array */ - public function findNodeBySessionId ($sessionId) { + public function findNodeLocalBySessionId ($sessionId) { // Default is empty data array $nodeData = array(); // Call the wrapper to do the job and get back a result instance - $resultInstance = $this->getWrapperInstance()->findNodeBySessionId($sessionId); + $resultInstance = $this->getWrapperInstance()->findNodeLocalBySessionId($sessionId); // Is the next entry valid? if ($resultInstance->next()) { 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 ad7636617..d865f5de6 100644 --- a/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php +++ b/application/hub/main/handler/message-types/requests/class_NodeMessageRequestNodeListHandler.php @@ -130,15 +130,17 @@ class NodeMessageRequestNodeListHandler extends BaseMessageHandler implements Ha $this->getConfigInstance()->setConfigEntry($targetKey, $this->getConfigInstance()->getConfigEntry($sourceKey)); } // END - foreach + // Query local DHT for nodes except given session id + $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData($messageData, $this, XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID, XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES, ','); + + // Set it serialized in configuration (temporarily) + $this->getConfigInstance()->setConfigEntry('node_list', base64_encode(serialize($nodeList))); + // Translate last exception into a status code $statusCode = $this->getTranslatedStatusFromLastException(); // Set it in configuration (temporarily) $this->getConfigInstance()->setConfigEntry('answer_status', $statusCode); - - // Query local DHT for nodes except given session id - $nodeList = $this->getDhtInstance()->queryLocalNodeListExceptByMessageData($messageData, $this, XmlRequestNodeListTemplateEngine::REQUEST_DATA_SESSION_ID, XmlRequestNodeListTemplateEngine::REQUEST_DATA_ACCEPTED_OBJECT_TYPES, ','); - die(__METHOD__ . ':nodeList='.print_r($nodeList, true)); } /** diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index 2c8f601d1..8c7c85d5d 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -97,7 +97,7 @@ class HubTools extends BaseHubSystem { $recipientIpPort = 'invalid:invalid'; // And ask it for ip:port by given session id - $recipient = $this->getDhtInstance()->findNodeBySessionId($sessionId); + $recipient = $this->getDhtInstance()->findNodeLocalBySessionId($sessionId); // Is the recipient valid? if ((isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_EXTERNAL_IP])) && (isset($recipient[NodeDistributedHashTableDatabaseWrapper::DB_COLUMN_LISTEN_PORT]))) { -- 2.39.5