/** * Append our port and forward the result. * * @param cls the 'struct PrettyPrinterContext*' * @param hostname hostname part of the address */ static void append_port (void *cls, const char *hostname) { struct PrettyPrinterContext *ppc = cls; static char rbuf[INET6_ADDRSTRLEN + 13]; if (hostname == NULL) { ppc->asc (ppc->asc_cls, NULL); GNUNET_free (ppc); return; } #if !BUILD_HTTPS const char *protocol = "http"; #else const char *protocol = "https"; #endif GNUNET_assert ((strlen (hostname) + 7) < (INET6_ADDRSTRLEN + 13)); if (ppc->addrlen == sizeof (struct IPv6HttpAddress)) { if (ppc->numeric == GNUNET_YES) GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port); else { if (strchr(hostname, ':') != NULL) GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, hostname, ppc->port); else GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port); } } else if (ppc->addrlen == sizeof (struct IPv4HttpAddress)) GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, hostname, ppc->port); ppc->asc (ppc->asc_cls, rbuf); }
/** * Function called for a quick conversion of the binary address to * a numeric address. Note that the caller must not free the * address and that the next call to this function is allowed * to override the address again. * * @param cls closure * @param addr binary address * @param addrlen length of the address * @return string representing the same address */ const char * http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) { struct IPv4HttpAddress *a4; struct IPv6HttpAddress *a6; char *address; static char rbuf[INET6_ADDRSTRLEN + 13]; uint16_t port; int res = 0; if (addrlen == sizeof (struct IPv6HttpAddress)) { a6 = (struct IPv6HttpAddress *) addr; address = GNUNET_malloc (INET6_ADDRSTRLEN); GNUNET_assert (NULL != inet_ntop (AF_INET6, &a6->ipv6_addr, address, INET6_ADDRSTRLEN)); port = ntohs (a6->u6_port); } else if (addrlen == sizeof (struct IPv4HttpAddress)) { a4 = (struct IPv4HttpAddress *) addr; address = GNUNET_malloc (INET_ADDRSTRLEN); GNUNET_assert (NULL != inet_ntop (AF_INET, &(a4->ipv4_addr), address, INET_ADDRSTRLEN)); port = ntohs (a4->u4_port); } else { /* invalid address */ GNUNET_break (0); return NULL; } #if !BUILD_HTTPS char *protocol = "http"; #else char *protocol = "https"; #endif GNUNET_assert (strlen (address) + 7 < (INET6_ADDRSTRLEN + 13)); if (addrlen == sizeof (struct IPv6HttpAddress)) res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://[%s]:%u/", protocol, address, port); else if (addrlen == sizeof (struct IPv4HttpAddress)) res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s://%s:%u/", protocol, address, port); GNUNET_free (address); GNUNET_assert (res != 0); return rbuf; }
/** * Display progress bar (if tty). * * @param x current position in the download * @param n total size of the download * @param w desired number of steps in the progress bar */ static void display_bar (unsigned long long x, unsigned long long n, unsigned int w) { char buf[w + 20]; unsigned int p; unsigned int endeq; float ratio_complete; #if !WINDOWS if (0 == isatty (1)) return; #else if (FILE_TYPE_CHAR != GetFileType (GetStdHandle (STD_OUTPUT_HANDLE))) return; #endif ratio_complete = x/(float)n; endeq = ratio_complete * w; GNUNET_snprintf (buf, sizeof (buf), "%3d%% [", (int)(ratio_complete*100) ); for (p=0; p<endeq; p++) strcat (buf, "="); for (p=endeq; p<w; p++) strcat (buf, " "); strcat (buf, "]\r"); printf ("%s", buf); fflush(stdout); }
/** * Function called by for each matching record. * * @param cls closure * @param zone_key public key of the zone * @param expire when does the corresponding block in the DHT expire (until * when should we never do a DHT lookup for the same name again)? * @param name name that is being mapped (at most 255 characters long) * @param rd_count number of entries in 'rd' array * @param rd array of records with data to store * @param signature signature of the record block, NULL if signature is unavailable (i.e. * because the user queried for a particular record type only) */ static void test_record (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, struct GNUNET_TIME_Absolute expire, const char *name, unsigned int rd_count, const struct GNUNET_NAMESTORE_RecordData *rd, const struct GNUNET_CRYPTO_RsaSignature *signature) { int *idp = cls; int id = *idp; struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded tzone_key; char tname[64]; unsigned int trd_count = 1 + (id % 1024); struct GNUNET_CRYPTO_RsaSignature tsignature; unsigned int i; GNUNET_snprintf (tname, sizeof (tname), "a%u", (unsigned int ) id); for (i=0;i<trd_count;i++) { GNUNET_assert (rd[i].data_size == id % 10); GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); GNUNET_assert (rd[i].record_type == 1 + (id % 13)); GNUNET_assert (rd[i].flags == (id % 7)); } memset (&tzone_key, (id % 241), sizeof (tzone_key)); memset (&tsignature, (id % 243), sizeof (tsignature)); GNUNET_assert (0 == strcmp (name, tname)); GNUNET_assert (0 == memcmp (&tzone_key, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))); GNUNET_assert (0 == memcmp (&tsignature, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature))); }
static void put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) { struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded zone_key; struct GNUNET_TIME_Absolute expire; char name[64]; unsigned int rd_count = 1 + (id % 1024); struct GNUNET_NAMESTORE_RecordData rd[rd_count]; struct GNUNET_CRYPTO_RsaSignature signature; unsigned int i; GNUNET_snprintf (name, sizeof (name), "a%u", (unsigned int ) id); expire = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES); for (i=0;i<rd_count;i++) { rd[i].data = "Hello World"; rd[i].data_size = id % 10; rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value; rd[i].record_type = 1 + (id % 13); rd[i].flags = (id % 7); } memset (&zone_key, (id % 241), sizeof (zone_key)); memset (&signature, (id % 243), sizeof (signature)); GNUNET_assert (GNUNET_OK == nsp->put_records (nsp->cls, &zone_key, expire, name, rd_count, rd, &signature)); }
int main (int argc, char *argv[]) { char cfg_name[128]; char *const xargv[] = { "test-plugin-namestore", "-c", cfg_name, NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); GNUNET_log_setup ("test-plugin-namestore", "WARNING", NULL); plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_plugin_namestore_%s.conf", plugin_name); GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, "test-plugin-namestore", "nohelp", options, &run, NULL); if (ok != 0) FPRINTF (stderr, "Missed some testcases: %d\n", ok); //GNUNET_DISK_directory_remove ("/tmp/gnunet-test-plugin-namestore-sqlite"); return ok; }
static void test_record (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *private_key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd) { int *idp = cls; int id = *idp; struct GNUNET_CRYPTO_EcdsaPrivateKey tzone_private_key; char tname[64]; unsigned int trd_count = 1 + (id % 1024); unsigned int i; GNUNET_snprintf (tname, sizeof (tname), "a%u", (unsigned int ) id); for (i=0;i<trd_count;i++) { GNUNET_assert (rd[i].data_size == id % 10); GNUNET_assert (0 == memcmp ("Hello World", rd[i].data, id % 10)); GNUNET_assert (rd[i].record_type == 1 + (id % 13)); GNUNET_assert (rd[i].flags == 0); } memset (&tzone_private_key, (id % 241), sizeof (tzone_private_key)); GNUNET_assert (0 == strcmp (label, tname)); GNUNET_assert (0 == memcmp (&tzone_private_key, private_key, sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))); }
/** * Convert a given address to a human-readable format. Note that the * return value will be overwritten on the next call to this function. * * @param address the address to convert * @return statically allocated (!) human-readable address */ const char * GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) { struct GNUNET_TRANSPORT_PluginFunctions *api; static char unable_to_show[1024]; static const char *s; if (NULL == address) return "<NULL>"; if (0 == address->address_length) return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */ api = GST_plugins_printer_find (address->transport_name); if (NULL == api) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to find transport plugin `%s'\n", address->transport_name); return "<plugin unknown>"; } if (0 == address->address_length) { GNUNET_snprintf (unable_to_show, sizeof (unable_to_show), "<unable to stringify %u-byte long address of %s transport>", (unsigned int) address->address_length, address->transport_name); return unable_to_show; } return (NULL != (s = api->address_to_string (NULL, address->address, address->address_length)) ? s : "<invalid>"); }
int main (int argc, char *argv[]) { char cfg_name[128]; char *const xargv[] = { "perf-datacache", "-c", cfg_name, NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; GNUNET_log_setup ("perf-datacache", "WARNING", NULL); plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); GNUNET_snprintf (cfg_name, sizeof (cfg_name), "perf_datacache_data_%s.conf", plugin_name); GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv, "perf-datacache", "nohelp", options, &run, NULL); if ( (0 != ok) && (77 != ok) ) FPRINTF (stderr, "Missed some perfcases: %d\n", ok); return ok; }
/** * Test our plugin's configuration (NAT traversal, etc.). * * @param cfg configuration to test */ static void do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg) { char *plugins; char *tok; unsigned long long bnd_port; unsigned long long adv_port; struct TestContext *tc; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins", &plugins)) { FPRINTF (stderr, "%s", _ ("No transport plugins configured, peer will never communicate\n")); ret = 4; return; } for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " ")) { char section[12 + strlen (tok)]; GNUNET_snprintf (section, sizeof (section), "transport-%s", tok); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port)) { FPRINTF (stderr, _("No port configured for plugin `%s', cannot test it\n"), tok); continue; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT", &adv_port)) adv_port = bnd_port; if (NULL == resolver) resolver = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-resolver", "gnunet-service-resolver", NULL); resolver_users++; GNUNET_RESOLVER_connect (cfg); tc = GNUNET_malloc (sizeof (struct TestContext)); tc->name = GNUNET_strdup (tok); tc->tst = GNUNET_NAT_test_start (cfg, (0 == strcasecmp (tok, "udp")) ? GNUNET_NO : GNUNET_YES, (uint16_t) bnd_port, (uint16_t) adv_port, &result_callback, tc); if (NULL == tc->tst) { display_test_result (tc, GNUNET_SYSERR); continue; } tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc); } GNUNET_free (plugins); }
static void put_record (struct GNUNET_NAMESTORE_PluginFunctions *nsp, int id) { struct GNUNET_CRYPTO_EcdsaPrivateKey zone_private_key; char label[64]; unsigned int rd_count = 1 + (id % 1024); struct GNUNET_GNSRECORD_Data rd[rd_count]; struct GNUNET_CRYPTO_EcdsaSignature signature; unsigned int i; GNUNET_snprintf (label, sizeof (label), "a%u", (unsigned int ) id); for (i=0;i<rd_count;i++) { rd[i].data = "Hello World"; rd[i].data_size = id % 10; rd[i].expiration_time = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES).abs_value_us; rd[i].record_type = 1 + (id % 13); rd[i].flags = 0; } memset (&zone_private_key, (id % 241), sizeof (zone_private_key)); memset (&signature, (id % 243), sizeof (signature)); GNUNET_assert (GNUNET_OK == nsp->store_records (nsp->cls, &zone_private_key, label, rd_count, rd)); }
int main (int argc, char *argv[]) { int ret; char *pos; char dir_name[128]; sleep (1); /* determine name of plugin to use */ plugin_name = argv[0]; while (NULL != (pos = strstr (plugin_name, "_"))) plugin_name = pos + 1; if (NULL != (pos = strstr (plugin_name, "."))) pos[0] = 0; else pos = (char *) plugin_name; GNUNET_snprintf (dir_name, sizeof (dir_name), "/tmp/test-gnunet-datastore-%s", plugin_name); GNUNET_DISK_directory_remove (dir_name); GNUNET_log_setup ("test-datastore-api-management", #if VERBOSE "DEBUG", #else "WARNING", #endif NULL); ret = check (); if (pos != plugin_name) pos[0] = '.'; GNUNET_DISK_directory_remove (dir_name); return ret; }
/** * @brief Iterator function for #store_valid_peers. * * Implements #GNUNET_CONTAINER_PeerMapIterator. * Writes single peer to disk. * * @param cls the file handle to write to. * @param peer current peer * @param value unused * * @return #GNUNET_YES if we should continue to * iterate, * #GNUNET_NO if not. */ static int store_peer_presistently_iterator (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) { const struct GNUNET_DISK_FileHandle *fh = cls; char peer_string[128]; int size; ssize_t ret; if (NULL == peer) { return GNUNET_YES; } size = GNUNET_snprintf (peer_string, sizeof (peer_string), "%s\n", GNUNET_i2s_full (peer)); GNUNET_assert (53 == size); ret = GNUNET_DISK_file_write (fh, peer_string, size); GNUNET_assert (size == ret); return GNUNET_YES; }
/** * Convert a given filesize into a fancy human-readable format. * * @param size number of bytes * @return fancy representation of the size (possibly rounded) for humans */ char * GNUNET_STRINGS_byte_size_fancy (unsigned long long size) { const char *unit = _( /* size unit */ "b"); char *ret; if (size > 5 * 1024) { size = size / 1024; unit = "KiB"; if (size > 5 * 1024) { size = size / 1024; unit = "MiB"; if (size > 5 * 1024) { size = size / 1024; unit = "GiB"; if (size > 5 * 1024) { size = size / 1024; unit = "TiB"; } } } } ret = GNUNET_malloc (32); GNUNET_snprintf (ret, 32, "%llu %s", size, unit); return ret; }
/** * Run "upnpc -r" to map our internal port. * * @param mini our handle */ static void run_upnpc_r (struct GNUNET_NAT_MiniHandle *mini) { char pstr[6]; GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) mini->port); mini->map_cmd = GNUNET_OS_command_run (&process_map_output, mini, MAP_TIMEOUT, "upnpc", "upnpc", "-r", pstr, mini->is_tcp ? "tcp" : "udp", NULL); if (NULL == mini->map_cmd) { mini->ac (mini->ac_cls, GNUNET_SYSERR, NULL, 0, GNUNET_NAT_ERROR_UPNPC_FAILED); return; } }
static void phone_send (void *cls) { char buf[32]; GNUNET_assert (NULL != phone_rdc); GNUNET_snprintf (buf, sizeof (buf), "phone"); phone_rdc (phone_rdc_cls, strlen (buf) + 1, buf); phone_task = GNUNET_SCHEDULER_add_delayed (FREQ, &phone_send, NULL); }
/** * Return unique variant of the namespace name. * Use it after GNUNET_PSEUDONYM_get_info() to make sure * that name is unique. * * @param cfg configuration * @param nsid cryptographic ID of the namespace * @param name name to uniquify * @param suffix if not NULL, filled with the suffix value * @return NULL on failure (should never happen), name on success. * Free the name with GNUNET_free(). */ char * GNUNET_PSEUDONYM_name_uniquify (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HashCode * nsid, const char *name, unsigned int *suffix) { struct GNUNET_HashCode nh; uint64_t len; char *fn; struct GNUNET_DISK_FileHandle *fh; unsigned int i; unsigned int idx; char *ret; struct stat sbuf; GNUNET_CRYPTO_hash (name, strlen (name), &nh); fn = get_data_filename (cfg, PS_NAMES_DIR, &nh); GNUNET_assert (fn != NULL); len = 0; if (0 == STAT (fn, &sbuf)) GNUNET_break (GNUNET_OK == GNUNET_DISK_file_size (fn, &len, GNUNET_YES, GNUNET_YES)); fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); i = 0; idx = -1; while ((len >= sizeof (struct GNUNET_HashCode)) && (sizeof (struct GNUNET_HashCode) == GNUNET_DISK_file_read (fh, &nh, sizeof (struct GNUNET_HashCode)))) { if (0 == memcmp (&nh, nsid, sizeof (struct GNUNET_HashCode))) { idx = i; break; } i++; len -= sizeof (struct GNUNET_HashCode); } if (idx == -1) { idx = i; if (sizeof (struct GNUNET_HashCode) != GNUNET_DISK_file_write (fh, nsid, sizeof (struct GNUNET_HashCode))) LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "write", fn); } GNUNET_DISK_file_close (fh); ret = GNUNET_malloc (strlen (name) + 32); GNUNET_snprintf (ret, strlen (name) + 32, "%s-%u", name, idx); if (suffix != NULL) *suffix = idx; GNUNET_free (fn); return ret; }
/** * Give relative time in human-readable fancy format. * This is one of the very few calls in the entire API that is * NOT reentrant! * * @param delta time in milli seconds * @param do_round are we allowed to round a bit? * @return time as human-readable string */ const char * GNUNET_STRINGS_relative_time_to_string (struct GNUNET_TIME_Relative delta, int do_round) { static char buf[128]; const char *unit = _( /* time unit */ "µs"); uint64_t dval = delta.rel_value_us; if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == delta.rel_value_us) return _("forever"); if (0 == delta.rel_value_us) return _("0 ms"); if ( ( (GNUNET_YES == do_round) && (dval > 5 * 1000) ) || (0 == (dval % 1000) )) { dval = dval / 1000; unit = _( /* time unit */ "ms"); if ( ( (GNUNET_YES == do_round) && (dval > 5 * 1000) ) || (0 == (dval % 1000) )) { dval = dval / 1000; unit = _( /* time unit */ "s"); if ( ( (GNUNET_YES == do_round) && (dval > 5 * 60) ) || (0 == (dval % 60) ) ) { dval = dval / 60; unit = _( /* time unit */ "m"); if ( ( (GNUNET_YES == do_round) && (dval > 5 * 60) ) || (0 == (dval % 60) )) { dval = dval / 60; unit = _( /* time unit */ "h"); if ( ( (GNUNET_YES == do_round) && (dval > 5 * 24) ) || (0 == (dval % 24)) ) { dval = dval / 24; if (1 == dval) unit = _( /* time unit */ "day"); else unit = _( /* time unit */ "days"); } } } } } GNUNET_snprintf (buf, sizeof (buf), "%llu %s", dval, unit); return buf; }
static void call_send (void *cls) { struct MicContext *mc = cls; char buf[32]; GNUNET_assert (NULL != mc->rdc); GNUNET_snprintf (buf, sizeof (buf), "call"); mc->rdc (mc->rdc_cls, strlen (buf) + 1, buf); mc->call_task = GNUNET_SCHEDULER_add_delayed (FREQ, &call_send, mc); }
/** * Return identifier for a client as a string. * * @param c client to identify * @return string for debugging */ const char * GSC_2s (struct CadetClient *c) { static char buf[32]; if (NULL == c) return "Client(NULL)"; GNUNET_snprintf (buf, sizeof (buf), "Client(%u)", c->id); return buf; }
static char * makeName (unsigned int i) { char *fn; fn = GNUNET_malloc (strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14); GNUNET_snprintf (fn, strlen ("/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST") + 14, "/tmp/gnunet-basic_fsui_test/BASIC_FSUI_TEST%u", i); GNUNET_disk_directory_create_for_file (NULL, fn); return fn; }
/** * Remove a mapping created with (mini)upnpc. Calling * this function will give 'upnpc' 1s to remove tha mapping, * so while this function is non-blocking, a task will be * left with the scheduler for up to 1s past this call. * * @param mini the handle */ void GNUNET_NAT_mini_map_stop (struct GNUNET_NAT_MiniHandle *mini) { char pstr[6]; if (NULL != mini->refresh_task) { GNUNET_SCHEDULER_cancel (mini->refresh_task); mini->refresh_task = NULL; } if (NULL != mini->refresh_cmd) { GNUNET_OS_command_stop (mini->refresh_cmd); mini->refresh_cmd = NULL; } if (NULL != mini->map_cmd) { GNUNET_OS_command_stop (mini->map_cmd); mini->map_cmd = NULL; } if (GNUNET_NO == mini->did_map) { GNUNET_free (mini); return; } mini->ac (mini->ac_cls, GNUNET_NO, (const struct sockaddr *) &mini->current_addr, sizeof (mini->current_addr), GNUNET_NAT_ERROR_SUCCESS); /* Note: oddly enough, deletion uses the external port whereas * addition uses the internal port; this rarely matters since they * often are the same, but it might... */ GNUNET_snprintf (pstr, sizeof (pstr), "%u", (unsigned int) ntohs (mini->current_addr.sin_port)); LOG (GNUNET_ERROR_TYPE_DEBUG, "Unmapping port %u with UPnP\n", ntohs (mini->current_addr.sin_port)); mini->unmap_cmd = GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT, "upnpc", "upnpc", "-d", pstr, mini->is_tcp ? "tcp" : "udp", NULL); }
/** * Handle LIST-message. * * @param cls closure (always NULL) * @param client identification of the client * @param message the actual message */ static void handle_list (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { struct GNUNET_ARM_ListResultMessage *msg; size_t string_list_size; size_t total_size; struct ServiceList *sl; uint16_t count; if (NULL == client) return; count = 0; string_list_size = 0; /* first count the running processes get their name's size */ for (sl = running_head; sl != NULL; sl = sl->next) { if (sl->proc != NULL) { string_list_size += strlen (sl->name); string_list_size += strlen (sl->binary); string_list_size += 4; count++; } } total_size = sizeof (struct GNUNET_ARM_ListResultMessage) + string_list_size; msg = GNUNET_malloc (total_size); msg->header.size = total_size; msg->header.type = GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT; msg->count = count; char *pos = (char *)&msg[1]; for (sl = running_head; sl != NULL; sl = sl->next) { if (sl->proc != NULL) { size_t s = strlen (sl->name) + strlen (sl->binary) + 4; GNUNET_snprintf(pos, s, "%s (%s)", sl->name, sl->binary); pos += s; } } GNUNET_SERVER_notify_transmit_ready (client, msg->header.size, GNUNET_TIME_UNIT_FOREVER_REL, &write_list_result, msg); GNUNET_SERVER_receive_done (client, GNUNET_OK); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { unsigned int i; char name[128]; h = GNUNET_STATISTICS_create ("test-statistics-api-loop", cfg); for (i = 0; i < ROUNDS; i++) { GNUNET_snprintf (name, sizeof (name), "test-%d", i % 32); GNUNET_STATISTICS_set (h, name, i, GNUNET_NO); GNUNET_snprintf (name, sizeof (name), "test-%d", i % 16); GNUNET_STATISTICS_update (h, name, 1, GNUNET_NO); } i = 0; GNUNET_break (NULL != GNUNET_STATISTICS_get (h, NULL, "test-0", &next, &check_1, cls)); }
/** * Get the static string for the peer this tunnel is directed. * * @param t Tunnel. * * @return Static string the destination peer's ID. */ const char * GCT_2s (const struct CadetTunnel *t) { static char buf[64]; if (NULL == t) return "T(NULL)"; GNUNET_snprintf (buf, sizeof (buf), "T(%s)", GCP_2s (t->destination)); return buf; }
/** * Convert public key to the respective absolute domain name in the * ".zkey" pTLD. * This is one of the very few calls in the entire API that is * NOT reentrant! * * @param pkey a public key with a point on the eliptic curve * @return string "X.zkey" where X is the public * key in an encoding suitable for DNS labels. */ const char * GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey) { static char ret[128]; char *pkeys; pkeys = GNUNET_CRYPTO_ecdsa_public_key_to_string (pkey); GNUNET_snprintf (ret, sizeof (ret), "%s.zkey", pkeys); GNUNET_free (pkeys); return ret; }
int main (int argc, char *argv[]) { char cfg_name[128]; plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]); GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); if (0 != GNUNET_TESTING_peer_run ("perf-gnunet-datastore", cfg_name, &run, NULL)) return 1; FPRINTF (stderr, "%s", "\n"); return ok; }
static int check () { struct GNUNET_OS_Process *proc; char cfg_name[128]; char *const argv[] = { "test-datastore-api-management", "-c", cfg_name, #if VERBOSE "-L", "DEBUG", #endif NULL }; struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; GNUNET_snprintf (cfg_name, sizeof (cfg_name), "test_datastore_api_data_%s.conf", plugin_name); proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", "gnunet-service-arm", #if VERBOSE "-L", "DEBUG", #endif "-c", cfg_name, NULL); GNUNET_assert (NULL != proc); GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-datastore-api-management", "nohelp", options, &run, NULL); sleep (1); /* give datastore chance to process 'DROP' request */ if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); ok = 1; } GNUNET_OS_process_wait (proc); GNUNET_OS_process_destroy (proc); proc = NULL; if (ok != 0) FPRINTF (stderr, "Missed some testcases: %u\n", ok); return ok; }
/** * Convert numeric DNS record type to a string. * * @param type type to convert * @return type as string, only valid until the next call to this function */ static const char * get_type (uint16_t type) { static char buf[6]; switch (type) { case GNUNET_DNSPARSER_TYPE_A: return "A"; case GNUNET_DNSPARSER_TYPE_NS: return "NS"; case GNUNET_DNSPARSER_TYPE_CNAME: return "CNAME"; case GNUNET_DNSPARSER_TYPE_SOA: return "SOA"; case GNUNET_DNSPARSER_TYPE_PTR: return "PTR"; case GNUNET_DNSPARSER_TYPE_MX: return "MX"; case GNUNET_DNSPARSER_TYPE_TXT: return "TXT"; case GNUNET_DNSPARSER_TYPE_AAAA: return "AAAA"; case GNUNET_DNSPARSER_TYPE_SRV: return "SRV"; } GNUNET_snprintf (buf, sizeof (buf), "%u", (unsigned int) type); return buf; }
/** * Convert a given address to a human-readable format. Note that the * return value will be overwritten on the next call to this function. * * @param address the address to convert * @return statically allocated (!) human-readable address */ const char * GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) { struct GNUNET_TRANSPORT_PluginFunctions *api; static char unable_to_show[1024]; if (address == NULL) return "<inbound>"; api = GST_plugins_find (address->transport_name); if (NULL == api) return "<plugin unknown>"; if (0 == address->address_length) { GNUNET_snprintf (unable_to_show, sizeof (unable_to_show), "<unable to stringify %u-byte long address of %s transport>", (unsigned int) address->address_length, address->transport_name); return unable_to_show; } return api->address_to_string (NULL, address->address, address->address_length); }