Revision 394bac21

View differences:

streaming.c
23 23
static struct input_desc *input;
24 24
static int cb_size;
25 25
static int transid=0;
26
struct chunkID_set *lock_set;
26 27

  
27 28
int _needs(struct chunkID_set *cset, int cb_size, int cid);
28 29

  
30
void chunk_lock(int chunkid,struct peer *from){
31
  if (!lock_set) lock_set = chunkID_set_init(16);
32

  
33
  chunkID_set_add_chunk(lock_set, chunkid);
34
}
35

  
36
void chunk_unlock(int chunkid){
37
  if (!lock_set) return;
38
  chunkID_set_remove_chunk(lock_set, chunkid);
39
}
40

  
41
int chunk_islocked(int chunkid){
42
  int r;
43

  
44
  if (!lock_set) return 0;
45
  r = chunkID_set_check(lock_set, chunkid);
46
  return (r >= 0);
47
}
48

  
29 49
void stream_init(int size, struct nodeID *myID)
30 50
{
31 51
  char conf[32];
......
72 92
  for (i = 0, d = 0; i < cset_off_size && d < max_deliver; i++) {
73 93
    int chunkid = chunkID_set_get_chunk(cset_off, i);
74 94
    dprintf("\tdo I need c%d ? :",chunkid);
75
    if (_needs(my_bmap, cb_size, chunkid)) {
95
    if (!chunk_islocked(chunkid) && _needs(my_bmap, cb_size, chunkid)) {
76 96
      chunkID_set_add_chunk(cset_acc, chunkid);
97
      chunk_lock(chunkid,from);
77 98
      d++;
78 99
    }
79 100
  }
......
97 118
  struct peer *p;
98 119

  
99 120
  res = decodeChunk(&c, buff + 1, len - 1);
121
  chunk_unlock(c.id);
100 122
  if (res > 0) {
101 123
    dprintf("Received chunk %d from peer: %s\n", c.id, node_addr(from));
102 124
    output_deliver(&c);

Also available in: Unified diff