static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { 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; } /* Set up peer */ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.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.id))); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s_full(&p.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_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); test_ats_info[1].value = htonl(10); test_ats_count = 2; /* Adding address without session */ test_session = &test_addr; create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); test_hello_address.peer = p.id; test_hello_address.transport_name = test_addr.plugin; test_hello_address.address = test_addr.addr; test_hello_address.address_length = test_addr.addr_len; GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); /* Request address */ GNUNET_ATS_suggest_address (sched_ats, &p.id); }
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, struct GNUNET_TESTING_Peer *peer) { die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); stats = GNUNET_STATISTICS_create ("ats", mycfg); GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); /* Connect to ATS scheduling */ sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); if (sched_ats == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); GNUNET_SCHEDULER_add_now (&end_badly, NULL); return; } /* Set up peer */ memset (&p.id, '1', sizeof (p.id)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s_full(&p.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 without session */ test_session = NULL; create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); test_hello_address.peer = p.id; test_hello_address.transport_name = test_addr.plugin; test_hello_address.address = test_addr.addr; test_hello_address.address_length = test_addr.addr_len; /* Adding address */ GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); }
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); }