Revision 9a1f5816

View differences:

loop.c
112 112
{
113 113
		if (loop_counter % 10 == 0)
114 114
			topology_update();
115
//		if (loop_counter % 100 == 0)
116
//		{
117
//			fprintf(stderr,"PEERSET\n");
118
//			struct peerset *pset = get_peers();
119
//    	struct peer **peers = peerset_get_peers(pset);
120
//			int i;
121
//    	for (i = 0; i < peerset_size(pset); i++) 
122
//				fprintf(stderr,"%s\n",node_addr_tr((peers[i])->id));
123
//		}
115
		if (loop_counter % 100 == 0)
116
			peerset_print(topology_get_neighbours(),"PEERSET");
124 117
#ifndef MONL
125 118
		if (loop_counter % 100 == 0)
126 119
		{
streaming.c
280 280
  struct peerset *pset;
281 281
  struct chunkID_set *my_bmap;
282 282

  
283
  pset = get_neighbours();
283
  pset = topology_get_neighbours();
284 284
  n = peerset_size(pset);
285 285
  neighbours = peerset_get_peers(pset);
286 286

  
......
321 321
void ack_chunk(struct chunk *c, struct nodeID *from, uint16_t trans_id)
322 322
{
323 323
  //reduce load a little bit if there are losses on the path from this guy
324
  double average_lossrate = get_average_lossrate_pset(get_neighbours());
324
  double average_lossrate = get_average_lossrate_pset(topology_get_neighbours());
325 325
  average_lossrate = finite(average_lossrate) ? average_lossrate : 0;	//start agressively, assuming 0 loss
326 326
  if (rand()/((double)RAND_MAX + 1) < 1 * average_lossrate ) {
327 327
    return;
......
677 677
  struct peer **neighbours;
678 678
  struct peerset *pset;
679 679

  
680
  pset = get_neighbours();
680
  pset = topology_get_neighbours();
681 681
  n = peerset_size(pset);
682 682
  neighbours = peerset_get_peers(pset);
683 683
  dprintf("Send Offer: %d neighbours\n", n);
......
813 813
	size_t selectedpairs_len = multiplicity;
814 814
	struct PeerChunk  * selectedpairs;
815 815

  
816
	pset = get_neighbours();
816
	pset = topology_get_neighbours();
817 817
	peers_num = peerset_size(pset);
818 818
	peers = peerset_get_peers(pset);
819 819
	peer_evaluation = push_strategy ? peerWeightLoss : SCHED_PEER;
......
843 843
  struct peer **neighbours;
844 844
  struct peerset *pset;
845 845

  
846
  pset = get_neighbours();
846
  pset = topology_get_neighbours();
847 847
  n = peerset_size(pset);
848 848
  neighbours = peerset_get_peers(pset);
849 849
  dprintf("Send Chunk: %d neighbours\n", n);
topology.c
79 79
	struct timeval tout_bmap;
80 80
} context;
81 81

  
82
struct peerset * get_neighbours()
82
struct peerset * topology_get_neighbours()
83 83
{
84 84
	return context.neighbourhood;
85 85
}
86 86

  
87
void peerset_print(const struct peerset * pset,const char * name)
88
{
89
	const struct peer * p;
90
	int i;
91
	if(name) fprintf(stderr,"%s\n",name);
92
	if(pset)
93
		peerset_for_each(pset,p,i)
94
			fprintf(stderr,"\t%s\n",node_addr_tr(p->id));
95
}
96

  
87 97
void update_metadata()
88 98
{
89 99
	context.my_metadata.cb_size = am_i_source() ? 0 : get_cb_size();
......
115 125
}
116 126

  
117 127
/*useful during bootstrap*/
118
int topology_node_insert(const struct nodeID *id)
128
int topology_node_insert(struct nodeID *id)
119 129
{
120 130
	struct metadata m = {0};
121 131
	if (topology_get_peer(id) == NULL)
......
188 198

  
189 199
		case NEIGHBOURHOOD_REMOVE:
190 200
			neighbourhood_remove_peer(from);
201
			break;
191 202
		default:
192 203
			dprintf("Unknown neighbourhood message type");
193 204
	}
......
226 237
		if(p==NULL)
227 238
		{
228 239
			peerset_add_peer(context.swarm_bucket,sample_nodes[i]);
229
			p = peerset_get_peer(context.swarm_bucket,sample_nodes[i]);
240
			p = topology_get_peer(sample_nodes[i]);
230 241
		}
231 242
		topology_peer_set_metadata(p,&(sample_metas[i]));	
232 243
	}
......
332 343

  
333 344
void peerset_destroy_reference_copy(struct peerset ** pset)
334 345
{
335
	struct peer * p;
336
	peerset_for_each(*pset,p)
337
		peerset_pop_peer(*pset,p->id);
346
	const struct peer * p;
347
	int i;
348
	while (peerset_size(*pset))
349
		peerset_pop_peer(*pset,(peerset_get_peers(*pset)[0])->id);
350

  
338 351
	peerset_destroy(pset);
339 352
}
340 353

  
341 354
struct peerset * peerset_create_reference_copy(const struct peerset * pset)
342 355
{
343 356
	struct peerset * ns;
344
	struct peer * p;
357
	const struct peer * p;
358
	int i;
345 359

  
346 360
	ns = peerset_init(0);
347
	peerset_for_each(pset,p)
361
	peerset_for_each(pset,p,i)
348 362
		peerset_push_peer(ns,p);
349 363
	return ns;
350 364
}
......
364 378
	return p;
365 379
}
366 380

  
367
void peerset_print(const struct peerset * pset,const char * name)
368
{
369
	struct peer * p;
370
	fprintf(stderr,"%s\n",name);
371
	peerset_for_each(pset,p)
372
		fprintf(stderr,"-\t%s\n",node_addr_tr(p->id));
373
}
374

  
375 381
/* move num peers from pset1 to pset2 after applying the filtering_mask function and following the given criterion */
376 382
void topology_move_peers(struct peerset * pset1, struct peerset * pset2,int num,enum peer_choice criterion,bool (*filter_mask)(const struct peer *))
377 383
{
......
413 419
	int bests_num;
414 420
	int others_num;
415 421
	struct peerset * old_neighs;
416
	struct peer * p;
422
	const struct peer * p;
423
	int i;
417 424

  
418 425
	update_metadata();
419 426
	topology_sample_peers();
......
442 449
	// advertise changes
443 450
	if(topo_out)
444 451
	{
445
		peerset_for_each(context.neighbourhood,p)
452
		peerset_for_each(context.neighbourhood,p,i)
446 453
			if(peerset_check(old_neighs,p->id) < 0)
447 454
				neighbourhood_send_msg(p,NEIGHBOURHOOD_ADD);
448
		peerset_for_each(old_neighs,p)
455
		peerset_for_each(old_neighs,p,i)
449 456
			if(peerset_check(context.neighbourhood,p->id) < 0)
450 457
				neighbourhood_send_msg(p,NEIGHBOURHOOD_REMOVE);
451 458
	}
topology.h
26 26

  
27 27
#define MSG_TYPE_NEIGHBOURHOOD   0x22
28 28

  
29
struct peerset *get_neighbours(void);
29
struct peerset *topology_get_neighbours(void);
30 30
void topology_update();
31 31
struct peer *nodeid_to_peer(const struct nodeID* id, int reg);
32
int topology_node_insert(const struct nodeID *neighbour);
32
int topology_node_insert(struct nodeID *neighbour);
33 33
int topology_init(struct nodeID *myID, const char *config);
34 34
void topology_message_parse(struct nodeID *from, const uint8_t *buff, int len);
35
void peerset_print(const struct peerset * pset,const char * name);
35 36

  
36 37
#endif	/* TOPOLOGY_H */

Also available in: Unified diff