Exemple #1
0
void p2p_cron_find(UCHAR * target)
{
	ITEM *item_b = NULL;
	BUCK *b = NULL;
	ITEM *item_n = NULL;
	UDP_NODE *n = NULL;
	unsigned long int j = 0;
	ITEM *ti = NULL;

	if ((item_b = bckt_find_any_match(_main->nbhd->bucket, target)) == NULL) {
		return;
	} else {
		b = list_value(item_b);
	}

	j = 0;
	item_n = list_start(b->nodes);
	while (item_n != NULL && j < 8) {
		n = list_value(item_n);

		if (_main->p2p->time_now.tv_sec > n->time_find) {

			ti = tdb_put(P2P_FIND_NODE);
			send_find_node_request(&n->c_addr, target, tdb_tid(ti));
			time_add_5_min_approx(&n->time_find);
		}

		item_n = list_next(item_n);
		j++;
	}
}
Exemple #2
0
void node_pinged( UDP_NODE *n ) {
	/* Remember no of pings */
	n->pinged++;

	/* Try again in ~5 minutes */
	time_add_5_min_approx( &n->time_ping );
}
Exemple #3
0
void node_ponged( UDP_NODE *n, IP *from ) {
	/* Reset no of pings */
	n->pinged = 0;

	/* Try again in ~5 minutes */
	time_add_5_min_approx( &n->time_ping );

	/* Update IP */
	node_update( n, from );
}
Exemple #4
0
void p2p_cron_lookup_all(void)
{
	ITEM *i = list_start(_main->identity);
	ID *identity = NULL;

	while (i != NULL) {
		identity = list_value(i);

		if (_main->p2p->time_now.tv_sec > identity->time_announce_host) {
			p2p_cron_lookup(identity->host_id, P2P_ANNOUNCE_START);
			time_add_5_min_approx(&identity->time_announce_host);
		}

		i = list_next(i);
	}
}
Exemple #5
0
void cache_renew( time_t now ) {
	ITEM *item = NULL;
	CACHE *cache = NULL;

	item = list_start( _main->cache->list );
	while( item != NULL ) {

		/* Lookup target on my own every 5 minutes */
		cache = list_value( item );
		if( now > cache->renew ) {
			p2p_localhost_lookup_remote( cache->target, NULL );
			time_add_5_min_approx( &cache->renew );
		}

		item = list_next( item );
	}
}
Exemple #6
0
void cache_put( UCHAR *target, UCHAR *nodes_compact_list, int nodes_compact_size ) {
	ITEM *item = NULL;
	CACHE *cache = cache_find( target );

	/* Found in cache, update cache, done */
	if( cache != NULL ) {
		cache_update( cache, target, nodes_compact_list, nodes_compact_size );
		return;
	}

	cache = (CACHE *) myalloc( sizeof(CACHE) );
	cache_update( cache, target, nodes_compact_list, nodes_compact_size );
	
	time_add_30_min( &cache->lifetime );
	time_add_5_min_approx( &cache->renew );

	item = list_put( _main->cache->list, cache );
	hash_put( _main->cache->hash, cache->target, SHA1_SIZE, item );
}
Exemple #7
0
void p2p_cron(void)
{
	/* Tick Tock */
	gettimeofday(&_main->p2p->time_now, NULL);

	if (nbhd_is_empty()) {

		/* Bootstrap PING */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_restart) {
			p2p_bootstrap();
			time_add_1_min_approx(&_main->p2p->time_restart);
		}

	} else {

		/* Create a new token every ~5 minutes */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_token) {
			tkn_put();
			time_add_5_min_approx(&_main->p2p->time_token);
		}

		/* Expire objects. Run once a minute. */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_expire) {
			tdb_expire(_main->p2p->time_now.tv_sec);
			nbhd_expire(_main->p2p->time_now.tv_sec);
			val_expire(_main->p2p->time_now.tv_sec);
			tkn_expire(_main->p2p->time_now.tv_sec);
			cache_expire(_main->p2p->time_now.tv_sec);
			time_add_1_min_approx(&_main->p2p->time_expire);
		}

		/* Split buckets. Evolve neighbourhood. Run often to evolve
		 * neighbourhood fast. */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_split) {
			nbhd_split(_main->conf->node_id, TRUE);
			time_add_5_sec_approx(&_main->p2p->time_split);
		}

		/* Find nodes every ~5 minutes. */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_find) {
			p2p_cron_find_myself();
			time_add_5_sec_approx(&_main->p2p->time_find);
		}

		/* Find random node every ~5 minutes for maintainance reasons. */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_maintainance) {
			p2p_cron_find_random();
			time_add_5_sec_approx(&_main->p2p->time_maintainance);
		}

		/* Announce my hostname every ~5 minutes. This includes a full search
		 * to get the needed tokens first. */
		if (_main->p2p->time_now.tv_sec >
		    _main->p2p->time_announce_host) {
			p2p_cron_lookup_all();
			time_add_5_sec_approx(&_main->p2p->time_announce_host);
		}

		/* Ping all nodes every ~5 minutes. */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_ping) {
			p2p_cron_ping();
			time_add_5_sec_approx(&_main->p2p->time_ping);
		}

		/* Renew cached requests */
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_cache) {
			cache_renew(_main->p2p->time_now.tv_sec);
			time_add_5_sec_approx(&_main->p2p->time_cache);
		}
	}

	/* Try to register multicast address until it works. */
	if (_main->udp->multicast == FALSE) {
		if (_main->p2p->time_now.tv_sec > _main->p2p->time_multicast) {
			udp_multicast(_main->udp, multicast_enabled,
				      multicast_start);
			time_add_5_min_approx(&_main->p2p->time_multicast);
		}
	}
}