/** * Initialize framework and start test * * @param cls closure * @param cfg configuration of the peer that was started * @param peer identity of the peer that was created */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { struct GNUNET_PeerIdentity self; GNUNET_TESTING_peer_get_identity (peer, &self); config = cfg; peer2_listen_socket = GNUNET_STREAM_listen (config, 10, /* App port */ &stream_listen_cb, NULL, GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, &stream_connect, GNUNET_STREAM_OPTION_END); GNUNET_assert (NULL != peer2_listen_socket); peer1.self = self; peer2.self = self; abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60), &do_abort, NULL); }
/** * Signature of the 'main' function for a (single-peer) testcase that * is run using 'GNUNET_TESTING_peer_run'. * * @param cls closure * @param cfg configuration of the peer that was started * @param peer identity of the peer that was created */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { config = cfg; GNUNET_TESTING_peer_get_identity (peer, &local_id); if (0) test_iter (); set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_INTERSECTION); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); /* test the real set reconciliation */ init_set1 (); }
/** * Connect to other client and send data * * @param cls Closue (unused). * @param tc TaskContext. */ static void do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_PeerIdentity id; if (NULL != tc && 0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) return; GNUNET_TESTING_peer_get_identity (me, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1, GNUNET_CADET_OPTION_DEFAULT); mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, sizeof (struct GNUNET_MessageHeader), &do_send, NULL); }
/** * Signature of the 'main' function for a (single-peer) testcase that * is run using 'GNUNET_TESTING_peer_run'. * * @param cls closure * @param cfg configuration of the peer that was started * @param peer identity of the peer that was created */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &timeout_fail, NULL); config = cfg; GNUNET_TESTING_peer_get_identity (peer, &local_id); test_iter (); set1 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); set2 = GNUNET_SET_create (cfg, GNUNET_SET_OPERATION_UNION); GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &app_id); /* test the real set reconciliation */ init_set1 (); }
/** * Initialize framework and start test * * @param cls closure * @param cfg configuration of the peer that was started * @param peer identity of the peer that was created */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { struct GNUNET_PeerIdentity id; GNUNET_TESTING_peer_get_identity (peer, &id); config = cfg; peer2_listen_socket = GNUNET_STREAM_listen (config, 10, &stream_listen_cb, &peer_data[1], GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS, &stream_connect, GNUNET_STREAM_OPTION_MAX_PAYLOAD_SIZE, payload_size[payload_size_index], GNUNET_STREAM_OPTION_END); GNUNET_assert (NULL != peer2_listen_socket); peer_data[0].id = id; peer_data[1].id = id; abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort, NULL); }
/** * Start a peer with the given configuration * @param tth the testing handle * @param cfgname configuration file * @param peer_id a unique number to identify the peer * @param rec receive callback * @param nc connect callback * @param nd disconnect callback * @param start_cb start callback * @param cb_cls closure for callback * @return the peer context */ struct PeerContext * GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, const char *cfgname, int peer_id, GNUNET_TRANSPORT_ReceiveCallback rec, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_TESTING_start_cb start_cb, void *cb_cls) { char *emsg = NULL; struct GNUNET_PeerIdentity *dummy; GNUNET_assert (NULL != tth); GNUNET_assert (NULL != tth->tl_system); if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "File not found: `%s' \n", cfgname); return NULL; } struct PeerContext *p = GNUNET_new (struct PeerContext); GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); /* Create configuration and call testing lib to modify it */ p->cfg = GNUNET_CONFIGURATION_create (); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_SYSERR == GNUNET_TESTING_configuration_create (tth->tl_system, p->cfg)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s'\n", cfgname); GNUNET_free (p); return NULL; } p->no = peer_id; /* Configure peer with configuration */ p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, p->cfg, p->no, NULL, &emsg); if (NULL == p->peer) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s': `%s'\n", cfgname, emsg); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); GNUNET_free_non_null (emsg); return NULL; } GNUNET_free_non_null (emsg); if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to create unique configuration based on `%s'\n", cfgname); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } memset(&dummy, '\0', sizeof (dummy)); GNUNET_TESTING_peer_get_identity (p->peer, &p->id); if (0 == memcmp (&dummy, &p->id, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Testing library failed to obtain peer identity for peer %u\n", p->no); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } else { GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", "Peer %u configured with identity `%s'\n", p->no, GNUNET_i2s_full (&p->id)); } p->tth = tth; p->nc = nc; p->nd = nd; p->rec = rec; p->start_cb = start_cb; if (cb_cls != NULL) p->cb_cls = cb_cls; else p->cb_cls = p; p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, ¬ify_connect, ¬ify_disconnect); if (NULL == p->th) { GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", "Failed to connect to transport service for peer `%s': `%s'\n", cfgname, emsg); GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); return NULL; } p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); GNUNET_assert (p->ghh != NULL); return p; }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { enum MHD_FLAG flags; char *bin; char *bin_identity; char *bin_gns; char *config; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "arm", "CONFIG", &config)) { fprintf (stderr, "Failed to locate configuration file. Skipping test.\n"); GNUNET_SCHEDULER_shutdown (); return; } char *const identity_args[] = { "gnunet-identity", "-C", "master-zone", "-c", config, NULL }; char *const identity2_args[] = { "gnunet-identity", "-e", "master-zone", "-s", "gns-master", "-c", config, NULL }; char *const identity3_args[] = { "gnunet-identity", "-e", "master-zone", "-s", "gns-intercept", "-c", config, NULL }; char *const gns_args[] = { "gnunet-gns", "-u", "www.gns", "-c", config, NULL }; GNUNET_TESTING_peer_get_identity (peer, &id); GNUNET_SCHEDULER_add_delayed (TIMEOUT, &do_shutdown, NULL); bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); GNUNET_asprintf (&bin_identity, "%s/%s", bin, "gnunet-identity"); if (0 != fork_and_exec (bin_identity, identity_args)) { fprintf (stderr, "Failed to run `gnunet-identity -C. Skipping test.\n"); GNUNET_SCHEDULER_shutdown (); GNUNET_free (bin_identity); GNUNET_free (config); GNUNET_free (bin); return; } if (0 != fork_and_exec (bin_identity, identity2_args)) { fprintf (stderr, "Failed to run `gnunet-identity -e. Skipping test.\n"); GNUNET_SCHEDULER_shutdown (); GNUNET_free (bin_identity); GNUNET_free (config); GNUNET_free (bin); return; } if (0 != fork_and_exec (bin_identity, identity3_args)) { fprintf (stderr, "Failed to run `gnunet-identity -e. Skipping test.\n"); GNUNET_SCHEDULER_shutdown (); GNUNET_free (bin_identity); GNUNET_free (config); GNUNET_free (bin); return; } GNUNET_free (bin_identity); /* do lookup just to launch GNS service */ GNUNET_asprintf (&bin_gns, "%s/%s", bin, "gnunet-gns"); if (0 != fork_and_exec (bin_gns, gns_args)) { fprintf (stderr, "Failed to run `gnunet-gns -u. Skipping test.\n"); GNUNET_SCHEDULER_shutdown (); GNUNET_free (bin_gns); GNUNET_free (config); GNUNET_free (bin); return; } GNUNET_free (bin_gns); GNUNET_free (config); GNUNET_free (bin); namestore = GNUNET_NAMESTORE_connect (cfg); GNUNET_assert (NULL != namestore); flags = MHD_USE_DEBUG; if (GNUNET_YES == use_v6) flags |= MHD_USE_DUAL_STACK; mhd = MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, MHD_OPTION_END); GNUNET_assert (NULL != mhd); mhd_main (); identity = GNUNET_IDENTITY_connect (cfg, &identity_cb, NULL); }