From: <arn...@us...> - 2006-03-17 22:58:09
|
Revision: 589 Author: arnetheduck Date: 2006-03-17 14:57:48 -0800 (Fri, 17 Mar 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=589&view=rev Log Message: ----------- sfv check added to hashing Modified Paths: -------------- dcplusplus/trunk/Example.xml dcplusplus/trunk/changelog.txt dcplusplus/trunk/client/HashManager.cpp dcplusplus/trunk/client/HashManager.h dcplusplus/trunk/client/StringDefs.cpp dcplusplus/trunk/client/StringDefs.h Modified: dcplusplus/trunk/Example.xml =================================================================== --- dcplusplus/trunk/Example.xml 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/Example.xml 2006-03-17 22:57:48 UTC (rev 589) @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8" standalone="yes"?> -<Language Name="Example Language" Author="arnetheduck" Version="0.687" Revision="1" RightToLeft="0"> +<Language Name="Example Language" Author="arnetheduck" Version="0.6875" Revision="1" RightToLeft="0"> <Strings> <String Name="Active">Active</String> <String Name="ActiveSearchString">Enabled / Search String</String> @@ -278,6 +278,7 @@ <String Name="Nick">Nick</String> <String Name="NickTaken">Your nick was already taken, please change to something else!</String> <String Name="NickUnknown"> (Nick unknown)</String> + <String Name="NoCrc32Match"> not shared; calculated CRC32 does not match the one found in SFV file.</String> <String Name="NoStr">No</String> <String Name="NoDirectorySpecified">No directory specified</String> <String Name="NoDownloadsFromSelf">You're trying to download from yourself!</String> Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/changelog.txt 2006-03-17 22:57:48 UTC (rev 589) @@ -4,6 +4,7 @@ * Fixed a 100% cpu / crash bug * [bug 872] Fixed a pm issue hopefully * [bug 812] Fixed pm's being sent to bots +* Files with invalid crc-32, as per their sfv file, are no longer shared -- 0.687 2006-02-26 -- * Fixed XML file list generation for invalid filenames from other os's Modified: dcplusplus/trunk/client/HashManager.cpp =================================================================== --- dcplusplus/trunk/client/HashManager.cpp 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/client/HashManager.cpp 2006-03-17 22:57:48 UTC (rev 589) @@ -24,6 +24,8 @@ #include "SimpleXML.h" #include "LogManager.h" #include "File.h" +#include "ZUtils.h" +#include "SFVReader.h" #define HASH_FILE_VERSION_STRING "2" static const u_int32_t HASH_FILE_VERSION=2; @@ -438,7 +440,7 @@ #define BUF_SIZE (256*1024) #ifdef _WIN32 -bool HashManager::Hasher::fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size) { +bool HashManager::Hasher::fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32) { HANDLE h = INVALID_HANDLE_VALUE; DWORD x, y; if(!GetDiskFreeSpace(Text::toT(Util::getFilePath(fname)).c_str(), &y, &x, &y, &y)) { @@ -503,8 +505,13 @@ } tth.update(hbuf, hn); - total -= hn; + if(xcrc32) (*xcrc32)(hbuf, hn); + { + Lock l(cs); + currentSize = max(currentSize - hn, _LL(0)); + } + if(size == 0) { ok = true; break; @@ -560,7 +567,8 @@ { Lock l(cs); if(!w.empty()) { - file = fname = w.begin()->first; + currentFile = fname = w.begin()->first; + currentSize = w.begin()->second; w.erase(w.begin()); last = w.empty(); } else { @@ -586,18 +594,24 @@ try { File f(fname, File::READ, File::OPEN); int64_t bs = max(TigerTree::calcBlockSize(f.getSize(), 10), MIN_BLOCK_SIZE); -#ifdef _WIN32 u_int32_t start = GET_TICK(); -#endif u_int32_t timestamp = f.getLastModified(); TigerTree slowTTH(bs); TigerTree* tth = &slowTTH; + + CRC32Filter crc32; + SFVReader sfv(fname); + CRC32Filter* xcrc32 = 0; + if(sfv.hasCRC()) + xcrc32 = &crc32; + size_t n = 0; #ifdef _WIN32 TigerTree fastTTH(bs); tth = &fastTTH; - if(!virtualBuf || !fastHash(fname, buf, fastTTH, size)) { + if(!virtualBuf || !fastHash(fname, buf, fastTTH, size, xcrc32)) { tth = &slowTTH; + crc32 = CRC32Filter(); #endif u_int32_t lastRead = GET_TICK(); @@ -612,8 +626,12 @@ } n = f.read(buf, bufSize); tth->update(buf, n); + if(xcrc32) (*xcrc32)(buf, n); - total -= n; + { + Lock l(cs); + currentSize = max(currentSize - n, _LL(0)); + } sizeLeft -= n; } while (n > 0 && !stop); #ifdef _WIN32 @@ -623,22 +641,25 @@ #endif f.close(); tth->finalize(); -#ifdef _WIN32 u_int32_t end = GET_TICK(); int64_t speed = 0; if(end > start) { - speed = size * 1000LL / (end - start); + speed = size * _LL(1000) / (end - start); } -#else - int64_t speed = 0; -#endif - HashManager::getInstance()->hashDone(fname, timestamp, *tth, speed); + if(xcrc32 && xcrc32->getValue() != sfv.getCRC()) { + LogManager::getInstance()->message(fname + STRING(NO_CRC32_MATCH)); + } else { + HashManager::getInstance()->hashDone(fname, timestamp, *tth, speed); + } } catch(const FileException& e) { LogManager::getInstance()->message(STRING(ERROR_HASHING) + fname + ": " + e.getError()); } - - total -= sizeLeft; } + { + Lock l(cs); + currentFile.clear(); + currentSize = 0; + } running = false; if(buf != NULL && (last || stop)) { if(virtualBuf) { Modified: dcplusplus/trunk/client/HashManager.h =================================================================== --- dcplusplus/trunk/client/HashManager.h 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/client/HashManager.h 2006-03-17 22:57:48 UTC (rev 589) @@ -35,6 +35,7 @@ STANDARD_EXCEPTION(HashException); class File; +class CRC32Filter; class HashManagerListener { public: @@ -117,13 +118,12 @@ class Hasher : public Thread { public: - Hasher() : stop(false), running(false), rebuild(false), total(0) { } + Hasher() : stop(false), running(false), rebuild(false), currentSize(0) { } void hashFile(const string& fileName, int64_t size) { Lock l(cs); if(w.insert(make_pair(fileName, size)).second) { s.signal(); - total += size; } } @@ -131,7 +131,6 @@ Lock l(cs); for(WorkIter i = w.begin(); i != w.end(); ) { if(Util::strnicmp(baseDir, i->first, baseDir.length()) == 0) { - total -= i->second; w.erase(i++); } else { ++i; @@ -141,18 +140,19 @@ virtual int run(); #ifdef _WIN32 - bool fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size); + bool fastHash(const string& fname, u_int8_t* buf, TigerTree& tth, int64_t size, CRC32Filter* xcrc32); #endif void getStats(string& curFile, int64_t& bytesLeft, size_t& filesLeft) { Lock l(cs); - curFile = file; + curFile = currentFile; filesLeft = w.size(); if(running) filesLeft++; - // Just in case... - if(total < 0) - total = 0; - bytesLeft = total; + bytesLeft = 0; + for(WorkMap::const_iterator i = w.begin(); i != w.end(); ++i) { + bytesLeft += i->second; + } + bytesLeft += currentSize; } void shutdown() { stop = true; @@ -176,8 +176,8 @@ bool stop; bool running; bool rebuild; - int64_t total; - string file; + string currentFile; + int64_t currentSize; }; friend class Hasher; Modified: dcplusplus/trunk/client/StringDefs.cpp =================================================================== --- dcplusplus/trunk/client/StringDefs.cpp 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/client/StringDefs.cpp 2006-03-17 22:57:48 UTC (rev 589) @@ -279,6 +279,7 @@ "Nick", "Your nick was already taken, please change to something else!", " (Nick unknown)", +" not shared; calculated CRC32 does not match the one found in SFV file.", "No", "No directory specified", "You're trying to download from yourself!", @@ -879,6 +880,7 @@ "Nick", "NickTaken", "NickUnknown", +"NoCrc32Match", "NoStr", "NoDirectorySpecified", "NoDownloadsFromSelf", Modified: dcplusplus/trunk/client/StringDefs.h =================================================================== --- dcplusplus/trunk/client/StringDefs.h 2006-03-16 22:49:30 UTC (rev 588) +++ dcplusplus/trunk/client/StringDefs.h 2006-03-17 22:57:48 UTC (rev 589) @@ -282,6 +282,7 @@ NICK, // "Nick" NICK_TAKEN, // "Your nick was already taken, please change to something else!" NICK_UNKNOWN, // " (Nick unknown)" + NO_CRC32_MATCH, // " not shared; calculated CRC32 does not match the one found in SFV file." NO_STR, // "No" NO_DIRECTORY_SPECIFIED, // "No directory specified" NO_DOWNLOADS_FROM_SELF, // "You're trying to download from yourself!" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |