def _setup_download(self): self._started = time.time() self._status.set_status("Retrieving Shares") # how many shares do we need? (seqnum, root_hash, IV, segsize, datalength, k, N, prefix, offsets_tuple) = self.verinfo # first, which servers can we use? versionmap = self.servermap.make_versionmap() shares = versionmap[self.verinfo] # this sharemap is consumed as we decide to send requests self.remaining_sharemap = DictOfSets() for (shnum, peerid, timestamp) in shares: self.remaining_sharemap.add(shnum, peerid) # If the servermap update fetched anything, it fetched at least 1 # KiB, so we ask for that much. # TODO: Change the cache methods to allow us to fetch all of the # data that they have, then change this method to do that. any_cache = self._node._read_from_cache(self.verinfo, shnum, 0, 1000) ss = self.servermap.connections[peerid] reader = MDMFSlotReadProxy(ss, self._storage_index, shnum, any_cache) reader.peerid = peerid self.readers[shnum] = reader assert len(self.remaining_sharemap) >= k self.shares = {} # maps shnum to validated blocks self._active_readers = [] # list of active readers for this dl. self._block_hash_trees = {} # shnum => hashtree # We need one share hash tree for the entire file; its leaves # are the roots of the block hash trees for the shares that # comprise it, and its root is in the verinfo. self.share_hash_tree = hashtree.IncompleteHashTree(N) self.share_hash_tree.set_hashes({0: root_hash})