diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-22 22:10:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-22 22:10:15 +0000 |
commit | b7585254768daa9b64fc33fb2562293c6fe3fc16 (patch) | |
tree | 3e5f824c8ad07a37988a7605bce47e85ffe58943 /src/transport/gnunet-transport.c | |
parent | 15a1ecaaeb9aa1aebba7404993e1b6945bbc014e (diff) | |
download | gnunet-b7585254768daa9b64fc33fb2562293c6fe3fc16.tar.gz gnunet-b7585254768daa9b64fc33fb2562293c6fe3fc16.zip |
simplify logic, do not report monitoring events for sessions in destroy, indentation, doxygen -- may help/fix #3591
Diffstat (limited to 'src/transport/gnunet-transport.c')
-rw-r--r-- | src/transport/gnunet-transport.c | 135 |
1 files changed, 88 insertions, 47 deletions
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index bf586b7f0..f4895e154 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -144,11 +144,6 @@ struct PeerResolutionContext | |||
144 | struct PeerResolutionContext *prev; | 144 | struct PeerResolutionContext *prev; |
145 | 145 | ||
146 | /** | 146 | /** |
147 | * The peer id | ||
148 | */ | ||
149 | struct GNUNET_PeerIdentity id; | ||
150 | |||
151 | /** | ||
152 | * address to resolve | 147 | * address to resolve |
153 | */ | 148 | */ |
154 | struct GNUNET_HELLO_Address *addrcp; | 149 | struct GNUNET_HELLO_Address *addrcp; |
@@ -516,6 +511,7 @@ shutdown_task (void *cls, | |||
516 | struct GNUNET_TIME_Relative duration; | 511 | struct GNUNET_TIME_Relative duration; |
517 | struct ValidationResolutionContext *cur; | 512 | struct ValidationResolutionContext *cur; |
518 | struct ValidationResolutionContext *next; | 513 | struct ValidationResolutionContext *next; |
514 | struct PeerResolutionContext *rc; | ||
519 | 515 | ||
520 | end = NULL; | 516 | end = NULL; |
521 | if (NULL != op_timeout) | 517 | if (NULL != op_timeout) |
@@ -550,12 +546,23 @@ shutdown_task (void *cls, | |||
550 | next = cur->next; | 546 | next = cur->next; |
551 | 547 | ||
552 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); | 548 | GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); |
553 | GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur); | 549 | GNUNET_CONTAINER_DLL_remove (vc_head, |
550 | vc_tail, | ||
551 | cur); | ||
554 | GNUNET_free (cur->transport); | 552 | GNUNET_free (cur->transport); |
555 | GNUNET_HELLO_address_free (cur->addrcp); | 553 | GNUNET_HELLO_address_free (cur->addrcp); |
556 | GNUNET_free (cur); | 554 | GNUNET_free (cur); |
557 | } | 555 | } |
558 | 556 | while (NULL != (rc = rc_head)) | |
557 | { | ||
558 | GNUNET_CONTAINER_DLL_remove (rc_head, | ||
559 | rc_tail, | ||
560 | rc); | ||
561 | GNUNET_TRANSPORT_address_to_string_cancel (rc->asc); | ||
562 | GNUNET_free (rc->transport); | ||
563 | GNUNET_free (rc->addrcp); | ||
564 | GNUNET_free (rc); | ||
565 | } | ||
559 | if (NULL != th) | 566 | if (NULL != th) |
560 | { | 567 | { |
561 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 568 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
@@ -649,7 +656,7 @@ operation_timeout (void *cls, | |||
649 | 656 | ||
650 | 657 | ||
651 | static void | 658 | static void |
652 | run_nat_test (); | 659 | run_nat_test (void); |
653 | 660 | ||
654 | 661 | ||
655 | /** | 662 | /** |
@@ -720,6 +727,7 @@ display_test_result (struct TestContext *tc, | |||
720 | run_nat_test (); | 727 | run_nat_test (); |
721 | } | 728 | } |
722 | 729 | ||
730 | |||
723 | /** | 731 | /** |
724 | * Function called by NAT to report the outcome of the nat-test. | 732 | * Function called by NAT to report the outcome of the nat-test. |
725 | * Clean up and update GUI. | 733 | * Clean up and update GUI. |
@@ -733,7 +741,8 @@ result_callback (void *cls, | |||
733 | { | 741 | { |
734 | struct TestContext *tc = cls; | 742 | struct TestContext *tc = cls; |
735 | 743 | ||
736 | display_test_result (tc, result); | 744 | display_test_result (tc, |
745 | result); | ||
737 | } | 746 | } |
738 | 747 | ||
739 | 748 | ||
@@ -965,11 +974,12 @@ run_nat_test () | |||
965 | (uint16_t) head->adv_port); | 974 | (uint16_t) head->adv_port); |
966 | 975 | ||
967 | head->tst = GNUNET_NAT_test_start (cfg, | 976 | head->tst = GNUNET_NAT_test_start (cfg, |
968 | (0 == strcasecmp (head->name, "udp")) ? GNUNET_NO : GNUNET_YES, | 977 | (0 == strcasecmp (head->name, "udp")) |
969 | (uint16_t) head->bnd_port, | 978 | ? GNUNET_NO : GNUNET_YES, |
970 | (uint16_t) head->adv_port, | 979 | (uint16_t) head->bnd_port, |
971 | TIMEOUT, | 980 | (uint16_t) head->adv_port, |
972 | &result_callback, head); | 981 | TIMEOUT, |
982 | &result_callback, head); | ||
973 | } | 983 | } |
974 | 984 | ||
975 | 985 | ||
@@ -1270,9 +1280,17 @@ notify_receive (void *cls, | |||
1270 | } | 1280 | } |
1271 | 1281 | ||
1272 | 1282 | ||
1283 | /** | ||
1284 | * Convert address to a printable format. | ||
1285 | * | ||
1286 | * @param address the address | ||
1287 | * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO | ||
1288 | * to try to use reverse DNS | ||
1289 | * @param state state the peer is in | ||
1290 | * @param state_timeout when will the peer's state expire | ||
1291 | */ | ||
1273 | static void | 1292 | static void |
1274 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, | 1293 | resolve_peer_address (const struct GNUNET_HELLO_Address *address, |
1275 | const struct GNUNET_HELLO_Address *address, | ||
1276 | int numeric, | 1294 | int numeric, |
1277 | enum GNUNET_TRANSPORT_PeerState state, | 1295 | enum GNUNET_TRANSPORT_PeerState state, |
1278 | struct GNUNET_TIME_Absolute state_timeout); | 1296 | struct GNUNET_TIME_Absolute state_timeout); |
@@ -1339,10 +1357,10 @@ process_peer_string (void *cls, | |||
1339 | { | 1357 | { |
1340 | FPRINTF (stderr, | 1358 | FPRINTF (stderr, |
1341 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", | 1359 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", |
1342 | GNUNET_i2s (&rc->id), | 1360 | GNUNET_i2s (&rc->addrcp->peer), |
1343 | rc->addrcp->transport_name, | 1361 | rc->addrcp->transport_name, |
1344 | (unsigned int) rc->addrcp->address_length); | 1362 | (unsigned int) rc->addrcp->address_length); |
1345 | print_info (&rc->id, | 1363 | print_info (&rc->addrcp->peer, |
1346 | rc->transport, | 1364 | rc->transport, |
1347 | NULL, | 1365 | NULL, |
1348 | rc->state, | 1366 | rc->state, |
@@ -1352,7 +1370,7 @@ process_peer_string (void *cls, | |||
1352 | } | 1370 | } |
1353 | if (GNUNET_OK == res) | 1371 | if (GNUNET_OK == res) |
1354 | { | 1372 | { |
1355 | print_info (&rc->id, | 1373 | print_info (&rc->addrcp->peer, |
1356 | rc->transport, | 1374 | rc->transport, |
1357 | address, | 1375 | address, |
1358 | rc->state, | 1376 | rc->state, |
@@ -1365,6 +1383,7 @@ process_peer_string (void *cls, | |||
1365 | } | 1383 | } |
1366 | /* NULL == address, last call, we are done */ | 1384 | /* NULL == address, last call, we are done */ |
1367 | 1385 | ||
1386 | rc->asc = NULL; | ||
1368 | GNUNET_assert (address_resolutions > 0); | 1387 | GNUNET_assert (address_resolutions > 0); |
1369 | address_resolutions--; | 1388 | address_resolutions--; |
1370 | if (GNUNET_NO == rc->printed) | 1389 | if (GNUNET_NO == rc->printed) |
@@ -1375,15 +1394,14 @@ process_peer_string (void *cls, | |||
1375 | (note: this should not be needed, as transport | 1394 | (note: this should not be needed, as transport |
1376 | should fallback to numeric conversion if DNS takes | 1395 | should fallback to numeric conversion if DNS takes |
1377 | too long) */ | 1396 | too long) */ |
1378 | resolve_peer_address (&rc->id, | 1397 | resolve_peer_address (rc->addrcp, |
1379 | rc->addrcp, | ||
1380 | GNUNET_YES, | 1398 | GNUNET_YES, |
1381 | rc->state, | 1399 | rc->state, |
1382 | rc->state_timeout); | 1400 | rc->state_timeout); |
1383 | } | 1401 | } |
1384 | else | 1402 | else |
1385 | { | 1403 | { |
1386 | print_info (&rc->id, | 1404 | print_info (&rc->addrcp->peer, |
1387 | rc->transport, | 1405 | rc->transport, |
1388 | NULL, | 1406 | NULL, |
1389 | rc->state, | 1407 | rc->state, |
@@ -1407,14 +1425,24 @@ process_peer_string (void *cls, | |||
1407 | op_timeout = NULL; | 1425 | op_timeout = NULL; |
1408 | } | 1426 | } |
1409 | ret = 0; | 1427 | ret = 0; |
1410 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 1428 | end = GNUNET_SCHEDULER_add_now (&shutdown_task, |
1429 | NULL); | ||
1411 | } | 1430 | } |
1412 | } | 1431 | } |
1413 | 1432 | ||
1414 | 1433 | ||
1434 | /** | ||
1435 | * Convert address to a printable format and print it | ||
1436 | * together with the given state data. | ||
1437 | * | ||
1438 | * @param address the address | ||
1439 | * @param numeric #GNUNET_YES to convert to numeric format, #GNUNET_NO | ||
1440 | * to try to use reverse DNS | ||
1441 | * @param state state the peer is in | ||
1442 | * @param state_timeout when will the peer's state expire | ||
1443 | */ | ||
1415 | static void | 1444 | static void |
1416 | resolve_peer_address (const struct GNUNET_PeerIdentity *id, | 1445 | resolve_peer_address (const struct GNUNET_HELLO_Address *address, |
1417 | const struct GNUNET_HELLO_Address *address, | ||
1418 | int numeric, | 1446 | int numeric, |
1419 | enum GNUNET_TRANSPORT_PeerState state, | 1447 | enum GNUNET_TRANSPORT_PeerState state, |
1420 | struct GNUNET_TIME_Absolute state_timeout) | 1448 | struct GNUNET_TIME_Absolute state_timeout) |
@@ -1422,12 +1450,11 @@ resolve_peer_address (const struct GNUNET_PeerIdentity *id, | |||
1422 | struct PeerResolutionContext *rc; | 1450 | struct PeerResolutionContext *rc; |
1423 | 1451 | ||
1424 | rc = GNUNET_new (struct PeerResolutionContext); | 1452 | rc = GNUNET_new (struct PeerResolutionContext); |
1425 | GNUNET_assert(NULL != rc); | 1453 | GNUNET_CONTAINER_DLL_insert (rc_head, |
1426 | GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc); | 1454 | rc_tail, |
1455 | rc); | ||
1427 | address_resolutions++; | 1456 | address_resolutions++; |
1428 | 1457 | rc->transport = GNUNET_strdup (address->transport_name); | |
1429 | rc->id = *id; | ||
1430 | rc->transport = GNUNET_strdup(address->transport_name); | ||
1431 | rc->addrcp = GNUNET_HELLO_address_copy (address); | 1458 | rc->addrcp = GNUNET_HELLO_address_copy (address); |
1432 | rc->printed = GNUNET_NO; | 1459 | rc->printed = GNUNET_NO; |
1433 | rc->state = state; | 1460 | rc->state = state; |
@@ -1485,9 +1512,16 @@ process_peer_iteration_cb (void *cls, | |||
1485 | address->transport_name); | 1512 | address->transport_name); |
1486 | 1513 | ||
1487 | if (NULL != address) | 1514 | if (NULL != address) |
1488 | resolve_peer_address (peer, address, numeric, state, state_timeout); | 1515 | resolve_peer_address (address, |
1516 | numeric, | ||
1517 | state, | ||
1518 | state_timeout); | ||
1489 | else | 1519 | else |
1490 | print_info (peer, NULL, NULL, state, state_timeout); | 1520 | print_info (peer, |
1521 | NULL, | ||
1522 | NULL, | ||
1523 | state, | ||
1524 | state_timeout); | ||
1491 | } | 1525 | } |
1492 | 1526 | ||
1493 | 1527 | ||
@@ -1653,13 +1687,12 @@ plugin_monitoring_cb (void *cls, | |||
1653 | /** | 1687 | /** |
1654 | * Function called with information about a peers | 1688 | * Function called with information about a peers |
1655 | * | 1689 | * |
1656 | * @param cls closure | 1690 | * @param cls closure, NULL |
1657 | * @param peer identity of the peer, NULL for final callback when operation done | 1691 | * @param peer identity of the peer, NULL for final callback when operation done |
1658 | * @param address binary address used to communicate with this peer, | 1692 | * @param address binary address used to communicate with this peer, |
1659 | * NULL on disconnect or when done | 1693 | * NULL on disconnect or when done |
1660 | * @param state current state this peer is in | 1694 | * @param state current state this peer is in |
1661 | * @param state_timeout time out for the current state | 1695 | * @param state_timeout time out for the current state |
1662 | * | ||
1663 | */ | 1696 | */ |
1664 | static void | 1697 | static void |
1665 | process_peer_monitoring_cb (void *cls, | 1698 | process_peer_monitoring_cb (void *cls, |
@@ -1684,22 +1717,28 @@ process_peer_monitoring_cb (void *cls, | |||
1684 | &operation_timeout, | 1717 | &operation_timeout, |
1685 | NULL); | 1718 | NULL); |
1686 | 1719 | ||
1687 | if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) | 1720 | if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, |
1721 | peer))) | ||
1688 | { | 1722 | { |
1689 | m = GNUNET_new (struct MonitoredPeer); | 1723 | m = GNUNET_new (struct MonitoredPeer); |
1690 | GNUNET_CONTAINER_multipeermap_put (monitored_peers, peer, | 1724 | GNUNET_CONTAINER_multipeermap_put (monitored_peers, |
1691 | m, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 1725 | peer, |
1726 | m, | ||
1727 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | ||
1692 | } | 1728 | } |
1693 | else | 1729 | else |
1694 | { | 1730 | { |
1695 | if ( (m->state == state) && | 1731 | if ( (m->state == state) && |
1696 | (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && | 1732 | (m->state_timeout.abs_value_us == state_timeout.abs_value_us) && |
1697 | ((NULL == address) && (NULL == m->address))) | 1733 | (NULL == address) && |
1734 | (NULL == m->address) ) | ||
1698 | { | 1735 | { |
1699 | return; /* No real change */ | 1736 | return; /* No real change */ |
1700 | } | 1737 | } |
1701 | if ( (m->state == state) && ((NULL != address) && (NULL != m->address)) && | 1738 | if ( (m->state == state) && |
1702 | (0 == GNUNET_HELLO_address_cmp(m->address, address))) | 1739 | (NULL != address) && |
1740 | (NULL != m->address) && | ||
1741 | (0 == GNUNET_HELLO_address_cmp(m->address, address)) ) | ||
1703 | return; /* No real change */ | 1742 | return; /* No real change */ |
1704 | } | 1743 | } |
1705 | 1744 | ||
@@ -1714,8 +1753,7 @@ process_peer_monitoring_cb (void *cls, | |||
1714 | m->state_timeout = state_timeout; | 1753 | m->state_timeout = state_timeout; |
1715 | 1754 | ||
1716 | if (NULL != address) | 1755 | if (NULL != address) |
1717 | resolve_peer_address (peer, | 1756 | resolve_peer_address (m->address, |
1718 | m->address, | ||
1719 | numeric, | 1757 | numeric, |
1720 | m->state, | 1758 | m->state, |
1721 | m->state_timeout); | 1759 | m->state_timeout); |
@@ -1970,11 +2008,14 @@ testservice_task (void *cls, | |||
1970 | } | 2008 | } |
1971 | else if (monitor_connections) /* -m: List information about peers continuously */ | 2009 | else if (monitor_connections) /* -m: List information about peers continuously */ |
1972 | { | 2010 | { |
1973 | monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 2011 | monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, |
2012 | GNUNET_NO); | ||
1974 | address_resolution_in_progress = GNUNET_YES; | 2013 | address_resolution_in_progress = GNUNET_YES; |
1975 | pic = GNUNET_TRANSPORT_monitor_peers (cfg, (NULL == cpid) ? NULL : &pid, | 2014 | pic = GNUNET_TRANSPORT_monitor_peers (cfg, |
1976 | GNUNET_NO, TIMEOUT, | 2015 | (NULL == cpid) ? NULL : &pid, |
1977 | &process_peer_monitoring_cb, (void *) cfg); | 2016 | GNUNET_NO, |
2017 | TIMEOUT, | ||
2018 | &process_peer_monitoring_cb, NULL); | ||
1978 | } | 2019 | } |
1979 | else if (monitor_plugins) /* -P: List information about plugins continuously */ | 2020 | else if (monitor_plugins) /* -P: List information about plugins continuously */ |
1980 | { | 2021 | { |