diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-22 20:54:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-22 20:54:15 +0000 |
commit | 9750132ba19a96ab1756de15e91c62405a1918fb (patch) | |
tree | 41312f4ff3224895507e127f712ffd9271a19cea /src/ats | |
parent | 7701720d1410c40923749c53b96ccb5770e1be09 (diff) | |
download | gnunet-9750132ba19a96ab1756de15e91c62405a1918fb.tar.gz gnunet-9750132ba19a96ab1756de15e91c62405a1918fb.zip |
towards a cleaner ATS scheduling API
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 10 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 158 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_address.c | 20 | ||||
-rw-r--r-- | src/ats/test_ats_api_scheduling_destroy_address_twice.c | 244 | ||||
-rw-r--r-- | src/ats/test_ats_solver_alternative_after_delete_address.c | 22 | ||||
-rw-r--r-- | src/ats/test_ats_solver_request_and_delete_address.c | 13 |
6 files changed, 119 insertions, 348 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index ea631709c..abe61d37e 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -116,7 +116,6 @@ TESTING_TESTS = \ | |||
116 | test_ats_api_scheduling_add_address_duplicate \ | 116 | test_ats_api_scheduling_add_address_duplicate \ |
117 | test_ats_api_scheduling_add_address_inbound \ | 117 | test_ats_api_scheduling_add_address_inbound \ |
118 | test_ats_api_scheduling_destroy_address \ | 118 | test_ats_api_scheduling_destroy_address \ |
119 | test_ats_api_scheduling_destroy_address_twice \ | ||
120 | test_ats_api_scheduling_add_session \ | 119 | test_ats_api_scheduling_add_session \ |
121 | test_ats_api_scheduling_destroy_session \ | 120 | test_ats_api_scheduling_destroy_session \ |
122 | test_ats_api_delayed_service_scheduling_add_address \ | 121 | test_ats_api_delayed_service_scheduling_add_address \ |
@@ -217,15 +216,6 @@ test_ats_api_scheduling_destroy_address_LDADD = \ | |||
217 | libgnunetats.la \ | 216 | libgnunetats.la \ |
218 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 217 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
219 | 218 | ||
220 | test_ats_api_scheduling_destroy_address_twice_SOURCES = \ | ||
221 | test_ats_api_scheduling_destroy_address_twice.c \ | ||
222 | test_ats_api_common.c test_ats_api_common.h | ||
223 | test_ats_api_scheduling_destroy_address_twice_LDADD = \ | ||
224 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
225 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
226 | libgnunetats.la \ | ||
227 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
228 | |||
229 | test_ats_api_scheduling_add_session_SOURCES = \ | 219 | test_ats_api_scheduling_add_session_SOURCES = \ |
230 | test_ats_api_scheduling_add_session.c test_ats_api_common.c | 220 | test_ats_api_scheduling_add_session.c test_ats_api_common.c |
231 | test_ats_api_scheduling_add_session_LDADD = \ | 221 | test_ats_api_scheduling_add_session_LDADD = \ |
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 1c30f2e66..52dcb49ba 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -1257,6 +1257,49 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1257 | 1257 | ||
1258 | 1258 | ||
1259 | /** | 1259 | /** |
1260 | * An address was used to initiate a session. | ||
1261 | * | ||
1262 | * @param ar address record to update information for | ||
1263 | * @param session session handle | ||
1264 | */ | ||
1265 | void | ||
1266 | GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar, | ||
1267 | struct Session *session) | ||
1268 | { | ||
1269 | GNUNET_break (NULL == ar->session); | ||
1270 | ar->session = session; | ||
1271 | } | ||
1272 | |||
1273 | |||
1274 | /** | ||
1275 | * A session was destroyed, disassociate it from the | ||
1276 | * given address record. If this was an incoming | ||
1277 | * addess, destroy the address as well. | ||
1278 | * | ||
1279 | * @param ar address record to update information for | ||
1280 | * @param session session handle | ||
1281 | * @return #GNUNET_YES if the @a ar was destroyed because | ||
1282 | * it was an incoming address, | ||
1283 | * #GNUNET_NO if the @ar was kept because we can | ||
1284 | * use it still to establish a new session | ||
1285 | */ | ||
1286 | int | ||
1287 | GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar, | ||
1288 | struct Session *session) | ||
1289 | { | ||
1290 | GNUNET_break (session == ar->session); | ||
1291 | ar->session = NULL; | ||
1292 | if (GNUNET_HELLO_address_check_option (ar->address, | ||
1293 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
1294 | { | ||
1295 | GNUNET_ATS_address_destroy (ar); | ||
1296 | return GNUNET_YES; | ||
1297 | } | ||
1298 | return GNUNET_NO; | ||
1299 | } | ||
1300 | |||
1301 | |||
1302 | /** | ||
1260 | * We have updated performance statistics for a given address. Note | 1303 | * We have updated performance statistics for a given address. Note |
1261 | * that this function can be called for addresses that are currently | 1304 | * that this function can be called for addresses that are currently |
1262 | * in use as well as addresses that are valid but not actively in use. | 1305 | * in use as well as addresses that are valid but not actively in use. |
@@ -1265,13 +1308,11 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1265 | * for later use). Update bandwidth assignments. | 1308 | * for later use). Update bandwidth assignments. |
1266 | * | 1309 | * |
1267 | * @param ar address record to update information for | 1310 | * @param ar address record to update information for |
1268 | * @param session session handle, can be NULL | ||
1269 | * @param ats performance data for the address | 1311 | * @param ats performance data for the address |
1270 | * @param ats_count number of performance records in @a ats | 1312 | * @param ats_count number of performance records in @a ats |
1271 | */ | 1313 | */ |
1272 | void | 1314 | void |
1273 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | 1315 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, |
1274 | struct Session *session, | ||
1275 | const struct GNUNET_ATS_Information *ats, | 1316 | const struct GNUNET_ATS_Information *ats, |
1276 | uint32_t ats_count) | 1317 | uint32_t ats_count) |
1277 | { | 1318 | { |
@@ -1281,7 +1322,6 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
1281 | memcpy (ar->ats, | 1322 | memcpy (ar->ats, |
1282 | ats, | 1323 | ats, |
1283 | ats_count * sizeof (struct GNUNET_ATS_Information)); | 1324 | ats_count * sizeof (struct GNUNET_ATS_Information)); |
1284 | ar->session = session; | ||
1285 | send_add_address_message (ar->sh, | 1325 | send_add_address_message (ar->sh, |
1286 | ar, | 1326 | ar, |
1287 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); | 1327 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); |
@@ -1291,111 +1331,73 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
1291 | /** | 1331 | /** |
1292 | * An address is now in use or not used any more. | 1332 | * An address is now in use or not used any more. |
1293 | * | 1333 | * |
1294 | * @param sh handle | 1334 | * @param ar the address |
1295 | * @param address the address | ||
1296 | * @param session session handle, can be NULL | ||
1297 | * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO | 1335 | * @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO |
1298 | * if address is not used any more | 1336 | * if address is not used any more |
1299 | */ | 1337 | */ |
1300 | void | 1338 | void |
1301 | GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, | 1339 | GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar, |
1302 | const struct GNUNET_HELLO_Address *address, | 1340 | int in_use) |
1303 | struct Session *session, | ||
1304 | int in_use) | ||
1305 | { | 1341 | { |
1342 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | ||
1306 | struct GNUNET_MQ_Envelope *ev; | 1343 | struct GNUNET_MQ_Envelope *ev; |
1307 | struct AddressUseMessage *m; | 1344 | struct AddressUseMessage *m; |
1308 | struct GNUNET_ATS_AddressRecord *ar; | ||
1309 | char *pm; | 1345 | char *pm; |
1310 | size_t namelen; | 1346 | size_t namelen; |
1311 | size_t msize; | 1347 | size_t msize; |
1312 | uint32_t s = 0; | ||
1313 | 1348 | ||
1314 | s = find_session_id (sh, session, address); | ||
1315 | if (s == NOT_FOUND) | ||
1316 | { | ||
1317 | /* trying to set unknown address to NO */ | ||
1318 | GNUNET_break (0); | ||
1319 | return; | ||
1320 | } | ||
1321 | ar = sh->session_array[s]; | ||
1322 | ar->in_use = in_use; | 1349 | ar->in_use = in_use; |
1323 | namelen = (NULL == address->transport_name) | 1350 | namelen = (NULL == ar->address->transport_name) |
1324 | ? 0 | 1351 | ? 0 |
1325 | : strlen (address->transport_name) + 1; | 1352 | : strlen (ar->address->transport_name) + 1; |
1326 | msize = address->address_length + namelen; | 1353 | msize = ar->address->address_length + namelen; |
1327 | 1354 | ||
1328 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); | 1355 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); |
1329 | m->peer = address->peer; | 1356 | m->peer = ar->address->peer; |
1330 | m->in_use = htons (in_use); | 1357 | m->in_use = htons (in_use); |
1331 | m->address_length = htons (address->address_length); | 1358 | m->address_length = htons (ar->address->address_length); |
1332 | m->address_local_info = htonl ((uint32_t) address->local_info); | 1359 | m->address_local_info = htonl ((uint32_t) ar->address->local_info); |
1333 | m->plugin_name_length = htons (namelen); | 1360 | m->plugin_name_length = htons (namelen); |
1334 | 1361 | ||
1335 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1336 | "Setting address used to %s for peer `%s', plugin `%s', session %p\n", | 1363 | "Setting address used to %s for peer `%s', plugin `%s', session %p\n", |
1337 | (GNUNET_YES == in_use) ? "YES" : "NO", | 1364 | (GNUNET_YES == in_use) ? "YES" : "NO", |
1338 | GNUNET_i2s (&address->peer), | 1365 | GNUNET_i2s (&ar->address->peer), |
1339 | address->transport_name, | 1366 | ar->address->transport_name, |
1340 | session); | 1367 | ar->session); |
1341 | 1368 | ||
1342 | m->session_id = htonl (s); | 1369 | m->session_id = htonl (ar->slot); |
1343 | pm = (char *) &m[1]; | 1370 | pm = (char *) &m[1]; |
1344 | /* FIXME: no need to send the address data */ | 1371 | /* FIXME: no need to send the address data */ |
1345 | memcpy (pm, address->address, address->address_length); | 1372 | memcpy (pm, ar->address->address, ar->address->address_length); |
1346 | memcpy (&pm[address->address_length], address->transport_name, namelen); | 1373 | memcpy (&pm[ar->address->address_length], |
1374 | ar->address->transport_name, namelen); | ||
1347 | GNUNET_MQ_send (sh->mq, ev); | 1375 | GNUNET_MQ_send (sh->mq, ev); |
1348 | } | 1376 | } |
1349 | 1377 | ||
1350 | 1378 | ||
1351 | /** | 1379 | /** |
1352 | * An address got destroyed, stop including it as a valid address. | 1380 | * An address got destroyed, stop using it as a valid address. |
1353 | * | ||
1354 | * If a session is given, only the session will be removed, if no session is | ||
1355 | * given the full address will be deleted. | ||
1356 | * | 1381 | * |
1357 | * FIXME: the above sentence already indicates that this API is a | 1382 | * @param ar address to destroy |
1358 | * mess and troublesome. FIX IT! | ||
1359 | * | ||
1360 | * @param sh handle | ||
1361 | * @param address the address | ||
1362 | * @param session session handle that is no longer valid, can be NULL | ||
1363 | */ | 1383 | */ |
1364 | void | 1384 | void |
1365 | GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, | 1385 | GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar) |
1366 | const struct GNUNET_HELLO_Address *address, | ||
1367 | struct Session *session) | ||
1368 | { | 1386 | { |
1369 | uint32_t s; | 1387 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; |
1370 | struct GNUNET_MQ_Envelope *ev; | 1388 | struct GNUNET_MQ_Envelope *ev; |
1371 | struct AddressDestroyedMessage *m; | 1389 | struct AddressDestroyedMessage *m; |
1372 | struct GNUNET_ATS_AddressRecord *ar; | ||
1373 | char *pm; | 1390 | char *pm; |
1374 | size_t namelen; | 1391 | size_t namelen; |
1375 | size_t msize; | 1392 | size_t msize; |
1376 | 1393 | ||
1377 | s = find_session_id (sh, session, address); | 1394 | GNUNET_break (NULL == ar->session); |
1378 | if (NOT_FOUND == s) | 1395 | GNUNET_assert (NULL != ar->address->transport_name); |
1379 | { | 1396 | namelen = strlen (ar->address->transport_name) + 1; |
1380 | GNUNET_assert (0); | ||
1381 | return; | ||
1382 | } | ||
1383 | ar = sh->session_array[s]; | ||
1384 | if (NULL != session) | ||
1385 | { | ||
1386 | /* FIXME: this is yucky, fix API! */ | ||
1387 | GNUNET_break (ar->session == session); | ||
1388 | ar->session = NULL; | ||
1389 | return; | ||
1390 | } | ||
1391 | |||
1392 | |||
1393 | GNUNET_assert (NULL != address->transport_name); | ||
1394 | namelen = strlen (address->transport_name) + 1; | ||
1395 | GNUNET_assert (namelen > 1); | 1397 | GNUNET_assert (namelen > 1); |
1396 | msize = address->address_length + namelen; | 1398 | msize = ar->address->address_length + namelen; |
1397 | if ((msize + sizeof (struct AddressDestroyedMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1399 | if ((msize + sizeof (struct AddressDestroyedMessage) >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1398 | (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || | 1400 | (ar->address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || |
1399 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) | 1401 | (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) |
1400 | { | 1402 | { |
1401 | GNUNET_break (0); | 1403 | GNUNET_break (0); |
@@ -1403,24 +1405,24 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1403 | } | 1405 | } |
1404 | 1406 | ||
1405 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); | 1407 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); |
1406 | m->peer = address->peer; | 1408 | m->peer = ar->address->peer; |
1407 | m->address_length = htons (address->address_length); | 1409 | m->address_length = htons (ar->address->address_length); |
1408 | m->address_local_info = htonl ((uint32_t) address->local_info); | 1410 | m->address_local_info = htonl ((uint32_t) ar->address->local_info); |
1409 | m->plugin_name_length = htons (namelen); | 1411 | m->plugin_name_length = htons (namelen); |
1410 | 1412 | ||
1411 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1412 | "Deleting address for peer `%s', plugin `%s', session %p\n", | 1414 | "Deleting address for peer `%s', plugin `%s', session %p\n", |
1413 | GNUNET_i2s (&address->peer), | 1415 | GNUNET_i2s (&ar->address->peer), |
1414 | address->transport_name, | 1416 | ar->address->transport_name, |
1415 | session); | 1417 | ar->session); |
1416 | 1418 | ||
1417 | m->session_id = htonl (s); | 1419 | m->session_id = htonl (ar->slot); |
1418 | pm = (char *) &m[1]; | 1420 | pm = (char *) &m[1]; |
1419 | memcpy (pm, | 1421 | memcpy (pm, |
1420 | address->address, | 1422 | ar->address->address, |
1421 | address->address_length); | 1423 | ar->address->address_length); |
1422 | memcpy (&pm[address->address_length], | 1424 | memcpy (&pm[ar->address->address_length], |
1423 | address->transport_name, | 1425 | ar->address->transport_name, |
1424 | namelen); | 1426 | namelen); |
1425 | GNUNET_MQ_send (sh->mq, ev); | 1427 | GNUNET_MQ_send (sh->mq, ev); |
1426 | ar->session = NULL; | 1428 | ar->session = NULL; |
diff --git a/src/ats/test_ats_api_scheduling_destroy_address.c b/src/ats/test_ats_api_scheduling_destroy_address.c index 323128ac2..5807ac456 100644 --- a/src/ats/test_ats_api_scheduling_destroy_address.c +++ b/src/ats/test_ats_api_scheduling_destroy_address.c | |||
@@ -46,6 +46,11 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | 46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Our address record. | ||
50 | */ | ||
51 | static struct GNUNET_ATS_AddressRecord *ar; | ||
52 | |||
53 | /** | ||
49 | * Return value | 54 | * Return value |
50 | */ | 55 | */ |
51 | static int ret; | 56 | static int ret; |
@@ -139,9 +144,8 @@ stat_cb (void *cls, const char *subsystem, | |||
139 | { | 144 | { |
140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 145 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
141 | "Statistics observed address added, now destroying address\n"); | 146 | "Statistics observed address added, now destroying address\n"); |
142 | GNUNET_ATS_address_destroyed (sched_ats, | 147 | GNUNET_ATS_address_destroy (ar); |
143 | &test_hello_address, | 148 | ar = NULL; |
144 | test_session); | ||
145 | } | 149 | } |
146 | return GNUNET_OK; | 150 | return GNUNET_OK; |
147 | } | 151 | } |
@@ -211,11 +215,11 @@ got_initial_value (void *cls, | |||
211 | test_hello_address.address_length = test_addr.addr_len; | 215 | test_hello_address.address_length = test_addr.addr_len; |
212 | 216 | ||
213 | /* Adding address */ | 217 | /* Adding address */ |
214 | GNUNET_ATS_address_add (sched_ats, | 218 | ar = GNUNET_ATS_address_add (sched_ats, |
215 | &test_hello_address, | 219 | &test_hello_address, |
216 | test_session, | 220 | test_session, |
217 | test_ats_info, | 221 | test_ats_info, |
218 | test_ats_count); | 222 | test_ats_count); |
219 | } | 223 | } |
220 | 224 | ||
221 | 225 | ||
diff --git a/src/ats/test_ats_api_scheduling_destroy_address_twice.c b/src/ats/test_ats_api_scheduling_destroy_address_twice.c deleted file mode 100644 index 995538e7e..000000000 --- a/src/ats/test_ats_api_scheduling_destroy_address_twice.c +++ /dev/null | |||
@@ -1,244 +0,0 @@ | |||
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 "gnunet_testing_lib.h" | ||
30 | #include "ats.h" | ||
31 | #include "test_ats_api_common.h" | ||
32 | |||
33 | /** | ||
34 | * Timeout task | ||
35 | */ | ||
36 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
37 | |||
38 | /** | ||
39 | * Statistics handle | ||
40 | */ | ||
41 | static struct GNUNET_STATISTICS_Handle *stats; | ||
42 | |||
43 | /** | ||
44 | * Scheduling handle | ||
45 | */ | ||
46 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
47 | |||
48 | /** | ||
49 | * Return value | ||
50 | */ | ||
51 | static int ret; | ||
52 | |||
53 | /** | ||
54 | * Test address | ||
55 | */ | ||
56 | static struct Test_Address test_addr; | ||
57 | |||
58 | /** | ||
59 | * Test peer | ||
60 | */ | ||
61 | static struct PeerContext p; | ||
62 | |||
63 | /** | ||
64 | * HELLO address | ||
65 | */ | ||
66 | struct GNUNET_HELLO_Address test_hello_address; | ||
67 | |||
68 | /** | ||
69 | * Session | ||
70 | */ | ||
71 | static void *test_session; | ||
72 | |||
73 | /** | ||
74 | * Test ats info | ||
75 | */ | ||
76 | struct GNUNET_ATS_Information test_ats_info[2]; | ||
77 | |||
78 | /** | ||
79 | * Test ats count | ||
80 | */ | ||
81 | static uint32_t test_ats_count; | ||
82 | |||
83 | |||
84 | static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
85 | |||
86 | |||
87 | static int | ||
88 | stat_cb(void *cls, const char *subsystem, | ||
89 | const char *name, uint64_t value, | ||
90 | int is_persistent) | ||
91 | { | ||
92 | static int initial_ats_stat_cb = GNUNET_YES; | ||
93 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n", | ||
94 | subsystem,name, value); | ||
95 | |||
96 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO)) | ||
97 | { | ||
98 | fprintf (stderr, "We now expect a warning about destroying an unknown address...\n"); | ||
99 | GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, test_session); | ||
100 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL); | ||
101 | } | ||
102 | if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES)) | ||
103 | { | ||
104 | initial_ats_stat_cb = GNUNET_NO; | ||
105 | } | ||
106 | if (1 == value) | ||
107 | { | ||
108 | GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, test_session); | ||
109 | } | ||
110 | |||
111 | return GNUNET_OK; | ||
112 | } | ||
113 | |||
114 | |||
115 | static void | ||
116 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
117 | { | ||
118 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
119 | |||
120 | if (die_task != NULL) | ||
121 | { | ||
122 | GNUNET_SCHEDULER_cancel (die_task); | ||
123 | die_task = NULL; | ||
124 | } | ||
125 | |||
126 | if (NULL != sched_ats) | ||
127 | { | ||
128 | GNUNET_ATS_scheduling_done (sched_ats); | ||
129 | sched_ats = NULL; | ||
130 | } | ||
131 | |||
132 | GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL); | ||
133 | if (NULL != stats) | ||
134 | { | ||
135 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | ||
136 | stats = NULL; | ||
137 | } | ||
138 | |||
139 | free_test_address (&test_addr); | ||
140 | |||
141 | ret = 0; | ||
142 | } | ||
143 | |||
144 | |||
145 | static void | ||
146 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
147 | { | ||
148 | die_task = NULL; | ||
149 | end ( NULL, NULL); | ||
150 | ret = GNUNET_SYSERR; | ||
151 | } | ||
152 | |||
153 | |||
154 | static void | ||
155 | address_suggest_cb (void *cls, | ||
156 | const struct GNUNET_PeerIdentity *peer, | ||
157 | const struct GNUNET_HELLO_Address *address, | ||
158 | struct Session *session, | ||
159 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
160 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | ||
161 | { | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion callback!\n"); | ||
163 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
164 | } | ||
165 | |||
166 | |||
167 | static int | ||
168 | dummy_stat (void *cls, | ||
169 | const char *subsystem, | ||
170 | const char *name, | ||
171 | uint64_t value, | ||
172 | int is_persistent) | ||
173 | { | ||
174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
175 | "Got dummy stat %s%s:%s = %llu\n", | ||
176 | is_persistent ? "!" : " ", subsystem, name, value); | ||
177 | return GNUNET_OK; | ||
178 | } | ||
179 | |||
180 | |||
181 | static void | ||
182 | got_initial_value (void *cls, int success) | ||
183 | { | ||
184 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
185 | |||
186 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n"); | ||
187 | |||
188 | /* Connect to ATS scheduling */ | ||
189 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
190 | if (sched_ats == NULL) | ||
191 | { | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
193 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
194 | return; | ||
195 | } | ||
196 | |||
197 | /* Set up peer */ | ||
198 | memset (&p.id, '1', sizeof (p.id)); | ||
199 | /* Prepare ATS Information */ | ||
200 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
201 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
202 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
203 | test_ats_info[1].value = htonl(1); | ||
204 | test_ats_count = 2; | ||
205 | |||
206 | /* Adding address without session */ | ||
207 | test_session = NULL; | ||
208 | create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1); | ||
209 | test_hello_address.peer = p.id; | ||
210 | test_hello_address.transport_name = test_addr.plugin; | ||
211 | test_hello_address.address = test_addr.addr; | ||
212 | test_hello_address.address_length = test_addr.addr_len; | ||
213 | |||
214 | /* Adding address */ | ||
215 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, test_ats_info, test_ats_count); | ||
216 | } | ||
217 | |||
218 | static void | ||
219 | run (void *cls, | ||
220 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
221 | struct GNUNET_TESTING_Peer *peer) | ||
222 | { | ||
223 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
224 | stats = GNUNET_STATISTICS_create ("ats", cfg); | ||
225 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | ||
226 | |||
227 | GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT, | ||
228 | &got_initial_value, &dummy_stat, | ||
229 | GNUNET_CONFIGURATION_dup (cfg)); | ||
230 | } | ||
231 | |||
232 | |||
233 | int | ||
234 | main (int argc, char *argv[]) | ||
235 | { | ||
236 | ret = 0; | ||
237 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | ||
238 | "test_ats_api.conf", | ||
239 | &run, NULL)) | ||
240 | return 1; | ||
241 | return ret; | ||
242 | } | ||
243 | |||
244 | /* end of file test_ats_api_scheduling_destroy_address.c */ | ||
diff --git a/src/ats/test_ats_solver_alternative_after_delete_address.c b/src/ats/test_ats_solver_alternative_after_delete_address.c index 85216419a..aa04e82d5 100644 --- a/src/ats/test_ats_solver_alternative_after_delete_address.c +++ b/src/ats/test_ats_solver_alternative_after_delete_address.c | |||
@@ -106,6 +106,16 @@ static struct GNUNET_HELLO_Address *first_suggestion = NULL; | |||
106 | 106 | ||
107 | static struct GNUNET_HELLO_Address *second_suggestion = NULL; | 107 | static struct GNUNET_HELLO_Address *second_suggestion = NULL; |
108 | 108 | ||
109 | /** | ||
110 | * 1st Address we will destroy. | ||
111 | */ | ||
112 | static struct GNUNET_ATS_AddressRecord *ar; | ||
113 | |||
114 | /** | ||
115 | * 2nd Address we will destroy. | ||
116 | */ | ||
117 | static struct GNUNET_ATS_AddressRecord *ar2; | ||
118 | |||
109 | 119 | ||
110 | static int | 120 | static int |
111 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | 121 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, |
@@ -198,7 +208,8 @@ address_suggest_cb (void *cls, | |||
198 | 208 | ||
199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 1st address for peer `%s' : `%s'\n", | 209 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 1st address for peer `%s' : `%s'\n", |
200 | GNUNET_i2s (&address->peer), (char *) address->address); | 210 | GNUNET_i2s (&address->peer), (char *) address->address); |
201 | GNUNET_ATS_address_destroyed (sched_ats, address, session); | 211 | GNUNET_ATS_address_destroy (ar); |
212 | ar = NULL; | ||
202 | first_address_deleted = GNUNET_YES; | 213 | first_address_deleted = GNUNET_YES; |
203 | 214 | ||
204 | return; | 215 | return; |
@@ -225,7 +236,8 @@ address_suggest_cb (void *cls, | |||
225 | 236 | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n", | 237 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer `%s' : `%s'\n", |
227 | GNUNET_i2s (&address->peer), (char *) address->address); | 238 | GNUNET_i2s (&address->peer), (char *) address->address); |
228 | GNUNET_ATS_address_destroyed (sched_ats, address, session); | 239 | GNUNET_ATS_address_destroy (ar2); |
240 | ar2 = NULL; | ||
229 | second_address_deleted = GNUNET_YES; | 241 | second_address_deleted = GNUNET_YES; |
230 | return; | 242 | return; |
231 | } | 243 | } |
@@ -318,9 +330,11 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
318 | 330 | ||
319 | 331 | ||
320 | /* Adding address */ | 332 | /* Adding address */ |
321 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info, test_ats_count); | 333 | ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, |
334 | test_ats_info, test_ats_count); | ||
322 | /* Adding alternative address */ | 335 | /* Adding alternative address */ |
323 | GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL, test_ats_info, test_ats_count); | 336 | ar2 = GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL, |
337 | test_ats_info, test_ats_count); | ||
324 | } | 338 | } |
325 | 339 | ||
326 | 340 | ||
diff --git a/src/ats/test_ats_solver_request_and_delete_address.c b/src/ats/test_ats_solver_request_and_delete_address.c index e1dad6dcf..bca340ac1 100644 --- a/src/ats/test_ats_solver_request_and_delete_address.c +++ b/src/ats/test_ats_solver_request_and_delete_address.c | |||
@@ -85,6 +85,10 @@ struct GNUNET_ATS_Information test_ats_info[2]; | |||
85 | */ | 85 | */ |
86 | static uint32_t test_ats_count; | 86 | static uint32_t test_ats_count; |
87 | 87 | ||
88 | /** | ||
89 | * The address we will delete. | ||
90 | */ | ||
91 | static struct GNUNET_ATS_AddressRecord *ar; | ||
88 | 92 | ||
89 | static int address_deleted = GNUNET_NO; | 93 | static int address_deleted = GNUNET_NO; |
90 | 94 | ||
@@ -152,7 +156,8 @@ address_suggest_cb (void *cls, | |||
152 | "Received sugggestion for peer `%s', deleting address\n", | 156 | "Received sugggestion for peer `%s', deleting address\n", |
153 | GNUNET_i2s (&address->peer)); | 157 | GNUNET_i2s (&address->peer)); |
154 | address_deleted = GNUNET_YES; | 158 | address_deleted = GNUNET_YES; |
155 | GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, NULL); | 159 | GNUNET_ATS_address_destroy (ar); |
160 | ar = NULL; | ||
156 | } | 161 | } |
157 | else | 162 | else |
158 | { | 163 | { |
@@ -231,9 +236,9 @@ run (void *cls, | |||
231 | test_hello_address.address_length = test_addr.addr_len; | 236 | test_hello_address.address_length = test_addr.addr_len; |
232 | 237 | ||
233 | /* Adding address */ | 238 | /* Adding address */ |
234 | GNUNET_ATS_address_add (sched_ats, &test_hello_address, | 239 | ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, |
235 | NULL, | 240 | NULL, |
236 | test_ats_info, test_ats_count); | 241 | test_ats_info, test_ats_count); |
237 | } | 242 | } |
238 | 243 | ||
239 | 244 | ||