Revision 4367dafd streaming.c

View differences:

streaming.c
13 13
#include "input.h"
14 14
#include "dbg.h"
15 15

  
16
#include "scheduler_la.h"
17

  
16 18
static struct chunk_buffer *cb;
17 19
static struct input_desc *input;
18 20

  
......
68 70
  }
69 71
}
70 72

  
73
/**
74
 *example function to filter chunks based on whether a given peer needs them. The real implementation
75
 * should look at buffermap information received about the given peer (or it should guess)
76
 */
77
int needs(const struct peer *p, const struct chunk *c){
78
  return 1;	//TODO: avoid at least sending to the source :)
79
}
80
double randomPeer(const struct peer **p){
81
  return 1;
82
}
83
double getChunkTimestamp(const struct chunk **c){
84
  return (double) (*c)->timestamp;
85
}
86

  
87

  
71 88
void send_chunk(const struct nodeID **neighbours, int n)
72 89
{
73 90
  struct chunk *buff;
74
  int target, c, size, res;
91
  int target, c, size, res, i;
75 92

  
76 93
  dprintf("Send Chunk: %d neighbours\n", n);
77 94
  if (n == 0) return;
......
80 97
  if (size == 0) return;
81 98

  
82 99
  /************ STUPID DUMB SCHEDULING ****************/
83
  target = n * (rand() / (RAND_MAX + 1.0)); /*0..n-1*/
84
  c = size * (rand() / (RAND_MAX + 1.0)); /*0..size-1*/
100
  //target = n * (rand() / (RAND_MAX + 1.0)); /*0..n-1*/
101
  //c = size * (rand() / (RAND_MAX + 1.0)); /*0..size-1*/
85 102
  /************ /STUPID DUMB SCHEDULING ****************/
86
  dprintf("\t sending chunk[%d] (%d) to ", buff[c].id, c);
87
  dprintf("%s\n", node_addr(neighbours[target]));
88 103

  
89
  res = sendChunk(neighbours[target], buff + c);
90
  dprintf("Result: %d\n", res);
104
  /************ USE SCHEDULER ****************/
105
  size_t selectedpairs_len = 1;
106
  struct chunk *pbuff[size];
107
  for (i=0;i<size;i++) pbuff[i]=buff+i;
108
  struct PeerChunk selectedpairs[1];
109
  schedSelectPeerFirst(SCHED_BEST, neighbours, n, pbuff, size, selectedpairs, &selectedpairs_len, needs, randomPeer, getChunkTimestamp);
110
  /************ /USE SCHEDULER ****************/
111

  
112
  for (i=0; i<selectedpairs_len ; i++){
113
    dprintf("\t sending chunk[%d] to ", selectedpairs[i].chunk->id);
114
    dprintf("%s\n", node_addr(selectedpairs[i].peer));
115

  
116
    res = sendChunk(selectedpairs[i].peer, selectedpairs[i].chunk);
117
    dprintf("Result: %d\n", res);
118
  }
91 119
}

Also available in: Unified diff