Skip to content

Commit

Permalink
moved peer.hpp and resolve_links.hpp to aux
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml authored and arvidn committed Jan 8, 2021
1 parent dd04258 commit b47eb1a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 34 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ set(libtorrent_include_files
operations
parse_url
pe_crypto
peer
peer_class
peer_class_set
peer_class_type_filter
Expand All @@ -84,7 +83,6 @@ set(libtorrent_include_files
puff
random
read_resume_data
resolve_links
session
session_handle
session_params
Expand Down Expand Up @@ -212,6 +210,7 @@ set(libtorrent_aux_include_files
packet_pool
part_file
path
peer
peer_connection
peer_list
piece_block_progress
Expand All @@ -223,6 +222,7 @@ set(libtorrent_aux_include_files
range
receive_buffer
request_blocks
resolve_links
resolver
resolver_interface
route
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ HEADERS = \
operations.hpp \
parse_url.hpp \
pe_crypto.hpp \
peer.hpp \
peer_class.hpp \
peer_class_set.hpp \
peer_class_type_filter.hpp \
Expand All @@ -485,7 +484,6 @@ HEADERS = \
puff.hpp \
random.hpp \
read_resume_data.hpp \
resolve_links.hpp \
session.hpp \
session_handle.hpp \
session_params.hpp \
Expand Down Expand Up @@ -588,6 +586,7 @@ HEADERS = \
aux_/packet_pool.hpp \
aux_/part_file.hpp \
aux_/path.hpp \
aux_/peer.hpp \
aux_/peer_connection.hpp \
aux_/peer_list.hpp \
aux_/piece_block_progress.hpp \
Expand All @@ -600,6 +599,7 @@ HEADERS = \
aux_/range.hpp \
aux_/receive_buffer.hpp \
aux_/request_blocks.hpp \
aux_/resolve_links.hpp \
aux_/resolver.hpp \
aux_/resolver_interface.hpp \
aux_/route.h \
Expand Down
7 changes: 4 additions & 3 deletions include/libtorrent/aux_/http_tracker_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ see LICENSE file.
namespace libtorrent {

struct bdecode_node;
struct peer_entry;
}

namespace aux {
namespace libtorrent::aux {

struct http_connection;
class http_parser;
struct peer_entry;

class TORRENT_EXTRA_EXPORT http_tracker_connection
: public tracker_connection
Expand Down Expand Up @@ -71,6 +72,6 @@ namespace aux {

TORRENT_EXTRA_EXPORT bool extract_peer_info(bdecode_node const& info
, peer_entry& ret, error_code& ec);
}}
}

#endif // TORRENT_HTTP_TRACKER_CONNECTION_HPP_INCLUDED
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ see LICENSE file.
#include "libtorrent/peer_id.hpp"
#include "libtorrent/address.hpp"

namespace libtorrent {
namespace libtorrent::aux {

struct TORRENT_EXTRA_EXPORT peer_entry
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ see LICENSE file.
#include "libtorrent/aux_/vector.hpp"
#include "libtorrent/fwd.hpp"

namespace libtorrent {
namespace libtorrent::aux {

#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
// this class is used for mutable torrents, to discover identical files
Expand Down
2 changes: 1 addition & 1 deletion include/libtorrent/aux_/tracker_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ see LICENSE file.
#include "libtorrent/fwd.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/peer_id.hpp"
#include "libtorrent/peer.hpp" // peer_entry
#include "libtorrent/aux_/peer.hpp" // peer_entry
#include "libtorrent/deadline_timer.hpp"
#include "libtorrent/union_endpoint.hpp"
#include "libtorrent/io_context.hpp"
Expand Down
6 changes: 3 additions & 3 deletions src/resolve_links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ You may use, distribute and modify this code under the terms of the BSD license,
see LICENSE file.
*/

#include "libtorrent/resolve_links.hpp"
#include "libtorrent/aux_/resolve_links.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/aux_/numeric_cast.hpp"

namespace libtorrent {
namespace libtorrent::aux {

#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
resolve_links::resolve_links(std::shared_ptr<torrent_info> ti)
Expand Down Expand Up @@ -109,4 +109,4 @@ void resolve_links::match(std::shared_ptr<const torrent_info> const& ti
}
#endif // TORRENT_DISABLE_MUTABLE_TORRENTS

} // namespace libtorrent
} // namespace libtorrent::aux
4 changes: 2 additions & 2 deletions src/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ see LICENSE file.
#include "libtorrent/bencode.hpp"
#include "libtorrent/hasher.hpp"
#include "libtorrent/entry.hpp"
#include "libtorrent/peer.hpp"
#include "libtorrent/aux_/peer.hpp"
#include "libtorrent/aux_/peer_connection.hpp"
#include "libtorrent/aux_/bt_peer_connection.hpp"
#include "libtorrent/aux_/web_peer_connection.hpp"
Expand All @@ -79,7 +79,7 @@ see LICENSE file.
#include "libtorrent/performance_counters.hpp" // for counters
#include "libtorrent/aux_/resolver_interface.hpp"
#include "libtorrent/aux_/alloca.hpp"
#include "libtorrent/resolve_links.hpp"
#include "libtorrent/aux_/resolve_links.hpp"
#include "libtorrent/aux_/file_progress.hpp"
#include "libtorrent/aux_/has_block.hpp"
#include "libtorrent/aux_/alert_manager.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/udp_tracker_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ see LICENSE file.
#include "libtorrent/aux_/time.hpp"
#include "libtorrent/aux_/io.hpp"
#include "libtorrent/aux_/ip_helpers.hpp" // for is_v6
#include "libtorrent/peer.hpp"
#include "libtorrent/aux_/peer.hpp"
#include "libtorrent/error_code.hpp"

#ifndef TORRENT_DISABLE_LOGGING
Expand Down
14 changes: 7 additions & 7 deletions test/test_resolve_links.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ see LICENSE file.
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS

#include "libtorrent/torrent_info.hpp"
#include "libtorrent/resolve_links.hpp"
#include "libtorrent/aux_/resolve_links.hpp"
#include "libtorrent/aux_/path.hpp" // for combine_path
#include "libtorrent/hex.hpp" // to_hex
#include "libtorrent/create_torrent.hpp"
Expand Down Expand Up @@ -91,13 +91,13 @@ TORRENT_TEST(resolve_links)
std::shared_ptr<torrent_info> ti2 = std::make_shared<torrent_info>(p);

std::printf("resolving\n");
resolve_links l(ti1);
aux::resolve_links l(ti1);
l.match(ti2, ".");

aux::vector<resolve_links::link_t, file_index_t> const& links = l.get_links();
aux::vector<aux::resolve_links::link_t, file_index_t> const& links = l.get_links();

auto const num_matches = std::size_t(std::count_if(links.begin(), links.end()
, std::bind(&resolve_links::link_t::ti, _1)));
, std::bind(&aux::resolve_links::link_t::ti, _1)));

// some debug output in case the test fails
if (num_matches > e.expected_matches)
Expand Down Expand Up @@ -148,13 +148,13 @@ TORRENT_TEST(range_lookup_duplicated_files)
auto ti2 = std::make_shared<torrent_info>(tmp2, from_span);

std::printf("resolving\n");
resolve_links l(ti1);
aux::resolve_links l(ti1);
l.match(ti2, ".");

aux::vector<resolve_links::link_t, file_index_t> const& links = l.get_links();
aux::vector<aux::resolve_links::link_t, file_index_t> const& links = l.get_links();

auto const num_matches = std::count_if(links.begin(), links.end()
, std::bind(&resolve_links::link_t::ti, _1));
, std::bind(&aux::resolve_links::link_t::ti, _1));

TEST_EQUAL(num_matches, 1);
}
Expand Down
22 changes: 11 additions & 11 deletions test/test_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ TORRENT_TEST(parse_hostname_peers)
TEST_EQUAL(resp.peers.size(), 2);
if (resp.peers.size() == 2)
{
peer_entry const& e0 = resp.peers[0];
peer_entry const& e1 = resp.peers[1];
aux::peer_entry const& e0 = resp.peers[0];
aux::peer_entry const& e1 = resp.peers[1];
TEST_EQUAL(e0.hostname, "test_hostname");
TEST_EQUAL(e0.port, 1000);
TEST_EQUAL(e0.pid, peer_id("aaaaaaaaaaaaaaaaaaaa"));
Expand All @@ -83,8 +83,8 @@ TORRENT_TEST(parse_peers4)
TEST_EQUAL(resp.peers4.size(), 2);
if (resp.peers.size() == 2)
{
ipv4_peer_entry const& e0 = resp.peers4[0];
ipv4_peer_entry const& e1 = resp.peers4[1];
aux::ipv4_peer_entry const& e0 = resp.peers4[0];
aux::ipv4_peer_entry const& e1 = resp.peers4[1];
TEST_CHECK(e0.ip == addr4("1.2.3.4").to_bytes());
TEST_EQUAL(e0.port, 0x3010);

Expand Down Expand Up @@ -251,10 +251,10 @@ TORRENT_TEST(parse_external_ip6)
}

namespace {
peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret)
aux::peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool expected_ret)
{
error_code ec;
peer_entry result;
aux::peer_entry result;
bdecode_node n;
bdecode(peer_field, peer_field + strlen(peer_field)
, n, ec, nullptr, 1000, 1000);
Expand All @@ -268,7 +268,7 @@ peer_entry extract_peer(char const* peer_field, error_code expected_ec, bool exp

TORRENT_TEST(extract_peer)
{
peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcd4:porti1337ee"
aux::peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcd4:porti1337ee"
, error_code(), true);
TEST_EQUAL(result.hostname, "abcd");
TEST_EQUAL(result.pid, peer_id("abababababababababab"));
Expand All @@ -277,7 +277,7 @@ TORRENT_TEST(extract_peer)

TORRENT_TEST(extract_peer_hostname)
{
peer_entry result = extract_peer("d2:ip11:example.com4:porti1ee"
aux::peer_entry result = extract_peer("d2:ip11:example.com4:porti1ee"
, error_code(), true);
TEST_EQUAL(result.hostname, "example.com");
TEST_EQUAL(result.pid, peer_id::min());
Expand All @@ -287,21 +287,21 @@ TORRENT_TEST(extract_peer_hostname)
TORRENT_TEST(extract_peer_not_a_dictionary)
{
// not a dictionary
peer_entry result = extract_peer("2:ip11:example.com"
aux::peer_entry result = extract_peer("2:ip11:example.com"
, errors::invalid_peer_dict, false);
}

TORRENT_TEST(extract_peer_missing_ip)
{
// missing IP
peer_entry result = extract_peer("d7:peer id20:abababababababababab4:porti1337ee"
aux::peer_entry result = extract_peer("d7:peer id20:abababababababababab4:porti1337ee"
, errors::invalid_tracker_response, false);
}

TORRENT_TEST(extract_peer_missing_port)
{
// missing port
peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcde"
aux::peer_entry result = extract_peer("d7:peer id20:abababababababababab2:ip4:abcde"
, errors::invalid_tracker_response, false);
}

Expand Down

0 comments on commit b47eb1a

Please sign in to comment.