Commits

Peter Hosey committed 0d85bbb

Make chunk-transfer speed not random, but dependent on each peer's available bandwidth.

All peers are imagined to have the same amount of bandwidth, and to use it equally on each other peer that they're sending to.

Downloading does not currently count against bandwidth.

Comments (0)

Files changed (1)

 {
   float starttime;
   float endtime;
-  float big;
 
   Kibble()
   {
     starttime = 0;
     endtime = 0;
-    big = (random(0,4));
   }
 }
 
   float chue;
   float ehue;
   float shue;
+  int bandwidth; //Time to send exactly one Bit to one peer
   color ccolor;
   int removing;
   int lastcheck;
     needBits = new ArrayList();
     knex = new ArrayList();
     actBits = new ArrayList();
+    bandwidth = 50;
 
     pushMatrix();
     translate(width / 2, height / 2);
       line(cxpos - w/2 + (1 * k.id), cypos - 5, cxpos - w / 2 + (1 * k.id), cypos + 5);
     }
   }
+
+  int speedPerConnection()
+  {
+    return bandwidth * knex.size();
+  }
 }
 
 class Connection
   boolean stream;
   ArrayList kibbles;
   int deadkibbles;
-  int speed;
   Bit theBit;
 
   Connection(Peer f, Peer t, Bit b)
     stream = true;
     lastdraw = millis();
     deadkibbles = 0;
-    speed = int(random(30,500));
   }
 
   int getIdxTo()
     }
     else
     {
+      var fSpeed = f.speedPerConnection();
+      var tSpeed = t.speedPerConnection();
+      var speed;
+      //Whichever one takes longer (has the least bandwidth available) governs the actual speed.
+      if (tSpeed > fSpeed) {
+        speed = tSpeed;
+      } else {
+        speed = fSpeed;
+      }
       if (lastdraw < millis() - speed)
       {   
         newKibble();
         colorMode(HSB);
         fill(theBit.bitHue, 255, 255);
         stroke(theBit.bitHue, 255, 255);
-        strokeWeight(1); // k.big);
-        ellipse(xpos, ypos, k.big, k.big);
+        strokeWeight(1);
+        ellipse(xpos, ypos, 1, 1);
       }
     }
   }