+from datetime import datetime
import os, sha, random
from twisted.internet import defer, reactor
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."""
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):
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"
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