-
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.
Showing
24 changed files
with
260 additions
and
54 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
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
21 changes: 21 additions & 0 deletions
21
library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc
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,21 @@ | ||
#include "multi_gateway_requestor.h" | ||
|
||
#include <mock_api.h> | ||
|
||
#include <ipfs_client/gw/gateway_request.h> | ||
|
||
namespace { | ||
ig::RequestPtr block_req() { | ||
auto rv = std::make_shared<ig::GatewayRequest>(); | ||
rv->type = ig::Type::Block; | ||
rv->main_param = | ||
"bafybeid4dzlxm6h4r6kfvx6jp6vj4nteplmbve224lx2s3lgjubyufsuo4"; | ||
return rv; | ||
} | ||
} // namespace | ||
|
||
TEST(MultiGatewayRequestor, FailsWithoutApi) { | ||
ig::MultiGatewayRequestor t; | ||
auto o = t.handle(block_req()); | ||
EXPECT_TRUE(o == ig::Requestor::HandleOutcome::DONE); | ||
} |
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,53 @@ | ||
#include "dnslink_name.h" | ||
|
||
#include "log_macros.h" | ||
|
||
using Self = ipfs::ipld::DnsLinkName; | ||
namespace ch = std::chrono; | ||
|
||
Self::DnsLinkName(std::string_view target_abs_path) | ||
: expiration_(ch::system_clock::now() + ch::minutes(5)) { | ||
SlashDelimited target{target_abs_path}; | ||
target_namespace_ = target.pop(); | ||
target_root_ = target.pop(); | ||
links_.emplace_back("", Link{target_root_, nullptr}); | ||
target_path_.assign(target.to_string()); | ||
} | ||
|
||
auto Self::resolve(ResolutionState& params) -> ResolveResult { | ||
auto& node = links_.at(0).second.node; | ||
if (!node) { | ||
node = params.GetBlock(target_root_); | ||
} | ||
if (!node) { | ||
return MoreDataNeeded(target_namespace_ + "/" + target_root_); | ||
} | ||
if (target_path_.empty()) { | ||
return node->resolve(params); | ||
} | ||
auto path = target_path_; | ||
path.append("/").append(params.PathToResolve().to_view()); | ||
auto altered = params.WithPath(path); | ||
LOG(WARNING) << "Odd case: name points at /ns/root/MORE/PATH (" | ||
<< target_namespace_ << '/' << target_root_ << '/' | ||
<< target_path_ << "): " << params.MyPath() | ||
<< " will be resolved as " << path; | ||
auto lower = node->resolve(params); | ||
if (auto* mdn = std::get_if<MoreDataNeeded>(&lower)) { | ||
if (expired()) { | ||
auto refresh_path = "/ipns/" + params.MyPath().pop_back(); | ||
mdn->ipfs_abs_paths_.push_back(refresh_path); | ||
} | ||
} | ||
return lower; | ||
} | ||
bool Self::expired() const { | ||
return expiration_ < ch::system_clock::now(); | ||
} | ||
bool Self::PreferOver(DagNode const& another) const { | ||
auto* other = another.as_dnslink(); | ||
if (!other) { | ||
return true; | ||
} | ||
return expiration_ > other->expiration_ + ch::seconds(1); | ||
} |
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,27 @@ | ||
#ifndef IPFS_IPLD_DNSLINK_NAME_H_ | ||
#define IPFS_IPLD_DNSLINK_NAME_H_ | ||
|
||
#include "ipfs_client/ipld/dag_node.h" | ||
|
||
#include <chrono> | ||
|
||
namespace ipfs::ipld { | ||
class DnsLinkName : public DagNode { | ||
std::string target_namespace_; | ||
std::string target_root_; | ||
std::string target_path_; | ||
std::chrono::system_clock::time_point expiration_; | ||
|
||
ResolveResult resolve(ResolutionState& params) override; | ||
bool PreferOver(DagNode const& another) const override; | ||
DnsLinkName const* as_dnslink() const override { return this; } | ||
|
||
public: | ||
DnsLinkName(std::string_view target_abs_path); | ||
virtual ~DnsLinkName() noexcept {} | ||
|
||
bool expired() const override; | ||
}; | ||
} // namespace ipfs::ipld | ||
|
||
#endif // IPFS_IPLD_DNSLINK_NAME_H_ |
Oops, something went wrong.