Skip to content

Commit

Permalink
- Return more relevant search results: https://bugs.launchpad.net/air…
Browse files Browse the repository at this point in the history
…dcpp/+bug/1265889

- Improve statistics (share and clients)
  • Loading branch information
maksis committed Jan 11, 2014
1 parent dd1ac64 commit c395d99
Show file tree
Hide file tree
Showing 20 changed files with 633 additions and 309 deletions.
8 changes: 8 additions & 0 deletions client/AdcHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,14 @@ void AdcHub::handle(AdcCommand::STA, AdcCommand& c) noexcept {
}
return;
}
case AdcCommand::ERROR_BAD_STATE:
{
string tmp;
if (c.getParam("FC", 1, tmp) && tmp.size() == 4) {
fire(ClientListener::StatusMessage(), this, c.getParam(1) + " (command " + tmp + ", client state " + Util::toString(state) + ")", ClientListener::FLAG_NORMAL);
return;
}
}
}

ChatMessage message = { c.getParam(1), u };
Expand Down
8 changes: 2 additions & 6 deletions client/AutoSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,15 @@ void AutoSearch::changeNumber(bool increase) noexcept {
}

bool AutoSearch::isExcluded(const string& aString) noexcept {
for (auto& i : excluded) {
if (i.match(aString))
return true;
}
return false;
return excluded.match_any(aString);
}

void AutoSearch::updateExcluded() noexcept {
excluded.clear();
if (!excludedString.empty()) {
auto ex = move(SearchQuery::parseSearchString(excludedString));
for (const auto& i : ex)
excluded.emplace_back(i);
excluded.addString(i);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/AutoSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class AutoSearch : public intrusive_ptr_base<AutoSearch>, public StringMatch {
time_t nextSearchChange = 0;
bool nextIsDisable = false;
string target;
StringSearch::List excluded;
StringSearch excluded;
};

}
Expand Down
10 changes: 0 additions & 10 deletions client/BloomFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

#include "typedefs.h"

#include "StringSearch.h"

namespace dcpp {

template<size_t N>
Expand All @@ -32,14 +30,6 @@ class BloomFilter {
~BloomFilter() { }

void add(const string& s) { xadd(s, N); }
bool match(const StringSearch::List& s) const {
for(const auto& i: s) {
if(!match(i.getPattern()))
return false;
}
return true;
}

bool match(const string& s) const {
if(s.length() >= N) {
string::size_type l = s.length() - N;
Expand Down
49 changes: 43 additions & 6 deletions client/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1015,8 +1015,7 @@ string ClientManager::getClientStats() const noexcept {
RLock l(cs);
map<CID, OnlineUser*> uniqueUserMap;
for(const auto& ou: onlineUsers | map_values) {
if (!ou->getIdentity().isBot() && !ou->isHidden())
uniqueUserMap.insert(make_pair(ou->getUser()->getCID(), ou));
uniqueUserMap.insert(make_pair(ou->getUser()->getCID(), ou));
}

int allUsers = onlineUsers.size();
Expand All @@ -1029,15 +1028,49 @@ string ClientManager::getClientStats() const noexcept {
int64_t uploadSpeed = 0;
int64_t downloadSpeed = 0;
int64_t nmdcConnection = 0;
int nmdcUsers = 0, adcUsers = 0;
int nmdcUsers = 0, adcUsers = 0, adcHasDownload = 0, adcHasUpload = 0, nmdcHasConnection = 0;
int hiddenUsers = 0, bots = 0, activeUsers = 0, operators = 0;
for(const auto& ou: uniqueUserMap | map_values) {
totalShare += Util::toInt64(ou->getIdentity().getShareSize());
if (ou->isHidden()) {
hiddenUsers++;
continue;
}

if (ou->getIdentity().isBot()) {
bots++;
if (!ou->getUser()->isNMDC()) {
continue;
}
}

if (ou->getIdentity().isOp()) {
operators++;
}

if (ou->getIdentity().isTcpActive()) {
activeUsers++;
}

if (ou->getUser()->isNMDC()) {
nmdcConnection += Util::toDouble(ou->getIdentity().getNmdcConnection()) * 1000 * 1000 / 8;
auto speed = Util::toDouble(ou->getIdentity().getNmdcConnection());
if (speed > 0) {
nmdcConnection += (speed * 1000.0 * 1000.0) / 8.0;
nmdcHasConnection++;
}
nmdcUsers++;
} else {
uploadSpeed += ou->getIdentity().getAdcConnectionSpeed(false);
downloadSpeed += ou->getIdentity().getAdcConnectionSpeed(true);
auto up = ou->getIdentity().getAdcConnectionSpeed(false);
if (up > 0) {
uploadSpeed += up;
adcHasUpload++;
}

auto down = ou->getIdentity().getAdcConnectionSpeed(true);
if (down > 0) {
downloadSpeed += ou->getIdentity().getAdcConnectionSpeed(true);
adcHasDownload++;
}
adcUsers++;
}
}
Expand All @@ -1048,6 +1081,10 @@ string ClientManager::getClientStats() const noexcept {
ret += lb;
ret += "All users: " + Util::toString(allUsers) + lb;
ret += "Unique users: " + Util::toString(uniqueUsers) + " (" + Util::toString(((double)uniqueUsers/(double)allUsers)*100.00) + "%)" + lb;
ret += "Active/operators/bots/hidden: " + Util::toString(activeUsers) + " (" + Util::toString(((double) activeUsers / (double) uniqueUsers)*100.00) + "%) / " +
Util::toString(operators) + " (" + Util::toString(((double) operators / (double) uniqueUsers)*100.00) + "%) / " +
Util::toString(bots) + " (" + Util::toString(((double) bots / (double) uniqueUsers)*100.00) + "%) / " +
Util::toString(hiddenUsers) + " (" + Util::toString(((double) hiddenUsers / (double) uniqueUsers)*100.00) + "%)" + lb;
ret += "Protocol users (ADC/NMDC): " + Util::toString(adcUsers) + "/" + Util::toString(nmdcUsers) + lb;
ret += "Total share: " + Util::formatBytes(totalShare) + " (" + Util::formatBytes((double)totalShare / (double)uniqueUsers) + " per user)" + lb;
ret += "Average ADC connection speed: " + Util::formatConnectionSpeed((double) downloadSpeed / (double) adcUsers) + " down, " + Util::formatConnectionSpeed((double) uploadSpeed / (double) adcUsers) + " up" + lb;
Expand Down
45 changes: 17 additions & 28 deletions client/DirectoryListing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,36 +374,28 @@ DirectoryListing::Directory::Directory(Directory* aParent, const string& aName,
}
}

void DirectoryListing::Directory::search(OrderedStringSet& aResults, SearchQuery& aStrings, StringList::size_type maxResults) const noexcept {
void DirectoryListing::Directory::search(OrderedStringSet& aResults, SearchQuery& aStrings) const noexcept {
if (getAdls())
return;

if (aStrings.root) {
auto pos = find_if(files, [aStrings](File* aFile) { return aFile->getTTH() == *aStrings.root; });
if (pos != files.end()) {
aResults.insert(getPath());
}
} else {
if(aStrings.matchesDirectory(name)) {
auto path = parent ? parent->getPath() : Util::emptyString;
auto res = find(aResults, path);
if (res == aResults.end() && aStrings.matchesSize(getTotalSize(false))) {
aResults.insert(path);
}
if(aStrings.matchesDirectory(name)) {
auto path = parent ? parent->getPath() : Util::emptyString;
auto res = find(aResults, path);
if (res == aResults.end() && aStrings.matchesSize(getTotalSize(false))) {
aResults.insert(path);
}
}

if(aStrings.itemType != SearchQuery::TYPE_DIRECTORY) {
for(auto& f: files) {
if(aStrings.matchesFileLower(Text::toLower(f->getName()), f->getSize(), f->getRemoteDate())) {
aResults.insert(getPath());
break;
}
}
for(auto& f: files) {
if(aStrings.matchesFile(f->getName(), f->getSize(), f->getRemoteDate(), f->getTTH())) {
aResults.insert(getPath());
break;
}
}

for(auto l = directories.begin(); (l != directories.end()) && (aResults.size() < maxResults); ++l) {
(*l)->search(aResults, aStrings, maxResults);
for(const auto& d: directories) {
d->search(aResults, aStrings);
if (aResults.size() >= aStrings.maxResults) return;
}
}

Expand Down Expand Up @@ -932,14 +924,11 @@ void DirectoryListing::searchImpl(const string& aSearchString, int64_t aSize, in

fire(DirectoryListingListener::SearchStarted());

auto search = SearchQuery::getSearch(aSearchString, Util::emptyString, aSize, aTypeMode, aSizeMode, aExtList, SearchQuery::MATCH_NAME, true);
if (search)
curSearch.reset(search);

curSearch.reset(SearchQuery::getSearch(aSearchString, Util::emptyString, aSize, aTypeMode, aSizeMode, aExtList, SearchQuery::MATCH_NAME, true, 100));
if (isOwnList && partialList) {
SearchResultList results;
try {
ShareManager::getInstance()->search(results, *curSearch, 50, Util::toInt(fileName), CID(), aDir);
ShareManager::getInstance()->search(results, *curSearch, Util::toInt(fileName), CID(), aDir);
} catch (...) {}

for (const auto& sr : results)
Expand All @@ -958,7 +947,7 @@ void DirectoryListing::searchImpl(const string& aSearchString, int64_t aSize, in
} else {
const auto dir = (aDir.empty()) ? root : findDirectory(Util::toNmdcFile(aDir), root);
if (dir)
dir->search(searchResults, *curSearch, 100);
dir->search(searchResults, *curSearch);

curResultCount = searchResults.size();
maxResultCount = searchResults.size();
Expand Down
2 changes: 1 addition & 1 deletion client/DirectoryListing.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DirectoryListing : public intrusive_ptr_base<DirectoryListing>, public Use
void clearAll() noexcept;

bool findIncomplete() const noexcept;
void search(OrderedStringSet& aResults, SearchQuery& aStrings, StringList::size_type maxResults) const noexcept;
void search(OrderedStringSet& aResults, SearchQuery& aStrings) const noexcept;
void findFiles(const boost::regex& aReg, File::List& aResults) const noexcept;

size_t getFileCount() const noexcept { return files.size(); }
Expand Down
6 changes: 3 additions & 3 deletions client/DualString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ DualString::DualString(const string& aStr) {
size_t DualString::initSizeArray(size_t strLen) {
size_t arrSize = strLen % ARRAY_BITS == 0 ? strLen / ARRAY_BITS : (strLen / ARRAY_BITS) + 1;
charSizes = new MaskType[arrSize];
for (int s = 0; s < arrSize; ++s) {
for (size_t s = 0; s < arrSize; ++s) {
charSizes[s] = 0;
}

Expand All @@ -102,7 +102,7 @@ DualString::DualString(const DualString& rhs) {
assign(rhs.begin(), rhs.end());
if (rhs.charSizes) {
auto size = initSizeArray(rhs.size());
for (int s = 0; s < size; ++s) {
for (size_t s = 0; s < size; ++s) {
charSizes[s] = rhs.charSizes[s];
}
}
Expand All @@ -118,7 +118,7 @@ DualString& DualString::operator= (const DualString& rhs) {
assign(rhs.begin(), rhs.end());
if (rhs.charSizes) {
auto size = initSizeArray(rhs.size());
for (int s = 0; s < size; ++s) {
for (size_t s = 0; s < size; ++s) {
charSizes[s] = rhs.charSizes[s];
}
}
Expand Down
13 changes: 8 additions & 5 deletions client/QueueManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1449,13 +1449,16 @@ void QueueManager::hashBundle(BundlePtr& aBundle) noexcept {
}

void QueueManager::removeFinishedBundle(BundlePtr& aBundle) noexcept {
WLock l(cs);
for(auto i = aBundle->getFinishedFiles().begin(); i != aBundle->getFinishedFiles().end(); ) {
fileQueue.remove(*i);
i = aBundle->getFinishedFiles().erase(i);
{
WLock l(cs);
for (auto i = aBundle->getFinishedFiles().begin(); i != aBundle->getFinishedFiles().end();) {
fileQueue.remove(*i);
i = aBundle->getFinishedFiles().erase(i);
}

bundleQueue.removeBundle(aBundle);
}

bundleQueue.removeBundle(aBundle);
fire(QueueManagerListener::BundleRemoved(), aBundle);
}

Expand Down
4 changes: 2 additions & 2 deletions client/SearchManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,13 @@ void SearchManager::respond(const AdcCommand& adc, OnlineUser& aUser, bool isUdp
}

SearchResultList results;
SearchQuery srch(adc.getParameters());
SearchQuery srch(adc.getParameters(), maxResults);

string token;
adc.getParam("TO", 0, token);

try {
ShareManager::getInstance()->search(results, srch, maxResults, aProfile, aUser.getUser()->getCID(), path);
ShareManager::getInstance()->search(results, srch, aProfile, aUser.getUser()->getCID(), path, token.find("/as") != string::npos);
} catch(const ShareException& e) {
if (replyDirect) {
//path not found (direct search)
Expand Down

0 comments on commit c395d99

Please sign in to comment.