about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2005-07-21 16:50:27 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2005-07-21 16:50:27 +0000
commit0ce6fa1d0c339c8cda5ed5288be6f8bd118e82fd (patch)
tree4c326c9c29750ede16e107fe2845c8e772f6b0d5
parent7ced6added6b66ff2d2c4370c315f463999b2752 (diff)
downloadbtpd-0ce6fa1d0c339c8cda5ed5288be6f8bd118e82fd.tar.gz
btpd-0ce6fa1d0c339c8cda5ed5288be6f8bd118e82fd.zip
* 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.

-rw-r--r--btpd/policy_if.c11
1 files 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))