From 2e00f351966a192c4b65e2dc64c4dad17e59a36c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 7 Feb 2013 20:32:55 +0000 Subject: [PATCH] Added prefix to allow more than one DHT instance --- application/hub/config.php | 4 ++-- .../chain/class_PackageFilterChainFactory.php | 4 ++-- .../hub/main/factories/dht/class_DhtObjectFactory.php | 11 ++++++----- .../tasks/node/dht/class_NodeDhtBootstrapTask.php | 2 +- .../node/dht/class_NodeDhtInitializationTask.php | 2 +- .../main/tasks/node/dht/class_NodeDhtQueryTask.php | 2 +- application/hub/main/tools/class_HubTools.php | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/application/hub/config.php b/application/hub/config.php index 853c88b02..970c197d9 100644 --- a/application/hub/config.php +++ b/application/hub/config.php @@ -740,8 +740,8 @@ $cfg->setConfigEntry('package_decoder_class', 'PackageDecoder'); // @TODO This is very static, rewrite it to more flexible $cfg->setConfigEntry('package_recipient_max_count', 3); -// CFG: DHT-CLASS -$cfg->setConfigEntry('dht_class', 'NodeDhtFacade'); +// CFG: NODE-DHT-CLASS +$cfg->setConfigEntry('node_dht_class', 'NodeDhtFacade'); /////////////////////////////////////////////////////////////////////////////// // Peer states diff --git a/application/hub/main/factories/chain/class_PackageFilterChainFactory.php b/application/hub/main/factories/chain/class_PackageFilterChainFactory.php index 9ded48174..be82d9def 100644 --- a/application/hub/main/factories/chain/class_PackageFilterChainFactory.php +++ b/application/hub/main/factories/chain/class_PackageFilterChainFactory.php @@ -48,7 +48,7 @@ class PackageFilterChainFactory extends ObjectFactory { $chainInstance = Registry::getRegistry()->getInstance($registryKey); } else { // Initialize a filter chain class - $chainInstance = ObjectFactory::createObjectByConfiguredName('package_filter_chain_class'); + $chainInstance = self::createObjectByConfiguredName('package_filter_chain_class'); // "Walk" through all tags entries foreach ($tags as $tag) { @@ -58,7 +58,7 @@ class PackageFilterChainFactory extends ObjectFactory { * simply means the tag is not valid. This however should be * handled some calls before this method is called. */ - $filterInstance = ObjectFactory::createObjectByConfiguredName('package_tag_' . $tag . '_filter'); + $filterInstance = self::createObjectByConfiguredName('package_tag_' . $tag . '_filter'); // Add this filter to the chain $chainInstance->addFilter($filterInstance); diff --git a/application/hub/main/factories/dht/class_DhtObjectFactory.php b/application/hub/main/factories/dht/class_DhtObjectFactory.php index 40c29be85..446ed71c9 100644 --- a/application/hub/main/factories/dht/class_DhtObjectFactory.php +++ b/application/hub/main/factories/dht/class_DhtObjectFactory.php @@ -35,19 +35,20 @@ class DhtObjectFactory extends ObjectFactory { /** * Returns a singleton (registry-based) DHT object instance * + * @param $prefix Prefix for DHT class name and registry key * @return $dhtInstance An instance of a DHT object class */ - public static final function createDhtObjectInstance () { + public static final function createDhtObjectInstance ($prefix) { // If there is no handler? - if (Registry::getRegistry()->instanceExists('dht')) { + if (Registry::getRegistry()->instanceExists($prefix . '_dht')) { // Get handler from registry - $dhtInstance = Registry::getRegistry()->getInstance('dht'); + $dhtInstance = Registry::getRegistry()->getInstance($prefix . '_dht'); } else { // Get the handler instance - $dhtInstance = self::createObjectByConfiguredName('dht_class'); + $dhtInstance = self::createObjectByConfiguredName($prefix . '_dht_class'); // Add it to the registry - Registry::getRegistry()->addInstance('dht', $dhtInstance); + Registry::getRegistry()->addInstance($prefix . '_dht', $dhtInstance); } // Return the instance diff --git a/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php b/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php index 5ee47c684..117b0205b 100644 --- a/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php +++ b/application/hub/main/tasks/node/dht/class_NodeDhtBootstrapTask.php @@ -42,7 +42,7 @@ class NodeDhtBootstrapTask extends BaseTask implements Taskable, Visitable { $taskInstance = new NodeDhtBootstrapTask(); // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance(); + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); // Set the DHT instance here $taskInstance->setDhtInstance($dhtInstance); diff --git a/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php b/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php index fabd032c3..c2081f590 100644 --- a/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php +++ b/application/hub/main/tasks/node/dht/class_NodeDhtInitializationTask.php @@ -42,7 +42,7 @@ class NodeDhtInitializationTask extends BaseTask implements Taskable, Visitable $taskInstance = new NodeDhtInitializationTask(); // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance(); + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); // Set the DHT instance here $taskInstance->setDhtInstance($dhtInstance); diff --git a/application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php b/application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php index 44bbced0a..7ec31632d 100644 --- a/application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php +++ b/application/hub/main/tasks/node/dht/class_NodeDhtQueryTask.php @@ -42,7 +42,7 @@ class NodeDhtQueryTask extends BaseTask implements Taskable, Visitable { $taskInstance = new NodeDhtQueryTask(); // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance(); + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); // Set the DHT instance here $taskInstance->setDhtInstance($dhtInstance); diff --git a/application/hub/main/tools/class_HubTools.php b/application/hub/main/tools/class_HubTools.php index b81939b76..ad25728bb 100644 --- a/application/hub/main/tools/class_HubTools.php +++ b/application/hub/main/tools/class_HubTools.php @@ -89,7 +89,7 @@ class HubTools extends BaseHubSystem { */ protected function resolveIpPortBySessionId ($sessionId, $protocol) { // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance(); + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); // And ask it for ip:port by given session id $recipient = $dhtInstance->findNodeBySessionId($sessionId, $protocol); @@ -121,7 +121,7 @@ class HubTools extends BaseHubSystem { */ public static function resolveSessionIdByIpPort ($ipPort, $protocol) { // Get a DHT instance - $dhtInstance = DhtObjectFactory::createDhtObjectInstance(); + $dhtInstance = DhtObjectFactory::createDhtObjectInstance('node'); // And ask it for session id by given ip:port $recipient = $dhtInstance->findNodeByIpPort($ipPort, $protocol); -- 2.39.5