KRPC calls callback with the response dictionary by itself.
authorCameron Dale <camrdale@gmail.com>
Thu, 27 Mar 2008 23:05:10 +0000 (16:05 -0700)
committerCameron Dale <camrdale@gmail.com>
Thu, 27 Mar 2008 23:05:10 +0000 (16:05 -0700)
Previously it was a dictionary, whose key 'rsp' contained the response dictionary.
The response dictionary has a key '_krpc_sender' added.

apt_p2p_Khashmir/actions.py
apt_p2p_Khashmir/khashmir.py
apt_p2p_Khashmir/knode.py
apt_p2p_Khashmir/krpc.py

index 870e37c..dfb0852 100644 (file)
@@ -172,7 +172,7 @@ class ActionBase:
         self.outstanding -= 1
         self.outstanding_results -= expected_results
         self.answered[node.id] = 1
-        self.processResponse(dict['rsp'])
+        self.processResponse(dict)
         self.schedule()
 
     def actionFailed(self, err, node, expected_results):
index 94af8ae..554608f 100644 (file)
@@ -219,7 +219,6 @@ class KhashmirBase(protocol.Factory):
             
             def _notStaleNodeHandler(dict, old=old, self=self):
                 """Got a pong from the old node, so update it."""
-                dict = dict['rsp']
                 if dict['id'] == old.id:
                     self.table.justSeenNode(old.id)
             
@@ -244,10 +243,10 @@ class KhashmirBase(protocol.Factory):
 
         def _pongHandler(dict, node=node, self=self, callback=callback):
             """Node responded properly, callback with response."""
-            n = self.Node(dict['rsp']['id'], dict['_krpc_sender'][0], dict['_krpc_sender'][1])
+            n = self.Node(dict['id'], dict['_krpc_sender'][0], dict['_krpc_sender'][1])
             self.insertNode(n)
             if callback:
-                callback((dict['rsp']['ip_addr'], dict['rsp']['port']))
+                callback((dict['ip_addr'], dict['port']))
 
         def _defaultPong(err, node=node, self=self, callback=callback, errback=errback):
             """Error occurred, fail node and errback or callback with error."""
index 1fbdbc3..9acf9b7 100644 (file)
@@ -13,7 +13,7 @@ class KNodeBase(Node):
     def checkSender(self, dict):
         """Check the sender's info to make sure it meets expectations."""
         try:
-            senderid = dict['rsp']['id']
+            senderid = dict['id']
         except KeyError:
             log.msg("No peer id in response")
             raise Exception, "No peer id in response."
index e577458..ecedb02 100644 (file)
@@ -321,7 +321,8 @@ class KRPC:
                 df = self.tids[msg[TID]]
                 #      callback
                 del(self.tids[msg[TID]])
-                df.callback({'rsp' : msg[RSP], '_krpc_sender': addr})
+                msg[RSP]['_krpc_sender'] = addr
+                df.callback(msg[RSP])
             else:
                 # no tid, this transaction timed out already...
                 if self.noisy:
@@ -493,8 +494,9 @@ class Receiver(protocol.Factory):
         return {'values': ['1'*length]*num}
 
 def make(port):
+    from stats import StatsLogger
     af = Receiver()
-    a = hostbroker(af, {'SPEW': False})
+    a = hostbroker(af, StatsLogger(None, None, {}), {'SPEW': False})
     a.protocol = KRPC
     p = reactor.listenUDP(port, a)
     return af, a, p
@@ -531,8 +533,7 @@ class KRPCTests(unittest.TestCase):
 
     def gotMsg(self, dict, should_be):
         _krpc_sender = dict['_krpc_sender']
-        msg = dict['rsp']
-        self.failUnlessEqual(msg['msg'], should_be)
+        self.failUnlessEqual(dict['msg'], should_be)
 
     def testManyEcho(self):
         for i in xrange(100):