From e66056405208b7ba28c848aba5a680fbc9f3a53f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Sun, 24 Feb 2013 16:04:22 +0100 Subject: Fix unintended rename of chunk* --- libktorrent/torrent/Makefile.am | 4 +- libktorrent/torrent/chunkselector.cpp | 185 ++++++++++++++++++++++++++++++++ libktorrent/torrent/chunkselector.h | 80 ++++++++++++++ libktorrent/torrent/chuntdeselector.cpp | 185 -------------------------------- libktorrent/torrent/chuntdeselector.h | 80 -------------- libktorrent/torrent/downloader.cpp | 2 +- 6 files changed, 268 insertions(+), 268 deletions(-) create mode 100644 libktorrent/torrent/chunkselector.cpp create mode 100644 libktorrent/torrent/chunkselector.h delete mode 100644 libktorrent/torrent/chuntdeselector.cpp delete mode 100644 libktorrent/torrent/chuntdeselector.h diff --git a/libktorrent/torrent/Makefile.am b/libktorrent/torrent/Makefile.am index 92a170d..d546228 100644 --- a/libktorrent/torrent/Makefile.am +++ b/libktorrent/torrent/Makefile.am @@ -8,7 +8,7 @@ libtorrent_la_LDFLAGS = $(all_libraries) noinst_HEADERS = advancedchokealgorithm.h announcelist.h authenticate.h \ authenticatebase.h authenticationmonitor.h bdecoder.h bencoder.h bnode.h cache.h \ cachefile.h cap.h choker.h chunk.h chunkcounter.h chunkdownload.h chunkmanager.h \ - chuntdeselector.h dndfile.h downloadcap.h downloader.h globals.h httptracker.h \ + chunkselector.h dndfile.h downloadcap.h downloader.h globals.h httptracker.h \ ipblocklist.h movedatafilesjob.h multifilecache.h newchokealgorithm.h \ oldchokealgorithm.h packet.h packetreader.h packetwriter.h peer.h peerdownloader.h peerid.h \ peermanager.h peersourcemanager.h peeruploader.h piece.h preallocationthread.h \ @@ -20,7 +20,7 @@ noinst_HEADERS = advancedchokealgorithm.h announcelist.h authenticate.h \ libtorrent_la_SOURCES = advancedchokealgorithm.cpp announcelist.cpp \ authenticate.cpp authenticatebase.cpp authenticationmonitor.cpp bdecoder.cpp \ bencoder.cpp bnode.cpp cache.cpp cachefile.cpp cap.cpp choker.cpp chunk.cpp \ - chunkcounter.cpp chunkdownload.cpp chunkmanager.cpp chuntdeselector.cpp dndfile.cpp \ + chunkcounter.cpp chunkdownload.cpp chunkmanager.cpp chunkselector.cpp dndfile.cpp \ downloadcap.cpp downloader.cpp globals.cpp httptracker.cpp ipblocklist.cpp \ movedatafilesjob.cpp multifilecache.cpp newchokealgorithm.cpp packet.cpp packetreader.cpp \ packetwriter.cpp peer.cpp peerdownloader.cpp peerid.cpp peermanager.cpp \ diff --git a/libktorrent/torrent/chunkselector.cpp b/libktorrent/torrent/chunkselector.cpp new file mode 100644 index 0000000..b1c42fa --- /dev/null +++ b/libktorrent/torrent/chunkselector.cpp @@ -0,0 +1,185 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#include +#include +#include +#include +#include +#include "chunkcounter.h" +#include "chunkselector.h" +#include "chunkmanager.h" +#include "downloader.h" +#include "peerdownloader.h" +#include "globals.h" +#include "peer.h" +#include "peermanager.h" + +namespace bt +{ + struct RareCmp + { + ChunkManager & cman; + ChunkCounter & cc; + bool warmup; + + RareCmp(ChunkManager & cman,ChunkCounter & cc,bool warmup) : cman(cman),cc(cc),warmup(warmup) {} + + bool operator()(Uint32 a,Uint32 b) + { + // do some sanity checks + if (a >= cman.getNumChunks() || b >= cman.getNumChunks()) + return false; + + // the sorting is done on two criteria, priority and rareness + Priority pa = cman.getChunk(a)->getPriority(); + Priority pb = cman.getChunk(b)->getPriority(); + if (pa == pb) + return normalCmp(a,b); // if both have same priority compare on rareness + else if (pa > pb) // pa has priority over pb, so select pa + return true; + else // pb has priority over pa, so select pb + return false; + } + + bool normalCmp(Uint32 a,Uint32 b) + { + // during warmup mode choose most common chunks + if (!warmup) + return cc.get(a) < cc.get(b); + else + return cc.get(a) > cc.get(b); + } + }; + + ChunkSelector::ChunkSelector(ChunkManager & cman,Downloader & downer,PeerManager & pman) + : cman(cman),downer(downer),pman(pman) + { + std::vector tmp; + for (Uint32 i = 0;i < cman.getNumChunks();i++) + { + if (!cman.getBitSet().get(i)) + { + tmp.push_back(i); + } + } + std::random_shuffle(tmp.begin(),tmp.end()); + // std::list does not support random_shuffle so we use a vector as a temporary storage + // for the random_shuffle + chunks.insert(chunks.begin(),tmp.begin(),tmp.end()); + sort_timer.update(); + } + + + ChunkSelector::~ChunkSelector() + {} + + + bool ChunkSelector::select(PeerDownloader* pd,Uint32 & chunk) + { + const BitSet & bs = cman.getBitSet(); + + + // sort the chunks every 2 seconds + if (sort_timer.getElapsedSinceUpdate() > 2000) + { + bool warmup = cman.getNumChunks() - cman.chunksLeft() <= 4; +// dataChecked(bs); + chunks.sort(RareCmp(cman,pman.getChunkCounter(),warmup)); + sort_timer.update(); + } + + std::list::iterator itr = chunks.begin(); + while (itr != chunks.end()) + { + Uint32 i = *itr; + Chunk* c = cman.getChunk(*itr); + + // if we have the chunk remove it from the list + if (bs.get(i)) + { + std::list::iterator tmp = itr; + itr++; + chunks.erase(tmp); + } + else + { + // pd has to have the selected chunk and it needs to be not excluded + if (pd->hasChunk(i) && !downer.areWeDownloading(i) && + !c->isExcluded() && !c->isExcludedForDownloading()) + { + // we have a chunk + chunk = i; + return true; + } + itr++; + } + } + + return false; + } + + void ChunkSelector::dataChecked(const BitSet & ok_chunks) + { + for (Uint32 i = 0;i < ok_chunks.getNumBits();i++) + { + bool in_chunks = std::find(chunks.begin(),chunks.end(),i) != chunks.end(); + if (in_chunks && ok_chunks.get(i)) + { + // if we have the chunk, remove it from the chunks list + chunks.remove(i); + } + else if (!in_chunks && !ok_chunks.get(i)) + { + // if we don't have the chunk, add it to the list if it wasn't allrready in there + chunks.push_back(i); + } + } + } + + void ChunkSelector::reincluded(Uint32 from, Uint32 to) + { + // lets do a safety check first + if (from >= cman.getNumChunks() || to >= cman.getNumChunks()) + { + Out(SYS_DIO|LOG_NOTICE) << "Internal error in chunkselector" << endl; + return; + } + + for (Uint32 i = from;i <= to;i++) + { + bool in_chunks = std::find(chunks.begin(),chunks.end(),i) != chunks.end(); + if (!in_chunks && cman.getChunk(i)->getStatus() != Chunk::ON_DISK) + { + // Out(SYS_DIO|LOG_DEBUG) << "ChunkSelector::reIncluded " << i << endl; + chunks.push_back(i); + } + } + } + + void ChunkSelector::reinsert(Uint32 chunk) + { + bool in_chunks = std::find(chunks.begin(),chunks.end(),chunk) != chunks.end(); + if (!in_chunks) + chunks.push_back(chunk); + } + + +} + diff --git a/libktorrent/torrent/chunkselector.h b/libktorrent/torrent/chunkselector.h new file mode 100644 index 0000000..3ba2f8a --- /dev/null +++ b/libktorrent/torrent/chunkselector.h @@ -0,0 +1,80 @@ +/*************************************************************************** + * Copyright (C) 2005 by Joris Guisson * + * joris.guisson@gmail.com * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef BTCHUNKSELECTOR_H +#define BTCHUNKSELECTOR_H + +#include +#include + +namespace bt +{ + class BitSet; + class PeerDownloader; + class ChunkManager; + class Downloader; + class PeerManager; + /** + * @author Joris Guisson + * + * Selects which Chunks to download. + */ + class ChunkSelector + { + ChunkManager & cman; + Downloader & downer; + PeerManager & pman; + std::list chunks; + Timer sort_timer; + public: + ChunkSelector(ChunkManager & cman,Downloader & downer,PeerManager &pman); + virtual ~ChunkSelector(); + + /** + * Select which chunk to download for a PeerDownloader. + * @param pd The PeerDownloader + * @param chunk Index of chunk gets stored here + * @return true upon succes, false otherwise + */ + bool select(PeerDownloader* pd,Uint32 & chunk); + + /** + * Data has been checked, and these chunks are OK. + * @param ok_chunks The ok_chunks + */ + void dataChecked(const BitSet & ok_chunks); + + /** + * A range of chunks has been reincluded. + * @param from The first chunk + * @param to The last chunk + */ + void reincluded(Uint32 from, Uint32 to); + + /** + * Reinsert a chunk. + * @param chunk The chunk + */ + void reinsert(Uint32 chunk); + }; + +} + +#endif + diff --git a/libktorrent/torrent/chuntdeselector.cpp b/libktorrent/torrent/chuntdeselector.cpp deleted file mode 100644 index 5bbd140..0000000 --- a/libktorrent/torrent/chuntdeselector.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#include -#include -#include -#include -#include -#include "chunkcounter.h" -#include "chuntdeselector.h" -#include "chunkmanager.h" -#include "downloader.h" -#include "peerdownloader.h" -#include "globals.h" -#include "peer.h" -#include "peermanager.h" - -namespace bt -{ - struct RareCmp - { - ChunkManager & cman; - ChunkCounter & cc; - bool warmup; - - RareCmp(ChunkManager & cman,ChunkCounter & cc,bool warmup) : cman(cman),cc(cc),warmup(warmup) {} - - bool operator()(Uint32 a,Uint32 b) - { - // do some sanity checks - if (a >= cman.getNumChunks() || b >= cman.getNumChunks()) - return false; - - // the sorting is done on two criteria, priority and rareness - Priority pa = cman.getChunk(a)->getPriority(); - Priority pb = cman.getChunk(b)->getPriority(); - if (pa == pb) - return normalCmp(a,b); // if both have same priority compare on rareness - else if (pa > pb) // pa has priority over pb, so select pa - return true; - else // pb has priority over pa, so select pb - return false; - } - - bool normalCmp(Uint32 a,Uint32 b) - { - // during warmup mode choose most common chunks - if (!warmup) - return cc.get(a) < cc.get(b); - else - return cc.get(a) > cc.get(b); - } - }; - - ChunkSelector::ChunkSelector(ChunkManager & cman,Downloader & downer,PeerManager & pman) - : cman(cman),downer(downer),pman(pman) - { - std::vector tmp; - for (Uint32 i = 0;i < cman.getNumChunks();i++) - { - if (!cman.getBitSet().get(i)) - { - tmp.push_back(i); - } - } - std::random_shuffle(tmp.begin(),tmp.end()); - // std::list does not support random_shuffle so we use a vector as a temporary storage - // for the random_shuffle - chunks.insert(chunks.begin(),tmp.begin(),tmp.end()); - sort_timer.update(); - } - - - ChunkSelector::~ChunkSelector() - {} - - - bool ChunkSelector::select(PeerDownloader* pd,Uint32 & chunk) - { - const BitSet & bs = cman.getBitSet(); - - - // sort the chunks every 2 seconds - if (sort_timer.getElapsedSinceUpdate() > 2000) - { - bool warmup = cman.getNumChunks() - cman.chunksLeft() <= 4; -// dataChecked(bs); - chunks.sort(RareCmp(cman,pman.getChunkCounter(),warmup)); - sort_timer.update(); - } - - std::list::iterator itr = chunks.begin(); - while (itr != chunks.end()) - { - Uint32 i = *itr; - Chunk* c = cman.getChunk(*itr); - - // if we have the chunk remove it from the list - if (bs.get(i)) - { - std::list::iterator tmp = itr; - itr++; - chunks.erase(tmp); - } - else - { - // pd has to have the selected chunk and it needs to be not excluded - if (pd->hasChunk(i) && !downer.areWeDownloading(i) && - !c->isExcluded() && !c->isExcludedForDownloading()) - { - // we have a chunk - chunk = i; - return true; - } - itr++; - } - } - - return false; - } - - void ChunkSelector::dataChecked(const BitSet & ok_chunks) - { - for (Uint32 i = 0;i < ok_chunks.getNumBits();i++) - { - bool in_chunks = std::find(chunks.begin(),chunks.end(),i) != chunks.end(); - if (in_chunks && ok_chunks.get(i)) - { - // if we have the chunk, remove it from the chunks list - chunks.remove(i); - } - else if (!in_chunks && !ok_chunks.get(i)) - { - // if we don't have the chunk, add it to the list if it wasn't allrready in there - chunks.push_back(i); - } - } - } - - void ChunkSelector::reincluded(Uint32 from, Uint32 to) - { - // lets do a safety check first - if (from >= cman.getNumChunks() || to >= cman.getNumChunks()) - { - Out(SYS_DIO|LOG_NOTICE) << "Internal error in chuntdeselector" << endl; - return; - } - - for (Uint32 i = from;i <= to;i++) - { - bool in_chunks = std::find(chunks.begin(),chunks.end(),i) != chunks.end(); - if (!in_chunks && cman.getChunk(i)->getStatus() != Chunk::ON_DISK) - { - // Out(SYS_DIO|LOG_DEBUG) << "ChunkSelector::reIncluded " << i << endl; - chunks.push_back(i); - } - } - } - - void ChunkSelector::reinsert(Uint32 chunk) - { - bool in_chunks = std::find(chunks.begin(),chunks.end(),chunk) != chunks.end(); - if (!in_chunks) - chunks.push_back(chunk); - } - - -} - diff --git a/libktorrent/torrent/chuntdeselector.h b/libktorrent/torrent/chuntdeselector.h deleted file mode 100644 index 3ba2f8a..0000000 --- a/libktorrent/torrent/chuntdeselector.h +++ /dev/null @@ -1,80 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Joris Guisson * - * joris.guisson@gmail.com * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - ***************************************************************************/ -#ifndef BTCHUNKSELECTOR_H -#define BTCHUNKSELECTOR_H - -#include -#include - -namespace bt -{ - class BitSet; - class PeerDownloader; - class ChunkManager; - class Downloader; - class PeerManager; - /** - * @author Joris Guisson - * - * Selects which Chunks to download. - */ - class ChunkSelector - { - ChunkManager & cman; - Downloader & downer; - PeerManager & pman; - std::list chunks; - Timer sort_timer; - public: - ChunkSelector(ChunkManager & cman,Downloader & downer,PeerManager &pman); - virtual ~ChunkSelector(); - - /** - * Select which chunk to download for a PeerDownloader. - * @param pd The PeerDownloader - * @param chunk Index of chunk gets stored here - * @return true upon succes, false otherwise - */ - bool select(PeerDownloader* pd,Uint32 & chunk); - - /** - * Data has been checked, and these chunks are OK. - * @param ok_chunks The ok_chunks - */ - void dataChecked(const BitSet & ok_chunks); - - /** - * A range of chunks has been reincluded. - * @param from The first chunk - * @param to The last chunk - */ - void reincluded(Uint32 from, Uint32 to); - - /** - * Reinsert a chunk. - * @param chunk The chunk - */ - void reinsert(Uint32 chunk); - }; - -} - -#endif - diff --git a/libktorrent/torrent/downloader.cpp b/libktorrent/torrent/downloader.cpp index 4b81f1b..582fa7e 100644 --- a/libktorrent/torrent/downloader.cpp +++ b/libktorrent/torrent/downloader.cpp @@ -33,7 +33,7 @@ #include #include #include "packetwriter.h" -#include "chuntdeselector.h" +#include "chunkselector.h" #include "ipblocklist.h" #include "ktversion.h" -- cgit v1.2.1