summaryrefslogtreecommitdiffstats
path: root/apps/ktcachecheck
diff options
context:
space:
mode:
Diffstat (limited to 'apps/ktcachecheck')
-rw-r--r--apps/ktcachecheck/Makefile.am12
-rw-r--r--apps/ktcachecheck/cachecheck.cpp102
-rw-r--r--apps/ktcachecheck/cachechecker.cpp110
-rw-r--r--apps/ktcachecheck/cachechecker.h61
-rw-r--r--apps/ktcachecheck/multicachechecker.cpp143
-rw-r--r--apps/ktcachecheck/multicachechecker.h44
-rw-r--r--apps/ktcachecheck/singlecachechecker.cpp110
-rw-r--r--apps/ktcachecheck/singlecachechecker.h43
8 files changed, 0 insertions, 625 deletions
diff --git a/apps/ktcachecheck/Makefile.am b/apps/ktcachecheck/Makefile.am
deleted file mode 100644
index a9f5d3e..0000000
--- a/apps/ktcachecheck/Makefile.am
+++ /dev/null
@@ -1,12 +0,0 @@
-INCLUDES = -I$(srcdir)/../../libktorrent $(all_includes)
-METASOURCES = AUTO
-
-bin_PROGRAMS = ktcachecheck
-
-ktcachecheck_SOURCES = cachecheck.cpp cachechecker.cpp singlecachechecker.cpp \
- multicachechecker.cpp
-ktcachecheck_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_TQT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor
-ktcachecheck_LDADD = $(LIB_TDEPARTS) ../../libktorrent/libktorrent.la \
- $(LIB_TDEFILE) $(LIB_TDEIO)
-noinst_HEADERS = cachechecker.h singlecachechecker.h multicachechecker.h
-KDE_CXXFLAGS = $(USE_EXCEPTIONS) $(USE_RTTI)
diff --git a/apps/ktcachecheck/cachecheck.cpp b/apps/ktcachecheck/cachecheck.cpp
deleted file mode 100644
index 191ed7a..0000000
--- a/apps/ktcachecheck/cachecheck.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 <iostream>
-#include <stdlib.h>
-#include <util/log.h>
-#include <util/error.h>
-#include <util/functions.h>
-#include <torrent/globals.h>
-#include <torrent/torrent.h>
-#include "singlecachechecker.h"
-#include "multicachechecker.h"
-
-
-using namespace bt;
-using namespace ktdebug;
-
-void Help()
-{
- Out() << "Usage : cachecheck <directory_containing_cache>" << endl;
- Out() << "OR cachecheck <torrent> <cache_file_or_dir> <index_file>" << endl;
- exit(0);
-}
-
-int main(int argc,char** argv)
-{
- Globals::instance().setDebugMode(true);
- Globals::instance().initLog("cachecheck.log");
- CacheChecker* cc = 0;
- try
- {
- Torrent tor;
- TQString tor_file,cache,index;
-
- if (argc == 2)
- {
- TQString cache_dir = argv[1];
- if (!cache_dir.endsWith(bt::DirSeparator()))
- cache_dir += bt::DirSeparator();
-
- tor_file = cache_dir + "torrent";
- cache = cache_dir + "cache";
- index = cache_dir + "index";
- }
- else if (argc == 4)
- {
- tor_file = argv[1];
- cache = argv[2];
- index = argv[3];
- }
- else
- {
- Help();
- }
-
-
- Out() << "Loading torrent : " << tor_file << " ... " << endl;
- tor.load(tor_file,false);
- if (tor.isMultiFile())
- cc = new MultiCacheChecker(tor);
- else
- cc = new SingleCacheChecker(tor);
-
- cc->check(cache,index);
- if (cc->foundFailedChunks())
- {
- std::string str;
- std::cout << "Found failed chunks, fix index file ? (y/n) ";
- std::cin >> str;
- if (str == "y" || str == "Y")
- {
- Out() << "Fixing index file ..." << endl;
- cc->fixIndex();
- Out() << "Finished !" << endl;
- }
- }
- }
- catch (Error & e)
- {
- Out() << "Error : " << e.toString() << endl;
- }
-
- delete cc;
- Globals::cleanup();
- return 0;
-}
diff --git a/apps/ktcachecheck/cachechecker.cpp b/apps/ktcachecheck/cachechecker.cpp
deleted file mode 100644
index 3c3b35e..0000000
--- a/apps/ktcachecheck/cachechecker.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 <tdelocale.h>
-#include <util/log.h>
-#include <util/file.h>
-#include <util/error.h>
-#include <util/array.h>
-#include <torrent/globals.h>
-#include <torrent/torrent.h>
-#include <torrent/chunkmanager.h>
-#include "cachechecker.h"
-
-using namespace bt;
-
-namespace ktdebug
-{
-
- CacheChecker::CacheChecker(bt::Torrent & tor) : tor(tor)
- {}
-
-
- CacheChecker::~CacheChecker()
- {}
-
- void CacheChecker::loadIndex(const TQString & index_file)
- {
- this->index_file = index_file;
- File fptr;
- if (!fptr.open(index_file,"rb"))
- throw Error(i18n("Cannot open index file %1 : %2").arg(index_file).arg(fptr.errorString()));
-
- if (fptr.seek(File::END,0) != 0)
- {
- fptr.seek(File::BEGIN,0);
-
- while (!fptr.eof())
- {
- NewChunkHeader hdr;
- fptr.read(&hdr,sizeof(NewChunkHeader));
- downloaded_chunks.insert(hdr.index);
- }
- }
- }
-
- struct ChunkHeader
- {
- unsigned int index; // the Chunks index
- unsigned int deprecated; // offset in cache file
- };
-
-
- void CacheChecker::fixIndex()
- {
- if (failed_chunks.size() == 0 && extra_chunks.size() == 0)
- return;
-
- File fptr;
- if (!fptr.open(index_file,"wb"))
- throw Error(i18n("Cannot open index file %1 : %2").arg(index_file).arg(fptr.errorString()));
-
- std::set<bt::Uint32>::iterator i;
- // first remove failed chunks from downloaded
- if (failed_chunks.size() > 0)
- {
- i = failed_chunks.begin();
- while (i != failed_chunks.end())
- {
- downloaded_chunks.erase(*i);
- i++;
- }
- }
-
- // add extra chunks to download
- if (extra_chunks.size() > 0)
- {
- i = extra_chunks.begin();
- while (i != extra_chunks.end())
- {
- downloaded_chunks.insert(*i);
- i++;
- }
- }
-
- // write remaining chunks
- i = downloaded_chunks.begin();
- while (i != downloaded_chunks.end())
- {
- ChunkHeader ch = {*i,0};
- fptr.write(&ch,sizeof(ChunkHeader));
- i++;
- }
- }
-}
diff --git a/apps/ktcachecheck/cachechecker.h b/apps/ktcachecheck/cachechecker.h
deleted file mode 100644
index 27d58ac..0000000
--- a/apps/ktcachecheck/cachechecker.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 DEBUGCACHECHECKER_H
-#define DEBUGCACHECHECKER_H
-
-#include <set>
-#include <tqstring.h>
-#include <util/functions.h>
-
-namespace bt
-{
- class Torrent;
-}
-
-namespace ktdebug
-{
-
- /**
- * @author Joris Guisson
- */
- class CacheChecker
- {
- public:
- CacheChecker(bt::Torrent & tor);
- virtual ~CacheChecker();
-
- void loadIndex(const TQString & index_file);
- void fixIndex();
- bool foundFailedChunks() const {return failed_chunks.size() > 0;}
- bool foundExtraChunks() const {return extra_chunks.size() > 0;}
-
- virtual void check(const TQString & cache,const TQString & index) = 0;
- protected:
- bt::Torrent & tor;
- TQString index_file;
- std::set<bt::Uint32> downloaded_chunks;
- std::set<bt::Uint32> failed_chunks;
- std::set<bt::Uint32> extra_chunks;
- };
-
-
-}
-
-#endif
diff --git a/apps/ktcachecheck/multicachechecker.cpp b/apps/ktcachecheck/multicachechecker.cpp
deleted file mode 100644
index 53e8fee..0000000
--- a/apps/ktcachecheck/multicachechecker.cpp
+++ /dev/null
@@ -1,143 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 <util/log.h>
-#include <util/file.h>
-#include <util/error.h>
-#include <util/array.h>
-#include <util/functions.h>
-#include <torrent/globals.h>
-#include <torrent/torrent.h>
-#include <torrent/chunkmanager.h>
-#include "multicachechecker.h"
-
-using namespace bt;
-
-namespace ktdebug
-{
-
- MultiCacheChecker::MultiCacheChecker(bt::Torrent& tor): CacheChecker(tor)
- {}
-
-
- MultiCacheChecker::~MultiCacheChecker()
- {}
-
-
- void MultiCacheChecker::check(const TQString& cache_dir, const TQString& index)
- {
- loadIndex(index);
- TQString cache = cache_dir;
- if (!cache.endsWith(bt::DirSeparator()))
- cache += bt::DirSeparator();
-
- Uint32 num_chunks = tor.getNumChunks();
- Uint64 curr_file_off = 0;
- Uint32 curr_file = 0;
- Uint64 chunk_size = tor.getChunkSize();
-
- Array<Uint8> buf((Uint32)tor.getChunkSize());
- Uint32 num_ok = 0,num_not_ok = 0,num_not_downloaded = 0,extra_ok = 0;
-
- for (Uint32 i = 0;i < num_chunks;i++)
- {
- if (i % 100 == 0)
- Out() << "Checked " << i << " chunks" << endl;
-
-
-
- Uint64 size = chunk_size;
- if (i == tor.getNumChunks() - 1 && tor.getFileLength() % chunk_size != 0)
- size = tor.getFileLength() % chunk_size;
-
- //Out() << "Loading chunk (size = " << size << ")" << endl;
- Uint64 bytes_offset = 0;
- while (bytes_offset < size)
- {
- TorrentFile & tf = tor.getFile(curr_file);
-// Out() << "Current file : " << tf.getPath() << " (" << curr_file << ")" << endl;
- Uint64 to_read = size - bytes_offset;
-// Out() << "to_read = " << to_read << endl;
- if (to_read <= tf.getSize() - curr_file_off)
- {
- // we can read the chunk from this file
- File fptr;
- if (!fptr.open(cache + tf.getPath(),"rb"))
- throw Error(TQString("Cannot open %1 : %2").arg(cache + tf.getPath()).arg(fptr.errorString()));
-
- fptr.seek(File::BEGIN,curr_file_off);
- fptr.read(buf + bytes_offset,to_read);
- bytes_offset += to_read;
- curr_file_off += to_read;
- }
- else
- {
-
- // read partially the data which can be read
- to_read = tf.getSize() - curr_file_off;
-// Out() << "Partially reading " << to_read << endl;
- File fptr;
- if (!fptr.open(cache + tf.getPath(),"rb"))
- throw Error(TQString("Cannot open %1 : %2").arg(cache + tf.getPath()).arg(fptr.errorString()));
-
- fptr.seek(File::BEGIN,curr_file_off);
- fptr.read(buf + bytes_offset,to_read);
- bytes_offset += to_read;
- // update curr_file and offset
- curr_file++;
- curr_file_off = 0;
- }
- } // end file reading while
-
- // calculate hash and check it
- SHA1Hash h = SHA1Hash::generate(buf,size);
- if (h != tor.getHash(i))
- {
- if (downloaded_chunks.count(i) == 0)
- {
- num_not_downloaded++;
- continue;
- }
- Out() << "Chunk " << i << " Failed :" << endl;
- Out() << "\tShould be : " << tor.getHash(i).toString() << endl;
- Out() << "\tIs : " << h.toString() << endl;
- num_not_ok++;
- failed_chunks.insert(i);
- }
- else
- {
- if (downloaded_chunks.count(i) == 0)
- {
- extra_ok++;
- extra_chunks.insert(i);
- continue;
- }
- num_ok++;
- }
- }
-
- Out() << "Cache Check Summary" << endl;
- Out() << "===================" << endl;
- Out() << "Extra Chunks : " << extra_ok << endl;
- Out() << "Chunks OK : " << num_ok << endl;
- Out() << "Chunks Not Downloaded : " << num_not_downloaded << endl;
- Out() << "Chunks Failed : " << num_not_ok << endl;
- }
-
-}
diff --git a/apps/ktcachecheck/multicachechecker.h b/apps/ktcachecheck/multicachechecker.h
deleted file mode 100644
index fc57792..0000000
--- a/apps/ktcachecheck/multicachechecker.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 DEBUGMULTICACHECHECKER_H
-#define DEBUGMULTICACHECHECKER_H
-
-#include "cachechecker.h"
-
-namespace ktdebug
-{
-
- /**
- @author Joris Guisson
- */
- class MultiCacheChecker : public CacheChecker
- {
- public:
- MultiCacheChecker(bt::Torrent& tor);
-
- ~MultiCacheChecker();
-
- virtual void check(const TQString& cache, const TQString& index);
-
- };
-
-}
-
-#endif
diff --git a/apps/ktcachecheck/singlecachechecker.cpp b/apps/ktcachecheck/singlecachechecker.cpp
deleted file mode 100644
index ab64fc3..0000000
--- a/apps/ktcachecheck/singlecachechecker.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 <util/log.h>
-#include <util/file.h>
-#include <util/error.h>
-#include <util/array.h>
-#include <util/functions.h>
-#include <torrent/globals.h>
-#include <torrent/torrent.h>
-#include <torrent/chunkmanager.h>
-#include "singlecachechecker.h"
-
-using namespace bt;
-
-namespace ktdebug
-{
-
- SingleCacheChecker::SingleCacheChecker(bt::Torrent& tor): CacheChecker(tor)
- {}
-
-
- SingleCacheChecker::~SingleCacheChecker()
- {}
-
-
- void SingleCacheChecker::check(const TQString& cache, const TQString& index)
- {
- loadIndex(index);
- Uint32 num_chunks = tor.getNumChunks();
- File fptr;
- if (!fptr.open(cache,"rb"))
- {
- throw Error(TQString("Cannot open file : %1 : %2")
- .arg(cache).arg( fptr.errorString()));
- }
-
- Uint32 num_ok = 0,num_not_ok = 0,num_not_downloaded = 0,extra_ok = 0;
-
- Array<Uint8> buf((Uint32)tor.getChunkSize());
- for (Uint32 i = 0;i < num_chunks;i++)
- {
- if (i % 100 == 0)
- Out(SYS_GEN|LOG_DEBUG) << "Checked " << i << " chunks" << endl;
- // Out() << "Chunk " << i << " : ";
- if (!fptr.eof())
- {
- Uint32 size = i == num_chunks - 1 && tor.getFileLength() % tor.getChunkSize() > 0 ?
- tor.getFileLength() % tor.getChunkSize() : (Uint32)tor.getChunkSize();
- fptr.seek(File::BEGIN,(Int64)i*tor.getChunkSize());
- fptr.read(buf,size);
- SHA1Hash h = SHA1Hash::generate(buf,size);
- bool ok = (h == tor.getHash(i));
- if (ok)
- {
- if (downloaded_chunks.count(i) == 0)
- {
- extra_ok++;
- extra_chunks.insert(i);
- continue;
- }
- num_ok++;
- // Out() << "OK" << endl;
- }
- else
- {
- if (downloaded_chunks.count(i) == 0)
- {
- num_not_downloaded++;
- continue;
- }
- Out() << "Chunk " << i << " Failed :" << endl;
- Out() << "\tShould be : " << tor.getHash(i).toString() << endl;
- Out() << "\tIs : " << h.toString() << endl;
- num_not_ok++;
- failed_chunks.insert(i);
- }
-
- }
- else
- {
- num_not_downloaded++;
- //Out() << "Not Downloaded" << endl;
- }
- }
- Out() << "Cache Check Summary" << endl;
- Out() << "===================" << endl;
- Out() << "Extra Chunks : " << extra_ok << endl;
- Out() << "Chunks OK : " << num_ok << endl;
- Out() << "Chunks Not Downloaded : " << num_not_downloaded << endl;
- Out() << "Chunks Failed : " << num_not_ok << endl;
- }
-
-}
diff --git a/apps/ktcachecheck/singlecachechecker.h b/apps/ktcachecheck/singlecachechecker.h
deleted file mode 100644
index fdec69d..0000000
--- a/apps/ktcachecheck/singlecachechecker.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2005 by Joris Guisson *
- * *
- * 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 DEBUGSINGLECACHECHECKER_H
-#define DEBUGSINGLECACHECHECKER_H
-
-#include "cachechecker.h"
-
-namespace ktdebug
-{
-
- /**
- @author Joris Guisson
- */
- class SingleCacheChecker : public CacheChecker
- {
- public:
- SingleCacheChecker(bt::Torrent& tor);
- virtual ~SingleCacheChecker();
-
- virtual void check(const TQString& cache, const TQString& index);
-
- };
-
-}
-
-#endif