From 0ce6fa1d0c339c8cda5ed5288be6f8bd118e82fd Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Thu, 21 Jul 2005 16:50:27 +0000 Subject: * Use torrent_get_piece instead of loop. Check for correctness. * Don't decrease busy count on a piece when a block arrives in end game. The busy count should always be zero at that stage. --- btpd/policy_if.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/btpd/policy_if.c b/btpd/policy_if.c index 33611fd..4cd4337 100644 --- a/btpd/policy_if.c +++ b/btpd/policy_if.c @@ -241,14 +241,12 @@ cm_on_block(struct peer *p, uint32_t index, uint32_t begin, uint32_t length, off_t cbegin = index * p->tp->meta.piece_length + begin; torrent_put_bytes(p->tp, data, cbegin, length); - struct piece *pc = BTPDQ_FIRST(&tp->getlst); - while (pc != NULL && pc->index != index) - pc = BTPDQ_NEXT(pc, entry); + struct piece *pc = torrent_get_piece(tp, index); + assert(pc != NULL); + uint32_t block = begin / PIECE_BLOCKLEN; set_bit(pc->have_field, block); - clear_bit(pc->down_field, block); pc->ngot++; - pc->nbusy--; if (tp->endgame) { BTPDQ_FOREACH(p, &tp->peers, cm_entry) { @@ -258,6 +256,9 @@ cm_on_block(struct peer *p, uint32_t index, uint32_t begin, uint32_t length, if (pc->ngot == pc->nblocks) cm_on_piece(pc); } else { + // XXX: Needs to be looked at if we introduce snubbing. + clear_bit(pc->down_field, block); + pc->nbusy--; if (pc->ngot == pc->nblocks) cm_on_piece(pc); if (peer_leech_ok(p)) -- cgit 1.4.1