static void test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { if (NULL == ph) ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (NULL == ph) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize performance handle\n"); ret = 2; } stage++; switch (stage) { case 1: /* Get all peers, all addresses */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 1: \n"); phal = GNUNET_ATS_performance_list_addresses (ph, NULL, GNUNET_YES, &all_addresses_cb, NULL); GNUNET_assert (NULL != phal); break; case 2: /* Get specific peer, all addresses */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 2: \n"); phal = GNUNET_ATS_performance_list_addresses (ph, &p[1].id, GNUNET_YES, &all_addresses_peer_cb, NULL); GNUNET_assert (NULL != phal); break; case 3: /* Get all peers, active addresses */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 3: \n"); phal = GNUNET_ATS_performance_list_addresses (ph, NULL, GNUNET_NO, &all_active_addresses_cb, NULL); GNUNET_assert (NULL != phal); break; case 4: /* Get specific peers, active addresses */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Run stage 4: \n"); phal = GNUNET_ATS_performance_list_addresses (ph, &p[1].id, GNUNET_NO, &all_active_addresses_peer_cb, NULL); GNUNET_assert (NULL != phal); break; default: /* done */ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "All tests successful, shutdown... \n"); GNUNET_SCHEDULER_add_now (&end, NULL); return; } }
/** * 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(); } }
void testservice_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GNUNET_PeerIdentity pid; struct GNUNET_CONFIGURATION_Handle *cfg = cls; unsigned int c; unsigned int type; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) { FPRINTF (stderr, _("Service `%s' is not running\n"), "ats"); return; } results = 0; if (NULL != pid_str) { if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (pid_str, &pid.hashPubKey)) { FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), pid_str); return; } } c = op_list_all + op_list_used + op_monitor + op_set_pref; if ((1 < c)) { FPRINTF (stderr, _("Please select one operation : %s or %s or %s or %s\n"), "--used", "--all", "--monitor", "--preference"); return; } if ((0 == c)) op_list_used = GNUNET_YES; /* set default */ if (op_list_all) { ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (NULL == ph) { fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); return; } alh = GNUNET_ATS_performance_list_addresses (ph, (NULL == pid_str) ? NULL : &pid, GNUNET_YES, ats_perf_cb, NULL); if (NULL == alh) { fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n")); end_task = GNUNET_SCHEDULER_add_now (&end, NULL); return; } end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); } else if (op_list_used) { ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (NULL == ph) fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); alh = GNUNET_ATS_performance_list_addresses (ph, (NULL == pid_str) ? NULL : &pid, GNUNET_NO, ats_perf_cb, NULL); if (NULL == alh) { fprintf (stderr, _("Cannot issue request to ATS service, exiting...\n")); end_task = GNUNET_SCHEDULER_add_now (&end, NULL); return; } end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); } else if (op_monitor) { ph = GNUNET_ATS_performance_init (cfg, ats_perf_cb, NULL); if (NULL == ph) fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &end, NULL); } else if (op_set_pref) { for (c = 0; c<strlen(type_str); c++) { if (isupper (type_str[c])) type_str[c] = tolower (type_str[c]); } if (0 == strcasecmp("latency", type_str)) type = GNUNET_ATS_PREFERENCE_LATENCY; else if (0 == strcasecmp("bandwidth", type_str)) type = GNUNET_ATS_PREFERENCE_BANDWIDTH; else { FPRINTF (stderr, "%s", _("Type required\n")); return; } /* set */ ph = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (NULL == ph) fprintf (stderr, _("Cannot connect to ATS service, exiting...\n")); GNUNET_ATS_change_preference (ph, &pid, type, (double) value, GNUNET_ATS_PREFERENCE_END); end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); } ret = 1; }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, struct GNUNET_TESTING_Peer *peer) { ret = 1; cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to connect to performance API\n"); GNUNET_SCHEDULER_add_now (end_badly, NULL); } stats = GNUNET_STATISTICS_create ("ats", cfg); GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); /* set up peer 0 */ memset (&p[0].id, '1', sizeof (p[0].id)); p0_addresses[0].plugin = "test"; p0_addresses[0].session = NULL; p0_addresses[0].addr = GNUNET_strdup ("test_p0_a0"); p0_addresses[0].addr_len = strlen (p0_addresses[0].addr) + 1; p0_ha[0].address = p0_addresses[0].addr; p0_ha[0].address_length = p0_addresses[0].addr_len; p0_ha[0].peer = p[0].id; p0_ha[0].transport_name = p0_addresses[0].plugin; p0_addresses[1].plugin = "test"; p0_addresses[1].session = NULL; p0_addresses[1].addr = GNUNET_strdup ("test_p0_a1"); p0_addresses[1].addr_len = strlen (p0_addresses[1].addr) + 1; p0_ha[1].address = p0_addresses[1].addr; p0_ha[1].address_length = p0_addresses[1].addr_len; p0_ha[1].peer = p[0].id; p0_ha[1].transport_name = p0_addresses[1].plugin; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 0: `%s'\n", GNUNET_i2s (&p[0].id)); memset (&p[1].id, '2', sizeof (p[1].id)); p1_addresses[0].plugin = "test"; p1_addresses[0].session = NULL; p1_addresses[0].addr = GNUNET_strdup ("test_p1_a0"); p1_addresses[0].addr_len = strlen (p1_addresses[0].addr) + 1; p1_ha[0].address = p1_addresses[0].addr; p1_ha[0].address_length = p1_addresses[0].addr_len; p1_ha[0].peer = p[1].id; p1_ha[0].transport_name = p1_addresses[0].plugin; p1_addresses[1].plugin = "test"; p1_addresses[1].session = NULL; p1_addresses[1].addr = GNUNET_strdup ("test_p1_a1"); p1_addresses[1].addr_len = strlen (p1_addresses[1].addr) + 1; p1_ha[1].address = p1_addresses[1].addr; p1_ha[1].address_length = p1_addresses[1].addr_len; p1_ha[1].peer = p[1].id; p1_ha[1].transport_name = p1_addresses[1].plugin; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer 1: `%s'\n", GNUNET_i2s (&p[1].id)); /* Add addresses */ sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL ); if (sched_ats == NULL ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); GNUNET_SCHEDULER_add_now (&end_badly, NULL); return; } GNUNET_ATS_address_add (sched_ats, &p0_ha[0], NULL, NULL, 0); GNUNET_ATS_address_add (sched_ats, &p0_ha[1], NULL, NULL, 0); GNUNET_ATS_address_add (sched_ats, &p1_ha[0], NULL, NULL, 0); GNUNET_ATS_address_add (sched_ats, &p1_ha[1], NULL, NULL, 0); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { char *quota_str; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_OUT", "a_str)) { fprintf (stderr, "Cannot load WAN outbound quota from configuration, exit!\n"); ret = 1; return; } if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_str, &wan_quota_out)) { fprintf (stderr, "Cannot load WAN outbound quota from configuration, exit!\n"); ret = 1; GNUNET_free (quota_str); return; } GNUNET_free (quota_str); quota_str = NULL; if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "ats", "WAN_QUOTA_IN", "a_str)) { fprintf (stderr, "Cannot load WAN inbound quota from configuration, exit!\n"); ret = 1; return; } if (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_str, &wan_quota_in)) { fprintf (stderr, "Cannot load WAN inbound quota from configuration, exit!\n"); GNUNET_free (quota_str); ret = 1; return; } GNUNET_free (quota_str); quota_str = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Configured WAN inbound quota: %llu\n", wan_quota_in); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Configured WAN outbound quota: %llu\n", wan_quota_out); die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); /* Connect to ATS scheduling */ sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); if (sched_ats == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); ret = 1; end (); return; } perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL); if (perf_ats == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n"); ret = 1; end (); return; } /* Set up peer 0 */ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); ret = GNUNET_SYSERR; end (); return; } GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id))); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s(&p[0].id)); /* Set up peer 0 */ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); ret = GNUNET_SYSERR; end (); return; } GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id))); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s(&p[1].id)); /* Prepare ATS Information */ test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); test_ats_info[1].value = htonl(1); test_ats_count = 2; /* Adding address with session */ test_session[0] = &test_addr[0]; create_test_address (&test_addr[0], "test0", test_session[0], "test0", strlen ("test0") + 1); test_hello_address[0].peer = p[0].id; test_hello_address[0].transport_name = test_addr[0].plugin; test_hello_address[0].address = test_addr[0].addr; test_hello_address[0].address_length = test_addr[0].addr_len; GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], test_session[0], test_ats_info, test_ats_count); /* Adding address with session */ test_session[1] = &test_addr[1]; create_test_address (&test_addr[1], "test1", test_session[1], "test1", strlen ("test1") + 1); test_hello_address[1].peer = p[1].id; test_hello_address[1].transport_name = test_addr[0].plugin; test_hello_address[1].address = test_addr[0].addr; test_hello_address[1].address_length = test_addr[0].addr_len; GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], test_session[1], test_ats_info, test_ats_count); /* Change bandwidth preference */ GNUNET_ATS_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); GNUNET_ATS_change_preference (perf_ats, &p[1].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); /* Change latency preference */ GNUNET_ATS_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_LATENCY,(double) 10, GNUNET_ATS_PREFERENCE_END); GNUNET_ATS_change_preference (perf_ats, &p[1].id, GNUNET_ATS_PREFERENCE_LATENCY,(double) 100, GNUNET_ATS_PREFERENCE_END); GNUNET_SCHEDULER_add_delayed (SLEEP, &sleep_task, NULL); }