-
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
b40c99a
commit 5d63748
Showing
22 changed files
with
280 additions
and
101 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
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,46 @@ | ||
#include <ipfs_client/gw/requestor_pool.h> | ||
|
||
#include <ipfs_client/gw/gateway_request.h> | ||
|
||
#include <mock_api.h> | ||
#include <mock_requestor.h> | ||
|
||
namespace { | ||
struct RequestorPoolTest : public ::testing::Test { | ||
std::vector<std::shared_ptr<MockRequestor>> members; | ||
std::shared_ptr<MockApi> api = std::make_shared<MockApi>(); | ||
std::shared_ptr<ig::RequestorPool> tested = | ||
std::make_shared<ig::RequestorPool>(); | ||
std::shared_ptr<ig::GatewayRequest> req = | ||
ig::GatewayRequest::fromIpfsPath("/ipns/ipfs.io"sv); | ||
void add() { | ||
auto p = std::make_shared<MockRequestor>(); | ||
members.push_back(p); | ||
tested->add(p); | ||
} | ||
void set_api() { | ||
auto p = std::make_shared<MockRequestor>(); | ||
p->api(api); | ||
p->or_else(tested); | ||
} | ||
}; | ||
} // namespace | ||
|
||
TEST_F(RequestorPoolTest, add_with_api_sets_member_api) { | ||
add(); | ||
EXPECT_EQ(members.size(), 1U); | ||
set_api(); | ||
add(); | ||
EXPECT_EQ(members.size(), 2U); | ||
EXPECT_TRUE(members.at(0)); | ||
EXPECT_TRUE(members.at(1)); | ||
EXPECT_FALSE(members.at(0)->api()); | ||
EXPECT_TRUE(members.at(1)->api()); | ||
} | ||
TEST_F(RequestorPoolTest, pending_doesnt_stop_parallel_requests) { | ||
add(); | ||
add(); | ||
members.at(0)->outcomes.push_back(MockRequestor::O::PENDING); | ||
members.at(1)->outcomes.push_back(MockRequestor::O::PENDING); | ||
tested->request(req); | ||
} |
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 |
---|---|---|
@@ -1,29 +1,67 @@ | ||
#include "symlink.h" | ||
|
||
#include <libp2p/multi/content_identifier_codec.hpp> | ||
|
||
#include "log_macros.h" | ||
|
||
using Self = ipfs::ipld::Symlink; | ||
|
||
Self::Symlink(std::string target) : target_{target} {} | ||
Self::Symlink(std::string target) | ||
: style_{from_target(target)}, target_{target} {} | ||
|
||
Self::~Symlink() {} | ||
|
||
auto Self::resolve(SlashDelimited path, BlockLookup, std::string& buf) | ||
auto Self::resolve(SlashDelimited path, BlockLookup, std::string& to_here) | ||
-> ResolveResult { | ||
if (target_.at(0) == '/') { | ||
buf.assign(target_); | ||
} else { | ||
if (std::count(buf.begin(), buf.end(), '/') > 1 && buf.back() == '/') { | ||
buf.resize(buf.size() - 1); | ||
} | ||
auto popped = buf.find_last_of('/'); | ||
if (popped < buf.size()) { | ||
buf.resize(popped + 1); // include the slash at the end | ||
} | ||
buf.append(target_); | ||
std::string result; | ||
switch (style_) { | ||
case Style::Absolute: | ||
result.assign(target_); | ||
break; | ||
case Style::Relative: { | ||
auto c = to_here.find_last_not_of('/'); | ||
c = to_here.find_last_of('/', c); | ||
DCHECK(c != to_here.size()) << to_here; | ||
result.assign(to_here, 0, c + 1).append(target_); | ||
} break; | ||
case Style::FromRoot: | ||
result.assign(SlashDelimited{to_here}.pop_n(2)) | ||
.append("/") | ||
.append(target_); | ||
} | ||
if (path) { | ||
if (buf.back() != '/') { | ||
buf.push_back('/'); | ||
} | ||
buf.append(path.pop_all()); | ||
result.append("/").append(path.pop_all()); | ||
} | ||
std::size_t i; | ||
while ((i = result.find("//")) != std::string::npos) { | ||
result.erase(i, 1); | ||
} | ||
DCHECK_GT(result.size(), 0U); | ||
if (result.back() == '/') { | ||
result.resize(result.size() - 1); | ||
} | ||
return PathChange{result}; | ||
} | ||
|
||
auto Self::from_target(std::string const& target) -> Style { | ||
DCHECK_GT(target.size(), 0U); | ||
if (target.at(0) != '/') { | ||
return Style::Relative; | ||
} | ||
SlashDelimited t{target}; | ||
auto ns = t.pop(); | ||
if (ns != "ipfs" && ns != "ipns") { | ||
return Style::FromRoot; | ||
} | ||
auto root = t.pop(); | ||
using namespace libp2p::multi; | ||
auto cid = ContentIdentifierCodec::fromString(root); | ||
if (!cid.has_value()) { | ||
return Style::FromRoot; | ||
} | ||
if (cid.value().content_type == MulticodecType::Code::LIBP2P_KEY) { | ||
return ns == "ipns" ? Style::Absolute : Style::FromRoot; | ||
} else { | ||
return ns == "ipfs" ? Style::Absolute : Style::FromRoot; | ||
} | ||
return buf; | ||
} |
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
Oops, something went wrong.