def new_download(self, infohash, torrent_data, permid): """ Start a new download in order to get the pieces that will be requested by the coordinator. After the download is started, find the appropriate Helper object and call it's method. @param infohash: the infohash of the torrent for which help is requested @param torrent_data: the content of the .torrent file @param permid: the permid of the coordonator @param challenge: The challenge sent by the coordinator """ # Create the name for the .torrent file in the helper cache basename = binascii.hexlify(infohash)+'.torrent' # ignore .tribe stuff, not vital torrentfilename = os.path.join(self.helpdir,basename) # Write the .torrent information in the .torrent helper cache file tfile = open(torrentfilename, "wb") tfile.write(torrent_data) tfile.close() if DEBUG: print >> sys.stderr, time.asctime(),'-', "helper: new_download: Got metadata required for helping",show_permid_short(permid) print >> sys.stderr, time.asctime(),'-', "helper: new_download: torrent: ",torrentfilename tdef = TorrentDef.load(torrentfilename) if self.dlconfig is None: dscfg = DownloadStartupConfig() else: dscfg = DownloadStartupConfig(self.dlconfig) dscfg.set_coopdl_coordinator_permid(permid) dscfg.set_dest_dir(self.helpdir) dscfg.set_proxy_mode(PROXY_MODE_OFF) # a helper does not use other helpers for downloading data # Start new download if DEBUG: print >> sys.stderr, time.asctime(),'-', "helper: new_download: Starting a new download" d=self.session.start_download(tdef,dscfg) d.set_state_callback(self.state_callback, getpeerlist=False) # Call the helper object got_ask_for_help method # If the object was created with start_helepr_download, an amount of time is required # before the download is fully operational, so the call to the the helper object got_ask_for_help method # is made using the network thread (the network thread executes tasks sequentially, so the start_download task should # be executed before the network_got_ask_for_help) network_got_ask_for_help_lambda = lambda:self.network_got_ask_for_help(permid, infohash) self.session.lm.rawserver.add_task(network_got_ask_for_help_lambda, 0)