diff --git a/include/libtorrent/piece_picker.hpp b/include/libtorrent/piece_picker.hpp index d0a660e89..577479939 100644 --- a/include/libtorrent/piece_picker.hpp +++ b/include/libtorrent/piece_picker.hpp @@ -72,6 +72,7 @@ namespace libtorrent class peer_connection; struct bitfield; struct counters; + struct torrent_peer; struct TORRENT_EXTRA_EXPORT piece_block { @@ -118,9 +119,8 @@ namespace libtorrent { block_info(): peer(0), num_peers(0), state(state_none) {} // the peer this block was requested or - // downloaded from. This is a pointer to - // a torrent_peer object - void* peer; + // downloaded from. + torrent_peer* peer; // the number of peers that has this block in their // download or request queues unsigned num_peers:14; @@ -130,7 +130,7 @@ namespace libtorrent #if TORRENT_USE_ASSERTS // to allow verifying the invariant of blocks belonging to the right piece int piece_index; - std::set peers; + std::set peers; #endif }; @@ -216,21 +216,21 @@ namespace libtorrent // increases the peer count for the given piece // (is used when a HAVE message is received) - void inc_refcount(int index, const void* peer); - void dec_refcount(int index, const void* peer); + void inc_refcount(int index, const torrent_peer* peer); + void dec_refcount(int index, const torrent_peer* peer); // increases the peer count for the given piece // (is used when a BITFIELD message is received) - void inc_refcount(bitfield const& bitmask, const void* peer); + void inc_refcount(bitfield const& bitmask, const torrent_peer* peer); // decreases the peer count for the given piece // (used when a peer disconnects) - void dec_refcount(bitfield const& bitmask, const void* peer); + void dec_refcount(bitfield const& bitmask, const torrent_peer* peer); // these will increase and decrease the peer count // of all pieces. They are used when seeds join // or leave the swarm. - void inc_refcount_all(const void* peer); - void dec_refcount_all(const void* peer); + void inc_refcount_all(const torrent_peer* peer); + void dec_refcount_all(const torrent_peer* peer); // This indicates that we just received this piece // it means that the refcounter will indicate that @@ -297,7 +297,7 @@ namespace libtorrent // (i.e. higher overhead per request). void pick_pieces(bitfield const& pieces , std::vector& interesting_blocks, int num_blocks - , int prefer_contiguous_blocks, void* peer + , int prefer_contiguous_blocks, torrent_peer* peer , int options, std::vector const& suggested_pieces , int num_peers , counters& pc @@ -314,7 +314,7 @@ namespace libtorrent , std::vector& backup_blocks , std::vector& backup_blocks2 , int num_blocks, int prefer_contiguous_blocks - , void* peer, std::vector const& ignore + , torrent_peer* peer, std::vector const& ignore , int options) const; // picks blocks only from downloading pieces @@ -324,12 +324,12 @@ namespace libtorrent , std::vector& backup_blocks , std::vector& backup_blocks2 , int num_blocks, int prefer_contiguous_blocks - , void* peer + , torrent_peer* peer , int options) const; // clears the peer pointer in all downloading pieces with this // peer pointer - void clear_peer(void* peer); + void clear_peer(torrent_peer* peer); #if TORRENT_USE_INVARIANT_CHECKS // this is an invariant check @@ -349,15 +349,15 @@ namespace libtorrent // marks this piece-block as queued for downloading // options are flags from options_t. - bool mark_as_downloading(piece_block block, void* peer + bool mark_as_downloading(piece_block block, torrent_peer* peer , int options = 0); // returns true if the block was marked as writing, // and false if the block is already finished or writing - bool mark_as_writing(piece_block block, void* peer); + bool mark_as_writing(piece_block block, torrent_peer* peer); - void mark_as_canceled(piece_block block, void* peer); - void mark_as_finished(piece_block block, void* peer); + void mark_as_canceled(piece_block block, torrent_peer* peer); + void mark_as_finished(piece_block block, torrent_peer* peer); // prevent blocks from being picked from this piece. // to unlock the piece, call restore_piece() on it @@ -390,7 +390,7 @@ namespace libtorrent // clears the given piece's download flag // this means that this piece-block can be picked again - void abort_download(piece_block block, void* peer = 0); + void abort_download(piece_block block, torrent_peer* peer = 0); // returns true if all blocks in this piece are finished // or if we have the piece @@ -409,7 +409,7 @@ namespace libtorrent // return the peer pointers to all peers that participated in // this piece - void get_downloaders(std::vector& d, int index) const; + void get_downloaders(std::vector& d, int index) const; std::vector get_download_queue() const; int get_download_queue_size() const; @@ -417,7 +417,7 @@ namespace libtorrent void get_download_queue_sizes(int* partial , int* full, int* finished, int* zero_prio) const; - void* get_downloader(piece_block block) const; + torrent_peer* get_downloader(piece_block block) const; // the number of filtered pieces we don't have int num_filtered() const { return m_num_filtered; } @@ -449,7 +449,7 @@ namespace libtorrent void verify_pick(std::vector const& picked , bitfield const& bits) const; - void check_peer_invariant(bitfield const& have, void const* p) const; + void check_peer_invariant(bitfield const& have, torrent_peer const* p) const; void check_invariant(const torrent* t = 0) const; #endif #if defined TORRENT_PICKER_LOG || defined TORRENT_DEBUG @@ -483,7 +483,7 @@ namespace libtorrent boost::tuple requested_from( piece_picker::downloading_piece const& p - , int num_blocks_in_piece, void* peer) const; + , int num_blocks_in_piece, torrent_peer* peer) const; bool can_pick(int piece, bitfield const& bitmask) const; bool is_piece_free(int piece, bitfield const& bitmask) const; @@ -617,7 +617,7 @@ namespace libtorrent #ifdef TORRENT_DEBUG_REFCOUNTS // all the peers that have this piece - std::set have_peers; + std::set have_peers; #endif enum @@ -639,18 +639,18 @@ namespace libtorrent max_peer_count = 0xffff #endif }; - + bool have() const { return index == we_have_index; } void set_have() { index = we_have_index; TORRENT_ASSERT(have()); } void set_not_have() { index = 0; TORRENT_ASSERT(!have()); } bool downloading() const { return download_state != piece_open; } - + bool filtered() const { return piece_priority == filter_priority; } // this function returns the effective priority of the piece. It's // actually the sort order of this piece compared to other pieces. A // lower index means it will be picked before a piece with a higher - // index. + // index. // The availability of the piece (the number of peers that have this // piece) is fundamentally controlling the priority. It's multiplied // by 3 to form 3 levels of priority for each availability. diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index a5304e31f..19a783866 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -721,7 +721,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS if (t && t->has_picker()) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif if (t->is_upload_only()) send_not_interested(); else t->peer_is_interesting(*this); @@ -1894,7 +1894,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS if (t && t->has_picker()) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif } @@ -2057,7 +2057,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS if (t && t->has_picker()) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif return; } @@ -2084,7 +2084,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS if (t && t->has_picker()) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif // this will cause us to send the INTERESTED message @@ -2849,13 +2849,13 @@ namespace libtorrent int num_blocks = t->picker().blocks_in_piece(piece); if (st.requested > 0 && st.writing + st.finished + st.requested == num_blocks) { - std::vector d; + std::vector d; t->picker().get_downloaders(d, piece); if (d.size() == 1) { // only make predictions if all remaining // blocks are requested from the same peer - torrent_peer* peer = static_cast(d[0]); + torrent_peer* peer = d[0]; if (peer->connection) { // we have a connection. now, what is the current @@ -3145,7 +3145,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS if (t && t->has_picker()) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif TORRENT_ASSERT(m_have_piece.all_set()); @@ -6505,7 +6505,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS \ && !defined TORRENT_NO_EXPENSIVE_INVARIANT_CHECK if (t && t->has_picker() && !m_disconnecting) - t->picker().check_peer_invariant(m_have_piece, this); + t->picker().check_peer_invariant(m_have_piece, peer_info_struct()); #endif if (!m_disconnect_started && m_initialized) diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 7d528533a..cb3b61fec 100644 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -349,7 +349,7 @@ namespace libtorrent { if (info[j].peer) { - torrent_peer* p = static_cast(info[j].peer); + torrent_peer* p = info[j].peer; TORRENT_ASSERT(p->in_use); TORRENT_ASSERT(p->connection == NULL || static_cast(p->connection)->m_in_use); @@ -435,7 +435,7 @@ namespace libtorrent #if TORRENT_USE_INVARIANT_CHECKS void piece_picker::check_peer_invariant(bitfield const& have - , void const* p) const + , torrent_peer const* p) const { #ifdef TORRENT_DEBUG_REFCOUNTS int num_pieces = have.size(); @@ -482,7 +482,7 @@ namespace libtorrent for (int j = 0; j < m_blocks_per_piece; ++j) { if (!info[j].peer) continue; - torrent_peer* p = static_cast(info[j].peer); + torrent_peer* p = info[j].peer; TORRENT_ASSERT(p->in_use); TORRENT_ASSERT(p->connection == NULL || static_cast(p->connection)->m_in_use); @@ -511,7 +511,7 @@ namespace libtorrent { TORRENT_ASSERT(info[k].piece_index == i->index); TORRENT_ASSERT(info[k].peer == 0 - || static_cast(info[k].peer)->in_use); + || info[k].peer->in_use); if (info[k].state == block_info::state_finished) { @@ -1136,7 +1136,7 @@ namespace libtorrent #endif } - void piece_picker::inc_refcount_all(const void* peer) + void piece_picker::inc_refcount_all(const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1162,7 +1162,7 @@ namespace libtorrent #endif } - void piece_picker::dec_refcount_all(const void* peer) + void piece_picker::dec_refcount_all(const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1209,7 +1209,7 @@ namespace libtorrent m_dirty = true; } - void piece_picker::inc_refcount(int index, const void* peer) + void piece_picker::inc_refcount(int index, const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1260,7 +1260,7 @@ namespace libtorrent m_dirty = true; } - void piece_picker::dec_refcount(int index, const void* peer) + void piece_picker::dec_refcount(int index, const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1297,7 +1297,7 @@ namespace libtorrent if (prev_priority >= 0) update(prev_priority, p.index); } - void piece_picker::inc_refcount(bitfield const& bitmask, const void* peer) + void piece_picker::inc_refcount(bitfield const& bitmask, const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1393,7 +1393,7 @@ namespace libtorrent if (updated) m_dirty = true; } - void piece_picker::dec_refcount(bitfield const& bitmask, const void* peer) + void piece_picker::dec_refcount(bitfield const& bitmask, const torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -1935,7 +1935,7 @@ namespace libtorrent // num_blocks of interesting blocks that the peer has. // prefer_contiguous_blocks can be set if this peer should download whole // pieces rather than trying to download blocks from the same piece as other - // peers. the void* is the pointer to the torrent_peer of the peer we're + // peers. the peer argument is the torrent_peer of the peer we're // picking pieces from. This is used when downloading whole pieces, to only // pick from the same piece the same peer is downloading from. @@ -1958,13 +1958,13 @@ namespace libtorrent void piece_picker::pick_pieces(bitfield const& pieces , std::vector& interesting_blocks, int num_blocks - , int prefer_contiguous_blocks, void* peer + , int prefer_contiguous_blocks, torrent_peer* peer , int options, std::vector const& suggested_pieces , int num_peers , counters& pc ) const { - TORRENT_ASSERT(peer == 0 || static_cast(peer)->in_use); + TORRENT_ASSERT(peer == 0 || peer->in_use); // prevent the number of partial pieces to grow indefinitely // make this scale by the number of peers we have. For large @@ -2571,7 +2571,7 @@ get_out: } #endif - void piece_picker::clear_peer(void* peer) + void piece_picker::clear_peer(torrent_peer* peer) { for (std::vector::iterator i = m_block_info.begin() , end(m_block_info.end()); i != end; ++i) @@ -2588,7 +2588,7 @@ get_out: // the first-fit range, which would be better boost::tuple piece_picker::requested_from( piece_picker::downloading_piece const& p - , int num_blocks_in_piece, void* peer) const + , int num_blocks_in_piece, torrent_peer* peer) const { bool exclusive = true; bool exclusive_active = true; @@ -2637,7 +2637,7 @@ get_out: , std::vector& backup_blocks , std::vector& backup_blocks2 , int num_blocks, int prefer_contiguous_blocks - , void* peer, std::vector const& ignore + , torrent_peer* peer, std::vector const& ignore , int options) const { TORRENT_ASSERT(piece >= 0); @@ -2717,7 +2717,7 @@ get_out: , std::vector& backup_blocks , std::vector& backup_blocks2 , int num_blocks, int prefer_contiguous_blocks - , void* peer, int options) const + , torrent_peer* peer, int options) const { if (!pieces[dp.index]) return num_blocks; TORRENT_ASSERT(!m_piece_map[dp.index].filtered()); @@ -3101,7 +3101,7 @@ get_out: // options may be 0 or piece_picker::reverse bool piece_picker::mark_as_downloading(piece_block block - , void* peer, int options) + , torrent_peer* peer, int options) { #ifdef TORRENT_PICKER_LOG std::cerr << "[" << this << "] " << "mark_as_downloading( {" @@ -3245,7 +3245,7 @@ get_out: return m_piece_map[piece].peer_count + m_seeds; } - bool piece_picker::mark_as_writing(piece_block block, void* peer) + bool piece_picker::mark_as_writing(piece_block block, torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -3437,7 +3437,7 @@ get_out: } } - void piece_picker::mark_as_canceled(const piece_block block, void* peer) + void piece_picker::mark_as_canceled(const piece_block block, torrent_peer* peer) { #ifdef TORRENT_PICKER_LOG std::cerr << "[" << this << "] " << "mark_as_cancelled( {" @@ -3501,7 +3501,7 @@ get_out: #endif } - void piece_picker::mark_as_finished(piece_block block, void* peer) + void piece_picker::mark_as_finished(piece_block block, torrent_peer* peer) { #if TORRENT_USE_INVARIANT_CHECKS check_piece_state(); @@ -3622,7 +3622,7 @@ get_out: } */ - void piece_picker::get_downloaders(std::vector& d, int index) const + void piece_picker::get_downloaders(std::vector& d, int index) const { TORRENT_ASSERT(index >= 0 && index <= int(m_piece_map.size())); @@ -3633,7 +3633,7 @@ get_out: if (state == piece_pos::piece_open) { - for (int i = 0; i < num_blocks; ++i) d.push_back(0); + for (int i = 0; i < num_blocks; ++i) d.push_back(NULL); return; } @@ -3644,12 +3644,12 @@ get_out: for (int j = 0; j != num_blocks; ++j) { TORRENT_ASSERT(binfo[j].peer == 0 - || static_cast(binfo[j].peer)->in_use); + || binfo[j].peer->in_use); d.push_back(binfo[j].peer); } } - void* piece_picker::get_downloader(piece_block block) const + torrent_peer* piece_picker::get_downloader(piece_block block) const { int state = m_piece_map[block.piece_index].download_queue(); if (state == piece_pos::piece_open) return 0; @@ -3661,16 +3661,16 @@ get_out: block_info const* binfo = blocks_for_piece(*i); TORRENT_ASSERT(binfo[block.block_index].piece_index == block.piece_index); if (binfo[block.block_index].state == block_info::state_none) - return 0; + return NULL; - void* peer = binfo[block.block_index].peer; + torrent_peer* peer = binfo[block.block_index].peer; TORRENT_ASSERT(peer == 0 || static_cast(peer)->in_use); return peer; } // this is called when a request is rejected or when // a peer disconnects. The piece might be in any state - void piece_picker::abort_download(piece_block block, void* peer) + void piece_picker::abort_download(piece_block block, torrent_peer* peer) { #ifdef TORRENT_EXPENSIVE_INVARIANT_CHECKS TORRENT_PIECE_PICKER_INVARIANT_CHECK; @@ -3679,7 +3679,7 @@ get_out: #ifdef TORRENT_PICKER_LOG std::cerr << "[" << this << "] " << "abort_download( {" << block.piece_index << ", " << block.block_index << "} )" << std::endl; #endif - TORRENT_ASSERT(peer == 0 || static_cast(peer)->in_use); + TORRENT_ASSERT(peer == 0 || peer->in_use); TORRENT_ASSERT(block.block_index != piece_block::invalid.block_index); TORRENT_ASSERT(block.piece_index != piece_block::invalid.piece_index); @@ -3695,7 +3695,7 @@ get_out: block_info* binfo = blocks_for_piece(*i); block_info& info = binfo[block.block_index]; - TORRENT_ASSERT(info.peer == 0 || static_cast(info.peer)->in_use); + TORRENT_ASSERT(info.peer == 0 || info.peer->in_use); TORRENT_ASSERT(info.piece_index == block.piece_index); TORRENT_ASSERT(info.state != block_info::state_none); diff --git a/src/smart_ban.cpp b/src/smart_ban.cpp index 609bf5f12..ab4f52d57 100644 --- a/src/smart_ban.cpp +++ b/src/smart_ban.cpp @@ -195,16 +195,16 @@ namespace // a bunch of read operations on it if (m_torrent.is_aborted()) return; - std::vector downloaders; + std::vector downloaders; m_torrent.picker().get_downloaders(downloaders, p); int size = m_torrent.torrent_file().piece_size(p); peer_request r = {p, 0, (std::min)(16*1024, size)}; piece_block pb(p, 0); - for (std::vector::iterator i = downloaders.begin() + for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { - if (*i != 0) + if (*i != NULL) { // for very sad and involved reasons, this read need to force a copy out of the cache // since the piece has failed, this block is very likely to be replaced with a newly @@ -212,8 +212,8 @@ namespace // block read will have been deleted by the time it gets back to the network thread m_torrent.session().disk_thread().async_read(&m_torrent.storage(), r , boost::bind(&smart_ban_plugin::on_read_failed_block - , shared_from_this(), pb, static_cast(*i)->address(), _1) - , reinterpret_cast(1) + , shared_from_this(), pb, (*i)->address(), _1) + , reinterpret_cast(1) , disk_io_job::force_copy); } diff --git a/src/torrent.cpp b/src/torrent.cpp index 1deef24ab..4aefc9226 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -4250,12 +4250,12 @@ namespace libtorrent remove_time_critical_piece(index, true); - std::vector downloaders; + std::vector downloaders; m_picker->get_downloaders(downloaders, index); // increase the trust point of all peers that sent // parts of this piece. - std::set peers; + std::set peers; // these torrent_peer pointers are owned by m_peer_list and they may be // invalidated if a peer disconnects. We cannot keep them across any @@ -4264,7 +4264,7 @@ namespace libtorrent std::remove_copy(downloaders.begin(), downloaders.end() , std::inserter(peers, peers.begin()), static_cast(0)); - for (std::set::iterator i = peers.begin() + for (std::set::iterator i = peers.begin() , end(peers.end()); i != end; ++i) { torrent_peer* p = static_cast(*i); @@ -4368,18 +4368,18 @@ namespace libtorrent } #endif - std::vector downloaders; + std::vector downloaders; if (m_picker) m_picker->get_downloaders(downloaders, index); // decrease the trust point of all peers that sent // parts of this piece. // first, build a set of all peers that participated - std::set peers; + std::set peers; std::copy(downloaders.begin(), downloaders.end(), std::inserter(peers, peers.begin())); #ifdef TORRENT_DEBUG - for (std::vector::iterator i = downloaders.begin() + for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { torrent_peer* p = static_cast(*i); @@ -4394,7 +4394,7 @@ namespace libtorrent // did we receive this piece from a single peer? bool single_peer = peers.size() == 1; - for (std::set::iterator i = peers.begin() + for (std::set::iterator i = peers.begin() , end(peers.end()); i != end; ++i) { torrent_peer* p = static_cast(*i); @@ -4497,7 +4497,7 @@ namespace libtorrent } #ifdef TORRENT_DEBUG - for (std::vector::iterator i = downloaders.begin() + for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i) { torrent_peer* p = (torrent_peer*)*i; @@ -4573,7 +4573,8 @@ namespace libtorrent { if (has_picker()) { - m_picker->inc_refcount(index, peer); + torrent_peer* pp = peer->peer_info_struct(); + m_picker->inc_refcount(index, pp); update_suggest_piece(index, 1); } #ifdef TORRENT_DEBUG @@ -4589,7 +4590,8 @@ namespace libtorrent { if (has_picker()) { - m_picker->inc_refcount(bits, peer); + torrent_peer* pp = peer->peer_info_struct(); + m_picker->inc_refcount(bits, pp); refresh_suggest_pieces(); } #ifdef TORRENT_DEBUG @@ -4604,7 +4606,8 @@ namespace libtorrent { if (has_picker()) { - m_picker->inc_refcount_all(peer); + torrent_peer* pp = peer->peer_info_struct(); + m_picker->inc_refcount_all(pp); } #ifdef TORRENT_DEBUG else @@ -4618,7 +4621,8 @@ namespace libtorrent { if (has_picker()) { - m_picker->dec_refcount(bits, peer); + torrent_peer* pp = peer->peer_info_struct(); + m_picker->dec_refcount(bits, pp); // TODO: update suggest_piece? } #ifdef TORRENT_DEBUG @@ -4633,7 +4637,8 @@ namespace libtorrent { if (m_picker.get()) { - m_picker->dec_refcount(index, peer); + torrent_peer* pp = peer->peer_info_struct(); + m_picker->dec_refcount(index, pp); update_suggest_piece(index, -1); } #ifdef TORRENT_DEBUG @@ -5127,14 +5132,14 @@ namespace libtorrent // this means we have outstanding requests (or queued // up requests that haven't been sent yet). Promote them // to deadline pieces immediately - std::vector downloaders; + std::vector downloaders; m_picker->get_downloaders(downloaders, piece); int block = 0; - for (std::vector::iterator i = downloaders.begin() + for (std::vector::iterator i = downloaders.begin() , end(downloaders.end()); i != end; ++i, ++block) { - torrent_peer* p = static_cast(*i); + torrent_peer* p = *i; if (p == 0 || p->connection == 0) continue; peer_connection* peer = static_cast(p->connection); peer->make_time_critical(piece_block(piece, block)); @@ -5944,6 +5949,7 @@ namespace libtorrent return; } + torrent_peer* pp = p->peer_info_struct(); if (ready_for_connections()) { TORRENT_ASSERT(p->associated_torrent().lock().get() == NULL @@ -5953,7 +5959,7 @@ namespace libtorrent { if (has_picker()) { - m_picker->dec_refcount_all(p); + m_picker->dec_refcount_all(pp); } } else @@ -5962,7 +5968,7 @@ namespace libtorrent { bitfield const& pieces = p->get_bitfield(); TORRENT_ASSERT(pieces.count() <= int(pieces.size())); - m_picker->dec_refcount(pieces, p); + m_picker->dec_refcount(pieces, pp); } } } @@ -5973,7 +5979,6 @@ namespace libtorrent trigger_unchoke(); } - torrent_peer* pp = p->peer_info_struct(); if (pp) { if (pp->optimistically_unchoked) @@ -11190,7 +11195,7 @@ namespace libtorrent inc_refcount("verify_piece"); m_ses.disk_thread().async_hash(m_storage.get(), piece, 0 , boost::bind(&torrent::on_piece_verified, shared_from_this(), _1) - , (void*)1); + , reinterpret_cast(1)); } announce_entry* torrent::find_tracker(tracker_request const& r) @@ -11210,7 +11215,7 @@ namespace libtorrent torrent_state st = get_peer_list_state(); std::vector
banned; m_peer_list->apply_ip_filter(*m_ip_filter, &st, banned); - + if (alerts().should_post()) { for (std::vector
::iterator i = banned.begin() @@ -11218,7 +11223,7 @@ namespace libtorrent alerts().emplace_alert(get_handle(), *i , peer_blocked_alert::ip_filter); } - + peers_erased(st.erased); } diff --git a/test/test_piece_picker.cpp b/test/test_piece_picker.cpp index 36945c099..4aa005f2f 100644 --- a/test/test_piece_picker.cpp +++ b/test/test_piece_picker.cpp @@ -124,16 +124,16 @@ boost::shared_ptr setup_picker( TEST_CHECK(!p->is_finished(piece_block(i, j))); if ((blocks & (1 << j)) == 0) continue; ++counter; - bool ret = p->mark_as_downloading(piece_block(i, j), (void*)tmp_peer); + bool ret = p->mark_as_downloading(piece_block(i, j), tmp_peer); TEST_CHECK(ret == true); TEST_CHECK(p->is_requested(piece_block(i, j)) == bool(blocks & (1 << j))); - p->mark_as_writing(piece_block(i, j), (void*)tmp_peer); + p->mark_as_writing(piece_block(i, j), tmp_peer); TEST_CHECK(!p->is_finished(piece_block(i, j))); // trying to mark a block as requested after it has been completed // should fail (return false) - ret = p->mark_as_downloading(piece_block(i, j), (void*)tmp_peer); + ret = p->mark_as_downloading(piece_block(i, j), tmp_peer); TEST_CHECK(ret == false); - p->mark_as_finished(piece_block(i, j), (void*)tmp_peer); + p->mark_as_finished(piece_block(i, j), tmp_peer); TEST_CHECK(p->is_downloaded(piece_block(i, j)) == bool(blocks & (1 << j))); TEST_CHECK(p->is_finished(piece_block(i, j)) == bool(blocks & (1 << j))); @@ -250,7 +250,7 @@ std::vector pick_pieces(boost::shared_ptr const& p , char const* availability , int num_blocks , int prefer_contiguous_blocks - , void* peer_struct + , torrent_peer* peer_struct , int options = piece_picker::rarest_first , std::vector const& suggested_pieces = empty_vector) { @@ -408,7 +408,7 @@ TORRENT_TEST(piece_picker) p->mark_as_downloading(piece_block(0, 2), &tmp2); p->mark_as_writing(piece_block(0, 2), &tmp2); - std::vector d; + std::vector d; p->get_downloaders(d, 0); TEST_EQUAL(d.size(), 4); TEST_CHECK(d[0] == NULL); @@ -1166,12 +1166,12 @@ TORRENT_TEST(piece_picker) p->mark_as_downloading(piece_block(2, 1), &tmp2); p->mark_as_downloading(piece_block(3, 1), &tmp3); - std::vector dls; - void* expected_dls1[] = {&tmp1, &tmp2, &tmp3, 0}; - void* expected_dls2[] = {0, &tmp1, 0, 0}; - void* expected_dls3[] = {0, &tmp2, 0, 0}; - void* expected_dls4[] = {0, &tmp3, 0, 0}; - void* expected_dls5[] = {&tmp1, 0, &tmp3, 0}; + std::vector dls; + torrent_peer* expected_dls1[] = {&tmp1, &tmp2, &tmp3, 0}; + torrent_peer* expected_dls2[] = {0, &tmp1, 0, 0}; + torrent_peer* expected_dls3[] = {0, &tmp2, 0, 0}; + torrent_peer* expected_dls4[] = {0, &tmp3, 0, 0}; + torrent_peer* expected_dls5[] = {&tmp1, 0, &tmp3, 0}; p->get_downloaders(dls, 0); TEST_CHECK(std::equal(dls.begin(), dls.end(), expected_dls1)); p->get_downloaders(dls, 1); @@ -1238,7 +1238,7 @@ TORRENT_TEST(piece_picker) // decrease refcount on something that's not in the piece list p->dec_refcount(5, &tmp0); p->inc_refcount(5, &tmp0); - + bitfield bits = string2vec("* "); TEST_EQUAL(bits.get_bit(0), true); TEST_EQUAL(bits.get_bit(1), false); @@ -1261,14 +1261,14 @@ TORRENT_TEST(piece_picker) TEST_EQUAL(test_pick(p), 0); // ======================================================== - + // test unverified_blocks, marking blocks and get_downloader print_title("test unverified blocks"); p = setup_picker("1111111", " ", "", "0300700"); TEST_CHECK(p->unverified_blocks() == 2 + 3); - TEST_CHECK(p->get_downloader(piece_block(4, 0)) == (void*)tmp_peer); - TEST_CHECK(p->get_downloader(piece_block(4, 1)) == (void*)tmp_peer); - TEST_CHECK(p->get_downloader(piece_block(4, 2)) == (void*)tmp_peer); + TEST_CHECK(p->get_downloader(piece_block(4, 0)) == tmp_peer); + TEST_CHECK(p->get_downloader(piece_block(4, 1)) == tmp_peer); + TEST_CHECK(p->get_downloader(piece_block(4, 2)) == tmp_peer); TEST_CHECK(p->get_downloader(piece_block(4, 3)) == 0); p->mark_as_downloading(piece_block(4, 3), &peer_struct); TEST_CHECK(p->get_downloader(piece_block(4, 3)) == &peer_struct); @@ -1300,7 +1300,7 @@ TORRENT_TEST(piece_picker) TEST_CHECK(p->unverified_blocks() == 2); // ======================================================== - + // test prefer_contiguous_blocks print_title("test prefer contiguous blocks"); p = setup_picker("1111111", " ", "", "");