Revision d74bc79c streaming.c

View differences:

streaming.c
114 114
}
115 115

  
116 116
/**
117
 *example function to filter chunks based on whether a given peer needs them. The real implementation
118
 * should look at buffermap information received about the given peer (or it should guess)
117
 *example function to filter chunks based on whether a given peer needs them.
118
 *
119
 * Looks at buffermap information received about the given peer.
119 120
 */
120 121
int needs(struct peer *p, struct chunk *c){
121
  return (! p->bmap || chunkID_set_check(p->bmap,c->id) < 0);
122
  fprintf(stderr,"%s needs c%d ? :",node_addr(p->id),c->id);
123
  if (! p->bmap) {
124
    fprintf(stderr,"no bmap\n");
125
    return 1;	// if we have no bmap information, we assume it needs the chunk (aggressive behaviour!)
126
  }
127

  
128
  if (chunkID_set_check(p->bmap,c->id) < 0) { //it might need the chunk
129
    int missing, min;
130
    //@TODO: add some bmap_timestamp based logic
131

  
132
    if (chunkID_set_size(p->bmap) == 0) {
133
      fprintf(stderr,"bmap empty\n");
134
      return 1;	// if the bmap seems empty, it needs the chunk
135
    }
136
    missing = p->cb_size - chunkID_set_size(p->bmap);
137
    missing = missing < 0 ? 0 : missing;
138
    min = chunkID_set_get_chunk(p->bmap,0);
139
      fprintf(stderr,"%s ... c->id(%d) >= min(%d) - missing(%d) ?\n",(c->id >= min - missing)?"YES":"NO",c->id, min, missing);
140
    return (c->id >= min - missing);
141
  }
142

  
143
  fprintf(stderr,"has it\n");
144
  return 0;
122 145
}
146

  
123 147
double randomPeer(struct peer **p){
124 148
  return 1;
125 149
}

Also available in: Unified diff