1 ## Copyright 2002-2004 Andrew Loewenstern, All Rights Reserved
2 # see LICENSE.txt for license information
4 from const import NULL_ID
8 def checkSender(self, dict):
10 senderid = dict['rsp']['id']
12 print ">>>> No peer id in response"
13 raise Exception, "No peer id in response."
15 if self.id != NULL_ID and senderid != self.id:
16 print "Got response from different node than expected."
17 self.table.invalidateNode(self)
21 def errBack(self, err):
26 df = self.conn.sendRequest('ping', {"id":id})
27 df.addErrback(self.errBack)
28 df.addCallback(self.checkSender)
30 def findNode(self, target, id):
31 df = self.conn.sendRequest('find_node', {"target" : target, "id": id})
32 df.addErrback(self.errBack)
33 df.addCallback(self.checkSender)
36 class KNodeRead(KNodeBase):
37 def findValue(self, key, id):
38 df = self.conn.sendRequest('find_value', {"key" : key, "id" : id})
39 df.addErrback(self.errBack)
40 df.addCallback(self.checkSender)
43 class KNodeWrite(KNodeRead):
44 def storeValue(self, key, value, id):
45 df = self.conn.sendRequest('store_value', {"key" : key, "value" : value, "id": id})
46 df.addErrback(self.errBack)
47 df.addCallback(self.checkSender)
49 def storeValues(self, key, value, id):
50 df = self.conn.sendRequest('store_values', {"key" : key, "values" : value, "id": id})
51 df.addErrback(self.errBack)
52 df.addCallback(self.checkSender)