*/
/**
- * @file mesh/gnunet-daemon-regexprofiler.c
+ * @file regex/gnunet-daemon-regexprofiler.c
* @brief daemon that uses mesh to announce a regular expression. Used in
* conjunction with gnunet-regex-profiler to announce regexes on serveral peers
* without the need to explicitly connect to the mesh service running on the
*/
static struct GNUNET_REGEX_announce_handle *announce_handle;
-/**
- * Hostkey generation context
- */
-static struct GNUNET_CRYPTO_RsaKeyGenerationContext *keygen;
-
/**
* Periodically reannounce regex.
*/
static struct GNUNET_TIME_Relative reannounce_freq;
/**
- * Local peer's PeerID.
+ * Random delay to spread out load on the DHT.
*/
-static struct GNUNET_PeerIdentity my_full_id;
+static struct GNUNET_TIME_Relative announce_delay;
/**
* Maximal path compression length for regex announcing.
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
- if (NULL != keygen)
- {
- GNUNET_CRYPTO_rsa_key_create_stop (keygen);
- keygen = NULL;
- }
if (NULL != announce_handle)
{
GNUNET_REGEX_announce_cancel (announce_handle);
/**
* Announce a previously announced regex re-using cached data.
*
- * @param cls Clocuse (not used).
+ * @param cls Closure (regex to announce if needed).
* @param tc TaskContext.
*/
static void
reannounce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
+ struct GNUNET_PeerIdentity id;
+ char *regex = cls;
+
reannounce_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ {
+ GNUNET_free (regex);
return;
- reannounce_task = GNUNET_SCHEDULER_add_delayed(reannounce_freq,
- &reannounce_regex,
- cls);
+ }
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
+ GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO);
+ if (NULL == announce_handle && NULL != regex)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "First time, creating regex: %s\n",
+ regex);
+ memset (&id, 0, sizeof (struct GNUNET_PeerIdentity));
+ announce_handle = GNUNET_REGEX_announce (dht_handle,
+ &id,
+ regex,
+ (unsigned int) max_path_compression,
+ stats_handle);
+ }
+ else
+ {
+ GNUNET_assert (NULL != announce_handle);
+ GNUNET_REGEX_reannounce (announce_handle);
+ }
+
+ reannounce_task =
+ GNUNET_SCHEDULER_add_delayed (
+ GNUNET_TIME_relative_add (reannounce_freq,
+ GNUNET_TIME_relative_multiply (
+ GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_CRYPTO_random_u32 (
+ GNUNET_CRYPTO_QUALITY_WEAK,
+ 600))),
+ &reannounce_regex,
+ cls);
}
static void
announce_regex (const char * regex)
{
+ char *copy;
+
if (NULL == regex || 0 == strlen (regex))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot announce empty regex\n");
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
- GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO);
- announce_handle = GNUNET_REGEX_announce (dht_handle,
- &my_full_id,
- regex,
- (unsigned int) max_path_compression,
- stats_handle);
GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == reannounce_task);
- reannounce_task = GNUNET_SCHEDULER_add_delayed (reannounce_freq,
+ copy = GNUNET_strdup (regex);
+ reannounce_task = GNUNET_SCHEDULER_add_delayed (announce_delay,
reannounce_regex,
- NULL);
+ (void *) copy);
}
}
-/**
- * Callback for hostkey read/generation
- *
- * @param cls Closure (not used).
- * @param pk The private key of the local peer.
- * @param emsg Error message if applicable.
- */
-static void
-key_generation_cb (void *cls,
- struct GNUNET_CRYPTO_RsaPrivateKey *pk,
- const char *emsg)
-{
- struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key;
-
- keygen = NULL;
- if (NULL == pk)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Regexprofiler could not access hostkey: %s. Exiting.\n"),
- emsg);
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
-
- GNUNET_CRYPTO_rsa_key_get_public (pk, &my_public_key);
- GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
- &my_full_id.hashPubKey);
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Regexprofiler for peer [%s] starting\n",
- GNUNET_i2s(&my_full_id));
- announce_regex (rx_with_pfx);
- GNUNET_free (rx_with_pfx);
-}
-
-
/**
* @brief Main function that will be run by the scheduler.
*
const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
char *regex = NULL;
- char *keyfile;
cfg = cfg_;
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY",
- &keyfile))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _
- ("%s service is lacking key configuration settings (%s). Exiting.\n"),
- "regexprofiler", "hostkey");
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
-
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", "MAX_PATH_COMPRESSION",
&max_path_compression))
GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
"REANNOUNCE_FREQ", &reannounce_freq))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"reannounce_freq not given. Using 10 minutes.\n");
reannounce_freq =
- GNUNET_TIME_relative_multiply(GNUNET_TIME_relative_get_minute_(), 10);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
}
+ announce_delay =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 600));
stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg);
/* Announcing regexes from policy_filename */
GNUNET_asprintf (&rx_with_pfx, "%s(%s)", regex_prefix, regex);
+ announce_regex (rx_with_pfx);
GNUNET_free (regex);
-
- keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile,
- &key_generation_cb,
- NULL);
- GNUNET_free (keyfile);
+ GNUNET_free (rx_with_pfx);
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- sleep (30);
return (GNUNET_OK ==
GNUNET_PROGRAM_run (argc, argv, "regexprofiler",
gettext_noop