about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-02-01 21:32:09 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-02-01 21:32:09 +0000
commit76fb776aea7179c0cba46e05737cff28c6ba8e6b (patch)
tree42254a163d78fdf60585696f1bb7bb9c3593796d
parent0c71b0ceb1f11ecc9dbca6751e861ac3b9e6c1b9 (diff)
downloadbtpd-76fb776aea7179c0cba46e05737cff28c6ba8e6b.tar.gz
btpd-76fb776aea7179c0cba46e05737cff28c6ba8e6b.zip
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.

-rw-r--r--btpd/upload.c16
1 files 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++;