Add debug logs for recent/top peers resetting.

This commit is contained in:
John Preston 2024-10-04 10:06:14 +04:00
parent a74c5a89a6
commit df2b020b42
3 changed files with 28 additions and 0 deletions

View file

@ -95,6 +95,7 @@ QByteArray RecentPeers::serialize() const {
void RecentPeers::applyLocal(QByteArray serialized) {
_list.clear();
if (serialized.isEmpty()) {
DEBUG_LOG(("Suggestions: Bad RecentPeers local, empty."));
return;
}
auto stream = Serialize::ByteArrayReader(serialized);
@ -102,8 +103,13 @@ void RecentPeers::applyLocal(QByteArray serialized) {
auto count = quint32();
stream >> streamAppVersion >> count;
if (!stream.ok()) {
DEBUG_LOG(("Suggestions: Bad RecentPeers local, not ok."));
return;
}
DEBUG_LOG(("Suggestions: "
"Start RecentPeers read, count: %1, version: %2."
).arg(count
).arg(streamAppVersion));
_list.reserve(count);
for (auto i = 0; i != int(count); ++i) {
const auto peer = Serialize::readPeer(
@ -114,9 +120,15 @@ void RecentPeers::applyLocal(QByteArray serialized) {
_list.push_back(peer);
} else {
_list.clear();
DEBUG_LOG(("Suggestions: Failed RecentPeers reading %1 / %2."
).arg(i + 1
).arg(count));
_list.clear();
return;
}
}
DEBUG_LOG(
("Suggestions: RecentPeers read OK, count: %1").arg(_list.size()));
}
} // namespace Data

View file

@ -274,11 +274,13 @@ QByteArray TopPeers::serialize() const {
void TopPeers::applyLocal(QByteArray serialized) {
if (_lastReceived) {
DEBUG_LOG(("Suggestions: Skipping TopPeers local, got already."));
return;
}
_list.clear();
_disabled = false;
if (serialized.isEmpty()) {
DEBUG_LOG(("Suggestions: Bad TopPeers local, empty."));
return;
}
auto stream = Serialize::ByteArrayReader(serialized);
@ -287,8 +289,14 @@ void TopPeers::applyLocal(QByteArray serialized) {
auto count = quint32();
stream >> streamAppVersion >> disabled >> count;
if (!stream.ok()) {
DEBUG_LOG(("Suggestions: Bad TopPeers local, not ok."));
return;
}
DEBUG_LOG(("Suggestions: "
"Start TopPeers read, count: %1, version: %2, disabled: %3."
).arg(count
).arg(streamAppVersion
).arg(disabled));
_list.reserve(count);
for (auto i = 0; i != int(count); ++i) {
auto rating = quint64();
@ -303,11 +311,15 @@ void TopPeers::applyLocal(QByteArray serialized) {
.rating = DeserializeRating(rating),
});
} else {
DEBUG_LOG(("Suggestions: "
"Failed TopPeers reading %1 / %2.").arg(i + 1).arg(count));
_list.clear();
return;
}
}
_disabled = (disabled == 1);
DEBUG_LOG(
("Suggestions: TopPeers read OK, count: %1").arg(_list.size()));
}
} // namespace Data

View file

@ -2956,11 +2956,13 @@ void Account::readSearchSuggestions() {
}
_searchSuggestionsRead = true;
if (!_searchSuggestionsKey) {
DEBUG_LOG(("Suggestions: No key."));
return;
}
FileReadDescriptor suggestions;
if (!ReadEncryptedFile(suggestions, _searchSuggestionsKey, _basePath, _localKey)) {
DEBUG_LOG(("Suggestions: Could not read file."));
ClearKey(_searchSuggestionsKey, _basePath);
_searchSuggestionsKey = 0;
writeMapDelayed();
@ -2973,6 +2975,8 @@ void Account::readSearchSuggestions() {
if (CheckStreamStatus(suggestions.stream)) {
_owner->session().topPeers().applyLocal(top);
_owner->session().recentPeers().applyLocal(recent);
} else {
DEBUG_LOG(("Suggestions: Could not read content."));
}
}