static void nick_2_cont (void *cls, int32_t success, const char *emsg) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Nick added : %s\n", (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_1, 1, s_rd_1, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey, s_name_2, 1, s_rd_2, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); GNUNET_NAMESTORE_records_store (nsh, privkey2, s_name_3, 1, s_rd_3, &put_cont, NULL); }
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; }
static void empty_zone_end (void *cls) { char *hostkey_file; GNUNET_assert (nsh == cls); zi = NULL; GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); if (NULL == nsqe) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Namestore cannot store no block\n")); } }
static int check () { char *binary_name; char *config_file_name; GNUNET_asprintf (&binary_name, "test-testing-topology-%s", topology_string); GNUNET_asprintf (&config_file_name, "test_testing_data_topology_%s.conf", topology_string); int ret; char *const argv[] = { binary_name, "-c", config_file_name, NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, binary_name, "nohelp", options, &run, &ok); if (ret != GNUNET_OK) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "`test-testing-topology-%s': Failed with error code %d\n", topology_string, ret); } GNUNET_free (binary_name); GNUNET_free (config_file_name); return ok; }
static void notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) { struct PeerContext *p = cls; /* Find PeerContext */ int no = 0; struct PeerContext *p2 = NULL; if (p != NULL) { GNUNET_assert (p->tth != NULL); p2 = find_peer_context (p->tth, peer); no = p->no; } char *p2_s; if (p2 != NULL) GNUNET_asprintf (&p2_s, "%u (`%s')", p2->no, GNUNET_i2s (&p2->id)); else GNUNET_asprintf (&p2_s, "`%s'", GNUNET_i2s (peer)); GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", "Peers %s disconnected from peer %u (`%s')\n", p2_s, no, GNUNET_i2s (&p->id)); GNUNET_free (p2_s); if (p == NULL) return; if (p->nd != NULL) p->nd (p->cb_cls, peer); }
/** * Test killing via pipe. */ static int check_instant_kill () { char *fn; #if !WINDOWS GNUNET_asprintf (&fn, "cat"); #else GNUNET_asprintf (&fn, "w32cat"); #endif hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) { GNUNET_free (fn); return 1; } proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, "gnunet-service-resolver", "-", NULL); if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); } GNUNET_free (fn); GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (proc)); GNUNET_OS_process_destroy (proc); proc = NULL; GNUNET_DISK_pipe_close (hello_pipe_stdout); GNUNET_DISK_pipe_close (hello_pipe_stdin); return 0; }
static void run_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { char *fn; const struct GNUNET_DISK_FileHandle *stdout_read_handle; const struct GNUNET_DISK_FileHandle *wh; #if !WINDOWS GNUNET_asprintf (&fn, "cat"); #else GNUNET_asprintf (&fn, "w32cat"); #endif hello_pipe_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_YES, GNUNET_NO); hello_pipe_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES); if ((hello_pipe_stdout == NULL) || (hello_pipe_stdin == NULL)) { GNUNET_break (0); ok = 1; GNUNET_free (fn); return; } proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ERR, hello_pipe_stdin, hello_pipe_stdout, fn, "test_gnunet_echo_hello", "-", NULL); GNUNET_free (fn); /* Close the write end of the read pipe */ GNUNET_DISK_pipe_close_end (hello_pipe_stdout, GNUNET_DISK_PIPE_END_WRITE); /* Close the read end of the write pipe */ GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_READ); wh = GNUNET_DISK_pipe_handle (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); /* Write the test_phrase to the cat process */ if (GNUNET_DISK_file_write (wh, test_phrase, strlen (test_phrase) + 1) != strlen (test_phrase) + 1) { GNUNET_break (0); ok = 1; return; } /* Close the write end to end the cycle! */ GNUNET_DISK_pipe_close_end (hello_pipe_stdin, GNUNET_DISK_PIPE_END_WRITE); stdout_read_handle = GNUNET_DISK_pipe_handle (hello_pipe_stdout, GNUNET_DISK_PIPE_END_READ); die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1), &end_task, NULL); GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_read_handle, &read_call, (void *) stdout_read_handle); }
/** * Obtain the location of ".my.cnf". * * @param cfg our configuration * @param section the section * @return NULL on error */ static char * get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) { char *cnffile; char *home_dir; struct stat st; #ifndef WINDOWS struct passwd *pw; #endif int configured; #ifndef WINDOWS pw = getpwuid (getuid ()); if (!pw) { GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_ERROR, "mysql", "getpwuid"); return NULL; } if (GNUNET_YES == GNUNET_CONFIGURATION_have_value (cfg, section, "CONFIG")) { GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, section, "CONFIG", &cnffile)); configured = GNUNET_YES; } else { home_dir = GNUNET_strdup (pw->pw_dir); GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); GNUNET_free (home_dir); configured = GNUNET_NO; } #else home_dir = (char *) GNUNET_malloc (_MAX_PATH + 1); plibc_conv_to_win_path ("~/", home_dir); GNUNET_asprintf (&cnffile, "%s/.my.cnf", home_dir); GNUNET_free (home_dir); configured = GNUNET_NO; #endif GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "mysql", _("Trying to use file `%s' for MySQL configuration.\n"), cnffile); if ((0 != STAT (cnffile, &st)) || (0 != ACCESS (cnffile, R_OK)) || (!S_ISREG (st.st_mode))) { if (configured == GNUNET_YES) GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "mysql", _("Could not access file `%s': %s\n"), cnffile, STRERROR (errno)); GNUNET_free (cnffile); return NULL; } return cnffile; }
static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name) { struct GNUNET_GNSRECORD_Data rd; struct GNUNET_CRYPTO_EcdsaPublicKey pub; if (NULL == name) return; if (NULL == ego) return; if (0 == strcmp (name, "phone-ego")) { GNUNET_IDENTITY_ego_get_public_key (ego, &pub); GNUNET_asprintf (&gns_name, "phone.%s", GNUNET_GNSRECORD_pkey_to_zkey (&pub)); phone = GNUNET_CONVERSATION_phone_create (cfg, ego, &phone_event_handler, NULL); GNUNET_assert (NULL != phone); memset (&rd, 0, sizeof (rd)); GNUNET_CONVERSATION_phone_get_record (phone, &rd); GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); rd.expiration_time = UINT64_MAX; qe = GNUNET_NAMESTORE_records_store (ns, GNUNET_IDENTITY_ego_get_private_key (ego), "phone" /* GNS label */, 1, &rd, &namestore_put_cont, NULL); return; } if (0 == strcmp (name, "caller-ego")) { GNUNET_IDENTITY_ego_get_public_key (ego, &pub); GNUNET_asprintf (&gns_caller_id, "%s", GNUNET_GNSRECORD_pkey_to_zkey (&pub)); call = GNUNET_CONVERSATION_call_start (cfg, ego, ego, gns_name, &call_speaker, &call_mic, &call_event_handler, NULL); return; } }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { char *hostkey_file; struct GNUNET_TIME_Absolute et; endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,&endbadly, NULL); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_CRYPTO_rsa_key_get_public(privkey, &pubkey); GNUNET_CRYPTO_hash(&pubkey, sizeof (pubkey), &zone); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_rsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); GNUNET_CRYPTO_rsa_key_get_public(privkey2, &pubkey2); GNUNET_CRYPTO_hash(&pubkey2, sizeof (pubkey), &zone2); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 1\n"); GNUNET_asprintf(&s_name_1, "dummy1"); s_rd_1 = create_record(1); et.abs_value = s_rd_1[0].expiration_time; sig_1 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_1, s_rd_1, 1); GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_1, s_rd_1, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 2 \n"); GNUNET_asprintf(&s_name_2, "dummy2"); s_rd_2 = create_record(1); et.abs_value = s_rd_2[0].expiration_time; sig_2 = GNUNET_NAMESTORE_create_signature(privkey, et, s_name_2, s_rd_2, 1); GNUNET_NAMESTORE_record_create(nsh, privkey, s_name_2, s_rd_2, &put_cont, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created record 3\n"); /* name in different zone */ GNUNET_asprintf(&s_name_3, "dummy3"); s_rd_3 = create_record(1); et.abs_value = s_rd_3[0].expiration_time; sig_3 = GNUNET_NAMESTORE_create_signature(privkey2, et, s_name_3, s_rd_3, 1); GNUNET_NAMESTORE_record_put (nsh, &pubkey2, s_name_3, GNUNET_TIME_UNIT_FOREVER_ABS, 1, s_rd_3, sig_3, &put_cont, NULL); }
/** * Callback called from the zone iterator when we iterate over * the empty zone. Check that we got no records and then * start the actual tests by filling the zone. */ static void empty_zone_proc (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) { char *hostkey_file; GNUNET_assert (nsh == cls); if (NULL != zone) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected empty zone but received zone private key\n")); GNUNET_break (0); if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } if ((NULL != label) || (NULL != rd) || (0 != rd_count)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Expected no zone content but received data\n")); GNUNET_break (0); if (endbadly_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (endbadly_task); endbadly_task = GNUNET_SCHEDULER_add_now (&endbadly, NULL); return; } zi = NULL; GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, "HGU0A0VCU334DN7F2I9UIUMVQMM7JMSD142LIMNUGTTV9R0CF4EG.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey2 = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey2 != NULL); nsqe = GNUNET_NAMESTORE_set_nick (nsh, privkey, ZONE_NICK_1, &nick_1_cont, &privkey); if (NULL == nsqe) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Namestore cannot store no block\n")); } }
static void write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves) { struct GNUNET_DISK_FileHandle *f; char * gfn; char *data; int c_s; GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn); fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n", lp->peer->no, gfn); f = GNUNET_DISK_file_open (gfn, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); GNUNET_free (gfn); return; } /* Write header */ if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE))) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); for (c_s = 0; c_s < slaves; c_s++) { GNUNET_asprintf (&data, "%s"\ "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\ "%s\n", (0 == c_s) ? "plot " :"", fs[c_s], LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT, lp->peer->no, c_s, fs[c_s], LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN, lp->peer->no, c_s, (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1"); if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); GNUNET_free (data); } if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); else GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); GNUNET_free (gfn); }
static void key_iterator (void *cls, const struct GNUNET_HashCode *key, const char *proof, int accepting, unsigned int num_edges, const struct REGEX_BLOCK_Edge *edges) { unsigned int i; struct IteratorContext *ctx = cls; char *out_str; char *state_id = GNUNET_strdup (GNUNET_h2s (key)); GNUNET_assert (NULL != proof); if (GNUNET_YES == ctx->should_save_graph) { if (GNUNET_YES == accepting) GNUNET_asprintf (&out_str, "\"%s\" [shape=doublecircle]\n", state_id); else GNUNET_asprintf (&out_str, "\"%s\" [shape=circle]\n", state_id); fwrite (out_str, strlen (out_str), 1, ctx->graph_filep); GNUNET_free (out_str); for (i = 0; i < num_edges; i++) { transition_counter++; GNUNET_asprintf (&out_str, "\"%s\" -> \"%s\" [label = \"%s (%s)\"]\n", state_id, GNUNET_h2s (&edges[i].destination), edges[i].label, proof); fwrite (out_str, strlen (out_str), 1, ctx->graph_filep); GNUNET_free (out_str); } } else { for (i = 0; i < num_edges; i++) transition_counter++; } for (i = 0; i < ctx->string_count; i++) { if (0 == strcmp (proof, ctx->strings[i])) ctx->match_count++; } if (GNUNET_OK != REGEX_BLOCK_check_proof (proof, strlen (proof), key)) { ctx->error++; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Proof check failed: proof: %s key: %s\n", proof, state_id); } GNUNET_free (state_id); }
/** * Create a HTTP address from a socketaddr * * @param protocol protocol * @param addr sockaddr * address * @param addrlen length of the address * @return the string */ char * http_common_address_from_socket (const char *protocol, const struct sockaddr *addr, socklen_t addrlen) { char *res; GNUNET_asprintf(&res, "%s://%s", protocol, GNUNET_a2s (addr, addrlen)); return res; }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { struct GNUNET_CRYPTO_RsaSignature signature; struct GNUNET_NAMESTORE_RecordData rd; char *hostkey_file; const char * name = "dummy.dummy.gnunet"; endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &endbadly, NULL); GNUNET_asprintf (&hostkey_file, "zonefiles%s%s", DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s' \n", hostkey_file); privkey = GNUNET_CRYPTO_rsa_key_create_from_file (hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); GNUNET_CRYPTO_rsa_key_get_public (privkey, &pubkey); GNUNET_CRYPTO_short_hash (&pubkey, sizeof (pubkey), &zone); memset (&signature, '\0', sizeof (signature)); rd.expiration_time = GNUNET_TIME_absolute_get().abs_value; rd.record_type = TEST_RECORD_TYPE; rd.data_size = TEST_RECORD_DATALEN; rd.data = GNUNET_malloc (TEST_RECORD_DATALEN); memset ((char *) rd.data, 'a', TEST_RECORD_DATALEN); nsh = GNUNET_NAMESTORE_connect (cfg); GNUNET_break (NULL != nsh); nsqe = GNUNET_NAMESTORE_record_put (nsh, &pubkey, name, GNUNET_TIME_UNIT_FOREVER_ABS, 1, &rd, &signature, &put_cont, (void*) name); GNUNET_free ((void *)rd.data); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_GNSRECORD_Block *block; struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; /* load privat key */ char *hostkey_file; GNUNET_asprintf(&hostkey_file, "zonefiles%s%s", DIR_SEPARATOR_STR, "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using zonekey file `%s'\n", hostkey_file); privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); GNUNET_free (hostkey_file); GNUNET_assert (privkey != NULL); struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get(); /* get public key */ GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); /* create record */ s_name = "DUMMY.dummy.gnunet"; s_rd = create_record (RECORDS); /* Create block */ GNUNET_assert (NULL != (block = GNUNET_GNSRECORD_block_create (privkey, expire,s_name, s_rd, RECORDS))); GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_verify (block)); GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_block_decrypt (block, &pubkey, s_name, &rd_decrypt_cb, s_name)); GNUNET_free (block); }
/** * Extracts the test filename from an absolute file name and removes the extension * @param file absolute file name * @param dest where to store result */ void GNUNET_TRANSPORT_TESTING_get_test_name (const char *file, char **dest) { char *filename = extract_filename (file); char *backup = filename; char *dotexe; if (filename == NULL) goto fail; /* remove "lt-" */ filename = strstr (filename, "tes"); if (filename == NULL) goto fail; /* remove ".exe" */ if (NULL != (dotexe = strstr (filename, ".exe"))) dotexe[0] = '\0'; goto suc; fail: (*dest) = NULL; return; suc: /* create filename */ GNUNET_asprintf (dest, "%s", filename); GNUNET_free (backup); }
/** * Extracts the plugin name from an absolute file name and the test name * * @param file absolute file name * @param test test name * @param dest where to store result */ void GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, const char *test, char **dest) { char *filename; char *dotexe; char *e = extract_filename (file); char *t = extract_filename (test); if (NULL == e) goto fail; /* remove "lt-" */ filename = strstr (e, "tes"); if (NULL == filename) goto fail; /* remove ".exe" */ if (NULL != (dotexe = strstr (filename, ".exe"))) dotexe[0] = '\0'; /* find last _ */ filename = strstr (filename, t); if (NULL == filename) goto fail; /* copy plugin */ filename += strlen (t); if ('\0' != *filename) filename++; GNUNET_asprintf (dest, "%s", filename); goto suc; fail: (*dest) = NULL; suc: GNUNET_free (t); GNUNET_free (e); }
static void gather_log_data () { char *peer_number; char *connect_number; struct GNUNET_OS_Process *mem_process; GNUNET_asprintf (&peer_number, "%llu", num_peers); GNUNET_asprintf (&connect_number, "%llu", expected_connections); mem_process = GNUNET_OS_start_process (NULL, NULL, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, "./memsize.pl", "memsize.pl", "totals.txt", peer_number, connect_number, NULL); GNUNET_OS_process_wait (mem_process); GNUNET_OS_process_destroy (mem_process); mem_process = NULL; }
static void end () { unsigned long long delta; char *value_name; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; FPRINTF (stderr, "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta); GNUNET_asprintf (&value_name, "reliable_%s", test_plugin); GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta), "kb/s"); GNUNET_free (value_name); if (die_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (die_task); if (th != NULL) GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); th = NULL; if (cc != NULL) GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); }
/** * 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; }
/** * Add another child node to the tree. * * @param parent parent of the child, NULL for top level * @param filename name of the file or directory * @param is_directory GNUNET_YES for directories * @return new entry that was just created */ static struct GNUNET_FS_ShareTreeItem * expand_tree (struct GNUNET_FS_ShareTreeItem *parent, const char *filename, int is_directory) { struct GNUNET_FS_ShareTreeItem *chld; size_t slen; chld = GNUNET_malloc (sizeof (struct GNUNET_FS_ShareTreeItem)); chld->parent = parent; chld->filename = GNUNET_strdup (filename); GNUNET_asprintf (&chld->short_filename, "%s%s", GNUNET_STRINGS_get_short_name (filename), is_directory == GNUNET_YES ? "/" : ""); /* make sure we do not end with '//' */ slen = strlen (chld->short_filename); if ( (slen >= 2) && (chld->short_filename[slen-1] == '/') && (chld->short_filename[slen-2] == '/') ) chld->short_filename[slen-1] = '\0'; chld->is_directory = is_directory; if (NULL != parent) GNUNET_CONTAINER_DLL_insert (parent->children_head, parent->children_tail, chld); return chld; }
/** * Send the 'SUBMIT_PAGE'. * * @param info information string to send to the user * @param request request information * @param connection connection to use */ static int fill_s_reply (const char *info, struct Request *request, struct MHD_Connection *connection) { int ret; char *reply; struct MHD_Response *response; GNUNET_asprintf (&reply, SUBMIT_PAGE, info, info); /* return static form */ response = MHD_create_response_from_buffer (strlen (reply), (void *) reply, MHD_RESPMEM_MUST_FREE); MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, MIME_HTML); ret = MHD_queue_response (connection, MHD_HTTP_OK, response); MHD_destroy_response (response); return ret; }
/** * Method called to inform about the egos of this peer. * * When used with #GNUNET_IDENTITY_connect, this function is * initially called for all egos and then again whenever a * ego's name changes or if it is deleted. At the end of * the initial pass over all egos, the function is once called * with 'NULL' for @a ego. That does NOT mean that the callback won't * be invoked in the future or that there was an error. * * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get, * this function is only called ONCE, and 'NULL' being passed in * @a ego does indicate an error (i.e. name is taken or no default * value is known). If @a ego is non-NULL and if '*ctx' * is set in those callbacks, the value WILL be passed to a subsequent * call to the identity callback of #GNUNET_IDENTITY_connect (if * that one was not NULL). * * When an identity is renamed, this function is called with the * (known) @a ego but the NEW @a name. * * When an identity is deleted, this function is called with the * (known) ego and "NULL" for the @a name. In this case, * the @a ego is henceforth invalid (and the @a ctx should also be * cleaned up). * * @param cls closure * @param ego ego handle * @param ctx context for application to store data for this ego * (during the lifetime of this process, initially NULL) * @param name name assigned by the user for this ego, * NULL if the user just deleted the ego and it * must thus no longer be used */ static void identity_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name) { const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; struct GNUNET_GNSRECORD_Data rd; char *rd_string; char *peername; if (NULL == name) return; if (NULL == ego) { if (NULL == qe) { fprintf (stderr, "Failed to find master-zone ego\n"); GNUNET_SCHEDULER_shutdown (); return; } GNUNET_IDENTITY_disconnect (identity); identity = NULL; return; } GNUNET_assert (NULL != name); if (0 != strcmp (name, "master-zone")) { fprintf (stderr, "Unexpected name %s\n", name); return; } zone_key = GNUNET_IDENTITY_ego_get_private_key (ego); rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; peername = GNUNET_strdup (GNUNET_i2s_full (&id)); GNUNET_asprintf (&rd_string, "6 %s %s", peername, "www"); GNUNET_free (peername); GNUNET_assert (GNUNET_OK == GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN, rd_string, (void**) &rd.data, &rd.data_size)); rd.record_type = GNUNET_GNSRECORD_TYPE_VPN; qe = GNUNET_NAMESTORE_records_store (namestore, zone_key, "www", 1, &rd, &commence_testing, NULL); GNUNET_free ((void**)rd.data); GNUNET_free (rd_string); }
/** * Main state machine that goes over all options and * runs the next requested function. * * @param cls unused * @param tc scheduler context */ static void state_machine (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { tt = GNUNET_SCHEDULER_NO_TASK; if (NULL != put_uri) { GPI_plugins_load (cfg); if (GNUNET_SYSERR == parse_hello_uri (put_uri)) fprintf (stderr, _("Invalid URI `%s'\n"), put_uri); GNUNET_free (put_uri); put_uri = NULL; return; } if (GNUNET_YES == get_info) { get_info = GNUNET_NO; GPI_plugins_load (cfg); pic = GNUNET_PEERINFO_iterate (peerinfo, NULL, TIMEOUT, &print_peer_info, NULL); return; } if (GNUNET_YES == get_self) { struct GNUNET_CRYPTO_HashAsciiEncoded enc; get_self = GNUNET_NO; GNUNET_CRYPTO_hash_to_enc (&my_peer_identity.hashPubKey, &enc); if (be_quiet) printf ("%s\n", (char *) &enc); else printf (_("I am peer `%s'.\n"), (const char *) &enc); } if (GNUNET_YES == get_uri) { struct GetUriContext *guc; char *pkey; guc = GNUNET_malloc (sizeof (struct GetUriContext)); pkey = GNUNET_CRYPTO_rsa_public_key_to_string (&my_public_key); GNUNET_asprintf (&guc->uri, "%s%s", HELLO_URI_PREFIX, pkey); GNUNET_free (pkey); GPI_plugins_load (cfg); pic = GNUNET_PEERINFO_iterate (peerinfo, &my_peer_identity, TIMEOUT, &print_my_uri, guc); get_uri = GNUNET_NO; return; } GNUNET_SCHEDULER_shutdown (); }
/** * Function called when the service shuts down. Unloads our namestore * plugin. * * @param api api to unload */ static void unload_plugin (struct GNUNET_NAMESTORE_PluginFunctions *api) { char *libname; GNUNET_asprintf (&libname, "libgnunet_plugin_namestore_%s", plugin_name); GNUNET_break (NULL == GNUNET_PLUGIN_unload (libname, api)); GNUNET_free (libname); }
int main (int argc, char *argv[]) { int ret; GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); GNUNET_log_setup (test_name, "WARNING", NULL); tth = GNUNET_TRANSPORT_TESTING_init (); GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); ret = check (); GNUNET_free (cfg_file_p1); GNUNET_free (cfg_file_p2); GNUNET_free (test_name); GNUNET_TRANSPORT_TESTING_done (tth); return ret; }
/** * Get the filename under which we would store the GNUNET_HELLO_Message * for the given host and protocol. * * @param id peer for which we need the filename for the HELLO * @return filename of the form DIRECTORY/HOSTID */ static char * get_host_filename (const struct GNUNET_PeerIdentity *id) { struct GNUNET_CRYPTO_HashAsciiEncoded fil; char *fn; GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); GNUNET_asprintf (&fn, "%s%s%s", networkIdDirectory, DIR_SEPARATOR_STR, &fil); return fn; }
/** * Connect both PUT and GET connection for a session * * @param s the session to connect * @return GNUNET_OK on success, GNUNET_SYSERR otherwise */ static int client_connect (struct Session *s) { struct HTTP_Client_Plugin *plugin = s->plugin; int res = GNUNET_OK; /* create url */ if (NULL == http_common_plugin_address_to_string (NULL, s->addr, s->addrlen)) { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Invalid address peer `%s'\n", GNUNET_i2s (&s->target)); return GNUNET_SYSERR; } GNUNET_asprintf (&s->url, "%s/%s;%u", http_common_plugin_address_to_string (plugin, s->addr, s->addrlen), GNUNET_h2s_full (&plugin->env->my_identity->hashPubKey), plugin->last_tag); plugin->last_tag++; GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Initiating outbound session peer `%s' using address `%s'\n", GNUNET_i2s (&s->target), s->url); if ((GNUNET_SYSERR == client_connect_get (s)) || (GNUNET_SYSERR == client_connect_put (s))) { GNUNET_break (0); return GNUNET_SYSERR; } GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, "Session %p: connected with connections GET %p and PUT %p\n", s, s->client_get, s->client_put); /* Perform connect */ plugin->cur_connections += 2; GNUNET_STATISTICS_set (plugin->env->stats, "# HTTP client connections", plugin->cur_connections, GNUNET_NO); /* Re-schedule since handles have changed */ if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel (plugin->client_perform_task); plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; } plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin); return res; }
/** * Main function */ int main (int argc, char **argv) { char *argv2[] = { "test_testbed_api_testbed_run", "-c", NULL, NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; char *testname; char *config_filename; int ret; if (NULL == (testname = strrchr (argv[0], (int) '_'))) { GNUNET_break (0); return 1; } testname++; testname = GNUNET_strdup (testname); #ifdef MINGW { char *period; /* check and remove .exe extension */ period = strrchr (testname, (int) '.'); if (NULL != period) *period = '\0'; else GNUNET_break (0); /* Windows with no .exe? */ } #endif if (0 == strcmp ("waitforever", testname)) wait_forever = GNUNET_YES; if ( (GNUNET_YES != wait_forever) && (0 != strcmp ("run", testname)) ) { GNUNET_asprintf (&config_filename, "test_testbed_api_testbed_run_%s.conf", testname); } else config_filename = GNUNET_strdup ("test_testbed_api.conf"); GNUNET_free (testname); argv2[2] = config_filename; result = GNUNET_SYSERR; ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, "test_testbed_api_testbed_run", "nohelp", options, &run, NULL); GNUNET_free (config_filename); if ((GNUNET_OK != ret) || (GNUNET_OK != result)) return 1; return 0; }