diff options
Diffstat (limited to 'src/transport/gnunet-service-transport.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index e55fc41ac..1a5d0af4b 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -929,7 +929,7 @@ static void disconnect_neighbour (struct NeighbourList *n, int check); | |||
929 | * | 929 | * |
930 | * @param neighbour target peer for which to transmit | 930 | * @param neighbour target peer for which to transmit |
931 | */ | 931 | */ |
932 | static void try_transmission_to_peer (struct NeighbourList *neighbour); | 932 | static void try_transmission_to_peer (struct NeighbourList *n); |
933 | 933 | ||
934 | 934 | ||
935 | struct ATS_info * ats_init (); | 935 | struct ATS_info * ats_init (); |
@@ -947,6 +947,9 @@ void ats_notify_ats_data (struct ATS_info * ats, | |||
947 | const struct GNUNET_PeerIdentity *peer, | 947 | const struct GNUNET_PeerIdentity *peer, |
948 | const struct GNUNET_TRANSPORT_ATS_Information *ats_data); | 948 | const struct GNUNET_TRANSPORT_ATS_Information *ats_data); |
949 | 949 | ||
950 | struct ForeignAddressList * ats_get_preferred_address (struct ATS_info * ats, | ||
951 | struct NeighbourList *n); | ||
952 | |||
950 | /** | 953 | /** |
951 | * Find an entry in the neighbour list for a particular peer. | 954 | * Find an entry in the neighbour list for a particular peer. |
952 | * | 955 | * |
@@ -1525,6 +1528,9 @@ find_ready_address(struct NeighbourList *neighbour) | |||
1525 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 1528 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
1526 | struct ForeignAddressList *best_address; | 1529 | struct ForeignAddressList *best_address; |
1527 | 1530 | ||
1531 | /* Hack to prefer unix domain sockets */ | ||
1532 | struct ForeignAddressList *unix_address = NULL; | ||
1533 | |||
1528 | best_address = NULL; | 1534 | best_address = NULL; |
1529 | while (head != NULL) | 1535 | while (head != NULL) |
1530 | { | 1536 | { |
@@ -1566,6 +1572,12 @@ find_ready_address(struct NeighbourList *neighbour) | |||
1566 | (unsigned long long) addresses->timeout.abs_value, | 1572 | (unsigned long long) addresses->timeout.abs_value, |
1567 | (unsigned int) addresses->distance); | 1573 | (unsigned int) addresses->distance); |
1568 | #endif | 1574 | #endif |
1575 | if (0==strcmp(head->plugin->short_name,"unix")) | ||
1576 | { | ||
1577 | if ((unix_address == NULL) || ((unix_address != NULL) && | ||
1578 | (addresses->latency.rel_value < unix_address->latency.rel_value))) | ||
1579 | unix_address = addresses; | ||
1580 | } | ||
1569 | if ( ( (best_address == NULL) || | 1581 | if ( ( (best_address == NULL) || |
1570 | (addresses->connected == GNUNET_YES) || | 1582 | (addresses->connected == GNUNET_YES) || |
1571 | (best_address->connected == GNUNET_NO) ) && | 1583 | (best_address->connected == GNUNET_NO) ) && |
@@ -1577,12 +1589,22 @@ find_ready_address(struct NeighbourList *neighbour) | |||
1577 | connected a chance some times... */ | 1589 | connected a chance some times... */ |
1578 | addresses = addresses->next; | 1590 | addresses = addresses->next; |
1579 | } | 1591 | } |
1592 | if (unix_address != NULL) | ||
1593 | break; | ||
1580 | head = head->next; | 1594 | head = head->next; |
1581 | } | 1595 | } |
1596 | if (unix_address != NULL) | ||
1597 | { | ||
1598 | best_address = unix_address; | ||
1599 | #if DEBUG_TRANSPORT | ||
1600 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Found unix address, forced this address\n"); | ||
1601 | #endif | ||
1602 | } | ||
1582 | if (best_address != NULL) | 1603 | if (best_address != NULL) |
1583 | { | 1604 | { |
1584 | #if DEBUG_TRANSPORT | 1605 | #if DEBUG_TRANSPORT |
1585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1606 | |
1607 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1586 | "Best address found (`%s') has latency of %llu ms.\n", | 1608 | "Best address found (`%s') has latency of %llu ms.\n", |
1587 | (best_address->addrlen > 0) | 1609 | (best_address->addrlen > 0) |
1588 | ? a2s (best_address->ready_list->plugin->short_name, | 1610 | ? a2s (best_address->ready_list->plugin->short_name, |
@@ -1599,6 +1621,7 @@ find_ready_address(struct NeighbourList *neighbour) | |||
1599 | 1, | 1621 | 1, |
1600 | GNUNET_NO); | 1622 | GNUNET_NO); |
1601 | } | 1623 | } |
1624 | |||
1602 | return best_address; | 1625 | return best_address; |
1603 | 1626 | ||
1604 | } | 1627 | } |
@@ -1626,7 +1649,7 @@ retry_transmission_task (void *cls, | |||
1626 | * @param neighbour target peer for which to transmit | 1649 | * @param neighbour target peer for which to transmit |
1627 | */ | 1650 | */ |
1628 | static void | 1651 | static void |
1629 | try_transmission_to_peer (struct NeighbourList *neighbour) | 1652 | try_transmission_to_peer (struct NeighbourList *n) |
1630 | { | 1653 | { |
1631 | struct ReadyList *rl; | 1654 | struct ReadyList *rl; |
1632 | struct MessageQueue *mq; | 1655 | struct MessageQueue *mq; |
@@ -1634,7 +1657,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
1634 | ssize_t ret; | 1657 | ssize_t ret; |
1635 | int force_address; | 1658 | int force_address; |
1636 | 1659 | ||
1637 | if (neighbour->messages_head == NULL) | 1660 | if (n->messages_head == NULL) |
1638 | { | 1661 | { |
1639 | #if DEBUG_TRANSPORT | 1662 | #if DEBUG_TRANSPORT |
1640 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1644,12 +1667,12 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
1644 | return; /* nothing to do */ | 1667 | return; /* nothing to do */ |
1645 | } | 1668 | } |
1646 | rl = NULL; | 1669 | rl = NULL; |
1647 | mq = neighbour->messages_head; | 1670 | mq = n->messages_head; |
1648 | force_address = GNUNET_YES; | 1671 | force_address = GNUNET_YES; |
1649 | if (mq->specific_address == NULL) | 1672 | if (mq->specific_address == NULL) |
1650 | { | 1673 | { |
1651 | /* TODO: ADD ATS */ | 1674 | /* TODO: ADD ATS */ |
1652 | mq->specific_address = find_ready_address(neighbour); | 1675 | mq->specific_address = ats_get_preferred_address(ats, n); |
1653 | GNUNET_STATISTICS_update (stats, | 1676 | GNUNET_STATISTICS_update (stats, |
1654 | gettext_noop ("# transport selected peer address freely"), | 1677 | gettext_noop ("# transport selected peer address freely"), |
1655 | 1, | 1678 | 1, |
@@ -1680,9 +1703,9 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
1680 | mq->message_buf_size, | 1703 | mq->message_buf_size, |
1681 | GNUNET_NO); | 1704 | GNUNET_NO); |
1682 | if (mq->client != NULL) | 1705 | if (mq->client != NULL) |
1683 | transmit_send_ok (mq->client, neighbour, &neighbour->id, GNUNET_NO); | 1706 | transmit_send_ok (mq->client, n, &n->id, GNUNET_NO); |
1684 | GNUNET_CONTAINER_DLL_remove (neighbour->messages_head, | 1707 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
1685 | neighbour->messages_tail, | 1708 | n->messages_tail, |
1686 | mq); | 1709 | mq); |
1687 | GNUNET_free (mq); | 1710 | GNUNET_free (mq); |
1688 | return; /* nobody ready */ | 1711 | return; /* nobody ready */ |
@@ -1691,11 +1714,11 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
1691 | gettext_noop ("# message delivery deferred (no address)"), | 1714 | gettext_noop ("# message delivery deferred (no address)"), |
1692 | 1, | 1715 | 1, |
1693 | GNUNET_NO); | 1716 | GNUNET_NO); |
1694 | if (neighbour->retry_task != GNUNET_SCHEDULER_NO_TASK) | 1717 | if (n->retry_task != GNUNET_SCHEDULER_NO_TASK) |
1695 | GNUNET_SCHEDULER_cancel (neighbour->retry_task); | 1718 | GNUNET_SCHEDULER_cancel (n->retry_task); |
1696 | neighbour->retry_task = GNUNET_SCHEDULER_add_delayed (timeout, | 1719 | n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout, |
1697 | &retry_transmission_task, | 1720 | &retry_transmission_task, |
1698 | neighbour); | 1721 | n); |
1699 | #if DEBUG_TRANSPORT | 1722 | #if DEBUG_TRANSPORT |
1700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1723 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1701 | "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", | 1724 | "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", |
@@ -1707,8 +1730,8 @@ try_transmission_to_peer (struct NeighbourList *neighbour) | |||
1707 | (unless that's already pending...) */ | 1730 | (unless that's already pending...) */ |
1708 | return; | 1731 | return; |
1709 | } | 1732 | } |
1710 | GNUNET_CONTAINER_DLL_remove (neighbour->messages_head, | 1733 | GNUNET_CONTAINER_DLL_remove (n->messages_head, |
1711 | neighbour->messages_tail, | 1734 | n->messages_tail, |
1712 | mq); | 1735 | mq); |
1713 | if (mq->specific_address->connected == GNUNET_NO) | 1736 | if (mq->specific_address->connected == GNUNET_NO) |
1714 | mq->specific_address->connect_attempts++; | 1737 | mq->specific_address->connect_attempts++; |
@@ -5675,6 +5698,23 @@ void ats_notify_ats_data (struct ATS_info * ats, | |||
5675 | ats_calculate_bandwidth_distribution(ats); | 5698 | ats_calculate_bandwidth_distribution(ats); |
5676 | } | 5699 | } |
5677 | 5700 | ||
5701 | struct ForeignAddressList * ats_get_preferred_address (struct ATS_info * ats, | ||
5702 | struct NeighbourList *n) | ||
5703 | { | ||
5704 | #if DEBUG_ATS | ||
5705 | GNUNET_log (GNUNET_ERROR_TYPE_BULK, "ats_get_prefered_transport for peer: %s\n",GNUNET_i2s(&n->id)); | ||
5706 | #endif | ||
5707 | struct ReadyList *next = n->plugins; | ||
5708 | while (next != NULL) | ||
5709 | { | ||
5710 | #if DEBUG_ATS | ||
5711 | GNUNET_log (GNUNET_ERROR_TYPE_BULK, "plugin: %s %i\n",next->plugin->short_name,strcmp(next->plugin->short_name,"unix")); | ||
5712 | #endif | ||
5713 | next = next->next; | ||
5714 | } | ||
5715 | return find_ready_address(n); | ||
5716 | } | ||
5717 | |||
5678 | /** | 5718 | /** |
5679 | * Initiate transport service. | 5719 | * Initiate transport service. |
5680 | * | 5720 | * |