]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_dht_Khashmir/DHT.py
Modify khashmir's config system to not use the const module.
[quix0rs-apt-p2p.git] / apt_dht_Khashmir / DHT.py
index ca5bb609bc38d1ad8a7d86418efb54e088d93d37..c4a0b340ec786d2537b4a331a2d0c117793c21bf 100644 (file)
@@ -17,21 +17,29 @@ class DHT:
     
     def loadConfig(self, config, section):
         """See L{apt_dht.interfaces.IDHT}."""
     
     def loadConfig(self, config, section):
         """See L{apt_dht.interfaces.IDHT}."""
-        self.config = config
+        self.config_parser = config
         self.section = section
         self.section = section
-        if self.config.has_option(section, 'port'):
-            self.port = self.config.get(section, 'port')
-        else:
-            self.port = self.config.get('DEFAULT', 'port')
+        self.config = []
+        for k in self.config_parser.options(section):
+            if k in ['K', 'HASH_LENGTH', 'CONCURRENT_REQS', 'STORE_REDUNDANCY', 
+                     'MAX_FAILURES', 'PORT']:
+                self.config[k] = self.config_parser.getint(section, k)
+            elif k in ['CHECKPOINT_INTERVAL', 'MIN_PING_INTERVAL', 
+                       'BUCKET_STALENESS', 'KEINITIAL_DELAY', 'KE_DELAY', 'KE_AGE']:
+                self.config[k] = self.config_parser.gettime(section, k)
+            else:
+                self.config[k] = self.config_parser.get(section, k)
+        if 'PORT' not in self.config:
+            self.config['PORT'] = self.config_parser.getint('DEFAULT', 'PORT')
     
     def join(self):
         """See L{apt_dht.interfaces.IDHT}."""
         if self.config is None:
             raise DHTError, "configuration not loaded"
 
     
     def join(self):
         """See L{apt_dht.interfaces.IDHT}."""
         if self.config is None:
             raise DHTError, "configuration not loaded"
 
-        self.khashmir = Khashmir('', self.port)
+        self.khashmir = Khashmir(self.config, self.config_parser.get('DEFAULT', 'cache_dir'))
         
         
-        for node in self.config.get(self.section, 'bootstrap'):
+        for node in self.config_parser.get(self.section, 'BOOTSTRAP'):
             host, port = node.rsplit(':', 1)
             self.khashmir.addContact(host, port)
             
             host, port = node.rsplit(':', 1)
             self.khashmir.addContact(host, port)