]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_dht_Khashmir/DHT.py
Change all print statements to log.msg calls.
[quix0rs-apt-p2p.git] / apt_dht_Khashmir / DHT.py
index 8930ffe9d58c40e83e169d0ceb3b964ed458cb10..d16f59837811e0bc561718a130c2fe0ddcaf3832 100644 (file)
@@ -1,4 +1,5 @@
 
+from datetime import datetime
 import os, sha, random
 
 from twisted.internet import defer, reactor
@@ -10,6 +11,8 @@ from zope.interface import implements
 from apt_dht.interfaces import IDHT
 from khashmir import Khashmir
 
+khashmir_dir = 'apt-dht-Khashmir'
+
 class DHTError(Exception):
     """Represents errors that occur in the DHT."""
 
@@ -35,7 +38,9 @@ class DHT:
         self.config_parser = config
         self.section = section
         self.config = {}
-        self.cache_dir = self.config_parser.get(section, 'cache_dir')
+        self.cache_dir = os.path.join(self.config_parser.get(section, 'cache_dir'), khashmir_dir)
+        if not os.path.exists(self.cache_dir):
+            os.makedirs(self.cache_dir)
         self.bootstrap = self.config_parser.getstringlist(section, 'BOOTSTRAP')
         self.bootstrap_node = self.config_parser.getboolean(section, 'BOOTSTRAP_NODE')
         for k in self.config_parser.options(section):
@@ -145,7 +150,7 @@ class DHT:
                 d.callback(final_result)
             del self.retrieving[key]
 
-    def storeValue(self, key, value):
+    def storeValue(self, key, value, originated = None):
         """See L{apt_dht.interfaces.IDHT}."""
         if self.config is None:
             raise DHTError, "configuration not loaded"
@@ -155,8 +160,10 @@ class DHT:
         if key in self.storing and value in self.storing[key]:
             raise DHTError, "already storing that key with the same value"
 
+        if originated is None:
+            originated = datetime.utcnow()
         d = defer.Deferred()
-        self.khashmir.storeValueForKey(key, value, self._storeValue)
+        self.khashmir.storeValueForKey(key, value, originated, self._storeValue)
         self.storing.setdefault(key, {})[value] = d
         return d