From: burris Date: Fri, 13 Sep 2002 20:07:12 +0000 (+0000) Subject: keys and values passed as binary instead of encoded strings X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=517b039ed7c53375d72da94bc6c4a45fdbaa2d48;p=quix0rs-apt-p2p.git keys and values passed as binary instead of encoded strings --- diff --git a/actions.py b/actions.py index 5825294..b870534 100644 --- a/actions.py +++ b/actions.py @@ -132,6 +132,7 @@ class GetValue(FindNode): self.table.insertNode(n) elif l.has_key('values'): def x(y, z=self.results): + y = y.data if not z.has_key(y): z[y] = 1 return y diff --git a/khashmir.py b/khashmir.py index 20cc062..27c2928 100644 --- a/khashmir.py +++ b/khashmir.py @@ -21,7 +21,7 @@ threadable.init() from bsddb3 import db ## find this at http://pybsddb.sf.net/ from bsddb3._db import DBNotFoundError -from base64 import decodestring as decode +from xmlrpclib import Binary # don't ping unless it's been at least this many seconds since we've heard from a peer MAX_PING_INTERVAL = 60 * 15 # fifteen minutes @@ -93,11 +93,8 @@ class Khashmir(xmlrpc.XMLRPC): """ returns the values found for key in global table """ nodes = self.table.findNodes(key) # decode values, they will be base64 encoded - def cbwrap(values, cb=callback): - values = map(lambda x: decode(x), values) - callback(values) # create our search state - state = GetValue(self, key, cbwrap) + state = GetValue(self, key, callback) reactor.callFromThread(state.goWithNodes, nodes) @@ -222,11 +219,11 @@ class Khashmir(xmlrpc.XMLRPC): return nodes, self.node.senderDict() def xmlrpc_store_value(self, key, value, sender): - key = decode(key) - h1 = sha(key+value).digest() + key = key.data + h1 = sha(key+value.data).digest() t = `time.time()` if not self.store.has_key(h1): - v = dumps((key, value, t)) + v = dumps((key, value.data, t)) self.store.put(h1, v) self.itime.put(t, h1) self.kw.put(key, h1) @@ -244,7 +241,7 @@ class Khashmir(xmlrpc.XMLRPC): def xmlrpc_find_value(self, key, sender): ip = self.crequest.getClientIP() - key = decode(key) + key = key.data sender['host'] = ip n = Node().initWithDict(sender) self.insertNode(n) @@ -258,6 +255,7 @@ class Khashmir(xmlrpc.XMLRPC): v = loads(self.store[h1])[1] l.append(v) tup = c.next() + l = map(lambda v: Binary(v), l) return {'values' : l}, self.node.senderDict() else: nodes = self.table.findNodes(key) diff --git a/knode.py b/knode.py index 52abbed..8a38462 100644 --- a/knode.py +++ b/knode.py @@ -2,7 +2,7 @@ from node import Node from twisted.internet.defer import Deferred from xmlrpcclient import XMLRPCClientFactory as factory from const import reactor -from base64 import encodestring as encode +from xmlrpclib import Binary class KNode(Node): def ping(self, sender): @@ -17,11 +17,11 @@ class KNode(Node): return df def storeValue(self, key, value, sender): df = Deferred() - f = factory('store_value', (encode(key), encode(value), sender), df.callback, df.errback) + f = factory('store_value', (Binary(key), Binary(value), sender), df.callback, df.errback) reactor.connectTCP(self.host, self.port, f) return df def findValue(self, key, sender): df = Deferred() - f = factory('find_value', (encode(key), sender), df.callback, df.errback) + f = factory('find_value', (Binary(key), sender), df.callback, df.errback) reactor.connectTCP(self.host, self.port, f) return df