From: Cameron Dale Date: Thu, 27 Mar 2008 23:05:10 +0000 (-0700) Subject: KRPC calls callback with the response dictionary by itself. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ff8f24ee57f4c415191660c381c27159b1342357;p=quix0rs-apt-p2p.git KRPC calls callback with the response dictionary by itself. Previously it was a dictionary, whose key 'rsp' contained the response dictionary. The response dictionary has a key '_krpc_sender' added. --- diff --git a/apt_p2p_Khashmir/actions.py b/apt_p2p_Khashmir/actions.py index 870e37c..dfb0852 100644 --- a/apt_p2p_Khashmir/actions.py +++ b/apt_p2p_Khashmir/actions.py @@ -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): diff --git a/apt_p2p_Khashmir/khashmir.py b/apt_p2p_Khashmir/khashmir.py index 94af8ae..554608f 100644 --- a/apt_p2p_Khashmir/khashmir.py +++ b/apt_p2p_Khashmir/khashmir.py @@ -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.""" diff --git a/apt_p2p_Khashmir/knode.py b/apt_p2p_Khashmir/knode.py index 1fbdbc3..9acf9b7 100644 --- a/apt_p2p_Khashmir/knode.py +++ b/apt_p2p_Khashmir/knode.py @@ -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." diff --git a/apt_p2p_Khashmir/krpc.py b/apt_p2p_Khashmir/krpc.py index e577458..ecedb02 100644 --- a/apt_p2p_Khashmir/krpc.py +++ b/apt_p2p_Khashmir/krpc.py @@ -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):