mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-17 16:58:50 +00:00
detect and ignore duplicates in negentropy sync
This commit is contained in:
@ -151,6 +151,7 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
|||||||
uint64_t inFlightUp = 0;
|
uint64_t inFlightUp = 0;
|
||||||
bool inFlightDown = false; // bool because we can't count on getting every EVENT we request (might've been deleted mid-query)
|
bool inFlightDown = false; // bool because we can't count on getting every EVENT we request (might've been deleted mid-query)
|
||||||
std::vector<std::string> have, need;
|
std::vector<std::string> have, need;
|
||||||
|
flat_hash_set<std::string> seenHave, seenNeed;
|
||||||
bool syncDone = false;
|
bool syncDone = false;
|
||||||
uint64_t totalHaves = 0, totalNeeds = 0;
|
uint64_t totalHaves = 0, totalNeeds = 0;
|
||||||
Decompressor decomp;
|
Decompressor decomp;
|
||||||
@ -168,6 +169,8 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
|||||||
try {
|
try {
|
||||||
auto inputMsg = from_hex(msg.at(2).get_string());
|
auto inputMsg = from_hex(msg.at(2).get_string());
|
||||||
|
|
||||||
|
std::vector<std::string> currHave, currNeed;
|
||||||
|
|
||||||
if (treeId) {
|
if (treeId) {
|
||||||
negentropy::storage::BTreeLMDB storageBtree(txn, negentropyDbi, *treeId);
|
negentropy::storage::BTreeLMDB storageBtree(txn, negentropyDbi, *treeId);
|
||||||
|
|
||||||
@ -176,11 +179,23 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
|
|||||||
|
|
||||||
Negentropy ne(subStorage, frameSizeLimit);
|
Negentropy ne(subStorage, frameSizeLimit);
|
||||||
ne.setInitiator();
|
ne.setInitiator();
|
||||||
neMsg = ne.reconcile(inputMsg, have, need);
|
neMsg = ne.reconcile(inputMsg, currHave, currNeed);
|
||||||
} else {
|
} else {
|
||||||
Negentropy ne(storageVector, frameSizeLimit);
|
Negentropy ne(storageVector, frameSizeLimit);
|
||||||
ne.setInitiator();
|
ne.setInitiator();
|
||||||
neMsg = ne.reconcile(inputMsg, have, need);
|
neMsg = ne.reconcile(inputMsg, currHave, currNeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &id : currHave) {
|
||||||
|
if (seenHave.contains(id)) continue;
|
||||||
|
seenHave.insert(id);
|
||||||
|
have.push_back(std::move(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto &id : currNeed) {
|
||||||
|
if (seenNeed.contains(id)) continue;
|
||||||
|
seenNeed.insert(id);
|
||||||
|
need.push_back(std::move(id));
|
||||||
}
|
}
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
LE << "Unable to parse negentropy message from relay: " << e.what();
|
LE << "Unable to parse negentropy message from relay: " << e.what();
|
||||||
|
Reference in New Issue
Block a user