def checkpoint(self, auto=0): self._saveSelfNode() self._dumpRoutingTable() self.refreshTable() if auto: reactor.callLater( randrange(int(const.CHECKPOINT_INTERVAL * .9), int(const.CHECKPOINT_INTERVAL * 1.1)), self.checkpoint, (1, ))
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 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 valueForKey(self, key, callback, searchlocal = 1): """ returns the values found for key in global table callback will be called with a list of values for each peer that returns unique values final callback will be an empty list - probably should change to 'more coming' arg """ nodes = self.table.findNodes(key) # get locals if searchlocal: l = self.retrieveValues(key) if len(l) > 0: reactor.callLater(0, callback, (l)) else: l = [] # create our search state state = GetValue(self, key, callback) reactor.callFromThread(state.goWithNodes, nodes, l)
def valueForKey(self, key, callback, searchlocal=1): """ returns the values found for key in global table callback will be called with a list of values for each peer that returns unique values final callback will be an empty list - probably should change to 'more coming' arg """ nodes = self.table.findNodes(key) # get locals if searchlocal: l = self.retrieveValues(key) if len(l) > 0: reactor.callLater(0, callback, (l)) else: l = [] # create our search state state = GetValue(self, key, callback) reactor.callFromThread(state.goWithNodes, nodes, l)
def checkpoint(self, auto=0): self._saveSelfNode() self._dumpRoutingTable() self.refreshTable() if auto: reactor.callLater(randrange(int(const.CHECKPOINT_INTERVAL * .9), int(const.CHECKPOINT_INTERVAL * 1.1)), self.checkpoint, (1,))
def _expire(self): c = self.store.cursor() s = "delete from kv where time < '%s';" % self.cut c.execute(s) reactor.callLater(const.KE_DELAY, self.doExpire)
def __init__(self, store): self.store = store reactor.callLater(const.KEINITIAL_DELAY, self.doExpire)