Revision 9a1f5816 topology.c

View differences:

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
	}

Also available in: Unified diff