コード例 #1
0
	void ChunkManager::recreateMissingFiles()
	{
		createFiles();
		if (tor.isMultiFile())
		{
			// loop over all files and mark all chunks of all missing files as
			// not downloaded
			for (Uint32 i = 0;i < tor.getNumFiles();i++)
			{
				TorrentFile & tf = tor.getFile(i);
				if (!tf.isMissing())
					continue;
				
				for (Uint32 j = tf.getFirstChunk(); j <= tf.getLastChunk();j++)
					resetChunk(j);
				tf.setMissing(false);
			}
		}
		else
		{
			// reset all chunks in case of single file torrent
			for (Uint32 j = 0; j < tor.getNumChunks();j++)
				resetChunk(j);
		}
		d->saveIndexFile();
		d->recalc_chunks_left = true;
		chunksLeft();
	}
コード例 #2
0
	void ChunkManager::dataChecked(const BitSet & ok_chunks)
	{
		// go over all chunks at check each of them
		for (Uint32 i = 0;i < chunks.count();i++)
		{
			Chunk* c = chunks[i];
			if (ok_chunks.get(i) && !bitset.get(i))
			{
				// We think we do not hae a chunk, but we do have it
				bitset.set(i,true);
				todo.set(i,false);
				// the chunk must be on disk
				c->setStatus(Chunk::ON_DISK);
				tor.updateFilePercentage(i,bitset); 
			}
			else if (!ok_chunks.get(i) && bitset.get(i))
			{
				Out(SYS_DIO|LOG_IMPORTANT) << "Previously OK chunk " << i << " is corrupt !!!!!" << endl;
				// We think we have a chunk, but we don't
				bitset.set(i,false);
				todo.set(i,!only_seed_chunks.get(i) && !excluded_chunks.get(i));
				if (c->getStatus() == Chunk::ON_DISK)
				{
					c->setStatus(Chunk::NOT_DOWNLOADED);
					tor.updateFilePercentage(i,bitset);
				}
				else if (c->getStatus() == Chunk::MMAPPED || c->getStatus() == Chunk::BUFFERED)
				{
					resetChunk(i);
				}
				else
				{
					tor.updateFilePercentage(i,bitset);
				}
			}
		}
		recalc_chunks_left = true;
		try
		{
			saveIndexFile();
		}
		catch (bt::Error & err)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : " << err.toString() << endl;
		}
		catch (...)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : unkown exception" << endl;
		}
		chunksLeft();
		corrupted_count = 0;
	}
コード例 #3
0
	void ChunkManager::dataChecked(const bt::BitSet& ok_chunks, bt::Uint32 from, bt::Uint32 to)
	{
		// go over all chunks at check each of them
		for (Uint32 i = from;i < (Uint32)d->chunks.size() && i <= to;i++)
		{
			Chunk* c = d->chunks[i];
			if (ok_chunks.get(i) && !bitset.get(i))
			{
				// We think we do not have a chunk, but we do have it
				bitset.set(i,true);
				d->todo.set(i,false);
				// the chunk must be on disk
				c->setStatus(Chunk::ON_DISK);
				tor.updateFilePercentage(i,*this); 
			}
			else if (!ok_chunks.get(i) && bitset.get(i))
			{
				Out(SYS_DIO|LOG_IMPORTANT) << "Previously OK chunk " << i << " is corrupt !!!!!" << endl;
				// We think we have a chunk, but we don't
				bitset.set(i,false);
				d->todo.set(i,!only_seed_chunks.get(i) && !excluded_chunks.get(i));
				if (c->getStatus() == Chunk::ON_DISK)
				{
					c->setStatus(Chunk::NOT_DOWNLOADED);
					tor.updateFilePercentage(i,*this);
				}
				else
				{
					tor.updateFilePercentage(i,*this);
				}
			}
		}
		d->recalc_chunks_left = true;
		try
		{
			d->saveIndexFile();
		}
		catch (bt::Error & err)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : " << err.toString() << endl;
		}
		catch (...)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : unknown exception" << endl;
		}
		chunksLeft();
	}
コード例 #4
0
	void ChunkManager::dndMissingFiles()
	{
	//	createFiles(); // create them again
		// loop over all files and mark all chunks of all missing files as
		// not downloaded
		for (Uint32 i = 0;i < tor.getNumFiles();i++)
		{
			TorrentFile & tf = tor.getFile(i);
			if (!tf.isMissing())
				continue;
				
			for (Uint32 j = tf.getFirstChunk(); j <= tf.getLastChunk();j++)
				resetChunk(j);
			tf.setMissing(false);
			tf.setDoNotDownload(true); // set do not download
		}
		d->savePriorityInfo();
		d->saveIndexFile();
		d->recalc_chunks_left = true;
		chunksLeft();
	}
コード例 #5
0
	void ChunkManager::markExistingFilesAsDownloaded()
	{
		if (tor.isMultiFile())
		{
			// loop over all files and mark all chunks of all existing files as
			// downloaded
			for (Uint32 i = 0;i < tor.getNumFiles();i++)
			{
				TorrentFile & tf = tor.getFile(i);
				if (!tf.isPreExistingFile())
					continue;
				
				// all the chunks in the middle of the file are OK
				for (Uint32 j = tf.getFirstChunk() + 1;j < tf.getLastChunk();j++)
				{
					Chunk* c = d->chunks[j];
					c->setStatus(Chunk::ON_DISK);
					bitset.set(j,true);
					d->todo.set(j,false);
					tor.updateFilePercentage(j,*this); 
				}
				
				// all files of the first chunk must be preexisting
				if (d->allFilesExistOfChunk(tf.getFirstChunk()))
				{
					Uint32 idx = tf.getFirstChunk();
					Chunk* c = d->chunks[idx];
					c->setStatus(Chunk::ON_DISK);
					bitset.set(idx,true);
					d->todo.set(idx,false);
					tor.updateFilePercentage(idx,*this); 
				}
				
				// all files of the last chunk must be preexisting
				if (d->allFilesExistOfChunk(tf.getLastChunk()))
				{
					Uint32 idx = tf.getLastChunk();
					Chunk* c = d->chunks[idx];
					c->setStatus(Chunk::ON_DISK);
					bitset.set(idx,true);
					d->todo.set(idx,false);
					tor.updateFilePercentage(idx,*this); 
				}
			}
		}
		else if (d->cache->hasExistingFiles())
		{
			for (Uint32 i = 0;i < d->chunks.size();i++)
			{
				Chunk* c = d->chunks[i];
				c->setStatus(Chunk::ON_DISK);
				bitset.set(i,true);
				d->todo.set(i,false);
				tor.updateFilePercentage(i,*this); 
			}
		}
		
		d->recalc_chunks_left = true;
		try
		{
			d->saveIndexFile();
		}
		catch (bt::Error & err)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : " << err.toString() << endl;
		}
		catch (...)
		{
			Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : unknown exception" << endl;
		}
		chunksLeft();
	}