Revision 08154cee

View differences:

topology.c
422 422
#endif
423 423
}
424 424

  
425
static double get_rx_chunks_of(const struct nodeID* n){
426
#ifdef MONL
427
  return get_rx_chunks(n);
428
#else
429
  return NAN;
430
#endif
431
}
432

  
425 433
static double get_transmitter_lossrate_of(const struct nodeID* n){
426 434
#ifdef MONL
427 435
  return get_transmitter_lossrate_of(n);
......
605 613
}
606 614

  
607 615
static double get_rx_chunks_rtt(const struct nodeID** a){
608
  double ra = add_noise( ( get_rx_bytes_chunks_of(*a) / get_rtt_of(*a) ), alpha_target);
616
  double ra = add_noise( ( get_rx_chunks_of(*a) / get_rtt_of(*a) ), alpha_target);
609 617
  dprintf( "rx_chunks_rtt: %s %f\n", node_addr(*a), ra);
610 618
  return ra;
611 619
}
......
659 667

  
660 668
int cmp_rx_bytes_chunks(const struct nodeID** a, const struct nodeID** b) {
661 669
  double ra, rb;
662
  ra = -(add_noise(get_rx_bytes_chunks_of(*a), alpha_target));
663
  rb = -(add_noise(get_rx_bytes_chunks_of(*b), alpha_target));
670
  ra = -(add_noise(get_rx_chunks_of(*a), alpha_target));
671
  rb = -(add_noise(get_rx_chunks_of(*b), alpha_target));
664 672
//   fprintf(stderr, "RX_BYTES_CHUNKS: %s %f %s %f\n", node_addr(*a), ra, node_addr(*b), rb );
665 673
  if ((isnan(ra) && isnan(rb)) || ra == rb) 
666 674
	return 0;
......
824 832
           ( timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].bmap_timestamp, &told, <)     )   ) {
825 833
        ftprintf(stderr,"Topo: dropping incoming inactive %s (peers:%d)\n", node_addr(peers[i].id), peerset_size(pset_incoming));
826 834
        //if (peerset_size(pset) > 1) {	// avoid dropping our last link to the world
827
        topoAddToBL(peers[i].id);
828
        remove_peer(peers[i--].id, topo_out, topo_in);
835
        if (peers[i].cb_size > 0) { 
836
	  topoAddToBL(peers[i].id);
837
          remove_peer(peers[i--].id, topo_out, topo_in);
838
	} else {  
839
		if (get_capacity() < 4000000.0) {
840
			topoAddToBL(peers[i].id);
841
			remove_peer(peers[i--].id, topo_out, topo_in);
842
		}
843
	}
829 844
        //}
830 845
      }
831 846
    }
......
847 862
        ftprintf(stderr,"Topo: adding on request %s (peers:%d)\n", node_addr(from), peerset_size(pset_outgoing));
848 863
	if (!peerset_get_peer(pset_outgoing, from)) {
849 864
		counter2++;
850
        	add_peer(from, &my_metadata, true, false);
865
        	add_peer(from, &received_metadata, true, false);
851 866
		}
852 867
// 	if (black_listed(node_addr(from)) && (peerset_get_peer(pset_outgoing, from)))
853 868
// 		remove_peer(from, topo_in, topo_out);
......
920 935

  
921 936
    for (i = 0, oldids_size = 0; i < n_ids; i++) {
922 937
      oldids[oldids_size++] = peers[i].id;
923
      fprintf(stderr," %s - RTT: %f, loss_rate %f\n", node_addr(peers[i].id) , get_rtt_of(peers[i].id), get_transmitter_lossrate(peers[i].id));
938
      fprintf(stderr," %s - RTT: %f, RX_BYTES_CHUNKS %f\n", node_addr(peers[i].id) , get_rtt_of(peers[i].id), get_rx_bytes_chunks_of(peers[i].id));
924 939
    }
925 940
    savedids_size = 0;
941

  
942
    const struct nodeID *tmps[max_ids];
943
    int tmps_size;
944

  
926 945
    
927 946
    if ((topo_keep_best) && ((strcmp(topo_keep_best_policy, "W_BW") == 0) || (strcmp(topo_keep_best_policy, "W_RTT") == 0) || (strcmp(topo_keep_best_policy, "W_RTT2") == 0) || (strcmp(topo_keep_best_policy, "W_RTT3") == 0) || (strcmp(topo_keep_best_policy, "W_RX_CHUNKS_RTT") == 0) || (strcmp(topo_keep_best_policy, "W_RTT_TRICK") == 0) || (strcmp(topo_keep_best_policy, "W_RTT_TRICK2") == 0) )) {
928
      const struct nodeID *tmps[max_ids];
929
      int tmps_size;
930 947
      peerEvaluateFunction peerevaluate = NULL;
931 948
      SchedOrdering ordering = SCHED_WEIGHTED;
932 949
      if (strcmp(topo_keep_best_policy, "W_BW") == 0) {
......
946 963
      }
947 964
      tmps_size = oldids_size;
948 965
      nidset_select(ordering, oldids, oldids_size, peerevaluate, tmps, &tmps_size);
949
      dprintf( "keep subnet end\n");
950 966
    // select the topo_mem portion of peers to be kept (uniform random)
951 967
    } else {  
952 968
	if ((topo_keep_best) && (strcmp(topo_keep_best_policy, "RND") != 0)) {
......
954 970
	} else {
955 971
		nidset_shuffle(oldids, oldids_size);
956 972
	}
973
	for (i=0; i< oldids_size; i++) {
974
		tmps[i] = oldids[i];
975
	}
957 976
    }
958 977
    for (i = 0; i < oldids_size; i++) {
959 978
	dprintf("QSORT KEEP BEST %s - RTT: %f, RX_CHUNKS %f, BW %f, SUBNET %d\n", node_addr(oldids[i]) , get_rtt_of(oldids[i]), get_rx_bytes_chunks(oldids[i]), get_capacity_of(oldids[i]) , get_subnet_of(oldids[i]));
......
961 980
    dprintf("QSORT KEEP BEST END\n");
962 981
    
963 982
    keep_size = selecteds_size = (int) (topo_mem * oldids_size);
964
    memcpy(selecteds, oldids, selecteds_size * sizeof(selecteds[0]));
983
    
984
    for (i=0; i< selecteds_size; i++) {
985
	    selecteds[i] = tmps[i];
986
    }
965 987

  
966 988
    // compose list of known nodeids
967 989
    nidset_add(nodeids, &nodeids_size, oldids, oldids_size, newids, newids_size);
......
976 998
    nidset_filter(desireds, &desireds_size, candidates, candidates_size, is_desired_unbled);
977 999
    
978 1000
    if ((topo_add_best) && ((strcmp(topo_add_best_policy, "W_BW") == 0) || (strcmp(topo_add_best_policy, "W_RTT") == 0) || (strcmp(topo_add_best_policy, "W_OFFERS") == 0) || (strcmp(topo_add_best_policy, "W_RTT_TRICK") == 0) || (strcmp(topo_add_best_policy, "W_RTT_TRICK2") == 0) )) {
979
      const struct nodeID *tmps[max_ids];
980
      int tmps_size;
1001
      const struct nodeID *tmps2[max_ids];
1002
      int tmps2_size;
981 1003
      peerEvaluateFunction peerevaluate = NULL;
982 1004
      SchedOrdering ordering = SCHED_WEIGHTED;
983 1005
      if (strcmp(topo_add_best_policy, "W_BW") == 0) {
......
991 1013
      } else if (strcmp(topo_add_best_policy, "W_RTT_TRICK2") == 0) {
992 1014
	peerevaluate = get_add_subnet_root2;
993 1015
      }
994
      tmps_size = MIN(desireds_size,desired_part);
995
      nidset_select(ordering, desireds, desireds_size, peerevaluate, tmps, &tmps_size);
996
      nidset_add_i(selecteds, &selecteds_size, max_ids, tmps, tmps_size);
997
      dprintf( "add subnet end\n");
1016
      tmps2_size = MIN(desireds_size,desired_part);
1017
      nidset_select(ordering, desireds, desireds_size, peerevaluate, tmps2, &tmps2_size);
1018
      nidset_add_i(selecteds, &selecteds_size, max_ids, tmps2, tmps2_size);
998 1019
    } else {
999 1020
      if ((topo_add_best) && (strcmp(topo_add_best_policy, "RND") != 0)) {
1000 1021
	fill_add_weights();
......
1054 1075
          fprintf(stderr," blacklisting and removing %s\n", node_addr(toremoves[i]));
1055 1076
          add_to_blacklist(node_addr(toremoves[i]));
1056 1077
          }
1078
       fprintf(stderr," removing %s, cb_size %d\n", node_addr(toremoves[i]), (nodeid_to_peer_incoming(toremoves[i], 0))->cb_size);
1057 1079
       // Check we are not removing the source if our bw is large enough
1058
       if (!removed_already && ((get_capacity() > (double) 4000000) && (nodeid_to_peer_incoming(toremoves[i], 0))->cb_size > 0)) {
1059
          fprintf(stderr," removing %s, cb_size %d\n", node_addr(toremoves[i]), (nodeid_to_peer_incoming(toremoves[i], 0))->cb_size);
1060
          remove_peer(toremoves[i], topo_out, topo_in);
1080
       if ((nodeid_to_peer_incoming(toremoves[i], 0))->cb_size == 0) {
1081
	       if ((get_capacity() < (double) 4000000)) {
1082
		       if (!removed_already) {
1083
			  remove_peer(toremoves[i], topo_out, topo_in);
1084
		       }
1085
	       }
1086
       } else {
1087
	  if (!removed_already) {
1088
		remove_peer(toremoves[i], topo_out, topo_in);
1061 1089
          }
1090
       }
1062 1091
    }
1063 1092
    fprintf(stderr,"Topo remove end\n");
1064 1093

  

Also available in: Unified diff