-
Notifications
You must be signed in to change notification settings - Fork 2
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
80fe930
commit becc6c4
Showing
22 changed files
with
1,287 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
} | ||
{ | ||
DontAskMeWhyGetEnvDoesThis | ||
Memcheck:Addr8 | ||
Memcheck:Cond | ||
... | ||
fun:getenv | ||
... | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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,100 @@ | ||
#include "directory_shard.h" | ||
|
||
#include "log_macros.h" | ||
|
||
#include <vocab/endian.h> | ||
|
||
#include <smhasher/MurmurHash3.h> | ||
|
||
#define ABSL_USES_STD_STRING_VIEW | ||
#include <absl/strings/match.h> | ||
|
||
#include <iomanip> | ||
#include <sstream> | ||
|
||
using namespace std::literals; | ||
|
||
using Self = ipfs::ipld::DirShard; | ||
|
||
auto Self::resolve(ipfs::SlashDelimited relpath, | ||
ipfs::ipld::DagNode::BlockLookup blu, | ||
std::string& to_here) -> ResolveResult { | ||
if (!relpath) { | ||
// TODO check if index.html is present and if not implement indexing | ||
auto result = resolve("index.html"sv, blu, to_here); | ||
auto resp = std::get_if<Response>(&result); | ||
if (resp) { | ||
resp->mime_ = "text/html"; | ||
} | ||
return result; | ||
} | ||
auto name = relpath.pop(); | ||
auto hash = hexhash(name); | ||
return resolve_internal(hash.begin(), hash.end(), name, relpath, blu, | ||
to_here); | ||
} | ||
auto Self::resolve_internal(ipfs::ipld::DirShard::HashIter hash_b, | ||
ipfs::ipld::DirShard::HashIter hash_e, | ||
std::string_view element_name, | ||
ipfs::SlashDelimited path_after_dir, | ||
ipfs::ipld::DagNode::BlockLookup blu, | ||
std::string& path_to_dir) -> ResolveResult { | ||
for (auto& [name, link] : links_) { | ||
if (hash_b != hash_e && !absl::StartsWith(name, *hash_b)) { | ||
continue; | ||
} | ||
if (!link.node) { | ||
link.node = blu(link.cid); | ||
} | ||
if (!link.node) { | ||
return MoreDataNeeded{std::vector{"/ipfs/" + link.cid}}; | ||
} | ||
if (absl::EndsWith(name, element_name)) { | ||
return link.node->resolve(path_after_dir, blu, path_to_dir); | ||
} | ||
auto downcast = link.node->as_hamt(); | ||
if (downcast) { | ||
if (hash_b == hash_e) { | ||
LOG(ERROR) << "Ran out of hash bits."; | ||
return ProvenAbsent{}; | ||
} | ||
return downcast->resolve_internal(std::next(hash_b), hash_e, element_name, | ||
path_after_dir, blu, path_to_dir); | ||
} else { | ||
return ProvenAbsent{}; | ||
} | ||
} | ||
return ProvenAbsent{}; | ||
} | ||
std::vector<std::string> Self::hexhash(std::string_view path_element) const { | ||
auto hex_width = 0U; | ||
for (auto x = fanout_; (x >>= 4); ++hex_width) | ||
; | ||
std::array<std::uint64_t, 2> digest = {0U, 0U}; | ||
MurmurHash3_x64_128(path_element.data(), path_element.size(), 0, | ||
digest.data()); | ||
auto corrected_digest = htobe64(digest[0]); | ||
VLOG(1) << "Hash: " << digest[0] << ' ' << digest[1] << " -> " | ||
<< corrected_digest; | ||
std::vector<std::string> result; | ||
for (auto d : digest) { | ||
auto hash_bits = htobe64(d); | ||
while (hash_bits) { | ||
// 2. Pop the log2(fanout_) lowest bits from the path component hash | ||
// digest,... | ||
auto popped = hash_bits % fanout_; | ||
hash_bits /= fanout_; | ||
std::ostringstream oss; | ||
// ... then hex encode (using 0-F) using little endian those bits ... | ||
oss << std::setfill('0') << std::setw(hex_width) << std::uppercase | ||
<< std::hex << popped; | ||
result.push_back(oss.str()); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
Self::DirShard(std::uint64_t fanout) : fanout_{fanout} {} | ||
Self* Self::as_hamt() { | ||
return this; | ||
} |
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_DIRECTORY_SHARD_H_ | ||
#define IPFS_DIRECTORY_SHARD_H_ 1 | ||
|
||
#include <ipfs_client/ipld/dag_node.h> | ||
|
||
namespace ipfs::ipld { | ||
class DirShard : public DagNode { | ||
std::uint64_t const fanout_; | ||
|
||
ResolveResult resolve(SlashDelimited, BlockLookup, std::string&) override; | ||
DirShard* as_hamt() override; | ||
|
||
std::vector<std::string> hexhash(std::string_view path_element) const; | ||
using HashIter = std::vector<std::string>::const_iterator; | ||
ResolveResult resolve_internal(HashIter, | ||
HashIter, | ||
std::string_view, | ||
SlashDelimited, | ||
BlockLookup, | ||
std::string&); | ||
|
||
public: | ||
explicit DirShard(std::uint64_t fanout = 256UL); | ||
}; | ||
} // namespace ipfs::ipld | ||
|
||
#endif // IPFS_DIRECTORY_SHARD_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "ipns_name.h" | ||
|
||
#include "log_macros.h" | ||
|
||
using Self = ipfs::ipld::IpnsName; | ||
|
||
Self::IpnsName(std::string target_abs_path) : target_path_{target_abs_path} {} | ||
|
||
auto Self::resolve(ipfs::SlashDelimited path, | ||
ipfs::ipld::DagNode::BlockLookup blu, | ||
std::string& up_to_here) -> ResolveResult { | ||
if (!target_) { | ||
SlashDelimited t{target_path_}; | ||
t.pop(); // Discard namespace, though realistically it's going to be ipfs | ||
// basically all the time | ||
target_ = blu(std::string{t.pop()}); | ||
} | ||
if (target_) { | ||
return target_->resolve(path, blu, up_to_here); | ||
} | ||
return MoreDataNeeded{std::vector{target_path_}}; | ||
} |
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,20 @@ | ||
#ifndef IPFS_IPLD_IPNS_NAME_H_ | ||
#define IPFS_IPLD_IPNS_NAME_H_ | ||
|
||
#include "ipfs_client/ipld/dag_node.h" | ||
|
||
namespace ipfs::ipld { | ||
class IpnsName : public DagNode { | ||
std::string const target_path_; | ||
NodePtr target_; | ||
|
||
ResolveResult resolve(SlashDelimited path, | ||
BlockLookup, | ||
std::string& up_to_here) override; | ||
|
||
public: | ||
IpnsName(std::string target_abs_path); | ||
}; | ||
} // namespace ipfs::ipld | ||
|
||
#endif // IPFS_IPLD_IPNS_NAME_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
Oops, something went wrong.