diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours_fsm.c | 163 |
1 files changed, 116 insertions, 47 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours_fsm.c b/src/transport/gnunet-service-transport_neighbours_fsm.c index e149facd0..bf264468d 100644 --- a/src/transport/gnunet-service-transport_neighbours_fsm.c +++ b/src/transport/gnunet-service-transport_neighbours_fsm.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include "gnunet-service-transport_clients.h" | 31 | #include "gnunet-service-transport_clients.h" |
32 | #include "gnunet-service-transport.h" | 32 | #include "gnunet-service-transport.h" |
33 | #include "gnunet_peerinfo_service.h" | 33 | #include "gnunet_peerinfo_service.h" |
34 | #include "gnunet-service-transport_blacklist.h" | ||
34 | #include "gnunet_constants.h" | 35 | #include "gnunet_constants.h" |
35 | #include "transport.h" | 36 | #include "transport.h" |
36 | 37 | ||
@@ -1719,6 +1720,100 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | |||
1719 | neighbour_connected (n, ats, ats_count, GNUNET_NO); | 1720 | neighbour_connected (n, ats, ats_count, GNUNET_NO); |
1720 | } | 1721 | } |
1721 | 1722 | ||
1723 | struct BlackListCheckContext | ||
1724 | { | ||
1725 | struct GNUNET_ATS_Information *ats; | ||
1726 | |||
1727 | uint32_t ats_count; | ||
1728 | |||
1729 | struct Session *session; | ||
1730 | |||
1731 | char *sender_address; | ||
1732 | |||
1733 | uint16_t sender_address_len; | ||
1734 | |||
1735 | char *plugin_name; | ||
1736 | |||
1737 | struct GNUNET_TIME_Absolute ts; | ||
1738 | }; | ||
1739 | |||
1740 | |||
1741 | static void | ||
1742 | handle_connect_blacklist_cont (void *cls, | ||
1743 | const struct GNUNET_PeerIdentity | ||
1744 | * peer, int result) | ||
1745 | { | ||
1746 | struct NeighbourMapEntry *n; | ||
1747 | struct BlackListCheckContext * bcc = cls; | ||
1748 | |||
1749 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1750 | "Result Connect blacklist check `%s': %s\n", GNUNET_i2s (peer), (result == GNUNET_OK) ? "OK" : "NO"); | ||
1751 | |||
1752 | /* not allowed */ | ||
1753 | if (GNUNET_OK != result) | ||
1754 | { | ||
1755 | GNUNET_free (bcc); | ||
1756 | return; | ||
1757 | } | ||
1758 | |||
1759 | n = lookup_neighbour (peer); | ||
1760 | if (NULL == n) | ||
1761 | n = setup_neighbour (peer); | ||
1762 | |||
1763 | if (bcc->ts.abs_value > n->connect_ts.abs_value) | ||
1764 | { | ||
1765 | if (NULL != bcc->session) | ||
1766 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
1767 | "transport-ats", | ||
1768 | "Giving ATS session %p of plugin %s address `%s' for peer %s\n", | ||
1769 | bcc->session, | ||
1770 | bcc->plugin_name, | ||
1771 | GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, bcc->sender_address_len), | ||
1772 | GNUNET_i2s (peer)); | ||
1773 | GNUNET_ATS_address_update (GST_ats, | ||
1774 | peer, | ||
1775 | bcc->plugin_name, bcc->sender_address, bcc->sender_address_len, | ||
1776 | bcc->session, bcc->ats, bcc->ats_count); | ||
1777 | n->connect_ts = bcc->ts; | ||
1778 | } | ||
1779 | |||
1780 | GNUNET_free (bcc); | ||
1781 | |||
1782 | if (n->state > S_NOT_CONNECTED) | ||
1783 | return; | ||
1784 | change_state (n, S_CONNECT_RECV); | ||
1785 | |||
1786 | /* Ask ATS for an address to connect via that address */ | ||
1787 | GNUNET_ATS_suggest_address(GST_ats, peer); | ||
1788 | |||
1789 | #if 0 | ||
1790 | |||
1791 | |||
1792 | |||
1793 | /* send CONNECT_ACK (SYN_ACK)*/ | ||
1794 | msg_len = sizeof (struct SessionConnectMessage); | ||
1795 | connect_msg.header.size = htons (msg_len); | ||
1796 | connect_msg.header.type = | ||
1797 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); | ||
1798 | connect_msg.reserved = htonl (0); | ||
1799 | connect_msg.timestamp = | ||
1800 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | ||
1801 | |||
1802 | ret = send_with_plugin(NULL, &n->id, (const void *) &connect_msg, | ||
1803 | msg_len, | ||
1804 | 0, | ||
1805 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1806 | session, plugin_name, sender_address, sender_address_len, | ||
1807 | GNUNET_YES, NULL, NULL); | ||
1808 | |||
1809 | if (ret == GNUNET_SYSERR) | ||
1810 | { | ||
1811 | change_state (n, S_NOT_CONNECTED); | ||
1812 | GNUNET_break (0); | ||
1813 | return; | ||
1814 | } | ||
1815 | #endif | ||
1816 | } | ||
1722 | 1817 | ||
1723 | /** | 1818 | /** |
1724 | * We received a 'SESSION_CONNECT' message from the other peer. | 1819 | * We received a 'SESSION_CONNECT' message from the other peer. |
@@ -1744,68 +1839,42 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, | |||
1744 | uint32_t ats_count) | 1839 | uint32_t ats_count) |
1745 | { | 1840 | { |
1746 | const struct SessionConnectMessage *scm; | 1841 | const struct SessionConnectMessage *scm; |
1747 | struct GNUNET_TIME_Absolute ts; | 1842 | struct BlackListCheckContext * bcc = NULL; |
1748 | struct NeighbourMapEntry *n; | ||
1749 | struct SessionConnectMessage connect_msg; | ||
1750 | size_t msg_len; | ||
1751 | int ret; | ||
1752 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1843 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1753 | "GST_neighbours_handle_connect SYN\n"); | 1844 | "GST_neighbours_handle_connect SYN\n"); |
1845 | |||
1754 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) | 1846 | if (ntohs (message->size) != sizeof (struct SessionConnectMessage)) |
1755 | { | 1847 | { |
1756 | GNUNET_break_op (0); | 1848 | GNUNET_break_op (0); |
1757 | return; | 1849 | return; |
1758 | } | 1850 | } |
1851 | |||
1759 | scm = (const struct SessionConnectMessage *) message; | 1852 | scm = (const struct SessionConnectMessage *) message; |
1760 | GNUNET_break_op (ntohl (scm->reserved) == 0); | 1853 | GNUNET_break_op (ntohl (scm->reserved) == 0); |
1761 | ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); | ||
1762 | n = lookup_neighbour (peer); | ||
1763 | if (NULL == n) | ||
1764 | n = setup_neighbour (peer); | ||
1765 | 1854 | ||
1766 | if (n->state > S_NOT_CONNECTED) | ||
1767 | return; | ||
1768 | 1855 | ||
1769 | change_state (n, S_CONNECT_RECV); | 1856 | /* do blacklist check*/ |
1857 | bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) + | ||
1858 | sizeof (struct GNUNET_ATS_Information) * ats_count + | ||
1859 | sender_address_len + | ||
1860 | strlen (plugin_name)+1); | ||
1770 | 1861 | ||
1771 | /* send CONNECT_ACK (SYN_ACK)*/ | 1862 | bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); |
1772 | msg_len = sizeof (struct SessionConnectMessage); | ||
1773 | connect_msg.header.size = htons (msg_len); | ||
1774 | connect_msg.header.type = | ||
1775 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK); | ||
1776 | connect_msg.reserved = htonl (0); | ||
1777 | connect_msg.timestamp = | ||
1778 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | ||
1779 | 1863 | ||
1780 | ret = send_with_plugin(NULL, &n->id, (const void *) &connect_msg, | 1864 | bcc->ats_count = ats_count; |
1781 | msg_len, | 1865 | bcc->sender_address_len = sender_address_len; |
1782 | 0, | 1866 | bcc->session = session; |
1783 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1784 | session, plugin_name, sender_address, sender_address_len, | ||
1785 | GNUNET_YES, NULL, NULL); | ||
1786 | 1867 | ||
1787 | if (ret == GNUNET_SYSERR) | 1868 | bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; |
1788 | { | 1869 | memcpy (bcc->ats, ats,sizeof (struct GNUNET_ATS_Information) * ats_count ); |
1789 | change_state (n, S_NOT_CONNECTED); | ||
1790 | GNUNET_break (0); | ||
1791 | return; | ||
1792 | } | ||
1793 | 1870 | ||
1794 | if (ts.abs_value > n->connect_ts.abs_value) | 1871 | bcc->sender_address = (char *) &bcc->ats[ats_count]; |
1795 | { | 1872 | memcpy (bcc->sender_address, sender_address , sender_address_len); |
1796 | if (NULL != session) | 1873 | |
1797 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 1874 | bcc->plugin_name = &bcc->sender_address[sender_address_len]; |
1798 | "transport-ats", | 1875 | strcpy (bcc->plugin_name, plugin_name); |
1799 | "Giving ATS session %p of plugin %s for peer %s\n", | 1876 | |
1800 | session, | 1877 | GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, bcc); |
1801 | plugin_name, | ||
1802 | GNUNET_i2s (peer)); | ||
1803 | GNUNET_ATS_address_update (GST_ats, | ||
1804 | peer, | ||
1805 | plugin_name, sender_address, sender_address_len, | ||
1806 | session, ats, ats_count); | ||
1807 | n->connect_ts = ts; | ||
1808 | } | ||
1809 | } | 1878 | } |
1810 | 1879 | ||
1811 | 1880 | ||