Revision e735a1b1 streaming.c

View differences:

streaming.c
103 103
struct chunkID_set *get_chunks_to_accept(struct peer *from, const struct chunkID_set *cset_off, int max_deliver){
104 104
  struct chunkID_set *cset_acc, *my_bmap;
105 105
  int i, d, cset_off_size;
106
  double lossrate;
106 107

  
107
  my_bmap = cb_to_bmap(cb);
108
  cset_off_size = chunkID_set_size(cset_off);
109 108
  cset_acc = chunkID_set_init(0);
110
  for (i = 0, d = 0; i < cset_off_size && d < max_deliver; i++) {
111
    int chunkid = chunkID_set_get_chunk(cset_off, i);
112
    dprintf("\tdo I need c%d ? :",chunkid);
113
    if (!chunk_islocked(chunkid) && _needs(my_bmap, cb_size, chunkid)) {
114
      chunkID_set_add_chunk(cset_acc, chunkid);
115
      chunk_lock(chunkid,from);
116
      d++;
109

  
110
  //reduce load a little bit if there are losses on the path from this guy
111
  lossrate = get_lossrate(from->id);
112
  lossrate = finite(lossrate) ? lossrate : 0;	//start agressively, assuming 0 loss
113
  if (rand()/((double)RAND_MAX + 1) >= lossrate ) {
114
    my_bmap = cb_to_bmap(cb);
115
    cset_off_size = chunkID_set_size(cset_off);
116
    for (i = 0, d = 0; i < cset_off_size && d < max_deliver; i++) {
117
      int chunkid = chunkID_set_get_chunk(cset_off, i);
118
      dprintf("\tdo I need c%d ? :",chunkid);
119
      if (!chunk_islocked(chunkid) && _needs(my_bmap, cb_size, chunkid)) {
120
        chunkID_set_add_chunk(cset_acc, chunkid);
121
        chunk_lock(chunkid,from);
122
        d++;
123
      }
117 124
    }
125
    chunkID_set_free(my_bmap);
118 126
  }
119 127

  
120
  chunkID_set_free(my_bmap);
121 128
  return cset_acc;
122 129
}
123 130

  
......
224 231

  
225 232
double peerWeightRtt(struct peer **p){
226 233
  double rtt = get_rtt((*p)->id);
227
  //dprintf("RTT to %s: %f\n", node_addr((*p)->id), rtt);
234
  dprintf("RTT to %s: %f\n", node_addr((*p)->id), rtt);
228 235
  return finite(rtt) ? 1 / rtt : 0.5;
229 236
}
230 237

  

Also available in: Unified diff