Revision 63a52683

View differences:

topology.c
107 107
		bind_msg_type(mTypes[i]);
108 108
	update_metadata();
109 109
	me = myID;
110
	struct timeval tnow;
111
	gettimeofday(&tnow, NULL);
110 112
	gettimeofday(&last_time_updated_peers, NULL);
113
	last_time_updated_peers.tv_sec -= UPDATE_PEERS_TIMEOUT;
111 114
	return (topInit(myID, &my_metadata, sizeof(my_metadata), config) && tmanInit(myID,&my_metadata, sizeof(my_metadata),rankFunct,0));
112 115
}
113 116

  
......
131 134
	const struct nodeID **n; const void *m;
132 135
	if (!buff || buff[0] == MSG_TYPE_TOPOLOGY) {
133 136
		res = topParseData(buff,len);
134
//		if (counter <= TMAN_MAX_IDLE)
135
//			counter++;
137
// 		if (counter <= TMAN_MAX_IDLE)
138
// 			counter++;
136 139
	}
137 140
	if (counter >= TMAN_MAX_IDLE && (!buff || buff[0] == MSG_TYPE_TMAN))
138 141
	{
......
240 243
  return NAN;
241 244
}
242 245

  
246
// //get the declared capacity of a node
247
// static double get_capacity_of_newid(const struct nodeID* n){
248
//   int i = 0;
249
//   for (i = 0; i < newids_size; i++){
250
// 	  if (strcmp(node_addr(n), node_addr(newids[i]))) {
251
// 		  return metas[i].capacity;
252
// 	  }
253
//   }
254
//   return NAN;
255
// }
256

  
243 257

  
244 258
// FF//get the declared capacity of a node
245 259
// static double get_offers_threads_of(const struct nodeID* n){
......
302 316
int blacklistness_lossrate(const struct nodeID* n) {
303 317
  double loss_rate = get_transmitter_lossrate(n);
304 318
  
305
  fprintf(stderr, "BLACKLIST: father loss %s rate is %f\n", node_addr(n), loss_rate);
319
  dprintf("BLACKLIST: father loss %s rate is %f\n", node_addr(n), loss_rate);
306 320
  
307 321
  if (isnan(loss_rate)) {
308 322
    return -1;
......
380 394

  
381 395
int cmp_rx_bytes_chunks(const struct nodeID** a, const struct nodeID** b) {
382 396
  double ra, rb;
383
  ra = get_rx_bytes_chunks_of(*a);
384
  rb = get_rx_bytes_chunks_of(*b);
397
  ra = -(get_rx_bytes_chunks_of(*a));
398
  rb = -(get_rx_bytes_chunks_of(*b));
385 399
//   fprintf(stderr, "RX_BYTES_CHUNKS: %s %f %s %f\n", node_addr(*a), ra, node_addr(*b), rb );
386 400
  if ((isnan(ra) && isnan(rb)) || ra == rb) 
387 401
	return 0;
......
430 444

  
431 445
// Use keep best policy specified at command line
432 446
int vcmp_keep_best(const void* a, const void* b) {
433
  if (strcmp(topo_keep_best_policy, "RX_CHUNKS") == 0) {
447
  if (strcmp(topo_keep_best_policy, "BW") == 0) {
448
	  return vcmp_bw(a, b);
449
  }  else if (strcmp(topo_keep_best_policy, "RX_CHUNKS") == 0) {
434 450
	  return vcmp_rx_bytes_chunks(a, b);
435 451
  } else if (strcmp(topo_keep_best_policy, "PACKET_LOSS") == 0) {
436 452
	  return vcmp_packet_loss( a, b);
......
445 461
// currently it just makes the peerset grow
446 462
void update_peers(struct nodeID *from, const uint8_t *buff, int len)
447 463
{
448
  int n_ids, metasize, i, newids_size, max_ids;
449
  static const struct nodeID **newids;
450
  static const struct metadata *metas;
464
  int n_ids, metasize, i, max_ids;
465
  struct nodeID **newids;
466
  int newids_size;
467
  struct metadata *metas;
468
  
451 469
  struct peer *peers;
452 470
  struct timeval tnow, told;
453 471
  static const struct nodeID **savedids;
454 472
  static int savedids_size;
455

  
473
  
456 474
  if timerisset(&tout_bmap) {
457 475
    gettimeofday(&tnow, NULL);
458 476
    timersub(&tnow, &tout_bmap, &told);
......
510 528

  
511 529
  int res_topo_parse_data = topoParseData(buff, len);
512 530

  
513
  // Exit if a gossiping message has been received TODO: increase newscast cache to 100
531
  // Exit if a gossiping message has been received
514 532
  if (res_topo_parse_data > 0) {
515 533
    reg_neigh_size(peerset_size(pset));
516 534
    return;
......
519 537
  // Look for peers which can be removed from blacklist
520 538
  check_black_list_timeouts();
521 539

  
522
  double time_difference = (tnow.tv_sec + tnow.tv_usec*1e-6) - (last_time_updated_peers.tv_sec + last_time_updated_peers.tv_usec*1e-6) + rand() - 2 * rand();
540
  double time_difference = (tnow.tv_sec + tnow.tv_usec*1e-6) - (last_time_updated_peers.tv_sec + last_time_updated_peers.tv_usec*1e-6);
523 541

  
524 542
  // Check if it's time to update the neighbourhood
525 543
  if (time_difference > UPDATE_PEERS_TIMEOUT) {
544
	  
526 545
    peers = peerset_get_peers(pset);
527 546
    n_ids = peerset_size(pset);
528 547
    
529 548
    newids = topoGetNeighbourhood(&newids_size);    //TODO handle both tman and topo
530
    metas = topGetMetadata(&metasize);    //TODO: check metasize
549
    metas = topGetMetadata(&metasize);
550
    int index = 0;
551
    for (index = 0; index < newids_size; index++) {
552
	    dprintf("METAS node %s, capacity %f\n", node_addr(newids[index]), metas[index].capacity);
553
    }
554
    dprintf("METAS my %f END\n", my_metadata.capacity);
531 555
    max_ids = n_ids + savedids_size + newids_size;
532 556
    ftprintf(stderr,"Topo modify start peers:%d candidates:%d\n", n_ids, newids_size);
533 557

  
......
551 575
    }
552 576

  
553 577
    // select the topo_mem portion of peers to be kept (uniform random)
554
    if (topo_keep_best) {
578
    if ((topo_keep_best) && (strcmp(topo_keep_best_policy, "RND") != 0)) {
555 579
      qsort(oldids, oldids_size, sizeof(oldids[0]), vcmp_keep_best);
556 580
    } else {
557 581
      nidset_shuffle(oldids, oldids_size);
558 582
    }
559 583
    for (i = 0; i < oldids_size; i++) {
560
        fprintf(stderr,"QSORT KEEP BEST %s - RTT: %f, RX_CHUNKS %f, PACKET_LOSS %f\n", node_addr(oldids[i]) , get_rtt_of(oldids[i]), get_rx_bytes_chunks(oldids[i]), get_transmitter_lossrate(oldids[i]));
584
        dprintf("QSORT KEEP BEST %s - RTT: %f, RX_CHUNKS %f, PACKET_LOSS %f, BW %f\n", node_addr(oldids[i]) , get_rtt_of(oldids[i]), get_rx_bytes_chunks(oldids[i]), get_transmitter_lossrate(oldids[i]), metas[i].capacity);
561 585
      }
562
    fprintf(stderr, "QSORT KEEP BEST END\n");
586
    dprintf("QSORT KEEP BEST END\n");
563 587
    
564 588
    keep_size = selecteds_size = (int) (topo_mem * oldids_size);
565 589
    memcpy(selecteds, oldids, selecteds_size * sizeof(selecteds[0]));
......
576 600
    // Filter out blacklisted ones    
577 601
    nidset_filter(desireds, &desireds_size, candidates, candidates_size, is_desired_unbled);
578 602
    
579
    if (topo_add_best) {
603
    if ((topo_keep_best) && (strcmp(topo_add_best_policy, "RND") != 0)) {
580 604
      qsort(desireds, desireds_size, sizeof(desireds[0]), vcmp_add_best);
581 605
    } else {
582 606
      nidset_shuffle(desireds, desireds_size);
583 607
    }
584 608
    for (i = 0; i < desireds_size; i++) {
585
        fprintf(stderr,"QSORT ADD BEST %s - RTT: %f, BW %f, BW*RTT %f\n", node_addr(desireds[i]) , get_rtt_of(desireds[i]), get_capacity_of(desireds[i]), (double) (get_capacity_of(desireds[i])*get_rtt_of(desireds[i])) );
609
        dprintf("QSORT ADD BEST %s - RTT: %f, BW %f, BW*RTT %f\n", node_addr(desireds[i]) , get_rtt_of(desireds[i]), metas[i].capacity, (double) (get_capacity_of(desireds[i])*get_rtt_of(desireds[i])) );
586 610
      }
587
    fprintf(stderr, "QSORT ADD BEST END\n");
611
    dprintf("QSORT ADD BEST END\n");
588 612
    nidset_add_i(selecteds, &selecteds_size, max_ids, desireds, MIN(desireds_size,desired_part));
589 613

  
590 614
    // random from the rest

Also available in: Unified diff