Revision cc0cd459 topology.c

View differences:

topology.c
35 35
static int counter = 0;
36 36
static int simpleRanker (const void *tin, const void *p1in, const void *p2in);
37 37
static tmanRankingFunction rankFunct = simpleRanker;
38
static double my_metadata;
38
struct metadata {
39
  double value;
40
};
41
static struct metadata my_metadata;
39 42
static int cnt = 0;
40 43
static struct nodeID *me = NULL;
41 44
static unsigned char mTypes[] = {MSG_TYPE_TOPOLOGY,MSG_TYPE_TMAN};
......
44 47
static void update_metadata(void) {
45 48

  
46 49
#ifndef MONL
47
	my_metadata = 1 + (((double)rand() / (double)RAND_MAX)*1000);
50
	my_metadata.value = 1 + (((double)rand() / (double)RAND_MAX)*1000);
48 51
#endif
49 52
#ifdef MONL
50
	my_metadata = get_receive_delay();
53
	my_metadata.value = get_receive_delay();
51 54
#endif
52 55
}
53 56

  
......
82 85
int topoAddNeighbour(struct nodeID *neighbour, void *metadata, int metadata_size)
83 86
{
84 87
	// TODO: check this!! Just to use this function to bootstrap ncast...
88
	struct metadata m = {0};	//TODO: check what metadata option should mean
89

  
85 90
	if (counter < TMAN_MAX_IDLE)
86
		return topAddNeighbour(neighbour,metadata,metadata_size);
87
	else return tmanAddNeighbour(neighbour,metadata,metadata_size);
91
		return topAddNeighbour(neighbour,&m,sizeof(m));
92
	else return tmanAddNeighbour(neighbour,&m,sizeof(m));
88 93
}
89 94

  
90 95
static int topoParseData(const uint8_t *buff, int len)
......
120 125
		tmanGivePeers(*n,neighbors,(void *)mdata);
121 126

  
122 127
		if (cnt % TMAN_LOG_EVERY == 0) {
123
			fprintf(stderr,"abouttopublish,%s,%s,,Tman_chunk_delay,%f\n",node_addr(me),node_addr(me),my_metadata);
128
			fprintf(stderr,"abouttopublish,%s,%s,,Tman_chunk_delay,%f\n",node_addr(me),node_addr(me),my_metadata.value);
124 129
			for (i=0;i<(*n) && i<NEIGHBORHOOD_TARGET_SIZE;i++) {
125 130
				d = *((double *)(mdata+i*msize));
126 131
				fprintf(stderr,"abouttopublish,%s,",node_addr(me));
......
144 149
		topAddToBlackList(id);
145 150
}
146 151

  
147
void add_peer(struct nodeID *id)
152
void add_peer(const struct nodeID *id, const struct metadata *m)
148 153
{
149 154
      dprintf("Adding %s to neighbourhood!\n", node_addr(id));
150 155
      peerset_add_peer(pset, id);
......
164 169
// currently it just makes the peerset grow
165 170
void update_peers(struct nodeID *from, const uint8_t *buff, int len)
166 171
{
167
  int n_ids, i;
172
  int n_ids, metasize, i;
168 173
  static const struct nodeID **ids;
174
  static const struct metadata *metas;
169 175
  struct peer *peers;
170 176
  struct timeval tnow, told;
171 177

  
......
194 200
    return;
195 201
  }
196 202

  
197
  ids = topoGetNeighbourhood(&n_ids);
203
  ids = topoGetNeighbourhood(&n_ids);	//TODO handle both tman and topo
204
  metas = topGetMetadata(&metasize);	//TODO: check metasize
198 205
  for(i = 0; i < n_ids; i++) {
199 206
    if(peerset_check(pset, ids[i]) < 0) {
200 207
      if (!NEIGHBORHOOD_TARGET_SIZE || peerset_size(pset) < NEIGHBORHOOD_TARGET_SIZE) {
201
        add_peer(ids[i]);
208
        add_peer(ids[i],&metas[i]);
202 209
      } else {  //rotate neighbourhood
203 210
        if (rand()/((double)RAND_MAX + 1) < NEIGHBORHOOD_ROTATE_RATIO) {
204
          add_peer(ids[i]);
211
          add_peer(ids[i],&metas[i]);
205 212
        }
206 213
      }
207 214
    }
......
237 244
    //fprintf(stderr,"warning: received message from unknown peer: %s!%s\n",node_addr(id), reg ? " Adding it to pset." : "");
238 245
    if (reg) {
239 246
      topoAddNeighbour(id, NULL, 0);
240
      add_peer(id);
247
      add_peer(id,NULL);
241 248
      p = peerset_get_peer(pset,id);
242 249
    }
243 250
  }

Also available in: Unified diff