move from vectors to unordered_sets

- When receiving a request to fetch RouterID's, the remote endpoint fulfilling the request stores them in an unordered set. When the request caller receives that payload, it is loaded into a vector in the same order. However, we should just load it directly into an unordered set to enforce both the order and that none appear twice
- The trust model will have to operate on multiple large lists of RouterID's and RC's efficiently, and maintaining a sort order ensures the values are workable immediately after deserialization
This commit is contained in:
dr7ana 2023-11-29 06:11:38 -08:00
parent 9bb85582a4
commit e1a5d935a6
2 changed files with 7 additions and 7 deletions

View File

@ -205,7 +205,7 @@ namespace llarp
}
void
NodeDB::ingest_rid_fetch_responses(const RouterID& source, std::vector<RouterID> ids)
NodeDB::ingest_rid_fetch_responses(const RouterID& source, std::unordered_set<RouterID> ids)
{
fetch_rid_responses[source] = std::move(ids);
}
@ -383,7 +383,7 @@ namespace llarp
"Failed to verify signature for fetch RouterIDs response."};
});
std::vector<RouterID> router_ids;
std::unordered_set<RouterID> router_ids;
for (const auto& s : router_id_strings)
{
@ -395,7 +395,7 @@ namespace llarp
return;
}
router_ids.emplace_back(s.data());
router_ids.emplace(s.data());
}
ingest_rid_fetch_responses(src, std::move(router_ids));
@ -627,7 +627,7 @@ namespace llarp
"Failed to verify signature for fetch RouterIDs response."};
});
std::vector<RouterID> router_ids;
std::unordered_set<RouterID> router_ids;
for (const auto& s : router_id_strings)
{
@ -641,7 +641,7 @@ namespace llarp
return;
}
router_ids.emplace_back(s.data());
router_ids.emplace(s.data());
}
ingest_rid_fetch_responses(target, std::move(router_ids));

View File

@ -75,7 +75,7 @@ namespace llarp
// logs the RID's that resulted in an error during RID fetching
std::unordered_set<RouterID> fail_sources;
// stores all RID fetch responses for greedy comprehensive processing
std::unordered_map<RouterID, std::vector<RouterID>> fetch_rid_responses;
std::unordered_map<RouterID, std::unordered_set<RouterID>> fetch_rid_responses;
// tracks fetch failures from the RC node performing the initial RC fetch and mediating
// the 12 RID requests to the 12 sources, NOT failures from the 12 sources themselves
std::atomic<int> fetch_failures{0};
@ -155,7 +155,7 @@ namespace llarp
process_fetched_rcs(RouterID source, std::vector<RemoteRC> rcs, rc_time timestamp);
void
ingest_rid_fetch_responses(const RouterID& source, std::vector<RouterID> ids = {});
ingest_rid_fetch_responses(const RouterID& source, std::unordered_set<RouterID> ids = {});
bool
process_fetched_rids();