int main (int argc, char *argv[]) { struct GNUNET_TIME_Absolute start; struct GNUNET_CRYPTO_PaillierPublicKey public_key; struct GNUNET_CRYPTO_PaillierPrivateKey private_key; struct GNUNET_CRYPTO_PaillierCiphertext c1; gcry_mpi_t m1; unsigned int i; start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) GNUNET_CRYPTO_paillier_create (&public_key, &private_key); printf ("10x key generation took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("UTIL", "Paillier key generation", 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "keys/ms"); m1 = gcry_mpi_new (0); m1 = gcry_mpi_set_ui (m1, 1); /* m1 = m1 * 2 ^ (GCPB - 3) */ gcry_mpi_mul_2exp (m1, m1, GNUNET_CRYPTO_PAILLIER_BITS - 3); start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) GNUNET_CRYPTO_paillier_encrypt (&public_key, m1, 2, &c1); printf ("10x encryption took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("UTIL", "Paillier encryption", 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) GNUNET_CRYPTO_paillier_decrypt (&private_key, &public_key, &c1, m1); printf ("10x decryption took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("UTIL", "Paillier decryption", 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); return 0; }
int main (int argc, char *const *argv) { unsigned int errorCount = 0; (void)argc; /* Unused. Silent compiler warning. */ if (NULL == argv || 0 == argv[0]) return 99; oneone = has_in_name (argv[0], "11"); if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; if (MHD_YES == MHD_is_feature_supported(MHD_FEATURE_THREADS)) { start_time = now(); errorCount += testInternalPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "internal select", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("internal select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); start_time = now(); errorCount += testMultithreadedPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "multithreaded post", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("Multithreaded select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); start_time = now(); errorCount += testMultithreadedPoolPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "thread with pool", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("thread with pool", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); } start_time = now(); errorCount += testExternalPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "external select", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("external select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); curl_global_cleanup (); return errorCount != 0; /* 0 == pass */ }
int main (int argc, char *const *argv) { unsigned int errorCount = 0; oneone = (NULL != strrchr (argv[0], (int) '/')) ? (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0; if (0 != curl_global_init (CURL_GLOBAL_WIN32)) return 2; start_time = now(); errorCount += testInternalPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "internal select", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("internal select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); start_time = now(); errorCount += testMultithreadedPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "multithreaded post", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("Multithreaded select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); start_time = now(); errorCount += testMultithreadedPoolPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "thread with pool", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("thread with pool", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); start_time = now(); errorCount += testExternalPost (); fprintf (stderr, oneone ? "%s: Sequential POSTs (http/1.1) %f/s\n" : "%s: Sequential POSTs (http/1.0) %f/s\n", "external select", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); GAUGER ("external select", oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), "requests/s"); if (errorCount != 0) fprintf (stderr, "Error (code: %u)\n", errorCount); curl_global_cleanup (); return errorCount != 0; /* 0 == pass */ }
int main (int argc, char *argv[]) { struct GNUNET_CRYPTO_EccDlogContext *edc; struct GNUNET_TIME_Absolute start; struct GNUNET_TIME_Relative delta; if (! gcry_check_version ("1.6.0")) { FPRINTF (stderr, _ ("libgcrypt has not the expected version (version %s is required).\n"), "1.6.0"); return 0; } if (getenv ("GNUNET_GCRYPT_DEBUG")) gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0); GNUNET_log_setup ("perf-crypto-ecc-dlog", "WARNING", NULL); start = GNUNET_TIME_absolute_get (); edc = GNUNET_CRYPTO_ecc_dlog_prepare (MAX_FACT, MAX_MEM); printf ("DLOG precomputation 1M/1K took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("UTIL", "ECC DLOG initialization", GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL, "ms/op"); start = GNUNET_TIME_absolute_get (); /* first do a baseline run without the DLOG */ test_dlog (edc, GNUNET_NO); delta = GNUNET_TIME_absolute_get_duration (start); start = GNUNET_TIME_absolute_get (); test_dlog (edc, GNUNET_YES); delta = GNUNET_TIME_relative_subtract (GNUNET_TIME_absolute_get_duration (start), delta); printf ("%u DLOG calculations took %s\n", TEST_ITER, GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES)); GAUGER ("UTIL", "ECC DLOG operations", delta.rel_value_us / 1000LL / TEST_ITER, "ms/op"); GNUNET_CRYPTO_ecc_dlog_release (edc); return 0; }
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); }
static void end () { unsigned long long delta; unsigned long long rate; char *value_name; unsigned int i; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); /* Calculcate statistics */ delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); FPRINTF (stderr, "\nThroughput was %llu KiBytes/s\n", rate); GNUNET_asprintf (&value_name, "unreliable_%s", test_plugin); GAUGER ("TRANSPORT", value_name, (int) rate, "kb/s"); GNUNET_free (value_name); if (die_task != NULL) 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); cc = NULL; } GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); GNUNET_TRANSPORT_TESTING_done (tth); ok = 0; for (i = 0; i < TOTAL_MSGS; i++) { if (get_bit (bitmap, i) == 0) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not receive message %d\n", i); ok = -1; } } }
/** * Stop the timer and report performance * * @param desc description of the threading mode we used */ static void stop (const char *desc) { double rps = ((double) (PAR * ROUNDS * 1000)) / ((double) (now() - start_time)); fprintf (stderr, "Parallel GETs using %s: %f %s\n", desc, rps, "requests/s"); GAUGER (desc, "Parallel GETs", rps, "requests/s"); }
int main (int argc, char *argv[]) { struct GNUNET_TIME_Absolute start; start = GNUNET_TIME_absolute_get (); perfHash (); printf ("Hash perf took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("NSE", "Proof-of-work hashing", 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "hashes/ms"); return 0; }
int main (int argc, char *argv[]) { struct GNUNET_TIME_Absolute start; start = GNUNET_TIME_absolute_get (); perfEncrypt (); printf ("Encrypt perf took %s\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GAUGER ("UTIL", "Symmetric encryption", 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "kb/ms"); return 0; }
/** * Stop a service that was started with "GNUNET_SERVICE_start". * * @param sctx the service context returned from the start function */ void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx) { unsigned int i; #if HAVE_MALLINFO { char *counter; if ( (GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "GAUGER_HEAP")) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name, "GAUGER_HEAP", &counter)) ) { struct mallinfo mi; mi = mallinfo (); GAUGER (sctx->service_name, counter, mi.usmblks, "blocks"); GNUNET_free (counter); } } #endif if (NULL != sctx->shutdown_task) { GNUNET_SCHEDULER_cancel (sctx->shutdown_task); sctx->shutdown_task = NULL; } if (NULL != sctx->server) GNUNET_SERVER_destroy (sctx->server); GNUNET_free_non_null (sctx->my_handlers); if (NULL != sctx->addrs) { i = 0; while (NULL != sctx->addrs[i]) GNUNET_free (sctx->addrs[i++]); GNUNET_free (sctx->addrs); } GNUNET_free_non_null (sctx->addrlens); 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); GNUNET_free (sctx); }
static void log_duration (const char *cryptosystem, const char *description) { struct GNUNET_TIME_Relative t; char s[64]; sprintf (s, "%6s %15s", cryptosystem, description); t = GNUNET_TIME_absolute_get_duration (start); t = GNUNET_TIME_relative_divide (t, l); FPRINTF (stdout, "%s: %10s\n", s, GNUNET_STRINGS_relative_time_to_string (t, GNUNET_NO)); GAUGER ("UTIL", s, t.rel_value_us, "us"); }
/** * Show the results of the test (banwidth acheived) and log them to GAUGER */ static void show_end_data (void) { static struct GNUNET_TIME_Absolute end_time; static struct GNUNET_TIME_Relative total_time; end_time = GNUNET_TIME_absolute_get(); total_time = GNUNET_TIME_absolute_get_difference(start_time, end_time); FPRINTF (stderr, "\nResults of test \"%s\"\n", test_name); FPRINTF (stderr, "Test time %s\n", GNUNET_STRINGS_relative_time_to_string (total_time, GNUNET_YES)); FPRINTF (stderr, "Test bandwidth: %f kb/s\n", 4 * TOTAL_PACKETS * 1.0 / (total_time.rel_value_us / 1000)); // 4bytes * ms FPRINTF (stderr, "Test throughput: %f packets/s\n\n", TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000)); // packets * ms GAUGER ("CADET", test_name, TOTAL_PACKETS * 1000.0 / (total_time.rel_value_us / 1000), "packets/s"); }
static void do_shutdown (void *cls) { unsigned long long delta; delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; FPRINTF (stderr, "\nThroughput was %llu kb/s\n", total_bytes * 1000000LL / 1024 / delta); GAUGER ("CORE", "Core throughput/s", total_bytes * 1000000LL / 1024 / delta, "kb/s"); if (NULL != err_task) { GNUNET_SCHEDULER_cancel (err_task); err_task = NULL; } terminate_peer (&p1); terminate_peer (&p2); }
/** * Main state machine. Executes the next step of the benchmark * depending on the current state. * * @param cls the `struct CpsRunContext` */ static void run_continuation (void *cls) { struct CpsRunContext *crc = cls; size_t size; static struct GNUNET_HashCode key; static char data[65536]; char gstr[128]; ok = (int) crc->phase; switch (crc->phase) { case RP_PUT: memset (&key, 256 - crc->i, sizeof (struct GNUNET_HashCode)); /* most content is 32k */ size = 32 * 1024; if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) /* but some of it is less! */ size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); crc->size = size = size - (size & 7); /* always multiple of 8 */ GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); memset (data, (int) crc->j, size); if (crc->j > 255) memset (data, (int) (crc->j - 255), size / 2); data[0] = crc->i; GNUNET_assert (NULL != GNUNET_DATASTORE_put (datastore, 0, &key, size, data, crc->j + 1, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), crc->j, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 1, 1, &check_success, crc)); break; case RP_CUT: /* trim down below MAX_SIZE again */ GNUNET_assert (NULL != GNUNET_DATASTORE_get_for_replication (datastore, 1, 1, &delete_value, crc)); break; case RP_REPORT: printf ( #if REPORT_ID "\n" #endif "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ stored_ops / 1024, /* total operations (in k) */ 1000LL * 1000LL * stored_ops / (1 + GNUNET_TIME_absolute_get_duration (start_time).rel_value_us)); crc->phase = RP_PUT; crc->j = 0; GNUNET_SCHEDULER_add_now (&run_continuation, crc); break; case RP_PUT_QUOTA: memset (&key, 256 - crc->i, sizeof (struct GNUNET_HashCode)); /* most content is 32k */ size = 32 * 1024; if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) /* but some of it is less! */ size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); crc->size = size = size - (size & 7); /* always multiple of 8 */ GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); memset (data, (int) crc->j, size); if (crc->j > 255) memset (data, (int) (crc->j - 255), size / 2); data[0] = crc->i; GNUNET_assert (NULL != GNUNET_DATASTORE_put (datastore, 0, /* reservation ID */ &key, size, data, crc->j + 1, /* type */ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), /* priority */ crc->j, /* anonymity */ 0, /* replication */ GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 1, 1, &check_success, crc)); break; case RP_DONE: GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); if ((crc->i == ITERATIONS) && (stored_ops > 0)) { GAUGER (gstr, "PUT operation duration", GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / stored_ops, "ms/operation"); fprintf (stdout, "\nPUT performance: %s for %llu operations\n", GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start_time), GNUNET_YES), stored_ops); fprintf (stdout, "PUT performance: %llu ms/operation\n", GNUNET_TIME_absolute_get_duration (start_time).rel_value_us / 1000LL / stored_ops); } GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); GNUNET_free (crc); ok = 0; break; case RP_ERROR: GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); GNUNET_free (crc); ok = 1; break; default: GNUNET_assert (0); } }
/** * 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; }
static void run_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct CpsRunContext *crc = cls; size_t size; static struct GNUNET_HashCode key; static char data[65536]; int i; int k; char gstr[128]; ok = (int) crc->phase; switch (crc->phase) { case RP_PUT: memset (&key, 256 - crc->i, sizeof (struct GNUNET_HashCode)); i = crc->j; k = crc->i; /* most content is 32k */ size = 32 * 1024; if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024); crc->size = size = size - (size & 7); /* always multiple of 8 */ GNUNET_CRYPTO_hash (&key, sizeof (struct GNUNET_HashCode), &key); memset (data, i, size); if (i > 255) memset (data, i - 255, size / 2); data[0] = k; GNUNET_assert (NULL != GNUNET_DATASTORE_put (datastore, 0, &key, size, data, i + 1, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100), i, 0, GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), 1, 1, TIMEOUT, &check_success, crc)); break; case RP_CUT: /* trim down below MAX_SIZE again */ GNUNET_assert (NULL != GNUNET_DATASTORE_get_for_replication (datastore, 1, 1, TIMEOUT, &delete_value, crc)); break; case RP_REPORT: printf ( #if REPORT_ID "\n" #endif "Stored %llu kB / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ stored_ops / 1024, /* total operations (in k) */ 1000 * stored_ops / (1 + GNUNET_TIME_absolute_get_duration (start_time).rel_value)); crc->phase = RP_PUT; crc->j = 0; GNUNET_SCHEDULER_add_continuation (&run_continuation, crc, GNUNET_SCHEDULER_REASON_PREREQ_DONE); break; case RP_DONE: GNUNET_snprintf (gstr, sizeof (gstr), "DATASTORE-%s", plugin_name); if ((crc->i == ITERATIONS) && (stored_ops > 0)) GAUGER (gstr, "PUT operation duration", GNUNET_TIME_absolute_get_duration (start_time).rel_value / stored_ops, "ms/operation"); GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); GNUNET_free (crc); ok = 0; break; case RP_ERROR: GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES); GNUNET_free (crc); ok = 1; break; default: GNUNET_assert (0); } }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_DATACACHE_Handle *h; struct GNUNET_HashCode k; struct GNUNET_HashCode n; struct GNUNET_TIME_Absolute exp; struct GNUNET_TIME_Absolute start; unsigned int i; char gstr[128]; ok = 0; h = GNUNET_DATACACHE_create (cfg, "perfcache"); if (h == NULL) { FPRINTF (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n"); ok = 77; /* mark test as skipped */ return; } exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS); start = GNUNET_TIME_absolute_get (); memset (&k, 0, sizeof (struct GNUNET_HashCode)); for (i = 0; i < ITERATIONS; i++) { if (0 == i % (ITERATIONS / 80)) FPRINTF (stderr, "%s", "."); GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode), (const char *) &n, 1 + i % 16, exp, 0, NULL)); k = n; } FPRINTF (stderr, "%s", "\n"); FPRINTF (stdout, "Stored %u items in %s\n", ITERATIONS, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name); GAUGER (gstr, "Time to PUT item in datacache", GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL / ITERATIONS, "ms/item"); start = GNUNET_TIME_absolute_get (); memset (&k, 0, sizeof (struct GNUNET_HashCode)); for (i = 0; i < ITERATIONS; i++) { if (0 == i % (ITERATIONS / 80)) FPRINTF (stderr, "%s", "."); GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n); GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n); k = n; } FPRINTF (stderr, "%s", "\n"); FPRINTF (stdout, "Found %u/%u items in %s (%u were deleted during storage processing)\n", found, ITERATIONS, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES), ITERATIONS - found); if (found > 0) GAUGER (gstr, "Time to GET item from datacache", GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL / found, "ms/item"); GNUNET_DATACACHE_destroy (h); ASSERT (ok == 0); return; FAILURE: if (h != NULL) GNUNET_DATACACHE_destroy (h); ok = GNUNET_SYSERR; }
/** * Evaluate RSA performance. * * @param len keylength to evaluate with */ static void eval (unsigned int len) { struct GNUNET_TIME_Absolute start; struct GNUNET_CRYPTO_RsaSignature *sig; struct GNUNET_CRYPTO_RsaSignature *rsig; struct GNUNET_CRYPTO_RsaPublicKey *public_key; struct GNUNET_CRYPTO_RsaPrivateKey *private_key; struct GNUNET_CRYPTO_RsaBlindingKeySecret bsec[10]; unsigned int i; char sbuf[128]; char *bbuf; size_t bbuf_len; struct GNUNET_HashCode hc; start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) { private_key = GNUNET_CRYPTO_rsa_private_key_create (len); GNUNET_CRYPTO_rsa_private_key_free (private_key); } printf ("10x %u-key generation took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-key generation", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "keys/ms"); private_key = GNUNET_CRYPTO_rsa_private_key_create (len); public_key = GNUNET_CRYPTO_rsa_private_key_get_public (private_key); for (i=0;i<10;i++) GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, &bsec[i], sizeof (bsec[0])); /* start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) rsa_blinding_key_derive(public_key, &bsec[i]); printf ("10x %u-blinding key generation took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-blinding key generation", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "keys/ms"); */ start = GNUNET_TIME_absolute_get (); GNUNET_CRYPTO_hash ("test", 4, &hc); for (i=0;i<10;i++) { GNUNET_CRYPTO_rsa_blind (&hc, &bsec[i], public_key, &bbuf, &bbuf_len); GNUNET_free (bbuf); } printf ("10x %u-blinding took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-blinding", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); GNUNET_CRYPTO_rsa_blind (&hc, &bsec[0], public_key, &bbuf, &bbuf_len); start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) { sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key, bbuf, bbuf_len); GNUNET_CRYPTO_rsa_signature_free (sig); } printf ("10x %u-signing took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-signing", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); sig = GNUNET_CRYPTO_rsa_sign_blinded (private_key, bbuf, bbuf_len); start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) { rsig = GNUNET_CRYPTO_rsa_unblind (sig, &bsec[0], public_key); GNUNET_CRYPTO_rsa_signature_free (rsig); } printf ("10x %u-unblinding took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-unblinding", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); rsig = GNUNET_CRYPTO_rsa_unblind (sig, &bsec[0], public_key); start = GNUNET_TIME_absolute_get (); for (i=0;i<10;i++) { GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_rsa_verify (&hc, rsig, public_key)); } printf ("10x %u-verifying took %s\n", len, GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES)); GNUNET_snprintf (sbuf, sizeof (sbuf), "RSA %u-verification", len); GAUGER ("UTIL", sbuf, 64 * 1024 / (1 + GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL), "ops/ms"); GNUNET_CRYPTO_rsa_signature_free (sig); GNUNET_CRYPTO_rsa_public_key_free (public_key); GNUNET_CRYPTO_rsa_private_key_free (private_key); GNUNET_free (bbuf); }