diff options
Diffstat (limited to 'src/ats/ats_api_scheduling.c')
-rw-r--r-- | src/ats/ats_api_scheduling.c | 158 |
1 files changed, 80 insertions, 78 deletions
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; |