Skip to content
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

Fix some more typos #7750

Draft
wants to merge 1 commit into
base: RC_2_0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions bindings/c/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TORRENT_EXPORT void* session_create(int tag, ...)
va_list lp;
va_start(lp, tag);

fingerprint fing("LT", lt::version_major, lt::version_minor, lt::version_tiny, 0);
fingerprint find("LT", lt::version_major, lt::version_minor, lt::version_tiny, 0);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think fing is supposed to refer to "fingerprint"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will exclude....(another thing to be added to exclusion list from my other PR)

std::pair<int, int> listen_range(-1, -1);
char const* listen_interface = "0.0.0.0";
int flags = session::start_default_features | session::add_default_plugins;
Expand All @@ -112,8 +112,8 @@ TORRENT_EXPORT void* session_create(int tag, ...)
case SES_FINGERPRINT:
{
char const* f = va_arg(lp, char const*);
fing.name[0] = f[0];
fing.name[1] = f[1];
find.name[0] = f[0];
find.name[1] = f[1];
break;
}
case SES_LISTENPORT:
Expand All @@ -123,16 +123,16 @@ TORRENT_EXPORT void* session_create(int tag, ...)
listen_range.second = va_arg(lp, int);
break;
case SES_VERSION_MAJOR:
fing.major_version = va_arg(lp, int);
find.major_version = va_arg(lp, int);
break;
case SES_VERSION_MINOR:
fing.minor_version = va_arg(lp, int);
find.minor_version = va_arg(lp, int);
break;
case SES_VERSION_TINY:
fing.revision_version = va_arg(lp, int);
find.revision_version = va_arg(lp, int);
break;
case SES_VERSION_TAG:
fing.tag_version = va_arg(lp, int);
find.tag_version = va_arg(lp, int);
break;
case SES_FLAGS:
flags = va_arg(lp, int);
Expand All @@ -157,7 +157,7 @@ TORRENT_EXPORT void* session_create(int tag, ...)
|| listen_range.second < listen_range.first))
listen_range.second = listen_range.first;

return new (std::nothrow) session(fing, listen_range, listen_interface, flags, alert_mask);
return new (std::nothrow) session(find, listen_range, listen_interface, flags, alert_mask);
}

TORRENT_EXPORT void session_close(void* ses)
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/src/torrent_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ list file_priorities(torrent_handle& handle)
return ret;
}

download_priority_t file_prioritity0(torrent_handle& h, file_index_t index)
download_priority_t file_priority0(torrent_handle& h, file_index_t index)
{
return h.file_priority(index);
}

void file_prioritity1(torrent_handle& h, file_index_t index, download_priority_t prio)
void file_priority1(torrent_handle& h, file_index_t index, download_priority_t prio)
{
return h.file_priority(index, prio);
}
Expand Down Expand Up @@ -532,8 +532,8 @@ void bind_torrent_handle()
.def("get_piece_priorities", &piece_priorities)
.def("prioritize_files", &prioritize_files)
.def("get_file_priorities", &file_priorities)
.def("file_priority", &file_prioritity0)
.def("file_priority", &file_prioritity1)
.def("file_priority", &file_priority0)
.def("file_priority", &file_priority1)
.def("file_status", _(file_status0))
.def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0)
.def("need_save_resume_data", _(need_save_resume_data0))
Expand Down
12 changes: 6 additions & 6 deletions cmake/Modules/GeneratePkgConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ set(_GeneratePkGConfigDir "${CMAKE_CURRENT_LIST_DIR}/GeneratePkgConfig")

include(GNUInstallDirs)

function(_get_target_property_merging_configs _var_name _target_name _propert_name)
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name} SET)
function(_get_target_property_merging_configs _var_name _target_name _property_name)
get_property(prop_set TARGET ${_target_name} PROPERTY ${_property_name} SET)
if (prop_set)
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name})
get_property(vals TARGET ${_target_name} PROPERTY ${_property_name})
else()
if (CMAKE_BUILD_TYPE)
list(APPEND configs ${CMAKE_BUILD_TYPE})
Expand All @@ -27,9 +27,9 @@ function(_get_target_property_merging_configs _var_name _target_name _propert_na
else()
set(target_cfg "${UPPERCFG}")
endif()
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg} SET)
get_property(prop_set TARGET ${_target_name} PROPERTY ${_property_name}_${target_cfg} SET)
if (prop_set)
get_property(val_for_cfg TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg})
get_property(val_for_cfg TARGET ${_target_name} PROPERTY ${_property_name}_${target_cfg})
list(APPEND vals "$<$<CONFIG:${cfg}>:${val_for_cfg}>")
break()
endif()
Expand All @@ -38,7 +38,7 @@ function(_get_target_property_merging_configs _var_name _target_name _propert_na
get_property(imported_cfgs TARGET ${_target_name} PROPERTY IMPORTED_CONFIGURATIONS)
# CMake docs say we can use any of the imported configs
list(GET imported_cfgs 0 imported_config)
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name}_${imported_config})
get_property(vals TARGET ${_target_name} PROPERTY ${_property_name}_${imported_config})
# remove config generator expression. Only in this case! Notice we use such expression
# ourselves in the loop above
string(REPLACE "$<$<CONFIG:${imported_config}>:" "$<1:" vals "${vals}")
Expand Down
10 changes: 5 additions & 5 deletions fuzzers/src/add_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ std::vector<sha256_hash> g_tree;
int const piece_size = 1024 * 1024;
int const blocks_per_piece = piece_size / lt::default_block_size;
int const num_pieces = 10;
int const num_leafs = merkle_num_leafs(num_pieces * blocks_per_piece);
int const num_nodes = merkle_num_nodes(num_leafs);
int const first_leaf = merkle_first_leaf(num_leafs);
int const num_leaves = merkle_num_leaves(num_pieces * blocks_per_piece);
Copy link
Owner

@arvidn arvidn Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this change. "leaf" is a term of art in computer science. Perhaps mostly used as adjective to describe the leaf nodes. I hesitate to call them "leaves" as that implies actual leaves on actual trees (not the computer science data structure "tree").

They are currently (as far as I know) consistently referred to as "leafs". I kind of see the "node" as implied in that name. Perhaps this is a controversial perspective. I would rather rename these "leaf_nodes" over "leaves". But I also think the current acronym is quite reasonable.

I think the change is controversial mostly because it's already internally consistent, and a rename would have to make sure it's consistently renamed everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaves are already mentioned throughout some parts of code in repo:
https://github.com/search?q=repo%3Aarvidn%2Flibtorrent%20leaves&type=code

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. so some decision has to be made then. do you think "leaves" is preferred over "lefs"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. so some decision has to be made then. do you think "leaves" is preferred over "lefs"?

I think changing to "leaves" would be ok, but it's up to you really.


https://en.wikipedia.org/wiki/Merkle_tree#Overview

A hash tree is a tree of hashes in which the leaves (i.e., leaf nodes, sometimes also called "leafs") are hashes of data blocks in, for instance, a file or set of files.

int const num_nodes = merkle_num_nodes(num_leaves);
int const first_leaf = merkle_first_leaf(num_leaves);

extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
{
Expand Down Expand Up @@ -113,7 +113,7 @@ extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
t.set_hash2(file_index_t{0}, piece_index_t::diff_type(i), r);
}

merkle_fill_tree(g_tree, num_leafs);
merkle_fill_tree(g_tree, num_leaves);

std::vector<char> buf;
bencode(std::back_inserter(buf), t.generate());
Expand Down Expand Up @@ -159,7 +159,7 @@ lt::add_torrent_params generate_atp(std::uint8_t const* data, size_t size)
ret.merkle_trees.resize(1);
ret.merkle_tree_mask.resize(1);
ret.verified_leaf_hashes.resize(1);
ret.verified_leaf_hashes[0].resize(num_leafs, true);
ret.verified_leaf_hashes[0].resize(num_leaves, true);

auto& t = ret.merkle_trees[0];
auto& mask = ret.merkle_tree_mask[0];
Expand Down
28 changes: 14 additions & 14 deletions include/libtorrent/aux_/merkle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ namespace libtorrent {

// given the number of blocks, how many leaves do we need? this rounds up to
// an even power of 2
TORRENT_EXTRA_EXPORT int merkle_num_leafs(int);
TORRENT_EXTRA_EXPORT int merkle_num_leaves(int);

// returns the number of nodes in the tree, given the number of leaves
TORRENT_EXTRA_EXPORT int merkle_num_nodes(int);

// given the number of leafs in the tree, returns the index to the first
// given the number of leaves in the tree, returns the index to the first
// leaf
TORRENT_EXTRA_EXPORT int merkle_first_leaf(int num_leafs);
TORRENT_EXTRA_EXPORT int merkle_first_leaf(int num_leaves);

// takes the number of leaves and returns the height of the merkle tree.
// does not include the root node in the layer count. i.e. if there's only a
Expand All @@ -75,35 +75,35 @@ namespace libtorrent {

// given a tree and the number of leaves, expect all leaf hashes to be set and
// compute all other hashes starting with the leaves.
TORRENT_EXTRA_EXPORT void merkle_fill_tree(span<sha256_hash> tree, int num_leafs, int level_start);
TORRENT_EXTRA_EXPORT void merkle_fill_tree(span<sha256_hash> tree, int num_leafs);
TORRENT_EXTRA_EXPORT void merkle_fill_tree(span<sha256_hash> tree, int num_leaves, int level_start);
TORRENT_EXTRA_EXPORT void merkle_fill_tree(span<sha256_hash> tree, int num_leaves);

// fills in nodes that can be computed from a tree with arbitrary nodes set
// all "orphan" hashes, i.e ones that do not contribute towards computing
// the root, will be cleared.
TORRENT_EXTRA_EXPORT void merkle_fill_partial_tree(span<sha256_hash> tree);

// given a merkle tree (`tree`), clears all hashes in the range of nodes:
// [ level_start, level_start+ num_leafs), as well as all of their parents,
// [ level_start, level_start+ num_leaves), as well as all of their parents,
// within the sub-tree. It does not clear the root of the sub-tree.
// see unit test for examples.
TORRENT_EXTRA_EXPORT void merkle_clear_tree(span<sha256_hash> tree, int num_leafs, int level_start);
TORRENT_EXTRA_EXPORT void merkle_clear_tree(span<sha256_hash> tree, int num_leaves, int level_start);

// given the leaf hashes, computes the merkle root hash. The pad is the hash
// to use for the right-side padding, in case the number of leaves is not a
// power of two.
TORRENT_EXTRA_EXPORT sha256_hash merkle_root(span<sha256_hash const> leaves, sha256_hash const& pad = {});

TORRENT_EXTRA_EXPORT
sha256_hash merkle_root_scratch(span<sha256_hash const> leaves, int num_leafs
sha256_hash merkle_root_scratch(span<sha256_hash const> leaves, int num_leaves
, sha256_hash pad, std::vector<sha256_hash>& scratch_space);

// given a flat index, return which layer the node is in
TORRENT_EXTRA_EXPORT int merkle_get_layer(int idx);
// given a flat index, return the offset in the layer
TORRENT_EXTRA_EXPORT int merkle_get_layer_offset(int idx);

// given "blocks" number of leafs in the full tree (i.e. at the block level)
// given "blocks" number of leaves in the full tree (i.e. at the block level)
// and given "pieces" nodes in the piece layer, compute the pad hash for the
// piece layer
TORRENT_EXTRA_EXPORT sha256_hash merkle_pad(int blocks, int pieces);
Expand Down Expand Up @@ -141,22 +141,22 @@ namespace libtorrent {
// hashes in dst that are invalid in src.
TORRENT_EXTRA_EXPORT
void merkle_validate_copy(span<sha256_hash const> src, span<sha256_hash> dst
, sha256_hash const& root, bitfield& verified_leafs);
, sha256_hash const& root, bitfield& verified_leaves);

TORRENT_EXTRA_EXPORT
bool merkle_validate_single_layer(span<sha256_hash const> tree);

// given a leaf index (0-based index in the leaf layer) and a tree, return
// the leafs_start, leafs_size and root_index representing a subtree that
// the leaves_start, leaves_size and root_index representing a subtree that
// can be validated. The block_index and leaf_size is the range of the leaf
// layer that can be verified, and the root_index is the node that needs to
// be known in (tree) to do so. The num_valid_leafs specifies how many of
// the leafs that are actually *supposed* to be non-zero. Any leafs beyond
// be known in (tree) to do so. The num_valid_leaves specifies how many of
// the leaves that are actually *supposed* to be non-zero. Any leaves beyond
// these are padding and expected to be zero.
// The caller must validate the hash at root_index.
TORRENT_EXTRA_EXPORT
std::tuple<int, int, int> merkle_find_known_subtree(span<sha256_hash const> const tree
, int block_index, int num_valid_leafs);
, int block_index, int num_valid_leaves);
}

#endif
8 changes: 4 additions & 4 deletions include/libtorrent/aux_/merkle_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct TORRENT_EXTRA_EXPORT merkle_tree
std::pair<std::vector<sha256_hash>, aux::vector<bool>> build_sparse_vector() const;

// get bits indicating if each leaf hash is verified
std::vector<bool> verified_leafs() const;
std::vector<bool> verified_leaves() const;

// returns true if the entire tree is known and verified
bool is_complete() const;
Expand All @@ -118,7 +118,7 @@ struct TORRENT_EXTRA_EXPORT merkle_tree

bool load_piece_layer(span<char const> piece_layer);

// the leafs in "tree" must be block hashes (i.e. leaf hashes in the this
// the leaves in "tree" must be block hashes (i.e. leaf hashes in the this
// tree). This function inserts those hashes as well as the nodes up the
// tree. The destination start index is the index, in this tree, to the first leaf
// where "tree" will be inserted.
Expand Down Expand Up @@ -161,7 +161,7 @@ struct TORRENT_EXTRA_EXPORT merkle_tree
int block_layer_start() const;
int piece_layer_start() const;
int num_pieces() const;
int num_leafs() const;
int num_leaves() const;

void optimize_storage();
void optimize_storage_piece_layer();
Expand All @@ -181,7 +181,7 @@ struct TORRENT_EXTRA_EXPORT merkle_tree
// yet
bitfield m_block_verified;

// number of blocks in the file this tree represents. The number of leafs in
// number of blocks in the file this tree represents. The number of leaves in
// the tree is rounded up to an even power of 2.
int m_num_blocks = 0;

Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/file_storage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ namespace aux {

// internal limitations restrict file sizes to not be larger than this
// We use int to index into file merkle trees, so a file may not contain more
// than INT_MAX entries. That means INT_MAX / 2 blocks (leafs) in each
// than INT_MAX entries. That means INT_MAX / 2 blocks (leaves) in each
// tree.
static constexpr std::int64_t max_file_size = (std::min)(
(std::int64_t(1) << 48) - 1
Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/torrent_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ TORRENT_VERSION_NAMESPACE_3

#if TORRENT_ABI_VERSION <= 2
// if this is a merkle torrent, this is the merkle
// tree. It has space for merkle_num_nodes(merkle_num_leafs(num_pieces))
// tree. It has space for merkle_num_nodes(merkle_num_leaves(num_pieces))
// hashes
aux::vector<sha1_hash> m_merkle_tree;
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/bt_peer_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ namespace {

// subtract one because the the base layer doesn't count
int const proof_hashes = std::max(0
, proof_layers - (merkle_num_layers(merkle_num_leafs(count)) - 1));
, proof_layers - (merkle_num_layers(merkle_num_leaves(count)) - 1));

if (m_recv_buffer.packet_size() != header_size
+ (count + proof_hashes) * int(sha256_hash::size()))
Expand Down
12 changes: 6 additions & 6 deletions src/create_torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ namespace {
TORRENT_ASSERT(file_size > 0);
auto const file_blocks = st->ct.files().file_num_blocks(current_file);
auto const piece_blocks = st->ct.files().blocks_in_piece2(piece);
int const num_leafs = merkle_num_leafs(file_blocks);
int const num_leaves = merkle_num_leaves(file_blocks);
// If the file is smaller than one piece then the block hashes
// should be padded to the next power of two instead of the next
// piece boundary.
int const padded_leafs = file_size < st->ct.piece_length()
? num_leafs
int const padded_leaves = file_size < st->ct.piece_length()
? num_leaves
: st->ct.piece_length() / default_block_size;

TORRENT_ASSERT(padded_leafs <= int(v2_blocks.size()));
for (auto i = piece_blocks; i < padded_leafs; ++i)
TORRENT_ASSERT(padded_leaves <= int(v2_blocks.size()));
for (auto i = piece_blocks; i < padded_leaves; ++i)
v2_blocks[i].clear();
sha256_hash const piece_root = merkle_root(
span<sha256_hash>(v2_blocks).first(padded_leafs));
span<sha256_hash>(v2_blocks).first(padded_leaves));
st->ct.set_hash2(current_file, file_piece_offset, piece_root);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/file_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,15 +1110,15 @@ namespace {
{
TORRENT_ASSERT_PRECOND(index >= file_index_t(0) && index < end_file());
TORRENT_ASSERT_PRECOND(m_piece_length > 0);
int const piece_layer_size = merkle_num_leafs(file_num_pieces(index));
int const piece_layer_size = merkle_num_leaves(file_num_pieces(index));
return merkle_num_nodes(piece_layer_size) - piece_layer_size;
}

int file_storage::file_first_block_node(file_index_t index) const
{
TORRENT_ASSERT_PRECOND(index >= file_index_t(0) && index < end_file());
TORRENT_ASSERT_PRECOND(m_piece_length > 0);
int const leaf_layer_size = merkle_num_leafs(file_num_blocks(index));
int const leaf_layer_size = merkle_num_leaves(file_num_blocks(index));
return merkle_num_nodes(leaf_layer_size) - leaf_layer_size;
}

Expand Down
Loading
Loading