]> git.mxchange.org Git - quix0rs-apt-p2p.git/commitdiff
finding values is now fixed
authorburris <burris>
Mon, 2 Sep 2002 17:32:28 +0000 (17:32 +0000)
committerburris <burris>
Mon, 2 Sep 2002 17:32:28 +0000 (17:32 +0000)
actions.py
const.py
khashmir.py
knode.py

index 052f6a4b26f6a3f913b93bc49f200c2f1b5d1e9c..3112027332d7c9a0b64f3cf3a1e2a785e596601f 100644 (file)
@@ -109,7 +109,6 @@ class GetValue(FindNode):
     """ get value task """
     def handleGotNodes(self, args):
        l, sender = args
-       l = l[0]
        if self.finished or self.answered.has_key(sender['id']):
            # a day late and a dollar short
            return
@@ -126,7 +125,7 @@ class GetValue(FindNode):
        elif l.has_key('values'):
            ## done
            self.finished = 1
-           return self.callback(l['values'])
+           reactor.callFromThread(self.callback, l['values'])
        self.schedule()
                
     ## get value
@@ -139,8 +138,9 @@ class GetValue(FindNode):
        for node in l[:K]:
            if not self.queried.has_key(node.id) and node.id != self.table.node.id:
                #xxx t.timeout = time.time() + GET_VALUE_TIMEOUT
-               df = node.getValue(node, self.target)
-               df.addCallbacks(self.handleGotNodes, self.defaultGotNodes)
+               df = node.findValue(self.target, self.table.node.senderDict())
+               df.addCallback(self.handleGotNodes)
+               df.addErrback(self.defaultGotNodes)
                self.outstanding = self.outstanding + 1
                self.queried[node.id] = 1
            if self.outstanding >= N:
@@ -158,7 +158,7 @@ class GetValue(FindNode):
                continue
            self.found[node.id] = node
            #xxx t.timeout = time.time() + FIND_NODE_TIMEOUT
-           df = node.findNode(self.target, self.table.node.senderDict())
+           df = node.findValue(self.target, self.table.node.senderDict())
            df.addCallbacks(self.handleGotNodes, self.defaultGotNodes)
            self.outstanding = self.outstanding + 1
            self.queried[node.id] = 1
index 0aad77d7ab46352a2899de55f7c6196f260bb207..a36d34309000fe5c0c63c68d1e923f9446aec318 100644 (file)
--- a/const.py
+++ b/const.py
@@ -1,5 +1,5 @@
+from twisted.internet.default import SelectReactor ## twistedmatrix.com
 
-from twisted.internet.default import SelectReactor
 reactor = SelectReactor(installSignalHandlers=0)
 from twisted.internet import main
 main.installReactor(reactor)
\ No newline at end of file
index 748ce2196b8b93d3e792f1875cb3a4771d1b1275..aa1902f2bbe96ec1dde250a4a5e7a029e353bc8a 100644 (file)
@@ -12,6 +12,8 @@ from actions import FindNode, GetValue
 from twisted.web import xmlrpc
 from twisted.internet.defer import Deferred
 from twisted.python import threadable
+from twisted.internet.app import Application
+from twisted.web import server
 threadable.init()
 
 from bsddb3 import db ## find this at http://pybsddb.sf.net/
@@ -28,8 +30,6 @@ class Khashmir(xmlrpc.XMLRPC):
     def __init__(self, host, port):
        self.node = Node(newID(), host, port)
        self.table = KTable(self.node)
-       from twisted.internet.app import Application
-       from twisted.web import server
        self.app = Application("xmlrpc")
        self.app.listenTCP(port, server.Site(self))
        self.store = db.DB()
@@ -204,7 +204,7 @@ class Khashmir(xmlrpc.XMLRPC):
        if self.store.has_key(key):
            return {'values' : self.store[key]}, self.node.senderDict()
        else:
-           nodes = self.table.findNodes(msg['key'])
+           nodes = self.table.findNodes(key)
            nodes = map(lambda node: node.senderDict(), nodes)
            return {'nodes' : nodes}, self.node.senderDict()
 
@@ -215,7 +215,11 @@ class Khashmir(xmlrpc.XMLRPC):
        pass
 
 
-#------
+
+
+
+
+#------ testing
 
 def test_build_net(quiet=0):
     from whrandom import randrange
@@ -309,7 +313,7 @@ def test_find_value(l, quiet=0):
                if(len(values) == 0):
                    print "find                FAILED"
                else:
-                   if values[0]['value'] != val:
+                   if values != val:
                        print "find                FAILED"
                    else:
                        print "find                FOUND"
@@ -317,11 +321,10 @@ def test_find_value(l, quiet=0):
                f.set()
        return callback
     b.valueForKey(key, mc(fa))
-    c.valueForKey(key, mc(fb))
-    d.valueForKey(key, mc(fc))
-    
     fa.wait()
+    c.valueForKey(key, mc(fb))
     fb.wait()
+    d.valueForKey(key, mc(fc))    
     fc.wait()
     
 if __name__ == "__main__":
index 66b8b5318d9c25e2425a0e0306e2c525e418708f..aecf14e4aa753b3e88ab8c64c108426f1772f92e 100644 (file)
--- a/knode.py
+++ b/knode.py
@@ -20,7 +20,7 @@ class KNode(Node):
        reactor.connectTCP(self.host, self.port, f)
        return df
     def findValue(self, key, sender):
+       df = Deferred()
        f = factory('find_value', (key, sender), df.callback, df.errback)
        reactor.connectTCP(self.host, self.port, f)
-       df = Deferred()
        return df