aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-01-20 17:17:59 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-01-20 17:17:59 +0000
commit95b657e52e52523cc7080406221896ed31327052 (patch)
tree66173bc5d93231bdcc564436ee90b44f6310c50d
parentcb819577d78ff466626cf061e434eccf0651765d (diff)
downloadgnunet-95b657e52e52523cc7080406221896ed31327052.tar.gz
gnunet-95b657e52e52523cc7080406221896ed31327052.zip
blacklist check on try connect
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c87
1 files changed, 65 insertions, 22 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 871b6c2cf..b82bd8694 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1763,6 +1763,51 @@ address_suggest_cont (void *cls,
1763} 1763}
1764 1764
1765 1765
1766struct BlacklistCheckSwitchContext
1767{
1768 struct BlacklistCheckSwitchContext *prev;
1769 struct BlacklistCheckSwitchContext *next;
1770
1771
1772 struct GST_BlacklistCheck *blc;
1773
1774 struct GNUNET_HELLO_Address *address;
1775 struct Session *session;
1776 struct GNUNET_ATS_Information *ats;
1777 uint32_t ats_count;
1778
1779 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
1780 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
1781};
1782
1783
1784static void
1785try_connect_bl_check_cont (void *cls,
1786 const struct GNUNET_PeerIdentity *peer, int result)
1787{
1788 struct BlacklistCheckSwitchContext *blc_ctx = cls;
1789 struct NeighbourMapEntry *n;
1790
1791 GNUNET_CONTAINER_DLL_remove (pending_bc_head, pending_bc_tail, blc_ctx);
1792 GNUNET_free (blc_ctx);
1793
1794 if (GNUNET_OK != result)
1795 {
1796 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1797 _("Blacklisting dissaproved to connect to peer `%s'\n"),
1798 GNUNET_i2s (peer));
1799 return;
1800 }
1801 n = setup_neighbour (peer);
1802 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1803
1804 GNUNET_ATS_reset_backoff (GST_ats, peer);
1805 n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer,
1806 &address_suggest_cont, n);
1807}
1808
1809
1810
1766/** 1811/**
1767 * Try to create a connection to the given target (eventually). 1812 * Try to create a connection to the given target (eventually).
1768 * 1813 *
@@ -1772,6 +1817,8 @@ void
1772GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) 1817GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1773{ 1818{
1774 struct NeighbourMapEntry *n; 1819 struct NeighbourMapEntry *n;
1820 struct GST_BlacklistCheck *blc;
1821 struct BlacklistCheckSwitchContext *blc_ctx;
1775 1822
1776 if (NULL == neighbours) 1823 if (NULL == neighbours)
1777 { 1824 {
@@ -1831,11 +1878,16 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
1831 break; 1878 break;
1832 } 1879 }
1833 } 1880 }
1834 n = setup_neighbour (target);
1835 set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1836 1881
1837 GNUNET_ATS_reset_backoff (GST_ats, target); 1882 /* Do blacklist check if connection is allowed */
1838 n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, target, &address_suggest_cont, n); 1883 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
1884 GNUNET_CONTAINER_DLL_insert (pending_bc_head, pending_bc_tail, blc_ctx);
1885
1886 if (NULL != (blc = GST_blacklist_test_allowed (target, NULL,
1887 &try_connect_bl_check_cont, blc_ctx)))
1888 {
1889 blc_ctx->blc = blc;
1890 }
1839} 1891}
1840 1892
1841 1893
@@ -2250,20 +2302,6 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
2250 return GNUNET_OK; 2302 return GNUNET_OK;
2251} 2303}
2252 2304
2253struct BlacklistCheckSwitchContext
2254{
2255 struct BlacklistCheckSwitchContext *prev;
2256 struct BlacklistCheckSwitchContext *next;
2257
2258 struct GNUNET_HELLO_Address *address;
2259 struct Session *session;
2260 struct GNUNET_ATS_Information *ats;
2261 uint32_t ats_count;
2262
2263 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
2264 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
2265};
2266
2267static void 2305static void
2268switch_address_bl_check_cont (void *cls, 2306switch_address_bl_check_cont (void *cls,
2269 const struct GNUNET_PeerIdentity *peer, int result) 2307 const struct GNUNET_PeerIdentity *peer, int result)
@@ -2272,7 +2310,6 @@ switch_address_bl_check_cont (void *cls,
2272 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2310 struct GNUNET_TRANSPORT_PluginFunctions *papi;
2273 struct NeighbourMapEntry *n; 2311 struct NeighbourMapEntry *n;
2274 2312
2275
2276 if ( (NULL == (n = lookup_neighbour (peer))) || (result == GNUNET_NO) || 2313 if ( (NULL == (n = lookup_neighbour (peer))) || (result == GNUNET_NO) ||
2277 (NULL == (papi = GST_plugins_find (blc_ctx->address->transport_name))) ) 2314 (NULL == (papi = GST_plugins_find (blc_ctx->address->transport_name))) )
2278 { 2315 {
@@ -2564,7 +2601,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
2564 } 2601 }
2565 2602
2566 GNUNET_CONTAINER_DLL_insert (pending_bc_head, pending_bc_tail, blc_ctx); 2603 GNUNET_CONTAINER_DLL_insert (pending_bc_head, pending_bc_tail, blc_ctx);
2567 GST_blacklist_test_allowed (peer, address->transport_name, 2604 blc_ctx->blc = GST_blacklist_test_allowed (peer, address->transport_name,
2568 &switch_address_bl_check_cont, blc_ctx); 2605 &switch_address_bl_check_cont, blc_ctx);
2569} 2606}
2570 2607
@@ -3661,9 +3698,15 @@ GST_neighbours_stop ()
3661 for (cur = next; NULL != cur; cur = next ) 3698 for (cur = next; NULL != cur; cur = next )
3662 { 3699 {
3663 next = cur->next; 3700 next = cur->next;
3664
3665 GNUNET_CONTAINER_DLL_remove (pending_bc_head, pending_bc_tail, cur); 3701 GNUNET_CONTAINER_DLL_remove (pending_bc_head, pending_bc_tail, cur);
3666 GNUNET_HELLO_address_free (cur->address); 3702
3703 if (NULL != cur->blc)
3704 {
3705 GST_blacklist_test_cancel (cur->blc);
3706 cur->blc = NULL;
3707 }
3708 if (NULL != cur->address)
3709 GNUNET_HELLO_address_free (cur->address);
3667 GNUNET_free_non_null (cur->ats); 3710 GNUNET_free_non_null (cur->ats);
3668 GNUNET_free (cur); 3711 GNUNET_free (cur);
3669 } 3712 }