X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=apt_dht_Khashmir%2Factions.py;h=6766cd9c6169dd8301cd6ff6c052d663175b0541;hb=8f102eb1964db2ac18d4bac9e399c069a4cb616e;hp=72637110860cd8fbcb6acbf1c630cae2783d8efa;hpb=3d6c833df60bcae0bb3aa809ea8c5813289e97f1;p=quix0rs-apt-p2p.git diff --git a/apt_dht_Khashmir/actions.py b/apt_dht_Khashmir/actions.py index 7263711..6766cd9 100644 --- a/apt_dht_Khashmir/actions.py +++ b/apt_dht_Khashmir/actions.py @@ -5,6 +5,7 @@ from twisted.internet import reactor from twisted.python import log from khash import intify +from util import uncompact class ActionBase: """ base class for some long running asynchronous proccesses like finding nodes or values """ @@ -44,13 +45,16 @@ class FindNode(ActionBase): dict = dict['rsp'] n = self.caller.Node(dict["id"], _krpc_sender[0], _krpc_sender[1]) self.caller.insertNode(n) + if dict["id"] in self.found: + self.found[dict["id"]].updateToken(dict.get('token', '')) l = dict["nodes"] if self.finished or self.answered.has_key(dict["id"]): # a day late and a dollar short return self.outstanding = self.outstanding - 1 self.answered[dict["id"]] = 1 - for node in l: + for compact_node in l: + node = uncompact(compact_node) n = self.caller.Node(node) if not self.found.has_key(n.id): self.found[n.id] = n @@ -125,7 +129,8 @@ class GetValue(FindNode): # go through nodes # if we have any closer than what we already got, query them if dict.has_key('nodes'): - for node in dict['nodes']: + for compact_node in dict['nodes']: + node = uncompact(compact_node) n = self.caller.Node(node) if not self.found.has_key(n.id): self.found[n.id] = n @@ -186,10 +191,9 @@ class GetValue(FindNode): class StoreValue(ActionBase): - def __init__(self, caller, target, value, originated, callback, config, store="storeValue"): + def __init__(self, caller, target, value, callback, config, store="storeValue"): ActionBase.__init__(self, caller, target, callback, config) self.value = value - self.originated = originated self.stored = [] self.store = store @@ -237,7 +241,7 @@ class StoreValue(ActionBase): except AttributeError: log.msg("%s doesn't have a %s method!" % (node, self.store)) else: - df = f(self.target, self.value, self.originated, self.caller.node.id) + df = f(self.target, self.value, node.token, self.caller.node.id) df.addCallback(self.storedValue, node=node) df.addErrback(self.storeFailed, node=node)