Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/dht/dht_router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ DhtRouter::find_node(const sockaddr* sa) {
}

DhtRouter::DhtBucketList::iterator
DhtRouter::split_bucket(const DhtBucketList::iterator& itr, DhtNode* node) {
DhtRouter::split_bucket(DhtBucketList::iterator itr, DhtNode* node) {
// Split bucket. Current bucket keeps the upper half thus keeping the
// map key valid, new bucket is the lower half of the original bucket.
DhtBucket* newBucket = itr->second->split(id());
Expand Down Expand Up @@ -586,7 +586,7 @@ DhtRouter::add_node_to_bucket(DhtNode* node) {
}

void
DhtRouter::delete_node(const DhtNodeList::accessor& itr) {
DhtRouter::delete_node(DhtNodeList::accessor itr) {
if (itr == m_nodes.end())
throw internal_error("DhtRouter::delete_node called with invalid iterator.");

Expand Down
4 changes: 2 additions & 2 deletions src/dht/dht_router.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ class DhtRouter : public DhtNode {
DhtBucketList::iterator find_bucket(const HashString& id);

bool add_node_to_bucket(DhtNode* node);
void delete_node(const DhtNodeList::accessor& itr);
void delete_node(DhtNodeList::accessor itr);

void store_closest_nodes(const HashString& id, DhtBucket* bucket);

DhtBucketList::iterator split_bucket(const DhtBucketList::iterator& itr, DhtNode* node);
DhtBucketList::iterator split_bucket(DhtBucketList::iterator itr, DhtNode* node);

void bootstrap();
void bootstrap_bucket(const DhtBucket* bucket);
Expand Down
6 changes: 3 additions & 3 deletions src/dht/dht_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace torrent {

class DhtTracker {
public:
// Maximum number of peers we return for a GET_PEERS query (default value only).
// Needs to be small enough so that a packet with a payload of num_peers*6 bytes
// Maximum number of peers we return for a GET_PEERS query (default value only).
// Needs to be small enough so that a packet with a payload of num_peers*6 bytes
// does not need fragmentation. Value chosen so that the size is approximately
// equal to a FIND_NODE reply (8*26 bytes).
static constexpr unsigned int max_peers = 32;
Expand All @@ -39,7 +39,7 @@ class DhtTracker {
char header[2];
SocketAddressCompact peer;

BencodeAddress(const SocketAddressCompact& p) : peer(p) { header[0] = '6'; header[1] = ':'; }
BencodeAddress(SocketAddressCompact p) : peer(p) { header[0] = '6'; header[1] = ':'; }

const char* bencode() const { return header; }

Expand Down
4 changes: 2 additions & 2 deletions src/download/available_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ AvailableList::pop_random() {

size_type idx = random() % size();

auto tmp = std::move(*(begin() + idx));
auto tmp = *(begin() + idx);

*(begin() + idx) = std::move(back());
*(begin() + idx) = back();
pop_back();

return tmp;
Expand Down
2 changes: 1 addition & 1 deletion src/download/available_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AvailableList : private std::vector<sa_inet_union> {
void insert(AddressList* source_list);
bool insert_unique(const sockaddr* sa);

void erase(iterator itr) { *itr = std::move(back()); pop_back(); }
void erase(iterator itr) { *itr = back(); pop_back(); }

// A place to temporarily put addresses before re-adding them to the
// AvailableList.
Expand Down
2 changes: 1 addition & 1 deletion src/download/chunk_selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ChunkSelector::initialize(ChunkStatistics* cs) {

untouched->set_size_bits(completed->size_bits());
untouched->allocate();
std::transform(completed->begin(), completed->end(), untouched->begin(), [](const Bitfield::value_type& v) { return ~v; });
std::transform(completed->begin(), completed->end(), untouched->begin(), [](auto v) { return ~v; });
untouched->update();

m_sharedQueue.enable(32);
Expand Down
2 changes: 1 addition & 1 deletion src/download/download_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ DownloadMain::receive_tracker_request() {
}

static bool
SocketAddressCompact_less(const SocketAddressCompact& a, const SocketAddressCompact& b) {
SocketAddressCompact_less(SocketAddressCompact a, SocketAddressCompact b) {
return (a.addr < b.addr) || ((a.addr == b.addr) && (a.port < b.port));
}

Expand Down
4 changes: 4 additions & 0 deletions src/net/udns_resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@
namespace torrent::net {

struct UdnsQuery {
UdnsQuery() = default;
// TODO: We already use deleted.
~UdnsQuery() { parent = nullptr; }

UdnsQuery(const UdnsQuery&) = delete;
UdnsQuery& operator=(const UdnsQuery&) = delete;

void* requester{};
std::string hostname;
int family{};
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/peer_connection_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ PeerConnectionBase::should_connection_unchoke(choke_queue* cq) const {
}

bool
PeerConnectionBase::down_chunk_start(const Piece& piece) {
PeerConnectionBase::down_chunk_start(Piece piece) {
if (!request_list()->downloading(piece)) {
if (piece.length() == 0) {
LT_LOG_PIECE_EVENTS("(down) skipping_empty %" PRIu32 " %" PRIu32 " %" PRIu32,
Expand Down Expand Up @@ -800,7 +800,7 @@ PeerConnectionBase::up_chunk_release() {
}

void
PeerConnectionBase::read_request_piece(const Piece& p) {
PeerConnectionBase::read_request_piece(Piece p) {
auto itr = std::find(m_peerChunks.upload_queue()->begin(),
m_peerChunks.upload_queue()->end(),
p);
Expand All @@ -819,7 +819,7 @@ PeerConnectionBase::read_request_piece(const Piece& p) {
}

void
PeerConnectionBase::read_cancel_piece(const Piece& p) {
PeerConnectionBase::read_cancel_piece(Piece p) {
auto itr = std::find(m_peerChunks.upload_queue()->begin(),
m_peerChunks.upload_queue()->end(),
p);
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/peer_connection_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ class PeerConnectionBase : public Peer, public SocketStream {

void load_up_chunk();

void read_request_piece(const Piece& p);
void read_cancel_piece(const Piece& p);
void read_request_piece(Piece p);
void read_cancel_piece(Piece p);

void write_prepare_piece();
void write_prepare_extension(int type, const DataBuffer& message);

bool down_chunk_start(const Piece& p);
bool down_chunk_start(Piece p);
void down_chunk_finished();

bool down_chunk();
Expand Down
17 changes: 9 additions & 8 deletions src/protocol/protocol_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define LIBTORRENT_NET_PROTOCOL_BASE_H

#include "net/protocol_buffer.h"
#include "torrent/data/piece.h"

namespace torrent {

class Piece;
class ThrottleList;

class ProtocolBase {
public:
Expand Down Expand Up @@ -69,9 +70,9 @@ class ProtocolBase {
void write_interested(bool s);
void write_have(uint32_t index);
void write_bitfield(size_type length);
void write_request(const Piece& p);
void write_cancel(const Piece& p);
void write_piece(const Piece& p);
void write_request(Piece p);
void write_cancel(Piece p);
void write_piece(Piece p);
void write_port(uint16_t port);
void write_extension(uint8_t id, uint32_t length);

Expand Down Expand Up @@ -126,7 +127,7 @@ ProtocolBase::read_request() {
uint32_t index = m_buffer.read_32();
uint32_t offset = m_buffer.read_32();
uint32_t length = m_buffer.read_32();

return Piece(index, offset, length);
Comment thread
neheb marked this conversation as resolved.
Comment thread
neheb marked this conversation as resolved.
}

Expand Down Expand Up @@ -170,7 +171,7 @@ ProtocolBase::write_bitfield(size_type length) {
}

inline void
ProtocolBase::write_request(const Piece& p) {
ProtocolBase::write_request(Piece p) {
Comment thread
neheb marked this conversation as resolved.
m_buffer.write_32(13);
write_command(REQUEST);
m_buffer.write_32(p.index());
Expand All @@ -179,7 +180,7 @@ ProtocolBase::write_request(const Piece& p) {
}

inline void
ProtocolBase::write_cancel(const Piece& p) {
ProtocolBase::write_cancel(Piece p) {
Comment thread
neheb marked this conversation as resolved.
m_buffer.write_32(13);
write_command(CANCEL);
m_buffer.write_32(p.index());
Expand All @@ -188,7 +189,7 @@ ProtocolBase::write_cancel(const Piece& p) {
}

inline void
ProtocolBase::write_piece(const Piece& p) {
ProtocolBase::write_piece(Piece p) {
Comment thread
neheb marked this conversation as resolved.
m_buffer.write_32(9 + p.length());
write_command(PIECE);
m_buffer.write_32(p.index());
Expand Down
6 changes: 3 additions & 3 deletions src/protocol/request_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ request_list_constants::destroy<BlockTransfer*>(BlockTransfer*& obj) {

// It is assumed invalid transfers have been removed.
struct request_list_same_piece {
request_list_same_piece(const Piece& p) : m_piece(p) {}
request_list_same_piece(Piece p) : m_piece(p) {}

bool operator () (const BlockTransfer* d) const {
return
Expand Down Expand Up @@ -157,7 +157,7 @@ RequestList::delay_remove_choked() {
}

void
RequestList::prepare_process_unordered(queues_type::iterator itr) {
RequestList::prepare_process_unordered(const queues_type::iterator& itr) {
m_queues.move_to(bucket_queued, m_queues.begin(bucket_queued), itr,
bucket_unordered);

Expand Down Expand Up @@ -198,7 +198,7 @@ RequestList::clear() {
}

bool
RequestList::downloading(const Piece& piece) {
RequestList::downloading(Piece piece) {
if (m_transfer != nullptr)
throw internal_error("RequestList::downloading(...) m_transfer != nullptr.");

Expand Down
4 changes: 2 additions & 2 deletions src/protocol/request_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class RequestList {
void clear();

// The returned transfer must still be valid.
bool downloading(const Piece& piece);
bool downloading(Piece piece);

void finished();
void skipped();
Expand Down Expand Up @@ -93,7 +93,7 @@ class RequestList {
private:
void delay_remove_choked();

void prepare_process_unordered(queues_type::iterator itr);
void prepare_process_unordered(const queues_type::iterator& itr);
void delay_process_unordered();

Delegator* m_delegator{};
Expand Down
14 changes: 7 additions & 7 deletions src/torrent/data/block.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Expand Down Expand Up @@ -106,7 +106,7 @@ Block::insert(PeerInfo* peerInfo) {

return m_queued.emplace_back(block);
}

void
Block::erase(BlockTransfer* transfer) {
if (transfer->is_erased())
Expand Down Expand Up @@ -251,7 +251,7 @@ Block::completed(BlockTransfer* transfer) {
// We need to invalidate those unfinished and keep the one that
// finished for later reference.
remove_non_leader_transfers();

// We now know that all transfers except the current leader we're
// handling has been invalidated.
if (m_transfers.empty() || m_transfers.back() != transfer)
Expand Down Expand Up @@ -281,7 +281,7 @@ Block::transfer_dissimilar(BlockTransfer* transfer) {
// Why not just delete? Gets done by completed(), though when
// erasing the leader we need to remove dissimilar unless we have
// another leader.

transfer->set_state(BlockTransfer::STATE_ERASED);
transfer->set_position(0);
transfer->set_block(NULL);
Expand Down Expand Up @@ -336,7 +336,7 @@ Block::failed_leader() {
}

void
Block::create_dummy(BlockTransfer* transfer, PeerInfo* peerInfo, const Piece& piece) {
Block::create_dummy(BlockTransfer* transfer, PeerInfo* peerInfo, Piece piece) {
transfer->set_peer_info(peerInfo);

transfer->set_block(NULL);
Expand Down Expand Up @@ -379,7 +379,7 @@ Block::invalidate_transfer(BlockTransfer* transfer) {

m_notStalled -= (transfer->stall() == 0);

// Do the canceling magic here.
// Do the canceling magic here.
if (transfer->peer_info()->connection() != NULL)
transfer->peer_info()->connection()->cancel_transfer(transfer);
}
Expand Down
6 changes: 3 additions & 3 deletions src/torrent/data/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class LIBTORRENT_EXPORT Block {
const BlockList* parent() const { return m_parent; }
void set_parent(BlockList* p) { m_parent = p; }

const Piece& piece() const { return m_piece; }
void set_piece(const Piece& p) { m_piece = p; }
auto piece() const { return m_piece; }
void set_piece(Piece p) { m_piece = p; }

uint32_t index() const { return m_piece.index(); }

Expand Down Expand Up @@ -89,7 +89,7 @@ class LIBTORRENT_EXPORT Block {
BlockFailed* failed_list() { return m_failedList; }
void set_failed_list(BlockFailed* f) { m_failedList = f; }

static void create_dummy(BlockTransfer* transfer, PeerInfo* peerInfo, const Piece& piece);
static void create_dummy(BlockTransfer* transfer, PeerInfo* peerInfo, Piece piece);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ readability-identifier-naming ⚠️
invalid case style for parameter peerInfo

Suggested change
static void create_dummy(BlockTransfer* transfer, PeerInfo* peerInfo, Piece piece);
static void create_dummy(BlockTransfer* transfer, PeerInfo* peer_info, Piece piece);


// If the queued or transfering is already removed from the block it
// will just delete the object. Made static so it can be called when
Expand Down
2 changes: 1 addition & 1 deletion src/torrent/data/block_failed.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BlockFailed : public std::vector<std::pair<char*, uint32_t> > {

void set_current(size_type idx) { m_current = idx; }
void set_current(iterator itr) { m_current = itr - begin(); }
void set_current(reverse_iterator itr) { m_current = itr.base() - begin() - 1; }
void set_current(const reverse_iterator& itr) { m_current = itr.base() - begin() - 1; }

iterator max_element();
reverse_iterator reverse_max_element();
Expand Down
6 changes: 3 additions & 3 deletions src/torrent/data/block_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Expand Down Expand Up @@ -44,7 +44,7 @@

namespace torrent {

BlockList::BlockList(const Piece& piece, uint32_t blockLength) :
BlockList::BlockList(Piece piece, uint32_t blockLength) :
m_piece(piece)

{
Expand Down
2 changes: 1 addition & 1 deletion src/torrent/data/block_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class LIBTORRENT_EXPORT BlockList : private std::vector<Block> {

using base_type::operator[];

BlockList(const Piece& piece, uint32_t blockLength);
BlockList(Piece piece, uint32_t blockLength);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ readability-identifier-naming ⚠️
invalid case style for parameter blockLength

Suggested change
BlockList(Piece piece, uint32_t blockLength);
BlockList(Piece piece, uint32_t block_length);

~BlockList();
BlockList(const BlockList&) = delete;
BlockList& operator=(const BlockList&) = delete;
Expand Down
2 changes: 1 addition & 1 deletion src/torrent/data/block_transfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class LIBTORRENT_EXPORT BlockTransfer {

void set_peer_info(key_type p);
void set_block(Block* b) { m_block = b; }
void set_piece(const Piece& p) { m_piece = p; }
void set_piece(Piece p) { m_piece = p; }
void set_state(state_type s) { m_state = s; }
void set_request_time(int32_t t) { m_request_time = t; }

Expand Down
2 changes: 1 addition & 1 deletion src/torrent/data/file_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ FileList::~FileList() {
}

bool
FileList::is_valid_piece(const Piece& piece) const {
FileList::is_valid_piece(Piece piece) const {
return
piece.index() < size_chunks() &&
piece.length() != 0 &&
Expand Down
Loading
Loading