Revision b2c34e56

View differences:

topology-ALTO.c
37 37
static unsigned char mTypes[] = {MSG_TYPE_TOPOLOGY};
38 38
static uint64_t currtime;
39 39
static struct nodeID **altoList;
40
static int altoList_size, g_neigh_size, newAltoQuery;
40
static int altoList_size, g_neigh_size, newAltoResults=2;
41 41
static struct nodeID **gossipNeighborhood;
42 42

  
43 43
/* ALTO begin --> */
......
169 169
	gettimeofday(&tnow, NULL);
170 170
	timenow = (tnow.tv_usec + tnow.tv_sec * 1000000ull);
171 171
	if ((timenow - currtime > (g_config.update_interval * 1000000)) &&
172
			(!newAltoQuery)) {
172
			(newAltoResults)) {
173 173

  
174 174
		/* fill the temporary peer list (used for ALTO query) */
175 175
		for (p=0; p < g_neigh_size; p++) {
......
197 197
		/*assert(rescode == 1);*/
198 198
		if (rescode != 1) {
199 199
			fprintf(stderr,"WARNING: ALTO query FAILED!\n");
200
			newAltoQuery = 0;
200
			newAltoResults = 1;
201 201
		}
202 202
		else {
203
			newAltoQuery = 1;
203
			newAltoResults = 0;
204 204
		}
205 205
	}
206 206

  
207 207
	if (ALTO_query_state() == ALTO_QUERY_READY) {
208 208

  
209
		if (newAltoQuery) {
209
		if (!newAltoResults) {
210 210
			gettimeofday(&tnow, NULL);
211 211
			currtime = (tnow.tv_usec + tnow.tv_sec * 1000000ull);
212 212
			fprintf(stderr,"Received ALTO server reply at : %u\n",(unsigned int)(((unsigned long)currtime)/1000000));
......
251 251

  
252 252
				fprintf(stderr,"ALTO peer %d: id  = %s ; rating = %d\n ", (i+1), node_addr(altoList[i]), ALTOInfo.peers[i].rating);
253 253
			}
254
			newAltoQuery = 0;
255
		}
254

  
256 255
		/* add remaining peers randomly */
257 256
		fprintf(stderr,"\nMore ALTO randomly picked peers:\n");
258 257
		for (j = ALTO_bucket_size; j < ALTO_bucket_size + RAND_bucket_size; j++) {
......
264 263
			gossipNeighborhood[p] = NULL;
265 264
			fprintf(stderr,"ALTO peer %d: id  = %s\n ", (j+1), node_addr(altoList[j]));
266 265
		}
266
		newAltoResults = 1;
267
	}
267 268
	}
268 269

  
269 270
}
......
296 297
	dprintf("before:%d, ",peerset_size(pset));
297 298
	topParseData(buff, len);
298 299
	nbrs = topGetNeighbourhood(&npeers);
299
	if (!newAltoQuery) {
300
	if (newAltoResults) {
300 301
		for (i=0; i < g_neigh_size; i++) {
301 302
			nodeid_free(gossipNeighborhood[i]);
302 303
		}
......
311 312
		PeerSelectorALTO();
312 313
	}
313 314

  
315
	if (ALTO_query_state() == ALTO_QUERY_READY && newAltoResults==1) {
314 316
	//	fprintf(stderr,"Composing peerset from ALTO selection\n");
315 317
	for (i=0; i<altoList_size; i++) {
316 318
		if(peerset_check(pset, altoList[i]) < 0) {
......
319 321
			}
320 322
		}
321 323
	}
322

  
324
	newAltoResults = 2;
325
	}
323 326
	if (peerset_size(pset) < NEIGHBORHOOD_TARGET_SIZE) { // ALTO selection didn't fill the peerset
324 327
		//	fprintf(stderr,"Composing peerset from ncast neighborhood\n");
325 328
		for (i=0;i<g_neigh_size;i++) {
......
347 350
		if ( (!timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].creation_timestamp, &told, <) ) ||
348 351
				( timerisset(&peers[i].bmap_timestamp) && timercmp(&peers[i].bmap_timestamp, &told, <)     )   ) {
349 352
			//if (peerset_size(pset) > 1) {	// avoid dropping our last link to the world
353
			topRemoveNeighbour(peers[i].id);
350 354
			remove_peer(peers[i--].id);
351 355
			//}
352 356
		}

Also available in: Unified diff