def setup(self, config, cache_dir): """Setup all the Khashmir sub-modules. @type config: C{dictionary} @param config: the configuration parameters for the DHT @type cache_dir: C{string} @param cache_dir: the directory to store all files in """ self.config = config self.port = config['PORT'] self.store = DB(os.path.join(cache_dir, 'khashmir.' + str(self.port) + '.db')) self.node = self._loadSelfNode('', self.port) self.table = KTable(self.node, config) self.token_secrets = [newID()] self.stats = StatsLogger(self.table, self.store) # Start listening self.udp = krpc.hostbroker(self, self.stats, config) self.udp.protocol = krpc.KRPC self.listenport = reactor.listenUDP(self.port, self.udp) # Load the routing table and begin checkpointing self._loadRoutingTable() self.refreshTable(force = True) self.next_checkpoint = reactor.callLater(60, self.checkpoint)
def setup(self, host, port, db='khashmir.db'): self._findDB(db) self.port = port self.node = self._loadSelfNode(host, port) self.table = KTable(self.node) #self.app = service.Application("krpc") self.udp = krpc.hostbroker(self) self.udp.protocol = krpc.KRPC self.listenport = reactor.listenUDP(port, self.udp) self.last = time.time() self._loadRoutingTable() KeyExpirer(store=self.store) self.refreshTable(force=1) reactor.callLater(60, self.checkpoint, (1, ))
def _load(self): do_load = False try: s = open(os.path.join(self.ddir, "routing_table"), 'r').read() dict = bdecode(s) except: id = newID() else: id = dict['id'] do_load = True self.node = self._Node(self.udp.connectionForAddr).init(id, self.host, self.port) self.table = KTable(self.node) if do_load: self._loadRoutingTable(dict['rt'])