diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-22 13:49:32 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-11-22 13:49:32 +0000 |
commit | 460dd88280de1904b27077aee1aafb27df68fc47 (patch) | |
tree | e49b0eeb082f362ff5fd8d5e3562e1c7de623bda /src/ats/test_ats_api_performance.c | |
parent | 9b42dfd0d4fb3c97a389d3352ecf8cb26c564cd7 (diff) | |
download | gnunet-460dd88280de1904b27077aee1aafb27df68fc47.tar.gz gnunet-460dd88280de1904b27077aee1aafb27df68fc47.zip |
stage 3
Diffstat (limited to 'src/ats/test_ats_api_performance.c')
-rw-r--r-- | src/ats/test_ats_api_performance.c | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/src/ats/test_ats_api_performance.c b/src/ats/test_ats_api_performance.c index 644121370..84aad42ab 100644 --- a/src/ats/test_ats_api_performance.c +++ b/src/ats/test_ats_api_performance.c | |||
@@ -34,7 +34,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task; | |||
34 | 34 | ||
35 | struct GNUNET_CONFIGURATION_Handle *cfg; | 35 | struct GNUNET_CONFIGURATION_Handle *cfg; |
36 | 36 | ||
37 | static struct GNUNET_ATS_SchedulingHandle *ats; | 37 | static struct GNUNET_ATS_SchedulingHandle *atsh; |
38 | static struct GNUNET_ATS_PerformanceHandle *ph; | 38 | static struct GNUNET_ATS_PerformanceHandle *ph; |
39 | struct GNUNET_ATS_AddressListHandle* phal; | 39 | struct GNUNET_ATS_AddressListHandle* phal; |
40 | 40 | ||
@@ -70,6 +70,7 @@ static struct Address p1_addresses[2]; | |||
70 | 70 | ||
71 | struct GNUNET_HELLO_Address p0_ha[2]; | 71 | struct GNUNET_HELLO_Address p0_ha[2]; |
72 | struct GNUNET_HELLO_Address p1_ha[2]; | 72 | struct GNUNET_HELLO_Address p1_ha[2]; |
73 | struct GNUNET_HELLO_Address *s_ha[2]; | ||
73 | 74 | ||
74 | static unsigned int stage = 0; | 75 | static unsigned int stage = 0; |
75 | 76 | ||
@@ -80,8 +81,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
80 | 81 | ||
81 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout in stage %u\n", stage); | 82 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout in stage %u\n", stage); |
82 | 83 | ||
83 | if (NULL != ats) | 84 | if (NULL != atsh) |
84 | GNUNET_ATS_scheduling_done (ats); | 85 | GNUNET_ATS_scheduling_done (atsh); |
85 | if (phal != NULL) | 86 | if (phal != NULL) |
86 | GNUNET_ATS_performance_list_addresses_cancel (phal); | 87 | GNUNET_ATS_performance_list_addresses_cancel (phal); |
87 | phal = NULL; | 88 | phal = NULL; |
@@ -107,8 +108,8 @@ end () | |||
107 | GNUNET_SCHEDULER_cancel (die_task); | 108 | GNUNET_SCHEDULER_cancel (die_task); |
108 | die_task = GNUNET_SCHEDULER_NO_TASK; | 109 | die_task = GNUNET_SCHEDULER_NO_TASK; |
109 | } | 110 | } |
110 | if (NULL != ats) | 111 | if (NULL != atsh) |
111 | GNUNET_ATS_scheduling_done (ats); | 112 | GNUNET_ATS_scheduling_done (atsh); |
112 | if (phal != NULL) | 113 | if (phal != NULL) |
113 | GNUNET_ATS_performance_list_addresses_cancel (phal); | 114 | GNUNET_ATS_performance_list_addresses_cancel (phal); |
114 | phal = NULL; | 115 | phal = NULL; |
@@ -163,20 +164,17 @@ void all_active_addresses_cb (void *cls, | |||
163 | 164 | ||
164 | if (address != NULL) | 165 | if (address != NULL) |
165 | { | 166 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer `%s' address `%s'\n", | ||
167 | GNUNET_i2s (&address->peer), address->address); | ||
168 | |||
169 | if (0 == memcmp (&address->peer, &p[0].id, | 167 | if (0 == memcmp (&address->peer, &p[0].id, |
170 | sizeof (struct GNUNET_PeerIdentity))) | 168 | sizeof (struct GNUNET_PeerIdentity))) |
171 | { | 169 | { |
172 | if (0 == strcmp(address->address, p0_addresses[0].addr)) | 170 | if (0 == strcmp(address->address, s_ha[0]->address)) |
173 | { | 171 | { |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 0 address 0\n"); | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 0 suggested address %s\n", s_ha[0]->address); |
175 | cb ++; | 173 | cb ++; |
176 | } | 174 | } |
177 | else | 175 | else |
178 | { | 176 | { |
179 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 0 address 0!\n"); | 177 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 0 address `%s', got address `%s'!\n", s_ha[0]->address, address->address); |
180 | GNUNET_ATS_performance_list_addresses_cancel (phal); | 178 | GNUNET_ATS_performance_list_addresses_cancel (phal); |
181 | fail = GNUNET_YES; | 179 | fail = GNUNET_YES; |
182 | } | 180 | } |
@@ -185,19 +183,18 @@ void all_active_addresses_cb (void *cls, | |||
185 | if (0 == memcmp (&address->peer, &p[1].id, | 183 | if (0 == memcmp (&address->peer, &p[1].id, |
186 | sizeof (struct GNUNET_PeerIdentity))) | 184 | sizeof (struct GNUNET_PeerIdentity))) |
187 | { | 185 | { |
188 | if (0 == strcmp(address->address, p1_addresses[1].addr)) | 186 | if (0 == strcmp(address->address, s_ha[1]->address)) |
189 | { | 187 | { |
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 1 address 1\n"); | 188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for peer 1 suggested address %s\n", s_ha[1]->address); |
191 | cb ++; | 189 | cb ++; |
192 | } | 190 | } |
193 | else | 191 | else |
194 | { | 192 | { |
195 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 1 address 1!\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Expected callback for peer 1 address `%s', got address `%s'!\n", s_ha[1]->address, address->address); |
196 | GNUNET_ATS_performance_list_addresses_cancel (phal); | 194 | GNUNET_ATS_performance_list_addresses_cancel (phal); |
197 | fail = GNUNET_YES; | 195 | fail = GNUNET_YES; |
198 | } | 196 | } |
199 | } | 197 | } |
200 | cb ++; | ||
201 | } | 198 | } |
202 | if ((address == NULL) || (GNUNET_YES == fail)) | 199 | if ((address == NULL) || (GNUNET_YES == fail)) |
203 | { | 200 | { |
@@ -399,22 +396,41 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
399 | const struct GNUNET_ATS_Information *ats, | 396 | const struct GNUNET_ATS_Information *ats, |
400 | uint32_t ats_count) | 397 | uint32_t ats_count) |
401 | { | 398 | { |
402 | static int suggest_p0; | 399 | static int suggest_p0 = GNUNET_NO; |
403 | static int suggest_p1; | 400 | static int suggest_p1 = GNUNET_NO; |
401 | static int running = GNUNET_NO; | ||
404 | 402 | ||
405 | if (0 == memcmp (&address->peer, &p[0].id, | 403 | if (0 == memcmp (&address->peer, &p[0].id, |
406 | sizeof (struct GNUNET_PeerIdentity))); | 404 | sizeof (struct GNUNET_PeerIdentity))) |
407 | suggest_p0++; | 405 | { |
406 | suggest_p0 = GNUNET_YES;; | ||
407 | |||
408 | if (s_ha[0] != NULL) | ||
409 | GNUNET_free (s_ha[0]); | ||
410 | s_ha[0] = GNUNET_HELLO_address_copy (address); | ||
411 | |||
412 | GNUNET_ATS_suggest_address_cancel (atsh, &p[0].id); | ||
413 | } | ||
408 | if (0 == memcmp (&address->peer, &p[1].id, | 414 | if (0 == memcmp (&address->peer, &p[1].id, |
409 | sizeof (struct GNUNET_PeerIdentity))); | 415 | sizeof (struct GNUNET_PeerIdentity))) |
410 | suggest_p1++; | 416 | { |
417 | suggest_p1 = GNUNET_YES; | ||
418 | |||
419 | if (s_ha[1] != NULL) | ||
420 | GNUNET_free (s_ha[1]); | ||
421 | s_ha[1] = GNUNET_HELLO_address_copy (address); | ||
411 | 422 | ||
412 | if ((GNUNET_YES >= suggest_p0) && (GNUNET_YES >= suggest_p1)) | 423 | GNUNET_ATS_suggest_address_cancel (atsh, &p[1].id); |
424 | } | ||
425 | |||
426 | |||
427 | if ((GNUNET_NO == running) && (GNUNET_YES == suggest_p0) && (GNUNET_YES == suggest_p1)) | ||
413 | { | 428 | { |
429 | running = GNUNET_YES; | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have address suggestion for both peers\n"); | 430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have address suggestion for both peers\n"); |
415 | test_performance_api(NULL, NULL); | 431 | GNUNET_SCHEDULER_add_now (&test_performance_api, NULL); |
416 | //GNUNET_SCHEDULER_add_now (&test_performance_api, NULL); | ||
417 | } | 432 | } |
433 | |||
418 | } | 434 | } |
419 | 435 | ||
420 | 436 | ||
@@ -484,25 +500,23 @@ run (void *cls, | |||
484 | 500 | ||
485 | 501 | ||
486 | /* Add addresses */ | 502 | /* Add addresses */ |
487 | ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | 503 | atsh = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); |
488 | if (ats == NULL) | 504 | if (atsh == NULL) |
489 | { | 505 | { |
490 | ret = GNUNET_SYSERR; | 506 | ret = GNUNET_SYSERR; |
491 | end (); | 507 | end (); |
492 | return; | 508 | return; |
493 | } | 509 | } |
494 | 510 | ||
495 | GNUNET_ATS_address_add (ats, &p0_ha[0], NULL, NULL, 0); | 511 | GNUNET_ATS_address_add (atsh, &p0_ha[0], NULL, NULL, 0); |
496 | GNUNET_ATS_address_add (ats, &p0_ha[1], NULL, NULL, 0); | 512 | GNUNET_ATS_address_add (atsh, &p0_ha[1], NULL, NULL, 0); |
497 | 513 | ||
498 | GNUNET_ATS_address_add (ats, &p1_ha[0], NULL, NULL, 0); | 514 | GNUNET_ATS_address_add (atsh, &p1_ha[0], NULL, NULL, 0); |
499 | GNUNET_ATS_address_add (ats, &p1_ha[1], NULL, NULL, 0); | 515 | GNUNET_ATS_address_add (atsh, &p1_ha[1], NULL, NULL, 0); |
500 | 516 | ||
501 | //GNUNET_ATS_address_in_use (ats, &p0_ha[0], NULL, GNUNET_YES); | ||
502 | //GNUNET_ATS_address_in_use (ats, &p1_ha[1], NULL, GNUNET_YES); | ||
503 | 517 | ||
504 | GNUNET_ATS_suggest_address (ats, &p[0].id); | 518 | GNUNET_ATS_suggest_address (atsh, &p[0].id); |
505 | GNUNET_ATS_suggest_address (ats, &p[1].id); | 519 | GNUNET_ATS_suggest_address (atsh, &p[1].id); |
506 | } | 520 | } |
507 | 521 | ||
508 | 522 | ||