From: burris Date: Sat, 14 Sep 2002 00:37:51 +0000 (+0000) Subject: don't return duplicates if we have a key in our store X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7a5a9a80d9f9f898ec5cf07a64227e2aec963bf6;p=quix0rs-apt-p2p.git don't return duplicates if we have a key in our store --- diff --git a/actions.py b/actions.py index 0a6062f..9458329 100644 --- a/actions.py +++ b/actions.py @@ -165,8 +165,11 @@ class GetValue(FindNode): reactor.callFromThread(self.callback,[]) ## get value - def goWithNodes(self, nodes): + def goWithNodes(self, nodes, found=None): self.results = {} + if found: + for n in found: + self.results[n] = 1 for node in nodes: if node.id == self.table.node.id: continue diff --git a/khashmir.py b/khashmir.py index 8ef6221..893bd02 100644 --- a/khashmir.py +++ b/khashmir.py @@ -92,15 +92,17 @@ class Khashmir(xmlrpc.XMLRPC): def valueForKey(self, key, callback): """ returns the values found for key in global table """ nodes = self.table.findNodes(key) - # create our search state - state = GetValue(self, key, callback) - reactor.callFromThread(state.goWithNodes, nodes) - + # get locals l = self.retrieveValues(key) if len(l) > 0: reactor.callFromThread(callback, l) + # create our search state + state = GetValue(self, key, callback) + reactor.callFromThread(state.goWithNodes, nodes, {'found' : l}) + + ## async, but in the current implementation there is no guarantee a store does anything so there is no callback right now def storeValueForKey(self, key, value, callback=None):