static void init_notify (void *cls, struct GNUNET_CORE_Handle *server, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established\n", GNUNET_i2s (my_identity)); GNUNET_assert (server != NULL); p->id = *my_identity; p->ch = server; if (cls == &p1) { GNUNET_assert (ok == 2); OKPP; /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); } else { GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); con_task = GNUNET_SCHEDULER_add_now (&connect_task, NULL); } }
static void init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to CORE service of `%4s' established\n", GNUNET_i2s (my_identity)); GNUNET_assert (NULL != my_identity); p->id = *my_identity; if (cls == &p1) { GNUNET_assert (ok == 2); OKPP; /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); } else { GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking core (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); connect_task = GNUNET_SCHEDULER_add_now (&try_connect, NULL); } }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_fixed_size (test, MTYPE, struct TestMessage, NULL), GNUNET_MQ_handler_end () }; GNUNET_assert (ok == 1); OKPP; setup_peer (&p1, "test_core_api_peer1.conf"); setup_peer (&p2, "test_core_api_peer2.conf"); err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); GNUNET_assert (NULL != (p1.ch = GNUNET_CORE_connect (p1.cfg, &p1, &init_notify, &connect_notify, &disconnect_notify, handlers))); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end () }; GNUNET_assert (ok == 1); OKPP; setup_peer (&p1, "test_core_api_peer1.conf"); setup_peer (&p2, "test_core_api_peer2.conf"); err_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300), &terminate_task_error, NULL); p1.ch = GNUNET_CORE_connect (p1.cfg, &p1, &init_notify, &connect_notify, &disconnect_notify, handlers); }
/** * Main function that will be run. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param c configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { static struct GNUNET_CORE_MessageHandler handlers[] = { {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, {NULL, 0, 0} }; unsigned long long opt; cfg = c; stats = GNUNET_STATISTICS_create ("topology", cfg); friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY"); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "MINIMUM-FRIENDS", &opt)) opt = 0; minimum_friend_count = (unsigned int) opt; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "TARGET-CONNECTION-COUNT", &opt)) opt = 16; target_connection_count = (unsigned int) opt; peers = GNUNET_CONTAINER_multihashmap_create (target_connection_count * 2, GNUNET_NO); if ((friends_only == GNUNET_YES) || (minimum_friend_count > 0)) read_friends_file (cfg); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology would like %u connections with at least %u friends\n", target_connection_count, minimum_friend_count); if ((friend_count < minimum_friend_count) && (blacklist == NULL)) blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); handle = GNUNET_CORE_connect (cfg, NULL, &core_init, &connect_notify, &disconnect_notify, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers); GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); if (NULL == transport) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to `%s' service.\n"), "transport"); GNUNET_SCHEDULER_shutdown (); return; } if (NULL == handle) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to `%s' service.\n"), "core"); GNUNET_SCHEDULER_shutdown (); return; } }
static void send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct TestMessageContext *pos = cls; if ((pos == test_messages) && (settle_time.rel_value > 0)) { topology_connections = 0; GNUNET_TESTING_get_topology (pg, &topology_cb, NULL); } if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) return; if (die_task == GNUNET_SCHEDULER_NO_TASK) { die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly, "from send test messages (timeout)"); } if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, pos); return; /* Otherwise we'll double schedule messages here! */ } /* * Connect to the sending peer */ pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, pos, &init_notify_peer1, &connect_notify_peers, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); GNUNET_assert (pos->peer1handle != NULL); if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) { GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); } else { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, pos->next); } }
/** * @brief This function initialises the flooding component. * * \latexonly \\ \\ \endlatexonly * \em Detailed \em description \n * This function initialises the flooding component. It also connects to the GNUnet core. */ void gnunet_search_flooding_init() { gnunet_search_flooding_message_queue = queue_construct(); gnunet_search_flooding_routing_table = (struct gnunet_search_flooding_routing_entry *) GNUNET_malloc( sizeof(struct gnunet_search_flooding_routing_entry) * GNUNET_SEARCH_FLOODING_ROUTING_TABLE_SIZE); gnunet_search_flooding_routing_table_length = 0; gnunet_search_flooding_routing_table_index = 0; _gnunet_search_flooding_message_notification_handler = NULL; static struct GNUNET_CORE_MessageHandler core_handlers[] = { { &gnunet_search_flooding_core_inbound_notify, GNUNET_MESSAGE_TYPE_SEARCH_FLOODING, 0 }, { NULL, 0, 0 } }; gnunet_search_flooding_core_handle = GNUNET_CORE_connect(gnunet_search_globals_cfg, 42, NULL, NULL, NULL, NULL, NULL/*&gnunet_search_flooding_core_inbound_notify*/, 0, NULL, 0, core_handlers); gnunet_search_flooding_handlers_set(&gnunet_search_flooding_message_notification_handler); }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_assert (ok == 1); OKPP; err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL); if (test == SYMMETRIC) { setup_peer (&p1, "test_core_quota_peer1.conf"); setup_peer (&p2, "test_core_quota_peer2.conf"); } else if (test == ASYMMETRIC_SEND_LIMITED) { setup_peer (&p1, "test_core_quota_asymmetric_send_limit_peer1.conf"); setup_peer (&p2, "test_core_quota_asymmetric_send_limit_peer2.conf"); } else if (test == ASYMMETRIC_RECV_LIMITED) { setup_peer (&p1, "test_core_quota_asymmetric_recv_limited_peer1.conf"); setup_peer (&p2, "test_core_quota_asymmetric_recv_limited_peer2.conf"); } GNUNET_assert (test != -1); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_size (p1.cfg, "ATS", "WAN_QUOTA_IN", ¤t_quota_p1_in)); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_size (p2.cfg, "ATS", "WAN_QUOTA_IN", ¤t_quota_p2_in)); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_size (p1.cfg, "ATS", "WAN_QUOTA_OUT", ¤t_quota_p1_out)); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_size (p2.cfg, "ATS", "WAN_QUOTA_OUT", ¤t_quota_p2_out)); p1.ch = GNUNET_CORE_connect (p1.cfg, &p1, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); }
static void send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct TestMessageContext *pos = cls; if (((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) || (cls == NULL)) return; if (die_task == GNUNET_SCHEDULER_NO_TASK) { die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly, "from create topology (timeout)"); } if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, pos); return; /* Otherwise we'll double schedule messages here! */ } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Attempting to send test message from %s to %s\n", pos->peer1->shortname, pos->peer2->shortname); /* * Connect to the sending peer */ pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, pos, &init_notify_peer1, &connect_notify_peer1, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); GNUNET_assert (pos->peer1handle != NULL); if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS) { GNUNET_SCHEDULER_add_now (&send_test_messages, pos->next); } else { GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, pos->next); } }
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { GNUNET_assert (ok == 1); OKPP; setup_peer (&p1, "test_core_api_peer1.conf"); setup_peer (&p2, "test_core_api_peer2.conf"); timeout_task_id = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, TIMEOUT), &timeout_task, NULL); p1.ch = GNUNET_CORE_connect (p1.cfg, &p1, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); }
/** * Main function that will be run by the scheduler. * * @param cls closure * @param cfg configuration */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { const static struct GNUNET_CORE_MessageHandler handlers[] = { {&receive, GNUNET_MESSAGE_TYPE_DUMMY, 0}, {NULL, 0, 0} }; core = GNUNET_CORE_connect (cfg, NULL, &init, &connect_cb, NULL, NULL, 0, NULL, 0, handlers); die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300), &cleanup, NULL); }
static void init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server, const struct GNUNET_PeerIdentity *my_identity) { struct TestMessageContext *pos = cls; total_server_connections++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%4s' established, setting up handles\n", GNUNET_i2s (my_identity)); /* * Connect to the receiving peer */ pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, pos, &init_notify_peer2, NULL, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers); }
static void init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size (test, MTYPE, struct TestMessage, NULL), GNUNET_MQ_handler_end () }; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to CORE service of `%s' established\n", GNUNET_i2s (my_identity)); p->id = *my_identity; if (cls == &p1) { GNUNET_assert (ok == 2); OKPP; /* connect p2 */ GNUNET_assert (NULL != (p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, handlers))); } else { GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking transport (1) to connect to peer `%s'\n", GNUNET_i2s (&p2.id)); p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1); } }
/** * Start the nodes management */ void GED_nodes_start () { /* Connecting to core service to find partners */ ch = GNUNET_CORE_connect (GED_cfg, NULL, &core_startup_handler, &core_connect_handler, &core_disconnect_handler, &core_receive_handler, GNUNET_NO, NULL, GNUNET_NO, NULL); if (NULL == ch) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Failed to connect to CORE service!\n")); return; } nodes_requested = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); nodes_active = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); nodes_inactive = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); }
/** * Initialize framework and start test * * @param cls Closure (unused). * @param cfg Configuration handle. * @param peer Testing peer handle. */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { static const struct GNUNET_CORE_MessageHandler handlers[] = { {&handle_test, GNUNET_MESSAGE_TYPE_TEST, 0}, {NULL, 0, 0} }; core = GNUNET_CORE_connect (cfg, NULL, &init_cb, &connect_cb, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers); if (NULL == core) { GNUNET_assert (0); return; } GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, NULL); }
static void init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; if (p == &p1) { /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); } else { GNUNET_assert (p == &p2); GNUNET_SCHEDULER_cancel (timeout_task_id); GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); } }
/** * Notify of all peer1's peers, once peer 2 is found, schedule connect * to peer two for message send. * * @param cls closure * @param peer peer identity this notification is about * @param atsi performance data for the connection * @param atsi_count number of atsi datums */ static void connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { struct TestMessageContext *pos = cls; if (0 == memcmp (&pos->peer2->id, peer, sizeof (struct GNUNET_PeerIdentity))) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection from `%s' to `%4s' verified.\n", GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey)); /* * Connect to the receiving peer */ pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, pos, &init_notify_peer2, &connect_notify_peer2, NULL, NULL, GNUNET_YES, NULL, GNUNET_YES, handlers); } }
static void init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end () }; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core connection to `%s' established\n", GNUNET_i2s (my_identity)); p->id = *my_identity; if (cls == &p1) { GNUNET_assert (ok == 2); OKPP; /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, handlers); } else { GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1); } }
static void init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) { struct PeerContext *p = cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connection to CORE service of `%4s' established\n", GNUNET_i2s (my_identity)); GNUNET_assert (NULL != my_identity); p->id = *my_identity; if (cls == &p1) { GNUNET_assert (ok == 2); OKPP; /* connect p2 */ p2.ch = GNUNET_CORE_connect (p2.cfg, &p2, &init_notify, &connect_notify, &disconnect_notify, &inbound_notify, GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); } else { GNUNET_assert (ok == 3); OKPP; GNUNET_assert (cls == &p2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking core (1) to connect to peer `%s' and vice-versa\n", GNUNET_i2s (&p2.id)); p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1); p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats, &p1.id, 1); } }
static void setup_learn_peer (struct PeerContext *p, const char *cfgname) { char *filename; unsigned int result; char *binary; binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); p->cfg = GNUNET_CONFIGURATION_create (); p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, NULL, binary, "gnunet-service-arm", "-c", cfgname, NULL); GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE", &filename)) { if (GNUNET_YES == GNUNET_DISK_file_test (filename)) { result = UNLINK (filename); if (result == 0) GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Hostlist file `%s' was removed\n"), filename); } GNUNET_free (filename); } p->core = GNUNET_CORE_connect (p->cfg, NULL, NULL, NULL, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, learn_handlers); GNUNET_assert (NULL != p->core); p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg); GNUNET_assert (NULL != p->stats); GNUNET_free (binary); }
/** * Function to call to start our services */ void NetworkManager::start(struct GNUNET_CONFIGURATION_Handle *config) { m_config = config; //Connect to peerinfo if (NULL == (m_peerInfo = GNUNET_PEERINFO_connect (config))) { qWarning("Failed to connect to PeerInfo service"); } //Initialize transport plugins m_gnunetTransportPlugins = new GnunetTransportPlugins(config,this); //Connect to peerinfo notifications m_peerInfoNotify = GNUNET_PEERINFO_notify (config, NULL, peerinfoProcessorCallback, this); if (m_peerInfoNotify == NULL) { qWarning("Failed to connect to PeerInfo Notify service"); } //Connect to the ats service m_ats = GNUNET_ATS_performance_init (config, ATSstatusChangeCallback, this); if (m_ats == NULL) { qWarning("Failed to connect to ATS service"); } //Monitor peer for connected transports m_peerMonitoring = GNUNET_TRANSPORT_monitor_peers (config, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &transportPeerChangeCallback, NULL); //Monitor peer for validated transports m_peerTransportValidation = GNUNET_TRANSPORT_monitor_validation_entries (config, NULL, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, &validationMonitorCallback, NULL); //Connect to core to receive all income and outcome messages ( for bandwidth calculation) m_core = GNUNET_CORE_connect (m_config, this, NULL, notifyConnectCallback, notifyDisconnectCallback, incomeMsgCallback, GNUNET_YES, outcomeMsgCallback, GNUNET_YES, NULL); //Inicialize NSE struct GNUNET_NSE_Handle *nse; nse = GNUNET_NSE_connect (config, checkNseMessageCallback, this); if(m_peerInfoNotify && m_ats && nse) { //status->setOkState(); } }
/** * Main function that will be run. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param cfg configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { static const struct GNUNET_CORE_MessageHandler learn_handlers[] = { {&advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, {NULL, 0, 0} }; static const struct GNUNET_CORE_MessageHandler no_learn_handlers[] = { {NULL, 0, 0} }; if ((! bootstrapping) && (! learning) #if HAVE_MHD && (! provide_hostlist) #endif ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("None of the functions for the hostlist daemon were enabled. I have no reason to run!\n")); return; } stats = GNUNET_STATISTICS_create ("hostlist", cfg); if (NULL == stats) { GNUNET_break (0); return; } if (bootstrapping) GNUNET_HOSTLIST_client_start (cfg, stats, &client_ch, &client_dh, &client_adv_handler, learning); core = GNUNET_CORE_connect (cfg, NULL, &core_init, &connect_handler, &disconnect_handler, NULL, GNUNET_NO, NULL, GNUNET_NO, learning ? learn_handlers : no_learn_handlers); #if HAVE_MHD if (provide_hostlist) GNUNET_HOSTLIST_server_start (cfg, stats, core, &server_ch, &server_dh, advertising); #endif GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, NULL); if (NULL == core) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to `%s' service.\n"), "core"); GNUNET_SCHEDULER_shutdown (); return; } }
/** * Handle network size estimate clients. * * @param cls closure * @param c configuration to use * @param service the initialized service */ static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) { struct GNUNET_MQ_MessageHandler core_handlers[] = { GNUNET_MQ_hd_fixed_size (p2p_estimate, GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, struct GNUNET_NSE_FloodMessage, NULL), GNUNET_MQ_handler_end () }; char *proof; struct GNUNET_CRYPTO_EddsaPrivateKey *pk; cfg = c; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "INTERVAL", &gnunet_nse_interval)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "INTERVAL"); GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "NSE", "WORKDELAY", &proof_find_delay)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY"); GNUNET_SCHEDULER_shutdown (); return; } if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "NSE", "WORKBITS", &nse_work_required)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS"); GNUNET_SCHEDULER_shutdown (); return; } if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8) { GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS", _("Value is too large.\n")); GNUNET_SCHEDULER_shutdown (); return; } #if ENABLE_NSE_HISTOGRAM { char *histogram_dir; char *histogram_fn; if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "HISTOGRAM_DIR", &histogram_dir)) { GNUNET_assert (0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir)); GNUNET_free (histogram_dir); histogram = GNUNET_BIO_write_open (histogram_fn); if (NULL == histogram) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to open histogram file `%s'\n", histogram_fn); GNUNET_free (histogram_fn); } logger_test = GNUNET_CLIENT_service_test ("testbed-logger", cfg, GNUNET_TIME_UNIT_SECONDS, &status_cb, NULL); } #endif GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); pk = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); GNUNET_assert (NULL != pk); my_private_key = pk; GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE"); GNUNET_free (my_private_key); my_private_key = NULL; GNUNET_SCHEDULER_shutdown (); return; } if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) || (sizeof (my_proof) != GNUNET_DISK_fn_read (proof, &my_proof, sizeof (my_proof)))) my_proof = 0; GNUNET_free (proof); proof_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, &find_proof, NULL); peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); nc = GNUNET_notification_context_create (1); /* Connect to core service and register core handlers */ core_api = GNUNET_CORE_connect (cfg, /* Main configuration */ NULL, /* Closure passed to functions */ &core_init, /* Call core_init once connected */ &handle_core_connect, /* Handle connects */ &handle_core_disconnect, /* Handle disconnects */ core_handlers); /* Register these handlers */ if (NULL == core_api) { GNUNET_SCHEDULER_shutdown (); return; } stats = GNUNET_STATISTICS_create ("nse", cfg); }
static void peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Daemon *d, const char *emsg) { struct PeerContext *new_peer; if (emsg != NULL) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", emsg); return; } GNUNET_assert (id != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", (num_peers - peers_left) + 1, num_peers); GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put (peer_daemon_hash, &id->hashPubKey, d, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); new_peer = GNUNET_malloc (sizeof (struct PeerContext)); new_peer->peer_handle = GNUNET_CORE_connect (cfg, d, NULL, &all_connect_handler, NULL, NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers); new_peer->daemon = d; new_peer->next = all_peers; all_peers = new_peer; peers_left--; if (peers_left == 0) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %d daemons started, now creating topology!\n", num_peers); GNUNET_SCHEDULER_cancel (die_task); die_task = GNUNET_SCHEDULER_NO_TASK; expected_connections = -1; if ((pg != NULL) && (peers_left == 0)) { expected_connections = GNUNET_TESTING_connect_topology (pg, connection_topology, connect_topology_option, connect_topology_option_modifier, TIMEOUT, 12, NULL, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n", expected_connections); } if (expected_connections == GNUNET_SYSERR) { die_task = GNUNET_SCHEDULER_add_now (&end_badly, "from connect topology (bad return)"); } else { /* Set up task in case topology creation doesn't finish * within a reasonable amount of time */ die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly, "from connect topology (timeout)"); } ok = 0; } }
/** * Main function that will be run. * * @param cls closure * @param args remaining command-line arguments * @param cfgfile name of the configuration file used (for saving, can be NULL!) * @param c configuration */ static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size (hello, GNUNET_MESSAGE_TYPE_HELLO, struct GNUNET_HELLO_Message, NULL), GNUNET_MQ_handler_end () }; unsigned long long opt; cfg = c; stats = GNUNET_STATISTICS_create ("topology", cfg); friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY"); if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "MINIMUM-FRIENDS", &opt)) opt = 0; minimum_friend_count = (unsigned int) opt; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "TARGET-CONNECTION-COUNT", &opt)) opt = 16; target_connection_count = (unsigned int) opt; peers = GNUNET_CONTAINER_multipeermap_create (target_connection_count * 2, GNUNET_NO); read_friends_file (cfg); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology would like %u connections with at least %u friends\n", target_connection_count, minimum_friend_count); if ( (friend_count < minimum_friend_count) && (NULL == blacklist)) blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); ats = GNUNET_ATS_connectivity_init (cfg); handle = GNUNET_CORE_connect (cfg, NULL, &core_init, &connect_notify, &disconnect_notify, handlers); GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL); if (NULL == handle) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to connect to `%s' service.\n"), "core"); GNUNET_SCHEDULER_shutdown (); return; } }