diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 152 |
1 files changed, 149 insertions, 3 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index 58cb0fbb3..45f1575fe 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -508,6 +508,8 @@ static unsigned long long bytes_in_send_queue; | |||
508 | static GNUNET_SCHEDULER_TaskIdentifier util_transmission_tk; | 508 | static GNUNET_SCHEDULER_TaskIdentifier util_transmission_tk; |
509 | 509 | ||
510 | 510 | ||
511 | static struct GNUNET_CONTAINER_MultiPeerMap *registered_quota_notifications; | ||
512 | |||
511 | /** | 513 | /** |
512 | * Lookup a neighbour entry in the neighbours hash map. | 514 | * Lookup a neighbour entry in the neighbours hash map. |
513 | * | 515 | * |
@@ -1689,13 +1691,152 @@ send_session_connect_ack_message (const struct GNUNET_HELLO_Address *address, | |||
1689 | 1691 | ||
1690 | } | 1692 | } |
1691 | 1693 | ||
1694 | struct QuotaNotificationRequest | ||
1695 | { | ||
1696 | struct GNUNET_PeerIdentity peer; | ||
1697 | struct Session *session; | ||
1698 | char *plugin; | ||
1699 | }; | ||
1700 | |||
1701 | struct QNR_LookContext | ||
1702 | { | ||
1703 | struct GNUNET_PeerIdentity peer; | ||
1704 | struct Session *session; | ||
1705 | const char *plugin; | ||
1706 | |||
1707 | struct QuotaNotificationRequest *res; | ||
1708 | }; | ||
1709 | |||
1710 | static int | ||
1711 | find_notification_request (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
1712 | { | ||
1713 | struct QNR_LookContext *qnr_ctx = cls; | ||
1714 | struct QuotaNotificationRequest *qnr = value; | ||
1715 | |||
1716 | if ((qnr->session == qnr_ctx->session) && | ||
1717 | (0 == memcmp (&qnr->peer, &qnr_ctx->peer, sizeof (struct GNUNET_PeerIdentity))) && | ||
1718 | (0 == strcmp(qnr_ctx->plugin, qnr->plugin))) | ||
1719 | { | ||
1720 | qnr_ctx->res = value; | ||
1721 | return GNUNET_NO; | ||
1722 | } | ||
1723 | return GNUNET_YES; | ||
1724 | } | ||
1725 | |||
1726 | void | ||
1727 | GST_neighbours_register_quota_notification(void *cls, | ||
1728 | const struct GNUNET_PeerIdentity *peer, const char *plugin, | ||
1729 | struct Session *session) | ||
1730 | { | ||
1731 | struct QuotaNotificationRequest *qnr; | ||
1732 | struct QNR_LookContext qnr_ctx; | ||
1733 | |||
1734 | qnr_ctx.peer = (*peer); | ||
1735 | qnr_ctx.plugin = plugin; | ||
1736 | qnr_ctx.session = session; | ||
1737 | qnr_ctx.res = NULL; | ||
1738 | int res; | ||
1739 | |||
1740 | res = GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications, | ||
1741 | peer, &find_notification_request, &qnr_ctx); | ||
1742 | if (NULL != qnr_ctx.res) | ||
1743 | { | ||
1744 | GNUNET_break(0); | ||
1745 | return; | ||
1746 | } | ||
1747 | |||
1748 | qnr = GNUNET_new (struct QuotaNotificationRequest); | ||
1749 | qnr->peer = (*peer); | ||
1750 | qnr->plugin = GNUNET_strdup (plugin); | ||
1751 | qnr->session = session; | ||
1752 | |||
1753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1754 | "Adding notification for peer `%s' plugin `%s' session %p \n", | ||
1755 | GNUNET_i2s (peer), plugin, session); | ||
1756 | |||
1757 | GNUNET_CONTAINER_multipeermap_put (registered_quota_notifications, peer, | ||
1758 | qnr, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
1759 | } | ||
1760 | |||
1761 | |||
1762 | void | ||
1763 | GST_neighbours_unregister_quota_notification(void *cls, | ||
1764 | const struct GNUNET_PeerIdentity *peer, const char *plugin, struct Session *session) | ||
1765 | { | ||
1766 | struct QNR_LookContext qnr_ctx; | ||
1767 | qnr_ctx.peer = (*peer); | ||
1768 | qnr_ctx.plugin = plugin; | ||
1769 | qnr_ctx.session = session; | ||
1770 | qnr_ctx.res = NULL; | ||
1771 | int res; | ||
1772 | |||
1773 | res = GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications, | ||
1774 | &find_notification_request, &qnr_ctx); | ||
1775 | if (NULL == qnr_ctx.res) | ||
1776 | { | ||
1777 | GNUNET_break(0); | ||
1778 | return; | ||
1779 | } | ||
1780 | |||
1781 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1782 | "Removing notification for peer `%s' plugin `%s' session %p \n", | ||
1783 | GNUNET_i2s (peer), plugin, session); | ||
1784 | |||
1785 | GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, peer, | ||
1786 | qnr_ctx.res); | ||
1787 | GNUNET_free (qnr_ctx.res->plugin); | ||
1788 | GNUNET_free (qnr_ctx.res); | ||
1789 | } | ||
1790 | |||
1791 | static int | ||
1792 | notification_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
1793 | { | ||
1794 | struct NeighbourMapEntry *n = cls; | ||
1795 | struct QuotaNotificationRequest *qnr = value; | ||
1796 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
1797 | struct GNUNET_TIME_Relative delay; | ||
1798 | int do_forward; | ||
1799 | |||
1800 | papi = GST_plugins_find(qnr->plugin); | ||
1801 | if (NULL == papi) | ||
1802 | { | ||
1803 | GNUNET_break (0); | ||
1804 | return GNUNET_OK; | ||
1805 | } | ||
1806 | |||
1807 | delay = GST_neighbours_calculate_receive_delay (key, 0, &do_forward); | ||
1808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1809 | "New inbound delay for peer `%s' is %llu ms\n", GNUNET_i2s (key), | ||
1810 | delay.rel_value_us / 1000); | ||
1811 | |||
1812 | if (NULL != papi->update_inbound_delay) | ||
1813 | papi->update_inbound_delay (papi->cls, key, qnr->session, delay); | ||
1814 | return GNUNET_OK; | ||
1815 | } | ||
1816 | |||
1817 | static | ||
1818 | int | ||
1819 | free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key, | ||
1820 | void *value) | ||
1821 | { | ||
1822 | struct NeighbourMapEntry *n = cls; | ||
1823 | struct QuotaNotificationRequest *qnr = value; | ||
1824 | |||
1825 | GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, key, | ||
1826 | qnr); | ||
1827 | GNUNET_free(qnr); | ||
1828 | |||
1829 | return GNUNET_OK; | ||
1830 | } | ||
1831 | |||
1692 | static void | 1832 | static void |
1693 | inbound_bw_tracker_update (void *cls) | 1833 | inbound_bw_tracker_update(void *cls) |
1694 | { | 1834 | { |
1695 | struct Neighbour *n = cls; | 1835 | struct NeighbourMapEntry *n = cls; |
1696 | 1836 | ||
1697 | /* Quota was updated, tell plugins to update the time to receive next */ | 1837 | /* Quota was updated, tell plugins to update the time to receive next */ |
1698 | 1838 | GNUNET_CONTAINER_multipeermap_get_multiple (registered_quota_notifications, | |
1839 | &n->id, ¬ification_cb, n); | ||
1699 | } | 1840 | } |
1700 | 1841 | ||
1701 | 1842 | ||
@@ -3655,6 +3796,7 @@ GST_neighbours_start (void *cls, | |||
3655 | disconnect_notify_cb = disconnect_cb; | 3796 | disconnect_notify_cb = disconnect_cb; |
3656 | neighbour_change_cb = peer_address_cb; | 3797 | neighbour_change_cb = peer_address_cb; |
3657 | neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); | 3798 | neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); |
3799 | registered_quota_notifications = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, GNUNET_NO); | ||
3658 | util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, | 3800 | util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, |
3659 | utilization_transmission, NULL); | 3801 | utilization_transmission, NULL); |
3660 | } | 3802 | } |
@@ -3723,6 +3865,10 @@ GST_neighbours_stop () | |||
3723 | GNUNET_free (cur); | 3865 | GNUNET_free (cur); |
3724 | } | 3866 | } |
3725 | 3867 | ||
3868 | GNUNET_CONTAINER_multipeermap_iterate (registered_quota_notifications, | ||
3869 | &free_notification_cb, NULL); | ||
3870 | GNUNET_CONTAINER_multipeermap_destroy (registered_quota_notifications); | ||
3871 | |||
3726 | neighbours = NULL; | 3872 | neighbours = NULL; |
3727 | callback_cls = NULL; | 3873 | callback_cls = NULL; |
3728 | connect_notify_cb = NULL; | 3874 | connect_notify_cb = NULL; |