]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_dht_Khashmir/actions.py
Return a token in find_node responses, use it in store_value requests.
[quix0rs-apt-p2p.git] / apt_dht_Khashmir / actions.py
index 72637110860cd8fbcb6acbf1c630cae2783d8efa..6766cd9c6169dd8301cd6ff6c052d663175b0541 100644 (file)
@@ -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)