From: <arn...@us...> - 2006-06-03 13:48:11
|
Revision: 610 Author: arnetheduck Date: 2006-06-03 06:47:39 -0700 (Sat, 03 Jun 2006) ViewCVS: http://svn.sourceforge.net/dcplusplus/?rev=610&view=rev Log Message: ----------- Passive adc search results Modified Paths: -------------- dcplusplus/trunk/DCPlusPlus.rc dcplusplus/trunk/client/AdcHub.cpp dcplusplus/trunk/client/AdcHub.h dcplusplus/trunk/client/DownloadManager.cpp dcplusplus/trunk/client/MerkleCheckOutputStream.h dcplusplus/trunk/client/SearchManager.cpp dcplusplus/trunk/client/SearchManager.h dcplusplus/trunk/client/version.h dcplusplus/trunk/windows/resource.h Modified: dcplusplus/trunk/DCPlusPlus.rc =================================================================== --- dcplusplus/trunk/DCPlusPlus.rc 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/DCPlusPlus.rc 2006-06-03 13:47:39 UTC (rev 610) @@ -933,8 +933,8 @@ // VS_VERSION_INFO VERSIONINFO - FILEVERSION 0,6,9,0 - PRODUCTVERSION 0,6,9,0 + FILEVERSION 0,6,9,1 + PRODUCTVERSION 0,6,9,1 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -951,12 +951,12 @@ BEGIN VALUE "Comments", "http://dcplusplus.sourceforge.net" VALUE "FileDescription", "DC++" - VALUE "FileVersion", "0, 6, 9, 0" + VALUE "FileVersion", "0, 6, 9, 1" VALUE "InternalName", "DC++" VALUE "LegalCopyright", "Copyright 2001-2006 Jacek Sieka" VALUE "OriginalFilename", "DCPlusPlus.exe" VALUE "ProductName", "DC++" - VALUE "ProductVersion", "0, 6, 9, 0" + VALUE "ProductVersion", "0, 6, 9, 1" END END BLOCK "VarFileInfo" Modified: dcplusplus/trunk/client/AdcHub.cpp =================================================================== --- dcplusplus/trunk/client/AdcHub.cpp 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/AdcHub.cpp 2006-06-03 13:47:39 UTC (rev 610) @@ -47,16 +47,11 @@ } OnlineUser& AdcHub::getUser(const u_int32_t aSID, const CID& aCID) { - OnlineUser* u = NULL; - { - Lock l(cs); - - SIDIter i = users.find(aSID); - if(i != users.end()) - return *i->second; + OnlineUser* u = findUser(aSID); + if(u) { + return *u; } - User::Ptr p = ClientManager::getInstance()->getUser(aCID); { @@ -69,9 +64,9 @@ return *u; } -OnlineUser* AdcHub::findUser(const u_int32_t aSID) { +OnlineUser* AdcHub::findUser(const u_int32_t aSID) const { Lock l(cs); - SIDIter i = users.find(aSID); + SIDMap::const_iterator i = users.find(aSID); return i == users.end() ? NULL : i->second; } @@ -315,15 +310,24 @@ } void AdcHub::handle(AdcCommand::SCH, AdcCommand& c) throw() { - SIDMap::const_iterator i = users.find(c.getFrom()); - if(i == users.end()) { + OnlineUser* ou = findUser(c.getFrom()); + if(!ou) { dcdebug("Invalid user in AdcHub::onSCH\n"); return; } - fire(ClientListener::AdcSearch(), this, c, i->second->getUser()->getCID()); + fire(ClientListener::AdcSearch(), this, c, ou->getUser()->getCID()); } +void AdcHub::handle(AdcCommand::RES, AdcCommand& c) throw() { + OnlineUser* ou = findUser(c.getFrom()); + if(!ou) { + dcdebug("Invalid user in AdcHub::onRES\n"); + return; + } + SearchManager::getInstance()->onRES(c, ou->getUser()); +} + void AdcHub::connect(const OnlineUser& user) { u_int32_t r = Util::rand(); connect(user, Util::toString(r), BOOLSETTING(USE_SSL) && user.getUser()->isSet(User::SSL)); Modified: dcplusplus/trunk/client/AdcHub.h =================================================================== --- dcplusplus/trunk/client/AdcHub.h 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/AdcHub.h 2006-06-03 13:47:39 UTC (rev 610) @@ -91,7 +91,7 @@ virtual string checkNick(const string& nick); OnlineUser& getUser(const u_int32_t aSID, const CID& aCID); - OnlineUser* findUser(const u_int32_t sid); + OnlineUser* findUser(const u_int32_t sid) const; void putUser(const u_int32_t sid); void clearUsers(); @@ -107,6 +107,7 @@ void handle(AdcCommand::STA, AdcCommand& c) throw(); void handle(AdcCommand::SCH, AdcCommand& c) throw(); void handle(AdcCommand::CMD, AdcCommand& c) throw(); + void handle(AdcCommand::RES, AdcCommand& c) throw(); template<typename T> void handle(T, AdcCommand&) { //Speaker<AdcHubListener>::fire(t, this, c); Modified: dcplusplus/trunk/client/DownloadManager.cpp =================================================================== --- dcplusplus/trunk/client/DownloadManager.cpp 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/DownloadManager.cpp 2006-06-03 13:47:39 UTC (rev 610) @@ -268,7 +268,8 @@ if(BOOLSETTING(ADVANCED_RESUME) && d->getTreeValid() && start > 0 && (d->getTigerTree().getLeaves().size() > 32 || // 32 leaves is 5 levels - d->getTigerTree().getBlockSize() * 10 < d->getSize())) { + d->getTigerTree().getBlockSize() * 10 < d->getSize())) + { d->setStartPos(getResumePos(d->getDownloadTarget(), d->getTigerTree(), start)); } else { int rollback = SETTING(ROLLBACK); @@ -326,19 +327,21 @@ int64_t DownloadManager::getResumePos(const string& file, const TigerTree& tt, int64_t startPos) { // Always discard data until the last block - startPos = startPos - (startPos % tt.getBlockSize()); if(startPos < tt.getBlockSize()) return 0; + startPos -= (startPos % tt.getBlockSize()); + DummyOutputStream dummy; vector<u_int8_t> buf((size_t)min((int64_t)1024*1024, tt.getBlockSize())); do { int64_t blockPos = startPos - tt.getBlockSize(); - MerkleCheckOutputStream<TigerTree, false> check(tt, &dummy, blockPos); try { + MerkleCheckOutputStream<TigerTree, false> check(tt, &dummy, blockPos); + File inFile(file, File::READ, File::OPEN); inFile.setPos(blockPos); int64_t bytesLeft = tt.getBlockSize(); Modified: dcplusplus/trunk/client/MerkleCheckOutputStream.h =================================================================== --- dcplusplus/trunk/client/MerkleCheckOutputStream.h 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/MerkleCheckOutputStream.h 2006-06-03 13:47:39 UTC (rev 610) @@ -32,10 +32,14 @@ MerkleCheckOutputStream(const TreeType& aTree, OutputStream* aStream, int64_t start) : s(aStream), real(aTree), cur(aTree.getBlockSize()), verified(0), bufPos(0) { // Only start at block boundaries dcassert(start % aTree.getBlockSize() == 0); - // Sanity check - dcassert(aTree.getLeaves().size() > (size_t)(start / aTree.getBlockSize())); cur.setFileSize(start); - cur.getLeaves().insert(cur.getLeaves().begin(), aTree.getLeaves().begin(), aTree.getLeaves().begin() + (size_t)(start / aTree.getBlockSize())); + + size_t nBlocks = static_cast<size_t>(start / aTree.getBlockSize()); + if(nBlocks > aTree.getLeaves().size()) { + dcdebug("Invalid tree / parameters"); + return; + } + cur.getLeaves().insert(cur.getLeaves().begin(), aTree.getLeaves().begin(), aTree.getLeaves().begin() + nBlocks); } virtual ~MerkleCheckOutputStream() throw() { if(managed) delete s; } Modified: dcplusplus/trunk/client/SearchManager.cpp =================================================================== --- dcplusplus/trunk/client/SearchManager.cpp 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/SearchManager.cpp 2006-06-03 13:47:39 UTC (rev 610) @@ -268,7 +268,7 @@ } SearchResult* sr = new SearchResult(user, type, slots, freeSlots, size, - file, hubName, url, remoteIp, tth.empty() ? NULL : new TTHValue(tth), false); + file, hubName, url, remoteIp, tth.empty() ? NULL : new TTHValue(tth), false, Util::emptyString); fire(SearchManagerListener::SR(), sr); sr->decRef(); } else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) { @@ -283,38 +283,11 @@ if(!user) return; - int freeSlots = -1; - int64_t size = -1; - string file; - string tth; + // This should be handled by AdcCommand really... + c.getParameters().erase(c.getParameters().begin()); - for(StringIter i = c.getParameters().begin() + 1; i != c.getParameters().end(); ++i) { - string& str = *i; - if(str.compare(0, 2, "FN") == 0) { - file = Util::toNmdcFile(str.substr(2)); - } else if(str.compare(0, 2, "SL") == 0) { - freeSlots = Util::toInt(str.substr(2)); - } else if(str.compare(0, 2, "SI") == 0) { - size = Util::toInt64(str.substr(2)); - } else if(str.compare(0, 2, "TR") == 0) { - tth = str.substr(2); - } - } + onRES(c, user, remoteIp); - if(!file.empty() && freeSlots != -1 && size != -1) { - - StringList names = ClientManager::getInstance()->getHubNames(user->getCID()); - string hubName = names.empty() ? STRING(OFFLINE) : Util::toString(names); - StringList hubs = ClientManager::getInstance()->getHubs(user->getCID()); - string hub = hubs.empty() ? STRING(OFFLINE) : Util::toString(hubs); - - SearchResult::Types type = (file[file.length() - 1] == '\\' ? SearchResult::TYPE_DIRECTORY : SearchResult::TYPE_FILE); - /// @todo Something about the slots - SearchResult* sr = new SearchResult(user, type, 0, freeSlots, size, - file, hubName, hub, remoteIp, tth.empty() ? NULL : new TTHValue(tth), true); - fire(SearchManagerListener::SR(), sr); - sr->decRef(); - } } /*else if(x.compare(1, 4, "SCH ") == 0 && x[x.length() - 1] == 0x0a) { try { respond(AdcCommand(x.substr(0, x.length()-1))); @@ -323,6 +296,44 @@ }*/ // Needs further DoS investigation } +void SearchManager::onRES(const AdcCommand& cmd, const User::Ptr& from, const string& remoteIp) { + int freeSlots = -1; + int64_t size = -1; + string file; + string tth; + string token; + + for(StringIterC i = cmd.getParameters().begin(); i != cmd.getParameters().end(); ++i) { + const string& str = *i; + if(str.compare(0, 2, "FN") == 0) { + file = Util::toNmdcFile(str.substr(2)); + } else if(str.compare(0, 2, "SL") == 0) { + freeSlots = Util::toInt(str.substr(2)); + } else if(str.compare(0, 2, "SI") == 0) { + size = Util::toInt64(str.substr(2)); + } else if(str.compare(0, 2, "TR") == 0) { + tth = str.substr(2); + } else if(str.compare(0, 2, "TO") == 0) { + token = str.substr(2); + } + } + + if(!file.empty() && freeSlots != -1 && size != -1) { + + StringList names = ClientManager::getInstance()->getHubNames(from->getCID()); + string hubName = names.empty() ? STRING(OFFLINE) : Util::toString(names); + StringList hubs = ClientManager::getInstance()->getHubs(from->getCID()); + string hub = hubs.empty() ? STRING(OFFLINE) : Util::toString(hubs); + + SearchResult::Types type = (file[file.length() - 1] == '\\' ? SearchResult::TYPE_DIRECTORY : SearchResult::TYPE_FILE); + /// @todo Something about the slots + SearchResult* sr = new SearchResult(from, type, 0, freeSlots, size, + file, hubName, hub, remoteIp, tth.empty() ? NULL : new TTHValue(tth), true, token); + fire(SearchManagerListener::SR(), sr); + sr->decRef(); + } +} + void SearchManager::respond(const AdcCommand& adc, const CID& from) { // Filter own searches if(from == ClientManager::getInstance()->getMe()->getCID()) Modified: dcplusplus/trunk/client/SearchManager.h =================================================================== --- dcplusplus/trunk/client/SearchManager.h 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/SearchManager.h 2006-06-03 13:47:39 UTC (rev 610) @@ -55,10 +55,10 @@ SearchResult(const User::Ptr& aUser, Types aType, int aSlots, int aFreeSlots, int64_t aSize, const string& aFile, const string& aHubName, - const string& aHubURL, const string& ip, TTHValue* aTTH, bool aUtf8) : + const string& aHubURL, const string& ip, TTHValue* aTTH, bool aUtf8, const string& aToken) : file(aFile), hubName(aHubName), hubURL(aHubURL), user(aUser), size(aSize), type(aType), slots(aSlots), freeSlots(aFreeSlots), IP(ip), - tth((aTTH != NULL) ? new TTHValue(*aTTH) : NULL), utf8(aUtf8), ref(1) { } + tth((aTTH != NULL) ? new TTHValue(*aTTH) : NULL), token(aToken), utf8(aUtf8), ref(1) { } string getFileName() const; string toSR(const Client& client) const; @@ -77,6 +77,7 @@ TTHValue* getTTH() const { return tth; } bool getUtf8() const { return utf8; } const string& getIP() const { return IP; } + const string& getToken() const { return token; } void incRef() { Thread::safeInc(ref); } void decRef() { @@ -102,6 +103,7 @@ int freeSlots; string IP; TTHValue* tth; + string token; bool utf8; volatile long ref; @@ -151,6 +153,8 @@ void onSearchResult(const string& aLine) { onData((const u_int8_t*)aLine.data(), aLine.length(), Util::emptyString); } + + void onRES(const AdcCommand& cmd, const User::Ptr& from, const string& removeIp = Util::emptyString); int32_t timeToSearch() { return (int32_t)(((((int64_t)lastSearch) + 5000) - GET_TICK() ) / 1000); Modified: dcplusplus/trunk/client/version.h =================================================================== --- dcplusplus/trunk/client/version.h 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/client/version.h 2006-06-03 13:47:39 UTC (rev 610) @@ -17,8 +17,8 @@ */ #define APPNAME "DC++" -#define VERSIONSTRING "0.69" -#define VERSIONFLOAT 0.69 +#define VERSIONSTRING "0.691" +#define VERSIONFLOAT 0.691 /* Update the .rc file as well... */ Modified: dcplusplus/trunk/windows/resource.h =================================================================== --- dcplusplus/trunk/windows/resource.h 2006-06-03 11:12:22 UTC (rev 609) +++ dcplusplus/trunk/windows/resource.h 2006-06-03 13:47:39 UTC (rev 610) @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by f:\Programmering\C++\dcplusplus\DCPlusPlus.rc +// Used by c:\Documents\VCProjects\DCPlusPlus\DCPlusPlus.rc // #define IDD_ABOUTBOX 100 #define IDC_TRAY_QUIT 102 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |