Ejemplo n.º 1
0
 def parse_message(self, msg):
     self.max_duration = 8000
     self.key = msg.pop(0)
     self.content = msg.pop(0)
     self.context = msg.pop(0)
     self.engine.hashtable[id_for_key(self.key)] = (self.engine.node.node_id, time.time(), self.content)
     self.closest = [  x.to_json() for x in self.engine.nodetree.closest_to(id_for_key(self.key)) ]
Ejemplo n.º 2
0
 def parse_message(self, msg):
     self.key = id_for_key(msg.pop(0))
     self.context = msg.pop(0)
     self.closest = self.engine.nodetree.closest_to(self.key)
     self.unqueried = list(self.closest)  # shallow is fine
     self.queried = []
     self.outstanding = {} # peer_id -> query time
     self.value = None
Ejemplo n.º 3
0
 def republish_closest(self):
     for k, v in self.engine.hashtable.items():
         node_id, last, content = v
         if node_id != self.engine.node.node_id and time.time() > last + self.closest_refresh:
             # are we the closest node we know of
             if self.engine.nodetree.closest_to(id_for_key(k)):
                 self.engine.txmap.create(StoreValue,
                   [k, content, 'default'], self.engine)
Ejemplo n.º 4
0
    def handle_peer(self, peer, txid, msgtype, content):
        if msgtype == 0x05:
            assert len(content) == 32
            entry = self.engine.hashtable.get(content)
            if entry:
                node_id, store_time, val = entry
                # found
                self.engine.send_external(peer, txid, 0x08, val)
            else:
                # send next closest nodes
                self.engine.send_external(peer, txid, 0x06,
                    FindNodes.pack_response(self.engine.nodetree.closest_to(content)))

        elif msgtype == 0x09:
            key = id_for_key(content)
            self.engine.hashtable[key] = (peer.node_id, time.time(), content)
Ejemplo n.º 5
0
 def parse_message(self, msg):
     self.key = msg.pop(0)
     self.context = msg.pop(0)
     self.engine.hashtable.pop(id_for_key(self.key), None)
     if self.callback:
         self.callback()
Ejemplo n.º 6
0
 def _send_query(self):
     self.engine.txmap.create(FindNodes,
               [z85.encode(id_for_key(self.key))], self.engine, callback=self._closest)