static void setup_peer (struct PeerContext *p, const char *cfgname) { char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); GNUNET_assert (p->th != NULL); p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); GNUNET_free (binary); }
static void setup_peer (struct PeerContext *p, const char *cfgname) { p->cfg = GNUNET_CONFIGURATION_create (); #if START_ARM p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", #endif "-c", cfgname, NULL); #endif GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, ¬ify_connect, NULL); GNUNET_assert (p->th != NULL); p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); }
static void task (void *cls) { struct sockaddr_in sa; struct sockaddr *sap[2]; socklen_t slens[2]; struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; sap[0] = (struct sockaddr *) &sa; slens[0] = sizeof (sa); sap[1] = NULL; slens[1] = 0; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN sa.sin_len = sizeof (sa); #endif sa.sin_family = AF_INET; sa.sin_port = htons (PORT); server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO); GNUNET_assert (server != NULL); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL); cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); mq = GNUNET_CLIENT_connect (cfg, "test-server", NULL, NULL, NULL); GNUNET_assert (NULL != mq); ok = 2; env = GNUNET_MQ_msg (msg, MY_TYPE); GNUNET_MQ_send (mq, env); }
static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_un un; const char *unixpath = "/tmp/testsock"; struct sockaddr *sap[2]; socklen_t slens[2]; memset (&un, 0, sizeof (un)); un.sun_family = AF_UNIX; strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1); #if HAVE_SOCKADDR_IN_SIN_LEN un.sun_len = (u_char) sizeof (un); #endif sap[0] = (struct sockaddr *) &un; slens[0] = sizeof (un); sap[1] = NULL; slens[1] = 0; server = GNUNET_SERVER_create (NULL, NULL, sap, slens, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); GNUNET_assert (server != NULL); handlers[0].callback_cls = cls; GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); client = GNUNET_CLIENT_connect ("test", cfg); GNUNET_assert (client != NULL); GNUNET_CLIENT_notify_transmit_ready (client, 256, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO, ¬ify_ready, NULL); }
/** * Functions with this signature are called whenever a * complete message is received by the tokenizer. * * Do not call GNUNET_SERVER_mst_destroy in callback * * @param cls closure * @param client identification of the client * @param message the actual message * * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing */ static int helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message) { struct GNUNET_TESTBED_ControllerProc *cp = cls; const struct GNUNET_TESTBED_HelperReply *msg; const char *hostname; char *config; uLongf config_size; uLongf xconfig_size; msg = (const struct GNUNET_TESTBED_HelperReply *) message; GNUNET_assert (sizeof (struct GNUNET_TESTBED_HelperReply) < ntohs (msg->header.size)); GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY == ntohs (msg->header.type)); config_size = (uLongf) ntohs (msg->config_size); xconfig_size = (uLongf) (ntohs (msg->header.size) - sizeof (struct GNUNET_TESTBED_HelperReply)); config = GNUNET_malloc (config_size); GNUNET_assert (Z_OK == uncompress ((Bytef *) config, &config_size, (const Bytef *) &msg[1], xconfig_size)); /* Replace the configuration template present in the host with the controller's running configuration */ GNUNET_CONFIGURATION_destroy (cp->host->cfg); cp->host->cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, config, config_size, GNUNET_NO)); GNUNET_free (config); if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) hostname = "localhost"; /* Change the hostname so that we can connect to it */ GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, "testbed", "hostname", hostname); cp->host->locked = GNUNET_NO; cp->host->controller_started = GNUNET_YES; cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); return GNUNET_OK; }
static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; struct sockaddr *sap[2]; socklen_t slens[2]; sap[0] = (struct sockaddr *) &sa; slens[0] = sizeof (sa); sap[1] = NULL; slens[1] = 0; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN sa.sin_len = sizeof (sa); #endif sa.sin_family = AF_INET; sa.sin_port = htons (PORT); server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO); GNUNET_assert (server != NULL); GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL); cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); cc = GNUNET_CLIENT_connect ("test-server", cfg); GNUNET_assert (cc != NULL); GNUNET_assert (NULL != GNUNET_CLIENT_notify_transmit_ready (cc, sizeof (struct GNUNET_MessageHeader), TIMEOUT, GNUNET_YES, &transmit_initial_message, NULL)); }
static int check_blacklist_config (char *cfg_file, struct GNUNET_PeerIdentity *peer, struct GNUNET_PeerIdentity *bl_peer) { struct GNUNET_CONFIGURATION_Handle *cfg; char *section; char *peer_str; cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; } peer_str = GNUNET_strdup (GNUNET_i2s_full(peer)); GNUNET_asprintf (§ion, "transport-blacklist-%s", peer_str); if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section, GNUNET_i2s_full(bl_peer))) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (section); GNUNET_free (peer_str); return GNUNET_SYSERR; } GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (section); GNUNET_free (peer_str); return GNUNET_OK; }
static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; struct sockaddr *sap[2]; socklen_t slens[2]; sap[0] = (struct sockaddr *) &sa; slens[0] = sizeof (sa); sap[1] = NULL; slens[1] = 0; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN sa.sin_len = sizeof (sa); #endif sa.sin_family = AF_INET; sa.sin_port = htons (PORT); server = GNUNET_SERVER_create (NULL, NULL, sap, slens, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); GNUNET_assert (server != NULL); handlers[0].callback_cls = cls; GNUNET_SERVER_add_handlers (server, handlers); GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); client = GNUNET_CLIENT_connect ("test", cfg); GNUNET_assert (client != NULL); GNUNET_CLIENT_notify_transmit_ready (client, 256, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO, ¬ify_ready, NULL); }
static void setup_learn_peer (struct PeerContext *p, const char *cfgname) { char *filename; unsigned int result; char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE", &filename)) { if (GNUNET_YES == GNUNET_DISK_file_test (filename)) { result = UNLINK (filename); if (result == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist file `%s' was removed\n"), filename); } GNUNET_free (filename); } p->core = GNUNET_CORE_connect (p->cfg, NULL, NULL, NULL, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, learn_handlers); GNUNET_assert (NULL != p->core); p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); GNUNET_assert (NULL != p->stats); GNUNET_free (binary); }
int main (int argc, char *argv[]) { int ok; struct GNUNET_HashCode rid1; struct GNUNET_HashCode id2; struct GNUNET_HashCode rid2; struct GNUNET_HashCode fid; struct GNUNET_HashCode id3; int old; int newVal; struct GNUNET_CONFIGURATION_Handle *cfg; char *name1; char *name2; char *name3; char *name1_unique; char *name2_unique; char *noname; int noname_is_a_dup; int notiCount, fakenotiCount; int count; static char m[1024 * 1024 * 10]; memset (m, 'b', sizeof (m)); m[sizeof (m) - 1] = '\0'; GNUNET_log_setup ("test-pseudonym", "WARNING", NULL); ok = GNUNET_YES; GNUNET_CRYPTO_random_disable_entropy_gathering (); (void) GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test"); cfg = GNUNET_CONFIGURATION_create (); if (-1 == GNUNET_CONFIGURATION_parse (cfg, "test_pseudonym_data.conf")) { GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (0); return -1; } notiCount = 0; fakenotiCount = 0; count = 0; GNUNET_PSEUDONYM_discovery_callback_register (cfg, &fake_noti_callback, &fakenotiCount); GNUNET_PSEUDONYM_discovery_callback_register (cfg, ¬i_callback, ¬iCount); GNUNET_PSEUDONYM_discovery_callback_unregister (&false_callback, &count); GNUNET_PSEUDONYM_discovery_callback_unregister (&fake_noti_callback, &fakenotiCount); /* ACTUAL TEST CODE */ old = GNUNET_PSEUDONYM_list_all (cfg, NULL, NULL); meta = GNUNET_CONTAINER_meta_data_create (); GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_TITLE, EXTRACTOR_METAFORMAT_UTF8, "text/plain", "test", strlen ("test") + 1); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 1); GNUNET_PSEUDONYM_add (cfg, &id1, meta); CHECK (notiCount == 2); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); old = newVal; GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id2); GNUNET_PSEUDONYM_add (cfg, &id2, meta); CHECK (notiCount == 3); newVal = GNUNET_PSEUDONYM_list_all (cfg, &iter, &ok); CHECK (old < newVal); GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_meta_data_insert (meta, "<test>", EXTRACTOR_METATYPE_COMMENT, EXTRACTOR_METAFORMAT_UTF8, "text/plain", m, strlen (m) + 1)); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &id3); GNUNET_PSEUDONYM_add (cfg, &id3, meta); GNUNET_PSEUDONYM_get_info (cfg, &id3, NULL, NULL, &name3, NULL); CHECK (name3 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id2, NULL, NULL, &name2, NULL); CHECK (name2 != NULL); GNUNET_PSEUDONYM_get_info (cfg, &id1, NULL, NULL, &name1, NULL); CHECK (name1 != NULL); CHECK (0 == strcmp (name1, name2)); name1_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id1, name1, NULL); name2_unique = GNUNET_PSEUDONYM_name_uniquify (cfg, &id2, name2, NULL); CHECK (0 != strcmp (name1_unique, name2_unique)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, "fake", &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name2, &rid2)); CHECK (GNUNET_SYSERR == GNUNET_PSEUDONYM_name_to_id (cfg, name1, &rid1)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name2_unique, &rid2)); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_name_to_id (cfg, name1_unique, &rid1)); CHECK (0 == memcmp (&id1, &rid1, sizeof (struct GNUNET_HashCode))); CHECK (0 == memcmp (&id2, &rid2, sizeof (struct GNUNET_HashCode))); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &fid); GNUNET_log_skip (1, GNUNET_NO); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &fid, 0)); GNUNET_log_skip (0, GNUNET_YES); CHECK (GNUNET_OK == GNUNET_PSEUDONYM_get_info (cfg, &fid, NULL, NULL, &noname, &noname_is_a_dup)); CHECK (noname != NULL); CHECK (noname_is_a_dup == GNUNET_YES); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 0)); CHECK (5 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); CHECK (-5 == GNUNET_PSEUDONYM_rank (cfg, &id1, -10)); CHECK (0 == GNUNET_PSEUDONYM_rank (cfg, &id1, 5)); GNUNET_free (name1); GNUNET_free (name2); GNUNET_free (name1_unique); GNUNET_free (name2_unique); GNUNET_free (name3); GNUNET_free (noname); /* END OF TEST CODE */ FAILURE: GNUNET_PSEUDONYM_discovery_callback_unregister (¬i_callback, ¬iCount); GNUNET_CONTAINER_meta_data_destroy (meta); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (GNUNET_OK == GNUNET_DISK_directory_remove ("/tmp/gnunet-pseudonym-test")); return (ok == GNUNET_YES) ? 0 : 1; }
/** * Start a peer with the given configuration * @param tth the testing handle * @param cfgname configuration file * @param peer_id a unique number to identify the peer * @param rec receive callback * @param nc connect callback * @param nd disconnect callback * @param start_cb start callback * @param cb_cls closure for callback * @return the peer context */ struct PeerContext * GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, const char *cfgname, int peer_id, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_TESTING_start_cb start_cb, void *cb_cls) { char *emsg = NULL; struct GNUNET_PeerIdentity *dummy; GNUNET_assert (NULL != tth); GNUNET_assert (NULL != tth->tl_system); if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "File not found: `%s' \n", cfgname); return NULL; } struct PeerContext *p = GNUNET_new (struct PeerContext); GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); /* Create configuration and call testing lib to modify it */ p->cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_SYSERR == GNUNET_TESTING_configuration_create (tth->tl_system, p->cfg)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s'\n", cfgname); GNUNET_free (p); return NULL; } p->no = peer_id; /* Configure peer with configuration */ p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, p->cfg, p->no, NULL, &emsg); if (NULL == p->peer) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s': `%s'\n", cfgname, emsg); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); GNUNET_free_non_null (emsg); return NULL; } GNUNET_free_non_null (emsg); if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s'\n", cfgname); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } memset(&dummy, '\0', sizeof (dummy)); GNUNET_TESTING_peer_get_identity (p->peer, &p->id); if (0 == memcmp (&dummy, &p->id, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to obtain peer identity for peer %u\n", p->no); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } else { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", "Peer %u configured with identity `%s'\n", p->no, GNUNET_i2s_full (&p->id)); } p->tth = tth; p->nc = nc; p->nd = nd; p->rec = rec; p->start_cb = start_cb; if (cb_cls != NULL) p->cb_cls = cb_cls; else p->cb_cls = p; p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, ¬ify_connect, ¬ify_disconnect); if (NULL == p->th) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Failed to connect to transport service for peer `%s': `%s'\n", cfgname, emsg); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); GNUNET_assert (p->ghh != NULL); return p; }
/** * Handle network size estimate clients. * * @param cls closure * @param server the initialized server * @param c configuration to use */ static void run (void *cls, struct GNUNET_SERVER_Handle *server, const struct GNUNET_CONFIGURATION_Handle *c) { static const struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_start_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_START, sizeof (struct GNUNET_MessageHeader)}, {&handle_get_default_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_GET_DEFAULT, 0}, {&handle_set_default_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_SET_DEFAULT, 0}, {&handle_create_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_CREATE, 0}, {&handle_rename_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_RENAME, 0}, {&handle_delete_message, NULL, GNUNET_MESSAGE_TYPE_IDENTITY_DELETE, 0}, {NULL, NULL, 0, 0} }; cfg = c; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", "EGODIR", &ego_directory)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "EGODIR"); GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "identity", "SUBSYSTEM_CFG", &subsystem_cfg_file)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "identity", "SUBSYSTEM_CFG"); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading subsystem configuration `%s'\n", subsystem_cfg_file); subsystem_cfg = GNUNET_CONFIGURATION_create (); if ( (GNUNET_YES == GNUNET_DISK_file_test (subsystem_cfg_file)) && (GNUNET_OK != GNUNET_CONFIGURATION_parse (subsystem_cfg, subsystem_cfg_file)) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to parse subsystem identity configuration file `%s'\n"), subsystem_cfg_file); GNUNET_SCHEDULER_shutdown (); return; } stats = GNUNET_STATISTICS_create ("identity", cfg); GNUNET_SERVER_add_handlers (server, handlers); nc = GNUNET_SERVER_notification_context_create (server, 1); if (GNUNET_OK != GNUNET_DISK_directory_create (ego_directory)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to create directory `%s' for storing egos\n"), ego_directory); } GNUNET_DISK_directory_scan (ego_directory, &process_ego_file, NULL); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }
/** * The main scheduler run task * * @param cls NULL * @param tc scheduler task context */ static void run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_TESTBED_Host **hosts; const struct GNUNET_CONFIGURATION_Handle *null_cfg; char *tmpdir; char *hostname; size_t hostname_len; unsigned int nhosts; null_cfg = GNUNET_CONFIGURATION_create (); nhosts = GNUNET_TESTBED_hosts_load_from_loadleveler (null_cfg, &hosts); if (0 == nhosts) { GNUNET_break (0); ret = GNUNET_SYSERR; return; } hostname_len = GNUNET_OS_get_hostname_max_length (); hostname = GNUNET_malloc (hostname_len); if (0 != gethostname (hostname, hostname_len)) { LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); GNUNET_free (hostname); destroy_hosts (hosts, nhosts); ret = GNUNET_SYSERR; return; } if (NULL == strstr (GNUNET_TESTBED_host_get_hostname (hosts[0]), hostname)) { LOG_DEBUG ("Exiting as `%s' is not the lowest host\n", hostname); GNUNET_free (hostname); ret = GNUNET_OK; return; } LOG_DEBUG ("Will be executing `%s' on host `%s'\n", argv2[0], hostname); GNUNET_free (hostname); destroy_hosts (hosts, nhosts); tmpdir = getenv ("TMPDIR"); if (NULL == tmpdir) tmpdir = getenv ("TMP"); if (NULL == tmpdir) tmpdir = getenv ("TEMP"); if (NULL == tmpdir) tmpdir = "/tmp"; (void) GNUNET_asprintf (&fn, "%s/gnunet-testbed-spawn.lock", tmpdir); /* Open the unique file; we can create it then we can spawn the child process else we exit */ fh = open (fn, O_CREAT | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); if (-1 == fh) { if (EEXIST == errno) { LOG_DEBUG ("Lock file already created by other process. Exiting\n"); ret = GNUNET_OK; return; } GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "open"); ret = GNUNET_SYSERR; return; } /* Spawn the new process here */ LOG (GNUNET_ERROR_TYPE_INFO, _("Spawning process `%s'\n"), argv2[0]); child = GNUNET_OS_start_process_vap (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, NULL, argv2[0], argv2); if (NULL == child) { GNUNET_break (0); ret = GNUNET_SYSERR; shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); return; } ret = GNUNET_OK; terminate_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &terminate_task, NULL); child_death_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), &child_death_task, NULL); }
/** * Function called with the result from the autoconfiguration. * * @param cls closure * @param diff minimal suggested changes to the original configuration * to make it work (as best as we can) * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code * @param type what the situation of the NAT */ static void auto_config_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type) { const char *nat_type; char unknown_type[64]; struct GNUNET_CONFIGURATION_Handle *new_cfg; ah = NULL; switch (type) { case GNUNET_NAT_TYPE_NO_NAT: nat_type = "NO NAT"; break; case GNUNET_NAT_TYPE_UNREACHABLE_NAT: nat_type = "NAT but we can traverse"; break; case GNUNET_NAT_TYPE_STUN_PUNCHED_NAT: nat_type = "NAT but STUN is able to identify the correct information"; break; case GNUNET_NAT_TYPE_UPNP_NAT: nat_type = "NAT but UPNP opened the ports"; break; default: SPRINTF (unknown_type, "NAT unknown, type %u", type); nat_type = unknown_type; break; } GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "NAT status: %s/%s\n", GNUNET_NAT_AUTO_status2string (result), nat_type); /* Shortcut: if there are no changes suggested, bail out early. */ if (GNUNET_NO == GNUNET_CONFIGURATION_is_dirty (diff)) { test_finished (); return; } /* Apply diff to original configuration and show changes to the user */ new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL; if (NULL != diff) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _("Suggested configuration changes:\n")); GNUNET_CONFIGURATION_iterate_section_values (diff, "nat", &auto_conf_iter, new_cfg); } /* If desired, write configuration to file; we write only the changes to the defaults to keep things compact. */ if ( (write_cfg) && (NULL != diff) ) { struct GNUNET_CONFIGURATION_Handle *def_cfg; GNUNET_CONFIGURATION_set_value_string (new_cfg, "ARM", "CONFIG", NULL); def_cfg = GNUNET_CONFIGURATION_create (); GNUNET_break (GNUNET_OK == GNUNET_CONFIGURATION_load (def_cfg, NULL)); if (GNUNET_OK != GNUNET_CONFIGURATION_write_diffs (def_cfg, new_cfg, cfg_file)) { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _("Failed to write configuration to `%s'\n"), cfg_file); global_ret = 1; } else { GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, _("Wrote updated configuration to `%s'\n"), cfg_file); } GNUNET_CONFIGURATION_destroy (def_cfg); } if (NULL != new_cfg) GNUNET_CONFIGURATION_destroy (new_cfg); test_finished (); }
/** * Run a standard GNUnet service startup sequence (initialize loggers * and configuration, parse options). * * @param argc number of command line arguments * @param argv command line arguments * @param service_name our service name * @param options service options * @param task main task of the service * @param task_cls closure for @a task * @return #GNUNET_SYSERR on error, #GNUNET_OK * if we shutdown nicely */ int GNUNET_SERVICE_run (int argc, char *const *argv, const char *service_name, enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_Main task, void *task_cls) { #define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) int err; int ret; char *cfg_fn; char *opt_cfg_fn; char *loglev; char *logfile; int do_daemonize; unsigned int i; unsigned long long skew_offset; unsigned long long skew_variance; long long clock_offset; struct GNUNET_SERVICE_Context sctx; struct GNUNET_CONFIGURATION_Handle *cfg; const char *xdg; struct GNUNET_GETOPT_CommandLineOption service_options[] = { GNUNET_GETOPT_OPTION_CFG_FILE (&opt_cfg_fn), {'d', "daemonize", NULL, gettext_noop ("do daemonize (detach from terminal)"), 0, GNUNET_GETOPT_set_one, &do_daemonize}, GNUNET_GETOPT_OPTION_HELP (NULL), GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), GNUNET_GETOPT_OPTION_LOGFILE (&logfile), GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION " " VCS_VERSION), GNUNET_GETOPT_OPTION_END }; err = 1; do_daemonize = 0; logfile = NULL; loglev = NULL; opt_cfg_fn = NULL; xdg = getenv ("XDG_CONFIG_HOME"); if (NULL != xdg) GNUNET_asprintf (&cfg_fn, "%s%s%s", xdg, DIR_SEPARATOR_STR, "gnunet.conf"); else cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); memset (&sctx, 0, sizeof (sctx)); sctx.options = options; sctx.ready_confirm_fd = -1; sctx.ret = GNUNET_OK; sctx.timeout = GNUNET_TIME_UNIT_FOREVER_REL; sctx.task = task; sctx.task_cls = task_cls; sctx.service_name = service_name; sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); /* setup subsystems */ ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv); if (GNUNET_SYSERR == ret) goto shutdown; if (GNUNET_NO == ret) { err = 0; goto shutdown; } if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) HANDLE_ERROR; if (NULL == opt_cfg_fn) opt_cfg_fn = GNUNET_strdup (cfg_fn); if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn)) { if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed configuration file `%s', exit ...\n"), opt_cfg_fn); goto shutdown; } } else { if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Malformed configuration, exit ...\n")); goto shutdown; } if (0 != strcmp (opt_cfg_fn, cfg_fn)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not access configuration file `%s'\n"), opt_cfg_fn); } if (GNUNET_OK != setup_service (&sctx)) goto shutdown; if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx))) HANDLE_ERROR; if (GNUNET_OK != set_user_id (&sctx)) goto shutdown; LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' runs with configuration from `%s'\n", service_name, opt_cfg_fn); if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_OFFSET", &skew_offset)) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", "SKEW_VARIANCE", &skew_variance))) { clock_offset = skew_offset - skew_variance; GNUNET_TIME_set_offset (clock_offset); LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); } /* actually run service */ err = 0; GNUNET_SCHEDULER_run (&service_task, &sctx); /* shutdown */ if ((1 == do_daemonize) && (NULL != sctx.server)) pid_file_delete (&sctx); GNUNET_free_non_null (sctx.my_handlers); shutdown: if (-1 != sctx.ready_confirm_fd) { if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); } #if HAVE_MALLINFO { char *counter; if ( (GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name, "GAUGER_HEAP")) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name, "GAUGER_HEAP", &counter)) ) { struct mallinfo mi; mi = mallinfo (); GAUGER (service_name, counter, mi.usmblks, "blocks"); GNUNET_free (counter); } } #endif GNUNET_SPEEDUP_stop_ (); GNUNET_CONFIGURATION_destroy (cfg); i = 0; if (NULL != sctx.addrs) while (NULL != sctx.addrs[i]) GNUNET_free (sctx.addrs[i++]); GNUNET_free_non_null (sctx.addrs); GNUNET_free_non_null (sctx.addrlens); GNUNET_free_non_null (logfile); GNUNET_free_non_null (loglev); GNUNET_free (cfg_fn); GNUNET_free_non_null (opt_cfg_fn); GNUNET_free_non_null (sctx.v4_denied); GNUNET_free_non_null (sctx.v6_denied); GNUNET_free_non_null (sctx.v4_allowed); GNUNET_free_non_null (sctx.v6_allowed); return err ? GNUNET_SYSERR : sctx.ret; }
/** * Run a standard GNUnet command startup sequence (initialize loggers * and configuration, parse options). * * @param argc number of command line arguments * @param argv command line arguments * @param binaryName our expected name * @param binaryHelp help text for the program * @param options command line options * @param task main function to run * @param task_cls closure for task * @param run_without_scheduler GNUNET_NO start the scheduler, GNUNET_YES do not * start the scheduler just run the main task * @return GNUNET_SYSERR on error, GNUNET_OK on success */ int GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler) { struct CommandContext cc; char *path; char *loglev; char *logfile; int ret; unsigned int cnt; unsigned long long skew_offset; unsigned long long skew_variance; long long clock_offset; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption defoptions[] = { GNUNET_GETOPT_OPTION_CFG_FILE (&cc.cfgfile), GNUNET_GETOPT_OPTION_HELP (binaryHelp), GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), GNUNET_GETOPT_OPTION_LOGFILE (&logfile), GNUNET_GETOPT_OPTION_VERSION (PACKAGE_VERSION) }; struct GNUNET_GETOPT_CommandLineOption *allopts; const char *gargs; char *lpfx; char *spc; logfile = NULL; gargs = getenv ("GNUNET_ARGS"); if (gargs != NULL) { char **gargv; unsigned int gargc; int i; char *tok; char *cargs; gargv = NULL; gargc = 0; for (i = 0; i < argc; i++) GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); cargs = GNUNET_strdup (gargs); tok = strtok (cargs, " "); while (NULL != tok) { GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); tok = strtok (NULL, " "); } GNUNET_free (cargs); GNUNET_array_append (gargv, gargc, NULL); argv = (char *const *) gargv; argc = gargc - 1; } memset (&cc, 0, sizeof (cc)); loglev = NULL; cc.task = task; cc.task_cls = task_cls; cc.cfg = cfg = GNUNET_CONFIGURATION_create (); /* prepare */ #if ENABLE_NLS setlocale (LC_ALL, ""); path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); if (path != NULL) { BINDTEXTDOMAIN ("GNUnet", path); GNUNET_free (path); } textdomain ("GNUnet"); #endif cnt = 0; while (options[cnt].name != NULL) cnt++; allopts = GNUNET_malloc ((cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + sizeof (defoptions)); memcpy (allopts, defoptions, sizeof (defoptions)); memcpy (&allopts [sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), &cmd_sorter); loglev = NULL; cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); lpfx = GNUNET_strdup (binaryName); if (NULL != (spc = strstr (lpfx, " "))) *spc = '\0'; if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv))) || (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) { GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free_non_null (cc.cfgfile); GNUNET_free_non_null (loglev); GNUNET_free_non_null (logfile); GNUNET_free (allopts); GNUNET_free (lpfx); return GNUNET_SYSERR; } (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); GNUNET_free (allopts); GNUNET_free (lpfx); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", &skew_offset) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_variance", &skew_variance))) { clock_offset = skew_offset - skew_variance; GNUNET_TIME_set_offset (clock_offset); } /* run */ cc.args = &argv[ret]; if (GNUNET_NO == run_without_scheduler) { GNUNET_SCHEDULER_run (&program_main, &cc); } else { GNUNET_RESOLVER_connect (cc.cfg); cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); } /* clean up */ GNUNET_SPEEDUP_stop_ (); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free_non_null (cc.cfgfile); GNUNET_free_non_null (loglev); GNUNET_free_non_null (logfile); return GNUNET_OK; }
int main (int argc, char *argv[]) { int ok; int status; const char *socksport = "1081"; GNUNET_log_setup ("test_client", "WARNING", NULL); pid_t pid = fork(); GNUNET_assert (pid >= 0); if (pid == 0) { execlp ("ssh", "ssh","-D",socksport, "-o","BatchMode yes", "-o","UserKnownHostsFile /tmp/gnunet_test_socks_ssh_garbage", "-o","StrictHostKeyChecking no", "127.0.0.1","-N",(char*)NULL); perror ("execlp (\"ssh\",\"ssh\",...,\"-D\",\"1081\",\"127.0.0.1\",\"-N\") "); printf ("" "Please ensure you have ssh installed and have sshd installed and running :\n" "\tsudo apt-get install openssh-client openssh-server\n" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); kill (getppid(), SIGALRM); return 1; } if (0 != sleep (1)) { /* sleep interrupted, likely SIGALRM, failure to launch child, terminate */ printf ("" "Please ensure you have ssh installed and have sshd installed and running :\n" "\tsudo apt-get install openssh-client openssh-server\n" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); return 77; } /* check if child exec()ed but died */ if (0 != waitpid (pid, &status, WNOHANG)) { printf ("" "If you run Tor as a network proxy then Tor might prevent ssh from connecting\n" "to localhost. Please either run make check from an unproxied user, or else\n" "add these lines to the beginning of your ~/.ssh/config file :" "\tHost 127.0.0.1 localhost\n" "\t CheckHostIP no\n" "\t Protocol 2\n" "\t ProxyCommand nc 127.0.0.1 22\n"); return 77; } cfg = GNUNET_CONFIGURATION_create (); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSHOST", "127.0.0.1"); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "SOCKSPORT", socksport); GNUNET_CONFIGURATION_set_value_number (cfg, MYNAME, "PORT", PORT); GNUNET_CONFIGURATION_set_value_string (cfg, MYNAME, "HOSTNAME", "127.0.0.1"); ok = 1; GNUNET_SCHEDULER_run (&task, &ok); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_break (0 == kill (pid, SIGTERM)); GNUNET_break (pid == waitpid (pid, &status, 0)); return ok; }
/** * Main function that will be run by the scheduler. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param cfg configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *mycfg) { struct GNUNET_CONFIGURATION_Handle *properties; char *file; end_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); cfg = mycfg; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "sysdaemon starting ... \n"); if (GNUNET_SYSERR ==GNUNET_CONFIGURATION_get_value_filename (mycfg, "sysmon", "CFGFILE", &file)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sysmon configuration file not set, exit! \n"); shutdown_now(); ret = 1; return; } properties = GNUNET_CONFIGURATION_create(); if (NULL == properties) { GNUNET_break (0); shutdown_now(); ret = 1; return; } if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (properties, file)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (properties); GNUNET_free (file); ret = 1; shutdown_now(); return; } GNUNET_free (file); GNUNET_CONFIGURATION_iterate_sections (properties, &load_property, properties); GNUNET_CONFIGURATION_destroy (properties); /* Creating statistics */ stats = GNUNET_STATISTICS_create ("sysmon", mycfg); if (NULL == stats) { GNUNET_break (0); shutdown_now(); ret = 1; return; } /* load properties */ if (GNUNET_SYSERR == load_default_properties ()) { GNUNET_break (0); shutdown_now(); ret = 1; return; } /* run properties */ if (GNUNET_SYSERR == run_properties ()) { GNUNET_break (0); shutdown_now(); ret = 1; return; } }
/*** * load gnunet configuration */ void gg_load_configuration(GNUNET_gstData * d) { char *audiobackend_string; cfg = GNUNET_CONFIGURATION_create(); GNUNET_CONFIGURATION_load(cfg, "mediahelper.conf"); char *section = "MEDIAHELPER"; GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_IN", &d->jack_pp_in); GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "JACK_PP_OUT", &d->jack_pp_out); GNUNET_CONFIGURATION_get_value_string(cfg, "MEDIAHELPER", "AUDIOBACKEND", &audiobackend_string); // printf("abstring: %s \n", audiobackend_string); if ( audiobackend_string == "AUTO" ) { d->audiobackend = AUTO; } else if ( audiobackend_string = "JACK" ) { d->audiobackend = JACK; } else if ( audiobackend_string = "ALSA" ) { d->audiobackend = ALSA; } else if ( audiobackend_string = "FAKE" ) { d->audiobackend = FAKE; } else if ( audiobackend_string = "TEST" ) { d->audiobackend = TEST; } else { d->audiobackend = AUTO; } if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "REMOVESILENCE") == GNUNET_YES) { d->dropsilence = TRUE; } else { d->dropsilence = FALSE; } if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "NO_GN_HEADERS") == GNUNET_YES) { d->pure_ogg = TRUE; } else { d->pure_ogg = FALSE; } if (GNUNET_CONFIGURATION_get_value_yesno(cfg, "MEDIAHELPER", "USERTP") == GNUNET_YES) { d->usertp = TRUE; } else { d->usertp = FALSE; } // GNUNET_CONFIGURATION_write(cfg, "mediahelper.conf"); }
int main (int argc, char *argv[]) { int failureCount = 0; char *c; GNUNET_log_setup ("test_configuration", "WARNING", NULL); cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (cfg != NULL); if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) { FPRINTF (stderr, "%s", "Failed to parse configuration file\n"); GNUNET_CONFIGURATION_destroy (cfg); return 1; } failureCount += testConfig (); if (failureCount > 0) goto error; failureCount = testConfigFilenames (); if (failureCount > 0) goto error; if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) { FPRINTF (stderr, "%s", "Failed to write configuration file\n"); GNUNET_CONFIGURATION_destroy (cfg); return 1; } GNUNET_CONFIGURATION_destroy (cfg); GNUNET_assert (0 == UNLINK ("/tmp/gnunet-test.conf")); cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); return 1; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); return 1; } if (0 != strcmp (c, "YES")) { GNUNET_break (0); GNUNET_free (c); GNUNET_CONFIGURATION_destroy (cfg); return 1; } GNUNET_free (c); GNUNET_CONFIGURATION_destroy (cfg); /* Testing configuration diffs */ cfgDefault = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfgDefault, NULL)) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfgDefault); return 1; } /* Nothing changed in the new configuration */ failureCount += checkDiffs (cfgDefault, EDIT_NOTHING); /* Modify all entries of the last section */ failureCount += checkDiffs (cfgDefault, EDIT_SECTION); /* Add a new section */ failureCount += checkDiffs (cfgDefault, ADD_NEW_SECTION); /* Add a new entry to the last section */ failureCount += checkDiffs (cfgDefault, ADD_NEW_ENTRY); /* Modify all entries in the configuration */ failureCount += checkDiffs (cfgDefault, EDIT_ALL); GNUNET_CONFIGURATION_destroy (cfgDefault); error: if (failureCount != 0) { FPRINTF (stderr, "Test failed: %u\n", failureCount); return 1; } return 0; }
/** * Checking configuration diffs */ static int checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfgDefault, int option) { struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_CONFIGURATION_Handle *cfgDiffs; struct DiffsCBData cbData; int ret; char *diffsFileName; initDiffsCBData (&cbData); cfg = GNUNET_CONFIGURATION_create (); /* load defaults */ GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, NULL)); /* Modify configuration and save it */ cfgDiffs = editConfiguration (cfg, option); diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); if (diffsFileName == NULL) { GNUNET_break (0); GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfgDiffs); return 1; } GNUNET_CONFIGURATION_write_diffs (cfgDefault, cfg, diffsFileName); GNUNET_CONFIGURATION_destroy (cfg); /* Compare the dumped configuration with modifications done */ cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName)); if (0 != remove (diffsFileName)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove", diffsFileName); cbData.callBackOption = COMPARE; cbData.cfgDiffs = cfgDiffs; GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); if (1 == (ret = cbData.status)) { FPRINTF (stderr, "%s", "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); goto housekeeping; } cbData.cfgDiffs = cfg; GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); if ((ret = cbData.status) == 1) FPRINTF (stderr, "%s", "Incorrect Configuration Diffs: Data may be missing in diffs\n"); housekeeping: #if 0 cbData.section = NULL; cbData.callBackOption = PRINT; printf ("\nExpected Diffs:\n"); GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); cbData.section = NULL; printf ("\nActual Diffs:\n"); GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); #endif GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfgDiffs); GNUNET_free (diffsFileName); return ret; }