diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-15 09:09:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-06-15 09:09:32 +0000 |
commit | 6c147cc9bfa5ac134269593d6e4dbcd0be66ac91 (patch) | |
tree | 20beca2ef4c929357afc59b6e9b2ec2171da312c /src/ats | |
parent | 36ca9fcc68935edd109481d30f9e6e15a825c282 (diff) | |
download | gnunet-6c147cc9bfa5ac134269593d6e4dbcd0be66ac91.tar.gz gnunet-6c147cc9bfa5ac134269593d6e4dbcd0be66ac91.zip |
- changes related to ATS_address_add + testcases for address deletion and adding
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 8 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 110 | ||||
-rw-r--r-- | src/ats/test_ats_api_reset_backoff.c | 1 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling.c | 15 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_add_address.c | 13 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_address.c | 228 |
6 files changed, 301 insertions, 74 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 5b1c6b2e4..87a7fc05a 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -54,9 +54,10 @@ gnunet_service_ats_LDADD = \ | |||
54 | 54 | ||
55 | 55 | ||
56 | check_PROGRAMS = \ | 56 | check_PROGRAMS = \ |
57 | test_ats_api_scheduling_add_address \ | ||
57 | test_ats_api_scheduling \ | 58 | test_ats_api_scheduling \ |
59 | test_ats_api_scheduling_destroy_address \ | ||
58 | test_ats_api_reset_backoff \ | 60 | test_ats_api_reset_backoff \ |
59 | test_ats_api_scheduling_add_address \ | ||
60 | $(GN_MLP_TEST) \ | 61 | $(GN_MLP_TEST) \ |
61 | $(GN_MLP_TEST_AVG) \ | 62 | $(GN_MLP_TEST_AVG) \ |
62 | $(GN_MLP_PERF) | 63 | $(GN_MLP_PERF) |
@@ -111,6 +112,11 @@ test_ats_api_scheduling_add_address_LDADD = \ | |||
111 | $(top_builddir)/src/util/libgnunetutil.la \ | 112 | $(top_builddir)/src/util/libgnunetutil.la \ |
112 | $(top_builddir)/src/ats/libgnunetats.la | 113 | $(top_builddir)/src/ats/libgnunetats.la |
113 | 114 | ||
115 | test_ats_api_scheduling_destroy_address_SOURCES = \ | ||
116 | test_ats_api_scheduling_destroy_address.c | ||
117 | test_ats_api_scheduling_destroy_address_LDADD = \ | ||
118 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
119 | $(top_builddir)/src/ats/libgnunetats.la | ||
114 | 120 | ||
115 | #test_ats_api_scheduling_get_type_SOURCES = \ | 121 | #test_ats_api_scheduling_get_type_SOURCES = \ |
116 | # test_ats_api_scheduling_get_type.c | 122 | # test_ats_api_scheduling_get_type.c |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 854716dc7..aedef817f 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -288,6 +288,44 @@ find_address (const struct GNUNET_PeerIdentity *peer, | |||
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | static struct ATS_Address * | ||
292 | lookup_address (const struct GNUNET_PeerIdentity *peer, | ||
293 | const char *plugin_name, const void *plugin_addr, | ||
294 | size_t plugin_addr_len, uint32_t session_id, | ||
295 | const struct GNUNET_ATS_Information *atsi, | ||
296 | uint32_t atsi_count) | ||
297 | { | ||
298 | struct ATS_Address *aa; | ||
299 | struct ATS_Address *old; | ||
300 | |||
301 | aa = create_address (peer, | ||
302 | plugin_name, | ||
303 | plugin_addr, plugin_addr_len, | ||
304 | session_id); | ||
305 | |||
306 | aa->mlp_information = NULL; | ||
307 | aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
308 | aa->ats_count = atsi_count; | ||
309 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
310 | |||
311 | /* Get existing address or address with session == 0 */ | ||
312 | old = find_address (peer, aa); | ||
313 | if (old == NULL) | ||
314 | { | ||
315 | GNUNET_free (aa); | ||
316 | return NULL; | ||
317 | } | ||
318 | else if (old->session_id != session_id) | ||
319 | { | ||
320 | |||
321 | GNUNET_free (aa); | ||
322 | GNUNET_break (0); | ||
323 | return NULL; | ||
324 | } | ||
325 | |||
326 | return old; | ||
327 | } | ||
328 | |||
291 | static int | 329 | static int |
292 | compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value) | 330 | compare_address_session_it (void *cls, const struct GNUNET_HashCode * key, void *value) |
293 | { | 331 | { |
@@ -400,7 +438,6 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
400 | const struct GNUNET_ATS_Information *atsi, | 438 | const struct GNUNET_ATS_Information *atsi, |
401 | uint32_t atsi_count) | 439 | uint32_t atsi_count) |
402 | { | 440 | { |
403 | struct ATS_Address *aa; | ||
404 | struct ATS_Address *old; | 441 | struct ATS_Address *old; |
405 | uint32_t i; | 442 | uint32_t i; |
406 | 443 | ||
@@ -409,51 +446,17 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
409 | 446 | ||
410 | GNUNET_assert (NULL != addresses); | 447 | GNUNET_assert (NULL != addresses); |
411 | 448 | ||
412 | aa = create_address (peer, | 449 | /* Get existing address */ |
413 | plugin_name, | 450 | old = lookup_address(peer, plugin_name, plugin_addr, plugin_addr_len, |
414 | plugin_addr, plugin_addr_len, | 451 | session_id, atsi, atsi_count); |
415 | session_id); | ||
416 | |||
417 | aa->mlp_information = NULL; | ||
418 | aa->ats = GNUNET_malloc (atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
419 | aa->ats_count = atsi_count; | ||
420 | memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information)); | ||
421 | |||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' %u\n", | ||
423 | GNUNET_i2s (peer), | ||
424 | session_id); | ||
425 | |||
426 | /* Get existing address or address with session == 0 */ | ||
427 | old = find_address (peer, aa); | ||
428 | if (old == NULL) | 452 | if (old == NULL) |
429 | { | 453 | { |
430 | GNUNET_assert (GNUNET_OK == | 454 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to update unknown address for peer `%s' `%s' session id %u\n", |
431 | GNUNET_CONTAINER_multihashmap_put (addresses, | 455 | GNUNET_i2s (peer), plugin_name, session_id); |
432 | &peer->hashPubKey, aa, | 456 | GNUNET_break (0); |
433 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 457 | return; |
434 | #if DEBUG_ATS | ||
435 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %p\n", | ||
436 | GNUNET_i2s (peer), aa); | ||
437 | #endif | ||
438 | old = aa; | ||
439 | } | ||
440 | else | ||
441 | { | ||
442 | #if DEBUG_ATS | ||
443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
444 | "Updated existing address for peer `%s' %p old session %u new session %u\n", | ||
445 | GNUNET_i2s (peer), old, | ||
446 | old->session_id, session_id); | ||
447 | #endif | ||
448 | GNUNET_free_non_null (old->ats); | ||
449 | old->session_id = session_id; | ||
450 | old->ats = NULL; | ||
451 | old->ats_count = 0; | ||
452 | old->ats = aa->ats; | ||
453 | old->ats_count = aa->ats_count; | ||
454 | GNUNET_free (aa->plugin); | ||
455 | GNUNET_free (aa); | ||
456 | } | 458 | } |
459 | |||
457 | for (i = 0; i < atsi_count; i++) | 460 | for (i = 0; i < atsi_count; i++) |
458 | switch (ntohl (atsi[i].type)) | 461 | switch (ntohl (atsi[i].type)) |
459 | { | 462 | { |
@@ -578,10 +581,23 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
578 | size_t plugin_addr_len, uint32_t session_id) | 581 | size_t plugin_addr_len, uint32_t session_id) |
579 | { | 582 | { |
580 | struct ATS_Address *aa; | 583 | struct ATS_Address *aa; |
584 | struct ATS_Address *old; | ||
581 | 585 | ||
582 | if (GNUNET_NO == running) | 586 | if (GNUNET_NO == running) |
583 | return; | 587 | return; |
584 | 588 | ||
589 | /* Get existing address */ | ||
590 | old = lookup_address(peer, plugin_name, plugin_addr, plugin_addr_len, | ||
591 | session_id, NULL, 0); | ||
592 | if (old == NULL) | ||
593 | { | ||
594 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", | ||
595 | GNUNET_i2s (peer), plugin_name, session_id); | ||
596 | GNUNET_break (0); | ||
597 | return; | ||
598 | } | ||
599 | |||
600 | |||
585 | GNUNET_break (0 < strlen (plugin_name)); | 601 | GNUNET_break (0 < strlen (plugin_name)); |
586 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); | 602 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); |
587 | 603 | ||
@@ -692,20 +708,16 @@ GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | |||
692 | GNUNET_i2s (peer), in_use); | 708 | GNUNET_i2s (peer), in_use); |
693 | #endif | 709 | #endif |
694 | 710 | ||
695 | struct ATS_Address *aa; | ||
696 | struct ATS_Address *old; | 711 | struct ATS_Address *old; |
697 | 712 | ||
698 | if (GNUNET_NO == running) | 713 | if (GNUNET_NO == running) |
699 | return GNUNET_SYSERR; | 714 | return GNUNET_SYSERR; |
700 | 715 | ||
701 | aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id); | 716 | old = lookup_address (peer, plugin_name, plugin_addr, plugin_addr_len, session_id, NULL, 0); |
702 | old = find_exact_address (peer, aa); | ||
703 | free_address (aa); | ||
704 | |||
705 | if (NULL == old) | 717 | if (NULL == old) |
706 | { | 718 | { |
707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 719 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
708 | "Unknown address `%s', %s %u %s \n", | 720 | "Trying to set unknown address `%s', %s %u %s \n", |
709 | GNUNET_i2s (peer), | 721 | GNUNET_i2s (peer), |
710 | plugin_name, session_id, | 722 | plugin_name, session_id, |
711 | (GNUNET_NO == in_use) ? "NO" : "YES"); | 723 | (GNUNET_NO == in_use) ? "NO" : "YES"); |
diff --git a/src/ats/test_ats_api_reset_backoff.c b/src/ats/test_ats_api_reset_backoff.c index 38c18e1ac..859cfc215 100644 --- a/src/ats/test_ats_api_reset_backoff.c +++ b/src/ats/test_ats_api_reset_backoff.c | |||
@@ -273,6 +273,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
273 | hello_addr.transport_name = address.plugin; | 273 | hello_addr.transport_name = address.plugin; |
274 | hello_addr.address = address.addr; | 274 | hello_addr.address = address.addr; |
275 | hello_addr.address_length = address.addr_len; | 275 | hello_addr.address_length = address.addr_len; |
276 | GNUNET_ATS_address_add (ats, &hello_addr, address.session, NULL, 0); | ||
276 | GNUNET_ATS_address_update (ats, &hello_addr, address.session, NULL, 0); | 277 | GNUNET_ATS_address_update (ats, &hello_addr, address.session, NULL, 0); |
277 | 278 | ||
278 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting address for peer `%s'\n", | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting address for peer `%s'\n", |
diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c index c9d2206b3..6a8e53395 100644 --- a/src/ats/test_ats_api_scheduling.c +++ b/src/ats/test_ats_api_scheduling.c | |||
@@ -134,15 +134,6 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
134 | address->address_length)); | 134 | address->address_length)); |
135 | GNUNET_assert (addr[0].session == session); | 135 | GNUNET_assert (addr[0].session == session); |
136 | 136 | ||
137 | |||
138 | /* TODO ats merge | ||
139 | * GNUNET_assert (ats_count == 2); | ||
140 | * GNUNET_assert (atsi[0].type == htons (1)); | ||
141 | * GNUNET_assert (atsi[0].type == htons (2)); | ||
142 | * GNUNET_assert (atsi[1].type == htons (2)); | ||
143 | * GNUNET_assert (atsi[1].type == htons (2)); | ||
144 | */ | ||
145 | |||
146 | ret = 0; | 137 | ret = 0; |
147 | 138 | ||
148 | GNUNET_SCHEDULER_add_now (&end, NULL); | 139 | GNUNET_SCHEDULER_add_now (&end, NULL); |
@@ -199,6 +190,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
199 | address0.transport_name = addr[0].plugin; | 190 | address0.transport_name = addr[0].plugin; |
200 | address0.address = addr[0].addr; | 191 | address0.address = addr[0].addr; |
201 | address0.address_length = addr[0].addr_len; | 192 | address0.address_length = addr[0].addr_len; |
193 | GNUNET_ATS_address_add (ats, &address0, addr[0].session, NULL, 0); | ||
202 | GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0); | 194 | GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0); |
203 | 195 | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); | 196 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); |
@@ -218,11 +210,6 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
218 | 210 | ||
219 | GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 2); | 211 | GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 2); |
220 | 212 | ||
221 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n"); | ||
222 | address0.peer = p[1].id; // FIXME: why? typo in old code? | ||
223 | GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0); | ||
224 | GNUNET_ATS_address_destroyed (ats, &address0, addr[0].session); | ||
225 | |||
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", | 213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", |
227 | GNUNET_i2s (&p[0].id)); | 214 | GNUNET_i2s (&p[0].id)); |
228 | GNUNET_ATS_suggest_address (ats, &p[0].id); | 215 | GNUNET_ATS_suggest_address (ats, &p[0].id); |
diff --git a/src/ats/test_ats_api_scheduling_add_address.c b/src/ats/test_ats_api_scheduling_add_address.c index 04ece4044..f3f0f55a7 100644 --- a/src/ats/test_ats_api_scheduling_add_address.c +++ b/src/ats/test_ats_api_scheduling_add_address.c | |||
@@ -18,17 +18,10 @@ | |||
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_api_scheduling.c | 21 | * @file ats/test_ats_api_scheduling_add_address.c |
22 | * @brief test automatic transport selection scheduling API | 22 | * @brief test adding addresses in automatic transport selection scheduling API |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * | ||
26 | * TODO: | ||
27 | * - write test case | ||
28 | * - extend API to get performance data | ||
29 | * - implement simplistic strategy based on say 'lowest latency' or strict ordering | ||
30 | * - extend API to get peer preferences, implement proportional bandwidth assignment | ||
31 | * - re-implement API against a real ATS service (!) | ||
32 | */ | 25 | */ |
33 | #include "platform.h" | 26 | #include "platform.h" |
34 | #include "gnunet_ats_service.h" | 27 | #include "gnunet_ats_service.h" |
@@ -223,4 +216,4 @@ main (int argc, char *argv[]) | |||
223 | return ret; | 216 | return ret; |
224 | } | 217 | } |
225 | 218 | ||
226 | /* end of file test_ats_api_scheduling.c */ | 219 | /* end of file test_ats_api_scheduling_add_address.c */ |
diff --git a/src/ats/test_ats_api_scheduling_destroy_address.c b/src/ats/test_ats_api_scheduling_destroy_address.c new file mode 100644 index 000000000..ae2b4727d --- /dev/null +++ b/src/ats/test_ats_api_scheduling_destroy_address.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2010,2011 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file ats/test_ats_api_scheduling_destroy_address.c | ||
22 | * @brief test destroying addresses in automatic transport selection scheduling API | ||
23 | * @author Christian Grothoff | ||
24 | * @author Matthias Wachs | ||
25 | * | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_ats_service.h" | ||
29 | #include "ats.h" | ||
30 | |||
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
32 | |||
33 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
34 | |||
35 | static struct GNUNET_ATS_SchedulingHandle *ats; | ||
36 | |||
37 | struct GNUNET_OS_Process *arm_proc; | ||
38 | |||
39 | |||
40 | |||
41 | static int ret; | ||
42 | static int stage; | ||
43 | |||
44 | struct Address | ||
45 | { | ||
46 | char *plugin; | ||
47 | size_t plugin_len; | ||
48 | |||
49 | void *addr; | ||
50 | size_t addr_len; | ||
51 | |||
52 | struct GNUNET_ATS_Information *ats; | ||
53 | int ats_count; | ||
54 | |||
55 | void *session; | ||
56 | }; | ||
57 | |||
58 | struct PeerContext | ||
59 | { | ||
60 | struct GNUNET_PeerIdentity id; | ||
61 | |||
62 | struct Address *addr; | ||
63 | }; | ||
64 | |||
65 | struct Address addr; | ||
66 | struct PeerContext p; | ||
67 | struct GNUNET_ATS_Information atsi; | ||
68 | struct GNUNET_HELLO_Address address0; | ||
69 | |||
70 | static void | ||
71 | stop_arm () | ||
72 | { | ||
73 | if (0 != GNUNET_OS_process_kill (arm_proc, SIGTERM)) | ||
74 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
75 | GNUNET_OS_process_wait (arm_proc); | ||
76 | GNUNET_OS_process_destroy (arm_proc); | ||
77 | arm_proc = NULL; | ||
78 | } | ||
79 | |||
80 | |||
81 | static void | ||
82 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
83 | { | ||
84 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
85 | if (ats != NULL) | ||
86 | GNUNET_ATS_scheduling_done (ats); | ||
87 | |||
88 | ret = GNUNET_SYSERR; | ||
89 | |||
90 | stop_arm (); | ||
91 | } | ||
92 | |||
93 | |||
94 | static void | ||
95 | end () | ||
96 | { | ||
97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
98 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
99 | { | ||
100 | GNUNET_SCHEDULER_cancel (die_task); | ||
101 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
102 | } | ||
103 | |||
104 | GNUNET_ATS_scheduling_done (ats); | ||
105 | |||
106 | if (2 == stage) | ||
107 | ret = 0; | ||
108 | else | ||
109 | { | ||
110 | GNUNET_break (0); | ||
111 | ret = 1; | ||
112 | } | ||
113 | |||
114 | stop_arm (); | ||
115 | } | ||
116 | |||
117 | |||
118 | static void | ||
119 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | ||
120 | struct Session *session, | ||
121 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
122 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
123 | const struct GNUNET_ATS_Information *atsi, | ||
124 | uint32_t ats_count) | ||
125 | { | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage %u: ATS suggests address `%s' session %p\n", | ||
127 | stage, GNUNET_i2s (&address->peer), session); | ||
128 | GNUNET_ATS_reset_backoff(ats, &address->peer); | ||
129 | |||
130 | GNUNET_assert (0 == | ||
131 | memcmp (&address->peer, &p.id, | ||
132 | sizeof (struct GNUNET_PeerIdentity))); | ||
133 | GNUNET_assert (0 == strcmp (address->transport_name, addr.plugin)); | ||
134 | GNUNET_assert (address->address_length == addr.addr_len); | ||
135 | GNUNET_assert (0 == | ||
136 | memcmp (address->address, addr.plugin, | ||
137 | address->address_length)); | ||
138 | GNUNET_assert (addr.session == session); | ||
139 | |||
140 | if (0 == stage) | ||
141 | { | ||
142 | /* Delete session */ | ||
143 | GNUNET_ATS_address_destroyed (ats, &address0, addr.session); | ||
144 | addr.session = NULL; | ||
145 | GNUNET_ATS_suggest_address (ats, &p.id); | ||
146 | } | ||
147 | if (1 == stage) | ||
148 | { | ||
149 | /* Delete address */ | ||
150 | GNUNET_ATS_address_destroyed (ats, &address0, addr.session); | ||
151 | addr.session = NULL; | ||
152 | GNUNET_ATS_suggest_address (ats, &p.id); | ||
153 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | ||
154 | } | ||
155 | stage++; | ||
156 | } | ||
157 | |||
158 | void | ||
159 | start_arm (const char *cfgname) | ||
160 | { | ||
161 | arm_proc = | ||
162 | GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm", | ||
163 | "gnunet-service-arm", | ||
164 | "-c", cfgname, NULL); | ||
165 | } | ||
166 | |||
167 | static void | ||
168 | check (void *cls, char *const *args, const char *cfgfile, | ||
169 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
170 | { | ||
171 | ret = GNUNET_SYSERR; | ||
172 | |||
173 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
174 | start_arm (cfgfile); | ||
175 | |||
176 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
177 | |||
178 | if (ats == NULL) | ||
179 | { | ||
180 | ret = GNUNET_SYSERR; | ||
181 | end (); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | /* set up peer */ | ||
186 | GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, | ||
187 | &p.id.hashPubKey); | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
189 | GNUNET_i2s (&p.id)); | ||
190 | |||
191 | addr.plugin = "test"; | ||
192 | addr.session = &addr; | ||
193 | addr.addr = GNUNET_strdup ("test"); | ||
194 | addr.addr_len = 4; | ||
195 | |||
196 | /* Adding address with session */ | ||
197 | address0.peer = p.id; | ||
198 | address0.transport_name = addr.plugin; | ||
199 | address0.address = addr.addr; | ||
200 | address0.address_length = addr.addr_len; | ||
201 | GNUNET_ATS_address_add (ats, &address0, addr.session, NULL, 0); | ||
202 | |||
203 | GNUNET_ATS_suggest_address (ats, &p.id); | ||
204 | } | ||
205 | |||
206 | int | ||
207 | main (int argc, char *argv[]) | ||
208 | { | ||
209 | static char *const argv2[] = { "test_ats_api_scheduling_destroy_address", | ||
210 | "-c", | ||
211 | "test_ats_api.conf", | ||
212 | "-L", "WARNING", | ||
213 | NULL | ||
214 | }; | ||
215 | |||
216 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
217 | GNUNET_GETOPT_OPTION_END | ||
218 | }; | ||
219 | |||
220 | GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, | ||
221 | "test_ats_api_scheduling_destroy_address", "nohelp", options, &check, | ||
222 | NULL); | ||
223 | |||
224 | |||
225 | return ret; | ||
226 | } | ||
227 | |||
228 | /* end of file test_ats_api_scheduling_destroy_address.c */ | ||