Revision 74a5d4ae streaming.c

View differences:

streaming.c
32 32
#include "measures.h"
33 33

  
34 34
#include "scheduler_la.h"
35
#include "chunkbuffer.h"
36
#include "chunkbuffer_helper.h"
37 35

  
38 36
struct chunk_attributes {
39 37
  uint64_t deadline;
......
109 107
  assert(!c->attributes && c->attributes_size == 0);
110 108

  
111 109
  c->attributes_size = sizeof(struct chunk_attributes);
112
  c->attributes = ca = (struct chunk_attributes *)malloc(c->attributes_size);
110
  c->attributes = ca = malloc(c->attributes_size);
113 111

  
114 112
  ca->deadline = c->timestamp;
115 113
  ca->deadline_increment = 2;
......
128 126
  return ca->hopcount;
129 127
}
130 128

  
131
void chunk_attributes_update_received(const struct chunk* c)
129
void chunk_attributes_update_received(struct chunk* c)
132 130
{
133 131
  struct chunk_attributes * ca;
134 132

  
......
142 140
  dprintf("Received chunk %d with hopcount %hu\n", c->id, ca->hopcount);
143 141
}
144 142

  
145
void chunk_attributes_update_sending(const struct chunk* c)
143
void chunk_attributes_update_sending(struct chunk* c)
146 144
{
147 145
  struct chunk_attributes * ca;
148 146

  
......
159 157
struct chunkID_set *cb_to_bmap(struct chunk_buffer *chbuf)
160 158
{
161 159
  struct chunk *chunks;
162
  size_t num_chunks;
163
  int i;
160
  int num_chunks, i;
164 161
  struct chunkID_set *my_bmap = chunkID_set_init("type=1");
165 162
  chunks = cb_get_chunks(chbuf, &num_chunks);
166 163

  
......
221 218
  n = peerset_size(pset);
222 219
  neighbours = peerset_get_peers(pset);
223 220
  {
224
    const struct nodeID *nodeids[n];
221
    struct nodeID *nodeids[n];
225 222
    for (i = 0; i<n; i++) nodeids[i] = neighbours[i].id;
226 223
#ifdef MONL
227 224
    return get_average_lossrate(nodeids, n);
......
242 239
  send_bmap(p);	//send explicit ack
243 240
}
244 241

  
245
void received_chunk(const struct nodeID *from, const uint8_t *buff, int len)
242
void received_chunk(struct nodeID *from, const uint8_t *buff, int len)
246 243
{
247 244
  int res;
248 245
  static struct chunk c;
......
301 298
 *
302 299
 * Looks at buffermap information received about the given peer.
303 300
 */
304
int needs(const struct nodeID *n, int cid){
301
int needs(struct nodeID *n, int cid){
305 302
  struct peer * p = nodeid_to_peer(n, 0);
306 303
  if (!p) return 1; // if we don't know this peer, but we assume it needs the chunk (aggressive behaviour!)
307 304

  
......
333 330
  return 0;
334 331
}
335 332

  
336
double peerWeightReceivedfrom(const struct nodeID * const *n){
333
double peerWeightReceivedfrom(struct nodeID **n){
337 334
  struct peer * p = nodeid_to_peer(*n, 0);
338 335
  if (!p) return 0;
339 336
  return timerisset(&p->bmap_timestamp) ? 1 : 0.1;
340 337
}
341 338

  
342
double peerWeightUniform(const struct nodeID * const *n){
339
double peerWeightUniform(struct nodeID **n){
343 340
  return 1;
344 341
}
345 342

  
346
double peerWeightRtt(const struct nodeID * const *n){
343
double peerWeightRtt(struct nodeID **n){
347 344
#ifdef MONL
348 345
  double rtt = get_rtt(*n);
349 346
  //dprintf("RTT to %s: %f\n", node_addr(p->id), rtt);
......
369 366
  return -latest;
370 367
}
371 368

  
372
double getChunkTimestamp(const int *cid){
373
  const struct chunk *c = cb_get_chunk(cb, *cid);
369
double getChunkTimestamp(int *cid){
370
  struct chunk *c = cb_get_chunk(cb, *cid);
374 371
  if (!c) return 0;
375 372

  
376 373
  return (double) c->timestamp;
......
382 379
  cset_acc_size = chunkID_set_size(cset_acc);
383 380
  reg_offer_accept(cset_acc_size > 0 ? 1 : 0);	//this only works if accepts are sent back even if 0 is accepted
384 381
  for (i = 0, d=0; i < cset_acc_size && d < max_deliver; i++) {
385
    const struct chunk *c;
382
    struct chunk *c;
386 383
    int chunkid = chunkID_set_get_chunk(cset_acc, i);
387 384
    c = cb_get_chunk(cb, chunkid);
388 385
    if (c && needs(to->id, chunkid) ) {	// 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
......
404 401
  return offer_per_tick;
405 402
}
406 403

  
407
int offer_max_deliver(const struct nodeID *n)
404
int offer_max_deliver(struct nodeID *n)
408 405
{
409 406
#ifdef MONL
410 407
  switch (get_hopcount(n)) {
......
420 417
void send_offer()
421 418
{
422 419
  struct chunk *buff;
423
  size_t size, i, n;
424
  int res;
420
  int size, res, i, n;
425 421
  struct peer *neighbours;
426 422
  struct peerset *pset;
427 423

  
......
436 432
  {
437 433
    size_t selectedpeers_len = offer_peer_count();
438 434
    int chunkids[size];
439
    const struct nodeID *nodeids[n];
440
    const struct nodeID *selectedpeers[selectedpeers_len];
435
    struct nodeID *nodeids[n];
436
    struct nodeID *selectedpeers[selectedpeers_len];
441 437

  
442 438
    //reduce load a little bit if there are losses on the path from this guy
443 439
    double average_lossrate = get_average_lossrate_pset(pset);
......
448 444

  
449 445
    for (i = 0;i < size; i++) chunkids[i] = (buff+i)->id;
450 446
    for (i = 0; i<n; i++) nodeids[i] = (neighbours+i)->id;
451
    schedSelectPeersForChunks(SCHED_WEIGHTED, nodeids, n, chunkids, size, selectedpeers, &selectedpeers_len, needs, (transid % 2) ? peerWeightReceivedfrom : peerWeightRtt);	//select a peer that needs at least one of our chunks
447
    selectPeersForChunks(SCHED_WEIGHTED, nodeids, n, chunkids, size, selectedpeers, &selectedpeers_len, needs, (transid % 2) ? peerWeightReceivedfrom : peerWeightRtt);	//select a peer that needs at least one of our chunks
452 448

  
453 449
    for (i=0; i<selectedpeers_len ; i++){
454 450
      int max_deliver = offer_max_deliver(selectedpeers[i]);
......
464 460
void send_chunk()
465 461
{
466 462
  struct chunk *buff;
467
  size_t size, i, n;
468
  int res;
463
  int size, res, i, n;
469 464
  struct peer *neighbours;
470 465
  struct peerset *pset;
471 466

  
......
487 482
  {
488 483
    size_t selectedpairs_len = 1;
489 484
    int chunkids[size];
490
    const struct nodeID *nodeids[n];
485
    struct nodeID *nodeids[n];
491 486
    struct PeerChunk selectedpairs[1];
492 487
  
493 488
    for (i = 0;i < size; i++) chunkids[i] = (buff+i)->id;
......
497 492

  
498 493
    for (i=0; i<selectedpairs_len ; i++){
499 494
      struct peer *p = nodeid_to_peer(selectedpairs[i].peer, 0);
500
      const struct chunk *c = cb_get_chunk(cb, selectedpairs[i].chunk);
495
      struct chunk *c = cb_get_chunk(cb, selectedpairs[i].chunk);
501 496
      dprintf("\t sending chunk[%d] to ", c->id);
502 497
      dprintf("%s\n", node_addr(p->id));
503 498

  

Also available in: Unified diff