+ closest_K = []
+ ans = 0
+ for node in self.sorted_nodes:
+ if node.id not in self.failed:
+ closest_K.append(node)
+ if node.id in self.answered:
+ ans += 1
+ if len(closest_K) >= K:
+ break
+
+ # If we have responses from the K closest nodes, then we are done
+ if ans >= K:
+ log.msg('Got the answers we need, aborting search')
+ return None
+
+ # Check the oustanding requests to see if they are still closest
+ for id in self.outstanding.keys():
+ if self.found[id] not in closest_K:
+ # Request is not important, allow another to go
+ log.msg("Request to %s/%s is taking too long, moving on" %
+ (self.found[id].host, self.found[id].port))
+ self.outstanding_results -= self.outstanding[id]
+ del self.outstanding[id]
+
+ return closest_K