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 870e37c80450220d84109077209e8e0905a4b976..dfb085241df0dac73e8e83eee74610a3572b8dbf 100644 (file)
@@ -172,7 +172,7 @@ class ActionBase:
         self.outstanding -= 1
         self.outstanding_results -= expected_results
         self.answered[node.id] = 1
         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):
         self.schedule()
 
     def actionFailed(self, err, node, expected_results):
index 94af8ae0ddc8aae044f1bad704a5ebca140cb631..554608feda1494ba7e1bfedf98379d9f5096caaa 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."""
             
             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)
             
                 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."""
 
         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:
             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."""
 
         def _defaultPong(err, node=node, self=self, callback=callback, errback=errback):
             """Error occurred, fail node and errback or callback with error."""
index 1fbdbc3302521f62efa406dc2daabd52fb7e8a3f..9acf9b777392857cfa247dd4d40505ba3338abac 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:
     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."
         except KeyError:
             log.msg("No peer id in response")
             raise Exception, "No peer id in response."
index e577458289afebba56bd0b6dfcc4065ce663a59c..ecedb02ccf938d3ef5b288f199ba4719704fc41d 100644 (file)
@@ -321,7 +321,8 @@ class KRPC:
                 df = self.tids[msg[TID]]
                 #      callback
                 del(self.tids[msg[TID]])
                 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:
             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):
         return {'values': ['1'*length]*num}
 
 def make(port):
+    from stats import StatsLogger
     af = Receiver()
     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
     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']
 
     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):
 
     def testManyEcho(self):
         for i in xrange(100):