From 76fb776aea7179c0cba46e05737cff28c6ba8e6b Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Wed, 1 Feb 2006 21:32:09 +0000 Subject: Peers we download from are given a weight of two compared to peers we seed to when we decide which peers to upload to. Also fix so that we don't prefer to upload to peers who has had a good rate but isn't uploading to us now. --- btpd/upload.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/btpd/upload.c b/btpd/upload.c index f8403ad..db7d5a3 100644 --- a/btpd/upload.c +++ b/btpd/upload.c @@ -19,8 +19,8 @@ rate_cmp(const void *arg1, const void *arg2) { struct peer *p1 = ((struct peer_sort *)arg1)->p; struct peer *p2 = ((struct peer_sort *)arg2)->p; - unsigned long rate1 = cm_full(p1->n->tp) ? p1->rate_up : p1->rate_dwn; - unsigned long rate2 = cm_full(p2->n->tp) ? p2->rate_up : p2->rate_dwn; + unsigned long rate1 = cm_full(p1->n->tp) ? p1->rate_up / 2: p1->rate_dwn; + unsigned long rate2 = cm_full(p2->n->tp) ? p2->rate_up / 2: p2->rate_dwn; if (rate1 < rate2) return -1; else if (rate1 == rate2) @@ -51,9 +51,15 @@ choke_do(void) int unchoked[m_npeers]; BTPDQ_FOREACH(p, &m_peerq, ul_entry) { - if (!peer_full(p) && - ((cm_full(p->n->tp) && p->rate_up > 0) - || (!cm_full(p->n->tp) && p->rate_dwn > 0))) { + int ok = 0; + if (!peer_full(p)) { + if (cm_full(p->n->tp)) { + if (p->rate_up > 0) + ok = 1; + } else if (peer_active_down(p) && p->rate_dwn > 0) + ok = 1; + } + if (ok) { worthy[nworthy].p = p; worthy[nworthy].i = i; nworthy++; -- cgit 1.4.1