def findNode(self, id, callback, errback=None): """ returns the contact info for node, or the k closest nodes, from the global table """ # get K nodes out of local table/cache, or the node we want nodes = self.table.findNodes(id) d = Deferred() if errback: d.addCallbacks(callback, errback) else: d.addCallback(callback) if len(nodes) == 1 and nodes[0].id == id: d.callback(nodes) else: # create our search state state = FindNode(self, id, d.callback) reactor.callFromThread(state.goWithNodes, nodes)
def findNode(self, id, callback): """Find the contact info for the K closest nodes in the global table. @type id: C{string} @param id: the target ID to find the K closest nodes of @type callback: C{method} @param callback: the method to call with the results, it must take 1 parameter, the list of K closest nodes """ # Mark the bucket as having been accessed self.table.touch(id) # Start with our node nodes = [copy(self.node)] # Start the finding nodes action state = FindNode(self, id, callback, self.config, self.stats) reactor.callLater(0, state.goWithNodes, nodes)
def findNode(self, id, callback, errback=None): """ returns the contact info for node, or the k closest nodes, from the global table """ # get K nodes out of local table/cache, or the node we want nodes = self.table.findNodes(id, invalid=True) l = [x for x in nodes if x.invalid] if len(l) > 4: nodes = sample(l, 4) + self.table.findNodes(id, invalid=False)[:4] d = Deferred() if errback: d.addCallbacks(callback, errback) else: d.addCallback(callback) if len(nodes) == 1 and nodes[0].id == id: d.callback(nodes) else: # create our search state state = FindNode(self, id, d.callback, self.rawserver.add_task) self.rawserver.external_add_task(0, state.goWithNodes, nodes)