Example #1
0
/**
 * Create a new callout queue subordinate to another.
 *
 * @param name		the name of the subqueue
 * @param parent	the parent callout queue
 * @param period	period between heartbeats, in ms
 *
 * @return a new callout queue
 */
cqueue_t *
cq_submake(const char *name, cqueue_t *parent, int period)
{
	struct csubqueue *csq;

	WALLOC0(csq);
	cq_initialize(&csq->sub_cq, name, parent->cq_time, period);
	csq->sub_cq.cq_magic = CSUBQUEUE_MAGIC;

	csq->heartbeat = cq_periodic_add(parent, period,
		cq_heartbeat_trampoline, &csq->sub_cq);

	csubqueue_check(csq);
	cqueue_check(&csq->sub_cq);

	return &csq->sub_cq;
}
Example #2
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 #3
0
/**
 * Convenience routine: insert periodic event in the main callout queue.
 *
 * Same as calling:
 *
 *     cq_periodic_add(cq_main(), period, event, arg);
 *
 * only it is shorter.
 */
cperiodic_t *
cq_periodic_main_add(int period, cq_invoke_t event, void *arg)
{
	cq_main_init();
	return cq_periodic_add(callout_queue, period, event, arg);
}