]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
keys and values passed as binary instead of encoded strings
authorburris <burris>
Fri, 13 Sep 2002 20:07:12 +0000 (20:07 +0000)
committerburris <burris>
Fri, 13 Sep 2002 20:07:12 +0000 (20:07 +0000)
actions.py
khashmir.py
knode.py

index 58252943436afacbe5231cf71dbee87917a1f58e..b870534121818c1adc806713fdc235a9cc0366d1 100644 (file)
@@ -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
index 20cc062f0b9a2128ba1d358634666510329e7295..27c29281eced0bc437748a9e4942f83bbd55958c 100644 (file)
@@ -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)
index 52abbed41f81d217b029e578579868274faade69..8a38462e46430bdb20ee96c02212c73312475334 100644 (file)
--- 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