diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-18 13:59:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-18 13:59:59 +0000 |
commit | bf30110e3d6bfef07963641ce6c3d53964a9e661 (patch) | |
tree | 36b58df8872b2301760f72b363627485f2aecf47 | |
parent | a93366a9273b903fa50f47f5a8cc019c7565e332 (diff) | |
download | gnunet-bf30110e3d6bfef07963641ce6c3d53964a9e661.tar.gz gnunet-bf30110e3d6bfef07963641ce6c3d53964a9e661.zip |
use ATS connectivity suggestion instead of deprecated GNUNET_TRANSPORT_try_connect
-rw-r--r-- | src/cadet/Makefile.am | 2 | ||||
-rw-r--r-- | src/cadet/gnunet-service-cadet_peer.c | 50 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index e88c3a0d3..d823b4872 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -62,6 +62,7 @@ gnunet_service_cadet_LDADD = \ | |||
62 | $(top_builddir)/src/util/libgnunetutil.la \ | 62 | $(top_builddir)/src/util/libgnunetutil.la \ |
63 | $(top_builddir)/src/transport/libgnunettransport.la \ | 63 | $(top_builddir)/src/transport/libgnunettransport.la \ |
64 | $(top_builddir)/src/core/libgnunetcore.la \ | 64 | $(top_builddir)/src/core/libgnunetcore.la \ |
65 | $(top_builddir)/src/ats/libgnunetats.la \ | ||
65 | $(top_builddir)/src/dht/libgnunetdht.la \ | 66 | $(top_builddir)/src/dht/libgnunetdht.la \ |
66 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 67 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
67 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ | 68 | $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ |
@@ -210,4 +211,3 @@ EXTRA_DIST = \ | |||
210 | cadet.h cadet_protocol.h \ | 211 | cadet.h cadet_protocol.h \ |
211 | test_cadet.conf \ | 212 | test_cadet.conf \ |
212 | test_cadet_drop.conf | 213 | test_cadet_drop.conf |
213 | |||
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c index 4d5c09260..7cc1381a4 100644 --- a/src/cadet/gnunet-service-cadet_peer.c +++ b/src/cadet/gnunet-service-cadet_peer.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "gnunet_util_lib.h" | 26 | #include "gnunet_util_lib.h" |
27 | #include "gnunet_signatures.h" | 27 | #include "gnunet_signatures.h" |
28 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
29 | #include "gnunet_ats_service.h" | ||
29 | #include "gnunet_core_service.h" | 30 | #include "gnunet_core_service.h" |
30 | #include "gnunet_statistics_service.h" | 31 | #include "gnunet_statistics_service.h" |
31 | #include "cadet_protocol.h" | 32 | #include "cadet_protocol.h" |
@@ -194,6 +195,13 @@ struct CadetPeer | |||
194 | * Handle to us offering the HELLO to the transport. | 195 | * Handle to us offering the HELLO to the transport. |
195 | */ | 196 | */ |
196 | struct GNUNET_TRANSPORT_OfferHelloHandle *hello_offer; | 197 | struct GNUNET_TRANSPORT_OfferHelloHandle *hello_offer; |
198 | |||
199 | /** | ||
200 | * Handle to our ATS request asking ATS to suggest an address | ||
201 | * to TRANSPORT for this peer (to establish a direct link). | ||
202 | */ | ||
203 | struct GNUNET_ATS_ConnectivitySuggestHandle *connectivity_suggestion; | ||
204 | |||
197 | }; | 205 | }; |
198 | 206 | ||
199 | 207 | ||
@@ -232,11 +240,16 @@ static unsigned long long max_peers; | |||
232 | static unsigned long long drop_percent; | 240 | static unsigned long long drop_percent; |
233 | 241 | ||
234 | /** | 242 | /** |
235 | * Handle to communicate with core. | 243 | * Handle to communicate with CORE. |
236 | */ | 244 | */ |
237 | static struct GNUNET_CORE_Handle *core_handle; | 245 | static struct GNUNET_CORE_Handle *core_handle; |
238 | 246 | ||
239 | /** | 247 | /** |
248 | * Handle to communicate with ATS. | ||
249 | */ | ||
250 | static struct GNUNET_ATS_ConnectivityHandle *ats_ch; | ||
251 | |||
252 | /** | ||
240 | * Handle to try to start new connections. | 253 | * Handle to try to start new connections. |
241 | */ | 254 | */ |
242 | static struct GNUNET_TRANSPORT_Handle *transport_handle; | 255 | static struct GNUNET_TRANSPORT_Handle *transport_handle; |
@@ -767,6 +780,11 @@ peer_destroy (struct CadetPeer *peer) | |||
767 | GNUNET_TRANSPORT_offer_hello_cancel (peer->hello_offer); | 780 | GNUNET_TRANSPORT_offer_hello_cancel (peer->hello_offer); |
768 | peer->hello_offer = NULL; | 781 | peer->hello_offer = NULL; |
769 | } | 782 | } |
783 | if (NULL != peer->connectivity_suggestion) | ||
784 | { | ||
785 | GNUNET_ATS_connectivity_suggest_cancel (peer->connectivity_suggestion); | ||
786 | peer->connectivity_suggestion = NULL; | ||
787 | } | ||
770 | GNUNET_free_non_null (peer->hello); | 788 | GNUNET_free_non_null (peer->hello); |
771 | GNUNET_free (peer); | 789 | GNUNET_free (peer); |
772 | return GNUNET_OK; | 790 | return GNUNET_OK; |
@@ -1790,7 +1808,7 @@ GCP_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1790 | LOG (GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); | 1808 | LOG (GNUNET_ERROR_TYPE_WARNING, "Remove DROP_PERCENT from config file.\n"); |
1791 | LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); | 1809 | LOG (GNUNET_ERROR_TYPE_WARNING, "**************************************\n"); |
1792 | } | 1810 | } |
1793 | 1811 | ats_ch = GNUNET_ATS_connectivity_init (c); | |
1794 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | 1812 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ |
1795 | NULL, /* Closure passed to CADET functions */ | 1813 | NULL, /* Closure passed to CADET functions */ |
1796 | &core_init, /* Call core_init once connected */ | 1814 | &core_init, /* Call core_init once connected */ |
@@ -1835,7 +1853,8 @@ GCP_init (const struct GNUNET_CONFIGURATION_Handle *c) | |||
1835 | void | 1853 | void |
1836 | GCP_shutdown (void) | 1854 | GCP_shutdown (void) |
1837 | { | 1855 | { |
1838 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peers\n"); | 1856 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1857 | "Shutting down peer subsystem\n"); | ||
1839 | in_shutdown = GNUNET_YES; | 1858 | in_shutdown = GNUNET_YES; |
1840 | GNUNET_CONTAINER_multipeermap_iterate (peers, | 1859 | GNUNET_CONTAINER_multipeermap_iterate (peers, |
1841 | &shutdown_peer, | 1860 | &shutdown_peer, |
@@ -1850,6 +1869,11 @@ GCP_shutdown (void) | |||
1850 | GNUNET_TRANSPORT_disconnect (transport_handle); | 1869 | GNUNET_TRANSPORT_disconnect (transport_handle); |
1851 | transport_handle = NULL; | 1870 | transport_handle = NULL; |
1852 | } | 1871 | } |
1872 | if (NULL != ats_ch) | ||
1873 | { | ||
1874 | GNUNET_ATS_connectivity_done (ats_ch); | ||
1875 | ats_ch = NULL; | ||
1876 | } | ||
1853 | GNUNET_PEER_change_rc (myid, -1); | 1877 | GNUNET_PEER_change_rc (myid, -1); |
1854 | GNUNET_CONTAINER_multipeermap_destroy (peers); | 1878 | GNUNET_CONTAINER_multipeermap_destroy (peers); |
1855 | peers = NULL; | 1879 | peers = NULL; |
@@ -1912,23 +1936,19 @@ GCP_get_short (const GNUNET_PEER_Id peer, int create) | |||
1912 | 1936 | ||
1913 | 1937 | ||
1914 | /** | 1938 | /** |
1915 | * Try to connect to a peer on transport level. | 1939 | * Function called once #GNUNET_TRANSPORT_offer_hello() is done. |
1940 | * Marks the operation as finished. | ||
1916 | * | 1941 | * |
1917 | * @param cls Closure (peer). | 1942 | * @param cls Closure (our `struct CadetPeer`). |
1918 | * @param tc TaskContext. | 1943 | * @param tc TaskContext. |
1919 | */ | 1944 | */ |
1920 | static void | 1945 | static void |
1921 | try_connect (void *cls, | 1946 | hello_offer_done (void *cls, |
1922 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1947 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1923 | { | 1948 | { |
1924 | struct CadetPeer *peer = cls; | 1949 | struct CadetPeer *peer = cls; |
1925 | 1950 | ||
1926 | peer->hello_offer = NULL; | 1951 | peer->hello_offer = NULL; |
1927 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | ||
1928 | return; | ||
1929 | |||
1930 | GNUNET_TRANSPORT_try_connect (transport_handle, | ||
1931 | GNUNET_PEER_resolve2 (peer->id), NULL, NULL); | ||
1932 | } | 1952 | } |
1933 | 1953 | ||
1934 | 1954 | ||
@@ -2556,8 +2576,12 @@ GCP_try_connect (struct CadetPeer *peer) | |||
2556 | mh = GNUNET_HELLO_get_header (hello); | 2576 | mh = GNUNET_HELLO_get_header (hello); |
2557 | peer->hello_offer = GNUNET_TRANSPORT_offer_hello (transport_handle, | 2577 | peer->hello_offer = GNUNET_TRANSPORT_offer_hello (transport_handle, |
2558 | mh, | 2578 | mh, |
2559 | &try_connect, | 2579 | &hello_offer_done, |
2560 | peer); | 2580 | peer); |
2581 | peer->connectivity_suggestion | ||
2582 | = GNUNET_ATS_connectivity_suggest (ats_ch, | ||
2583 | GNUNET_PEER_resolve2 (peer->id), | ||
2584 | 1 /* strength */); | ||
2561 | GCC_check_connections (); | 2585 | GCC_check_connections (); |
2562 | } | 2586 | } |
2563 | 2587 | ||