Revision d447f71d streaming.c

View differences:

streaming.c
47 47
  return 0;
48 48
}
49 49

  
50
// a simple implementation that request everything that we miss ... up to max deliver
51
struct chunkID_set *get_chunks_to_accept(struct peer *from, const struct chunkID_set *cset_off, int max_deliver){
52
  struct chunkID_set *cset_acc = chunkID_set_init(0);
53
  int i, d, cset_off_size;
54

  
55
  cset_off_size = chunkID_set_size(cset_off);
56
  for (i = 0, d = 0; i < cset_off_size && d < max_deliver; i++) {
57
    int chunkid = chunkID_set_get_chunk(cset_off, i);
58
    if (! cb_get_chunk(cb, chunkid)) {
59
      chunkID_set_add_chunk(cset_acc, chunkid);
60
      d++;
61
    }
62
  }
63

  
64
  return cset_acc;
65
}
66

  
50 67
struct chunkID_set *cb_to_bmap(struct chunk_buffer *chbuf)
51 68
{
52 69
  struct chunk *chunks;
......
161 178
  return (double) (*c)->timestamp;
162 179
}
163 180

  
181
void send_accepted_chunks(struct peer *to, struct chunkID_set *cset_acc, int max_deliver){
182
  int i, d, cset_acc_size;
183

  
184
  cset_acc_size = chunkID_set_size(cset_acc);
185
  for (i = 0, d=0; i < cset_acc_size && d < max_deliver; i++) {
186
    struct chunk *c;
187
    int chunkid = chunkID_set_get_chunk(cset_acc, i);
188
    c = cb_get_chunk(cb, chunkid);
189
    if (c && needs(to, c) ) {	// we should have the chunk, and he should not have it. Although the "accept" should have been an answer to our "offer", we do some verification
190
      int res = sendChunk(to->id, c);
191
      if (res >= 0) {
192
        chunkID_set_add_chunk(to->bmap, c->id); //don't send twice ... assuming that it will actually arrive
193
        d++;
194
      }
195
    }
196
  }
197
}
198

  
164 199

  
165 200
void send_chunk(const struct peerset *pset)
166 201
{

Also available in: Unified diff