Example #1
0
/**
 * Initialize node stability caching.
 */
G_GNUC_COLD void
stable_init(void)
{
    dbstore_kv_t kv = { KUID_RAW_SIZE, NULL, sizeof(struct lifedata), 0 };
    dbstore_packing_t packing =
    { serialize_lifedata, deserialize_lifedata, NULL };

    g_assert(NULL == db_lifedata);
    g_assert(NULL == stable_sync_ev);
    g_assert(NULL == stable_prune_ev);

    /* Legacy: remove after 0.97 -- RAM, 2011-05-03 */
    dbstore_move(settings_config_dir(), settings_dht_db_dir(), db_stable_base);

    db_lifedata = dbstore_open(db_stable_what, settings_dht_db_dir(),
                               db_stable_base, kv, packing, STABLE_DB_CACHE_SIZE, kuid_hash, kuid_eq,
                               GNET_PROPERTY(dht_storage_in_memory));

    dbmw_set_map_cache(db_lifedata, STABLE_MAP_CACHE_SIZE);
    stable_prune_old();

    stable_sync_ev = cq_periodic_main_add(STABLE_SYNC_PERIOD,
                                          stable_sync, NULL);

    stable_prune_ev = cq_periodic_main_add(STABLE_PRUNE_PERIOD,
                                           stable_periodic_prune, NULL);
}
Example #2
0
/**
 * Initialize security token caching.
 */
G_GNUC_COLD void
tcache_init(void)
{
	dbstore_kv_t kv = { KUID_RAW_SIZE, NULL, sizeof(struct tokdata),
		sizeof(struct tokdata) + MAX_INT_VAL(uint8) };
	dbstore_packing_t packing =
		{ serialize_tokdata, deserialize_tokdata, free_tokdata };

	g_assert(NULL == db_tokdata);
	g_assert(NULL == tcache_prune_ev);

	/* Legacy: remove after 0.97 -- RAM, 2011-05-03 */
	dbstore_move(settings_config_dir(), settings_dht_db_dir(), db_tcache_base);

	db_tokdata = dbstore_create(db_tcache_what, settings_dht_db_dir(),
		db_tcache_base, kv, packing, TOK_DB_CACHE_SIZE, kuid_hash, kuid_eq,
		GNET_PROPERTY(dht_storage_in_memory));

	dbmw_set_map_cache(db_tokdata, TOK_MAP_CACHE_SIZE);
	dbmw_set_debugging(db_tokdata, &tcache_dbmw_dbg);

	token_life = MIN(TOK_LIFE, token_lifetime());

	if (GNET_PROPERTY(dht_tcache_debug))
		g_debug("DHT cached token lifetime set to %u secs",
			(unsigned) token_life);

	tcache_prune_ev = cq_periodic_main_add(TCACHE_PRUNE_PERIOD,
		tcache_periodic_prune, NULL);
}
Example #3
0
/**
 * Initialize local key management.
 */
G_GNUC_COLD void
keys_init(void)
{
	size_t i;
	dbstore_kv_t kv = { KUID_RAW_SIZE, NULL, sizeof(struct keydata), 0 };
	dbstore_packing_t packing =
		{ serialize_keydata, deserialize_keydata, NULL };

	g_assert(NULL == keys_periodic_ev);
	g_assert(NULL == keys);
	g_assert(NULL == db_keydata);

	keys_periodic_ev = cq_periodic_main_add(LOAD_PERIOD * 1000,
		keys_periodic_load, NULL);

	keys = hikset_create(
		offsetof(struct keyinfo, kuid), HASH_KEY_FIXED, KUID_RAW_SIZE);
	install_periodic_kball(KBALL_FIRST);

	db_keydata = dbstore_open(db_keywhat, settings_dht_db_dir(), db_keybase,
		kv, packing, KEYS_DB_CACHE_SIZE, kuid_hash, kuid_eq,
		GNET_PROPERTY(dht_storage_in_memory));

	for (i = 0; i < G_N_ELEMENTS(decimation_factor); i++)
		decimation_factor[i] = pow(KEYS_DECIMATION_BASE, i);

	values_init();
	keys_init_keyinfo();
	keys_sync_ev = cq_periodic_main_add(KEYS_SYNC_PERIOD, keys_sync, NULL);
}
Example #4
0
/**
 * Close node stability caching.
 */
G_GNUC_COLD void
stable_close(void)
{
    dbstore_close(db_lifedata, settings_dht_db_dir(), db_stable_base);
    db_lifedata = NULL;
    cq_periodic_remove(&stable_sync_ev);
    cq_periodic_remove(&stable_prune_ev);
}
Example #5
0
/**
 * Initialize the DHT publisher.
 */
void G_COLD
publisher_init(void)
{
	size_t i;
	dbstore_kv_t kv = { SHA1_RAW_SIZE, NULL, sizeof(struct pubdata), 0 };
	dbstore_packing_t packing =
		{ serialize_pubdata, deserialize_pubdata, NULL };

	publish_cq = cq_main_submake("publisher", PUBLISHER_CALLOUT);
	publisher_sha1 = hikset_create(
		offsetof(struct publisher_entry, sha1), HASH_KEY_FIXED, SHA1_RAW_SIZE);

	db_pubdata = dbstore_open(db_pubdata_what, settings_dht_db_dir(),
		db_pubdata_base, kv, packing, PUBLISH_DB_CACHE_SIZE,
		sha1_hash, sha1_eq, GNET_PROPERTY(dht_storage_in_memory));

	cq_periodic_add(publish_cq, PUBLISH_SYNC_PERIOD, publisher_sync, NULL);

	for (i = 0; i < N_ITEMS(inverse_decimation); i++) {
		double n = i + 1.0;
		double v = log(n / KDA_K);

		inverse_decimation[i] = 1.0 / (1.0 + v * v);

		if (GNET_PROPERTY(publisher_debug) > 4) {
			g_debug("PUBLISHER inverse_decimation[%zu] = %g",
				i, inverse_decimation[i]);
		}
	}

	for (i = 0; i < N_ITEMS(inverse_decimation); i++) {
		if (inverse_decimation[i] >= PUBLISH_MIN_DECIMATION) {
			publisher_minimum = i + 1;
			break;
		}
	}

	g_assert(publisher_minimum > 0);

	if (GNET_PROPERTY(publisher_debug)) {
		g_debug("PUBLISHER minimum amount of nodes we accept: %u",
			publisher_minimum);
	}

	publisher_trim_pubdata();
}
Example #6
0
/**
 * Shutdown the DHT publisher.
 */
void G_COLD
publisher_close(void)
{
	/*
	 * Purge data we no longer know about from the persisted DB.
	 */

	dbmw_foreach_remove(db_pubdata, publisher_remove_orphan, NULL);

	/*
	 * Final cleanup.
	 */

	hikset_foreach(publisher_sha1, free_entry, NULL);
	hikset_free_null(&publisher_sha1);

	dbstore_close(db_pubdata, settings_dht_db_dir(), db_pubdata_base);
	db_pubdata = NULL;

	cq_free_null(&publish_cq);
}
Example #7
0
/**
 * Close local key management.
 */
G_GNUC_COLD void
keys_close(void)
{
	values_close();

	dbstore_close(db_keydata, settings_dht_db_dir(), db_keybase);
	db_keydata = NULL;

	if (keys) {
		hikset_foreach(keys, keys_free_kv, NULL);
		hikset_free_null(&keys);
	}

	kuid_atom_free_null(&kball.furthest);
	kuid_atom_free_null(&kball.closest);

	gnet_stats_set_general(GNR_DHT_KEYS_HELD, 0);
	gnet_stats_set_general(GNR_DHT_CACHED_KEYS_HELD, 0);

	cq_cancel(&kball_ev);
	cq_periodic_remove(&keys_periodic_ev);
	cq_periodic_remove(&keys_sync_ev);
}