-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement GC of ManagerBase::requests_ #143
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,11 @@ See the LICENSE.txt file in the project root for more information. | |
#ifndef P2P_MANAGER_BASE | ||
#define P2P_MANAGER_BASE | ||
|
||
/// Size of a sync-requests active bucket, in items (requests); there are two buckets. | ||
/// This needs to be large enough to hold the maximum number of requests that can be conceivable generated | ||
/// in the maximum time period that it takes to answer a request. | ||
#define REQUEST_BUCKET_SIZE_LIMIT 100000 | ||
|
||
#include "discovery.h" | ||
#include "session.h" // encoding.h -> utils/options.h | ||
|
||
|
@@ -63,13 +68,9 @@ namespace P2P { | |
DiscoveryWorker discoveryWorker_; ///< DiscoveryWorker object. | ||
const std::string instanceIdStr_; ///< Instance ID for LOGxxx(). | ||
const NodeID nodeId_; ///< This ManagerBase's own NodeID. | ||
|
||
/// List of currently active sessions. | ||
boost::unordered_flat_map<NodeID, std::shared_ptr<Session>, SafeHash> sessions_; | ||
|
||
// TODO: Somehow find a way to clean up requests_ after a certain time/being used. | ||
/// List of currently active requests. | ||
boost::unordered_flat_map<RequestID, std::shared_ptr<Request>, SafeHash> requests_; | ||
boost::unordered_flat_map<NodeID, std::shared_ptr<Session>, SafeHash> sessions_; ///< List of currently active sessions. | ||
std::array<boost::unordered_flat_map<RequestID, std::shared_ptr<Request>, SafeHash>, 2> requests_; ///< Request buckets. | ||
uint64_t activeRequests_ = 0; ///< Index of the current (active) request bucket (either 0 or 1). | ||
|
||
/** | ||
* Send a Request to a given node. | ||
|
@@ -142,6 +143,19 @@ namespace P2P { | |
*/ | ||
void trySpawnInboundSession(tcp::socket&& socket); | ||
|
||
/** | ||
* Insert a new request into requests_. | ||
* @param request The newly created request to be tracked by requests_. | ||
*/ | ||
void insertRequest(const std::shared_ptr<Request>& request); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this function intends to take ownership of the Like that: void insertRequest(std::shared_ptr<Request> request) {
requests_[activeRequests_][request->id()] = std::move(request); // note the move
// ...
} Moving a I'd suggest also making such change in other places too, where a |
||
|
||
/** | ||
* Handles a message that is a generic answer to a synchronous generic remote request. | ||
* @param nodeId The node that is answering the request (so it can be disconnected on error). | ||
* @param message The message that is supposed to be an answer to a request that is tracked in requests_. | ||
*/ | ||
void handleRequestAnswer(const NodeID& nodeId, const std::shared_ptr<const Message>& message); | ||
|
||
public: | ||
/** | ||
* Constructor. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?