From c0f3340789f65a0097d87f4ca1ac8131fc147f62 Mon Sep 17 00:00:00 2001 From: burris Date: Fri, 13 Sep 2002 21:18:51 +0000 Subject: [PATCH] now search local store for keys in addititon to net only return keys that actually match! --- khashmir.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/khashmir.py b/khashmir.py index 7eec1c8..ece2851 100644 --- a/khashmir.py +++ b/khashmir.py @@ -92,10 +92,14 @@ class Khashmir(xmlrpc.XMLRPC): def valueForKey(self, key, callback): """ returns the values found for key in global table """ nodes = self.table.findNodes(key) - # decode values, they will be base64 encoded # create our search state state = GetValue(self, key, callback) reactor.callFromThread(state.goWithNodes, nodes) + + # get locals + l = self.retrieveValues(key) + if len(l) > 0: + callback(l) @@ -196,6 +200,20 @@ class Khashmir(xmlrpc.XMLRPC): self.findNode(id, callback) + def retrieveValues(self, key): + if self.kw.has_key(key): + c = self.kw.cursor() + tup = c.set(key) + l = [] + while(tup and tup[0] == key): + h1 = tup[1] + v = loads(self.store[h1])[1] + l.append(v) + tup = c.next() + l = map(lambda v: Binary(v), l) + return l + return [] + ##### ##### INCOMING MESSAGE HANDLERS @@ -247,16 +265,8 @@ class Khashmir(xmlrpc.XMLRPC): n = Node().initWithDict(sender) self.insertNode(n) - if self.kw.has_key(key): - c = self.kw.cursor() - tup = c.set(key) - l = [] - while(tup): - h1 = tup[1] - v = loads(self.store[h1])[1] - l.append(v) - tup = c.next() - l = map(lambda v: Binary(v), l) + l = self.retrieveValues(key) + if len(l): return {'values' : l}, self.node.senderDict() else: nodes = self.table.findNodes(key) -- 2.39.5