/** * Main function */ int main (int argc, char **argv) { struct GNUNET_CONFIGURATION_Handle *cfg; char pwd[PATH_MAX]; char *binary; uint64_t event_mask; result = GNUNET_SYSERR; event_mask = 0; cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_YES == GNUNET_CONFIGURATION_parse (cfg, "test_testbed_api_barriers.conf.in")); if (NULL == getcwd (pwd, PATH_MAX)) return 1; GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, "gnunet-service-test-barriers")); GNUNET_CONFIGURATION_set_value_string (cfg, "test-barriers","BINARY", binary); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, "test_testbed_api_barriers.conf")); GNUNET_CONFIGURATION_destroy (cfg); cfg = NULL; GNUNET_free (binary); binary = NULL; (void) GNUNET_TESTBED_test_run ("test_testbed_api_barriers", "test_testbed_api_barriers.conf", NUM_PEERS, event_mask, NULL, NULL, &test_master, NULL); (void) unlink ("test_testbed_api_barriers.conf"); if (GNUNET_OK != result) return 1; return 0; }
/** * Handler for SET_DEFAULT message from client, updates * default identity for some service. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_set_default_message (void *cls, const struct SetDefaultMessage *sdm) { struct Ego *ego; struct GNUNET_SERVICE_Client *client = cls; const char *str; str = (const char *) &sdm[1]; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_DEFAULT for service `%s' from client\n", str); for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == key_cmp (ego->pk, &sdm->private_key)) { GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, str, "DEFAULT_IDENTIFIER", ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); send_result_code (client, 0, NULL); GNUNET_SERVICE_client_continue (client); return; } } send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); GNUNET_SERVICE_client_continue (client); }
static char * generate_config (char *cfg_file, unsigned long long quota_in, unsigned long long quota_out) { char *networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkTypeString; char *in_name; char *out_name; char *fname = NULL; struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); int c; GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file); GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname); for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) { GNUNET_asprintf (&in_name, "%s_QUOTA_IN", networks[c]); GNUNET_asprintf (&out_name, "%s_QUOTA_OUT", networks[c]); GNUNET_CONFIGURATION_set_value_number (cfg, "ats", in_name, quota_in); GNUNET_CONFIGURATION_set_value_number (cfg, "ats", out_name, quota_out); GNUNET_free (in_name); GNUNET_free (out_name); } GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname)); GNUNET_CONFIGURATION_destroy (cfg); return fname; }
/** * Handler for SET_DEFAULT message from client, updates * default identity for some service. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_set_default_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_IDENTITY_SetDefaultMessage *sdm; uint16_t size; uint16_t name_len; struct Ego *ego; const char *str; size = ntohs (message->size); if (size <= sizeof (struct GNUNET_IDENTITY_SetDefaultMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } sdm = (const struct GNUNET_IDENTITY_SetDefaultMessage *) message; name_len = ntohs (sdm->name_len); GNUNET_break (0 == ntohs (sdm->reserved)); if (name_len + sizeof (struct GNUNET_IDENTITY_SetDefaultMessage) != size) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } str = (const char *) &sdm[1]; if ('\0' != str[name_len - 1]) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received SET_DEFAULT for service `%s' from client\n", str); for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == key_cmp (ego->pk, &sdm->private_key)) { GNUNET_CONFIGURATION_set_value_string (subsystem_cfg, str, "DEFAULT_IDENTIFIER", ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); send_result_code (client, 0, NULL); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } send_result_code (client, 1, _("Unknown ego specified for service (internal error)")); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
/** * Change the state of the sensor. * Write the change to file to make it persistent. * * @param sensor sensor info struct * @param state new enabled state: #GNUNET_YES / #GNUNET_NO */ static void set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state) { LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor `%s': Setting enabled to %d.\n", sensor->name, state); sensor->enabled = GNUNET_NO; GNUNET_assert (NULL != sensor->cfg); GNUNET_CONFIGURATION_set_value_string (sensor->cfg, sensor->name, "ENABLED", (GNUNET_YES == state) ? "YES" : "NO"); GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file); }
/** * Handler for DELETE message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_delete_message (void *cls, const struct DeleteMessage *dm) { struct Ego *ego; const char *name; char *fn; struct GNUNET_SERVICE_Client *client = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); name = (const char *) &dm[1]; for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, name)) { GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_delete, ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); fn = get_ego_filename (ego); if (0 != UNLINK (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); GNUNET_free (ego->identifier); ego->identifier = NULL; notify_listeners (ego); GNUNET_free (ego->pk); GNUNET_free (ego); send_result_code (client, 0, NULL); GNUNET_SERVICE_client_continue (client); return; } } send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVICE_client_continue (client); }
static char * generate_config (char *cfg_file, unsigned long long quota_in, unsigned long long quota_out) { char *fname = NULL; struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, cfg_file); GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname); GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_IN", quota_in); GNUNET_CONFIGURATION_set_value_number (cfg, "ats", "WAN_QUOTA_OUT", quota_out); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname)); GNUNET_CONFIGURATION_destroy (cfg); return fname; }
static int init () { struct GNUNET_CONFIGURATION_Handle *cfg; char pwd[PATH_MAX]; char *binary; cfg = GNUNET_CONFIGURATION_create (); if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, "test_arm_api_data.conf")) return GNUNET_SYSERR; if (NULL == getcwd (pwd, PATH_MAX)) return GNUNET_SYSERR; GNUNET_assert (0 < GNUNET_asprintf (&binary, "%s/%s", pwd, BINARY)); GNUNET_CONFIGURATION_set_value_string (cfg, SERVICE, "BINARY", binary); GNUNET_free (binary); if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, CFGFILENAME)) { GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; } GNUNET_CONFIGURATION_destroy (cfg); #if LOG_BACKOFF killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); if (NULL == (killLogFilePtr = FOPEN (killLogFileName, "w"))) { GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fopen", killLogFileName); GNUNET_free (killLogFileName); return GNUNET_SYSERR; } #endif return GNUNET_OK; }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { enum MHD_FLAG flags; struct GNUNET_CRYPTO_EcdsaPrivateKey *host_key; struct GNUNET_GNSRECORD_Data rd; char *zone_keyfile; namestore = GNUNET_NAMESTORE_connect (cfg); GNUNET_assert (NULL != namestore); flags = MHD_USE_DEBUG; mhd = MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, MHD_OPTION_END); GNUNET_assert (NULL != mhd); mhd_main (); tmp_cfgfile = GNUNET_DISK_mktemp ("test_gns_proxy_tmp.conf"); if (NULL == tmp_cfgfile) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create tmp cfg!\n"); do_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *)cfg, tmp_cfgfile)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to write tmp cfg\n"); do_shutdown (); return; } proxy_proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, NULL, "gnunet-gns-proxy", "gnunet-gns-proxy", "-c", tmp_cfgfile, NULL); if (NULL == proxy_proc) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unable to start proxy\n"); do_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns", "ZONEKEY", &zone_keyfile)) { GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n"); return; } host_key = GNUNET_CRYPTO_ecdsa_key_create_from_file (zone_keyfile); rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (GNUNET_DNSPARSER_TYPE_A, "127.0.0.1", (void**)&rd.data, &rd.data_size)); rd.record_type = GNUNET_DNSPARSER_TYPE_A; GNUNET_NAMESTORE_record_create (namestore, host_key, "www", &rd, &commence_testing, NULL); GNUNET_free ((void**)rd.data); GNUNET_free (zone_keyfile); GNUNET_free (host_key); }
/** * Handler for DELETE message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_delete_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_IDENTITY_DeleteMessage *dm; uint16_t size; uint16_t name_len; struct Ego *ego; const char *name; char *fn; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received DELETE message from client\n"); size = ntohs (message->size); if (size <= sizeof (struct GNUNET_IDENTITY_DeleteMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } dm = (const struct GNUNET_IDENTITY_DeleteMessage *) message; name = (const char *) &dm[1]; name_len = ntohs (dm->name_len); if ( (name_len + sizeof (struct GNUNET_IDENTITY_DeleteMessage) != size) || (0 != ntohs (dm->reserved)) || ('\0' != name[name_len - 1]) ) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, name)) { GNUNET_CONTAINER_DLL_remove (ego_head, ego_tail, ego); GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_delete, ego->identifier); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); fn = get_ego_filename (ego); if (0 != UNLINK (fn)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); GNUNET_free (fn); GNUNET_free (ego->identifier); ego->identifier = NULL; notify_listeners (ego); GNUNET_free (ego->pk); GNUNET_free (ego); send_result_code (client, 0, NULL); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
/** * Handler for RENAME message from client, creates * new identity. * * @param cls unused * @param client who sent the message * @param message the message received */ static void handle_rename_message (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { const struct GNUNET_IDENTITY_RenameMessage *rm; uint16_t size; uint16_t old_name_len; uint16_t new_name_len; struct Ego *ego; const char *old_name; const char *new_name; struct RenameContext rename_ctx; char *fn_old; char *fn_new; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received RENAME message from client\n"); size = ntohs (message->size); if (size <= sizeof (struct GNUNET_IDENTITY_RenameMessage)) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } rm = (const struct GNUNET_IDENTITY_RenameMessage *) message; old_name_len = ntohs (rm->old_name_len); new_name_len = ntohs (rm->new_name_len); old_name = (const char *) &rm[1]; new_name = &old_name[old_name_len]; if ( (old_name_len + new_name_len + sizeof (struct GNUNET_IDENTITY_RenameMessage) != size) || ('\0' != old_name[old_name_len - 1]) || ('\0' != new_name[new_name_len - 1]) ) { GNUNET_break (0); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } /* check if new name is already in use */ for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, new_name)) { send_result_code (client, 1, gettext_noop ("target name already exists")); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } /* locate old name and, if found, perform rename */ for (ego = ego_head; NULL != ego; ego = ego->next) { if (0 == strcmp (ego->identifier, old_name)) { fn_old = get_ego_filename (ego); GNUNET_free (ego->identifier); rename_ctx.old_name = old_name; rename_ctx.new_name = new_name; GNUNET_CONFIGURATION_iterate_sections (subsystem_cfg, &handle_ego_rename, &rename_ctx); if (GNUNET_OK != GNUNET_CONFIGURATION_write (subsystem_cfg, subsystem_cfg_file)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to write subsystem default identifier map to `%s'.\n"), subsystem_cfg_file); ego->identifier = GNUNET_strdup (new_name); fn_new = get_ego_filename (ego); if (0 != RENAME (fn_old, fn_new)) GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "rename", fn_old); GNUNET_free (fn_old); GNUNET_free (fn_new); notify_listeners (ego); send_result_code (client, 0, NULL); GNUNET_SERVER_receive_done (client, GNUNET_OK); return; } } /* failed to locate old name */ send_result_code (client, 1, gettext_noop ("no matching ego found")); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
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; }