-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b70126
commit bd36a2d
Showing
9 changed files
with
90 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "deduplicating_requestor.h" | ||
|
||
#include <ipfs_client/gw/gateway_request.h> | ||
|
||
#include "log_macros.h" | ||
|
||
using Self = ipfs::gw::DeduplicatingRequestor; | ||
|
||
std::string_view Self::name() const { | ||
return "dedup"; | ||
} | ||
auto Self::handle(ipfs::gw::Requestor::RequestPtr r) -> HandleOutcome { | ||
auto d = r->describe_http(); | ||
if (!d.has_value()) { | ||
return HandleOutcome::NOT_HANDLED; | ||
} | ||
auto& k = d.value(); | ||
auto it = seen_.find(k); | ||
if (seen_.end() == it) { | ||
seen_.emplace(k, r); | ||
return HandleOutcome::NOT_HANDLED; | ||
} | ||
auto& w = it->second; | ||
auto old = w.lock(); | ||
if (old == r) { | ||
LOG(INFO) | ||
<< name() | ||
<< " has seen the EXACT same request pass by (same object in memory)."; | ||
return HandleOutcome::NOT_HANDLED; | ||
} | ||
if (old) { | ||
LOG(INFO) << "Dedup squashed a new version of the request " | ||
<< old->debug_string() << " in " << r->debug_string(); | ||
return HandleOutcome::DONE; | ||
} else { | ||
LOG(INFO) << r->debug_string() | ||
<< " has occurred before, but the old copy is dead and gone."; | ||
it->second = r; | ||
return HandleOutcome::NOT_HANDLED; | ||
} | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef IPFS_DEDUPLICATING_REQUESTOR_H_ | ||
#define IPFS_DEDUPLICATING_REQUESTOR_H_ | ||
|
||
#include <ipfs_client/gw/requestor.h> | ||
|
||
#include <ipfs_client/context_api.h> | ||
|
||
#include <map> | ||
|
||
namespace ipfs::gw { | ||
class DeduplicatingRequestor final : public Requestor { | ||
std::string_view name() const override; | ||
HandleOutcome handle(RequestPtr) override; | ||
|
||
std::map<HttpRequestDescription, std::weak_ptr<GatewayRequest>> seen_; | ||
}; | ||
} // namespace ipfs::gw | ||
|
||
#endif // IPFS_DEDUPLICATING_REQUESTOR_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters