X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_p2p_Khashmir%2Fknode.py;h=9acf9b777392857cfa247dd4d40505ba3338abac;hb=d563aab35fc0fd1fab59e0f6d594fbb05735cf21;hp=e7fb6b3720a750a5c77bfa224105b20002f5c4fc;hpb=7b1167d8ce780312d3689c9309c7e9c64060c085;p=quix0rs-apt-p2p.git diff --git a/apt_p2p_Khashmir/knode.py b/apt_p2p_Khashmir/knode.py index e7fb6b3..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." @@ -21,58 +21,48 @@ class KNodeBase(Node): if self.id != NULL_ID and senderid != self.id: log.msg("Got response from different node than expected.") self.table.invalidateNode(self) + raise Exception, "Node ID has changed" return dict - def errBack(self, err): - """Log an error that has occurred.""" - log.err(err) - return err - def ping(self, id): """Ping the node.""" df = self.conn.sendRequest('ping', {"id":id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df def join(self, id): """Use the node to bootstrap into the system.""" df = self.conn.sendRequest('join', {"id":id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df - def findNode(self, id, target): + def find_node(self, id, target): """Request the nearest nodes to the target that the node knows about.""" df = self.conn.sendRequest('find_node', {"target" : target, "id": id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df class KNodeRead(KNodeBase): """More advanced node that can also find and send values.""" - def findValue(self, id, key): + def find_value(self, id, key): """Request the nearest nodes to the key that the node knows about.""" df = self.conn.sendRequest('find_value', {"key" : key, "id" : id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df - def getValue(self, id, key, num): + def get_value(self, id, key, num): """Request the values that the node has for the key.""" df = self.conn.sendRequest('get_value', {"key" : key, "num": num, "id" : id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df class KNodeWrite(KNodeRead): """Most advanced node that can also store values.""" - def storeValue(self, id, key, value, token): + def store_value(self, id, key, value, token): """Store a value in the node.""" df = self.conn.sendRequest('store_value', {"key" : key, "value" : value, "token" : token, "id": id}) - df.addErrback(self.errBack) df.addCallback(self.checkSender) return df