aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-04 09:43:19 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-04 09:43:19 +0000
commita27256cef4f5afc24f5f2daa64779908a26d88c3 (patch)
tree7937ffa2795ac2bd83ce12297cdb179ea20b8571
parent24b2fde844fe17a446e71024ba06eb689a6e850d (diff)
downloadgnunet-a27256cef4f5afc24f5f2daa64779908a26d88c3.tar.gz
gnunet-a27256cef4f5afc24f5f2daa64779908a26d88c3.zip
-run refresh_routes() asynchronously, as the recursion in #3152 looks suspicious
-rw-r--r--src/dv/gnunet-service-dv.c95
1 files changed, 67 insertions, 28 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index f386b987a..56e5c403e 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -324,7 +324,7 @@ struct ConsensusSet
324 struct Route **targets; 324 struct Route **targets;
325 325
326 /** 326 /**
327 * Size of the 'targets' array. 327 * Size of the @e targets array.
328 */ 328 */
329 unsigned int array_length; 329 unsigned int array_length;
330 330
@@ -383,6 +383,14 @@ static struct GNUNET_STATISTICS_Handle *stats;
383 */ 383 */
384static struct GNUNET_ATS_PerformanceHandle *ats; 384static struct GNUNET_ATS_PerformanceHandle *ats;
385 385
386/**
387 * Task scheduled to refresh routes based on direct neighbours.
388 */
389static GNUNET_SCHEDULER_TaskIdentifier rr_task;
390
391/**
392 * #GNUNET_YES if we are shutting down.
393 */
386static int in_shutdown; 394static int in_shutdown;
387 395
388/** 396/**
@@ -618,7 +626,7 @@ core_transmit_notify (void *cls, size_t size, void *buf)
618 0 /* priority */, 626 0 /* priority */,
619 GNUNET_TIME_UNIT_FOREVER_REL, 627 GNUNET_TIME_UNIT_FOREVER_REL,
620 &dn->peer, 628 &dn->peer,
621 msize, 629 msize,
622 &core_transmit_notify, dn); 630 &core_transmit_notify, dn);
623 return off; 631 return off;
624} 632}
@@ -682,7 +690,7 @@ forward_payload (struct DirectNeighbor *target,
682 0 /* priority */, 690 0 /* priority */,
683 GNUNET_TIME_UNIT_FOREVER_REL, 691 GNUNET_TIME_UNIT_FOREVER_REL,
684 &target->peer, 692 &target->peer,
685 msize, 693 msize,
686 &core_transmit_notify, target); 694 &core_transmit_notify, target);
687} 695}
688 696
@@ -979,7 +987,7 @@ handle_core_connect (void *cls,
979 * @param cls NULL 987 * @param cls NULL
980 * @param key key of the value 988 * @param key key of the value
981 * @param value value to free 989 * @param value value to free
982 * @return GNUNET_OK to continue to iterate 990 * @return #GNUNET_OK to continue to iterate
983 */ 991 */
984static int 992static int
985free_targets (void *cls, 993free_targets (void *cls,
@@ -999,7 +1007,7 @@ free_targets (void *cls,
999 * @param key key value stored under 1007 * @param key key value stored under
1000 * @param value a 'struct Target' that may or may not be useful; not that 1008 * @param value a 'struct Target' that may or may not be useful; not that
1001 * the distance in 'target' does not include the first hop yet 1009 * the distance in 'target' does not include the first hop yet
1002 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 1010 * @return #GNUNET_YES to continue iteration, #GNUNET_NO to stop
1003 */ 1011 */
1004static int 1012static int
1005check_possible_route (void *cls, 1013check_possible_route (void *cls,
@@ -1045,8 +1053,8 @@ check_possible_route (void *cls,
1045 * 1053 *
1046 * @param cls NULL 1054 * @param cls NULL
1047 * @param key peer identity of the given direct neighbor 1055 * @param key peer identity of the given direct neighbor
1048 * @param value a 'struct DirectNeighbor' to check for additional routes 1056 * @param value a `struct DirectNeighbor` to check for additional routes
1049 * @return GNUNET_YES to continue iteration 1057 * @return #GNUNET_YES to continue iteration
1050 */ 1058 */
1051static int 1059static int
1052refresh_routes (void *cls, 1060refresh_routes (void *cls,
@@ -1067,6 +1075,36 @@ refresh_routes (void *cls,
1067 1075
1068 1076
1069/** 1077/**
1078 * Task to run #refresh_routes() on all direct neighbours.
1079 *
1080 * @param cls NULL
1081 * @param tc unused
1082 */
1083static void
1084refresh_routes_task (void *cls,
1085 const struct GNUNET_SCHEDULER_TaskContext *tc)
1086{
1087 rr_task = GNUNET_SCHEDULER_NO_TASK;
1088 GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors,
1089 &refresh_routes,
1090 NULL);
1091}
1092
1093
1094/**
1095 * Asynchronously run #refresh_routes() at the next opportunity
1096 * on all direct neighbours.
1097 */
1098static void
1099schedule_refresh_routes ()
1100{
1101 if (GNUNET_SCHEDULER_NO_TASK == rr_task)
1102 rr_task = GNUNET_SCHEDULER_add_now (&refresh_routes_task,
1103 NULL);
1104}
1105
1106
1107/**
1070 * Get distance information from 'atsi'. 1108 * Get distance information from 'atsi'.
1071 * 1109 *
1072 * @param atsi performance data 1110 * @param atsi performance data
@@ -1254,9 +1292,7 @@ handle_ats_update (void *cls,
1254 "# peers connected (1-hop)", 1292 "# peers connected (1-hop)",
1255 -1, GNUNET_NO); 1293 -1, GNUNET_NO);
1256 handle_direct_disconnect (neighbor); 1294 handle_direct_disconnect (neighbor);
1257 GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors, 1295 schedule_refresh_routes ();
1258 &refresh_routes,
1259 NULL);
1260 return; 1296 return;
1261 } 1297 }
1262 neighbor->distance = distance; 1298 neighbor->distance = distance;
@@ -1498,9 +1534,7 @@ handle_set_union_result (void *cls,
1498 if (GNUNET_YES == neighbor->target_removed) 1534 if (GNUNET_YES == neighbor->target_removed)
1499 { 1535 {
1500 /* check if we got an alternative for the removed routes */ 1536 /* check if we got an alternative for the removed routes */
1501 GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors, 1537 schedule_refresh_routes ();
1502 &refresh_routes,
1503 NULL);
1504 } 1538 }
1505 /* add targets that appeared (and check for improved routes) */ 1539 /* add targets that appeared (and check for improved routes) */
1506 GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table_consensus, 1540 GNUNET_CONTAINER_multipeermap_iterate (neighbor->neighbor_table_consensus,
@@ -1825,10 +1859,7 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1825 1859
1826 if (GNUNET_YES == in_shutdown) 1860 if (GNUNET_YES == in_shutdown)
1827 return; 1861 return;
1828 1862 schedule_refresh_routes ();
1829 GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors,
1830 &refresh_routes,
1831 NULL);
1832} 1863}
1833 1864
1834 1865
@@ -1838,11 +1869,12 @@ handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
1838 * @param cls NULL 1869 * @param cls NULL
1839 * @param key key value stored under 1870 * @param key key value stored under
1840 * @param value the route to be freed 1871 * @param value the route to be freed
1841 * 1872 * @return #GNUNET_YES to continue iteration, #GNUNET_NO to stop
1842 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1843 */ 1873 */
1844static int 1874static int
1845free_route (void *cls, const struct GNUNET_PeerIdentity * key, void *value) 1875free_route (void *cls,
1876 const struct GNUNET_PeerIdentity *key,
1877 void *value)
1846{ 1878{
1847 struct Route *route = value; 1879 struct Route *route = value;
1848 1880
@@ -1862,11 +1894,12 @@ free_route (void *cls, const struct GNUNET_PeerIdentity * key, void *value)
1862 * @param cls NULL 1894 * @param cls NULL
1863 * @param key key value stored under 1895 * @param key key value stored under
1864 * @param value the direct neighbor to be freed 1896 * @param value the direct neighbor to be freed
1865 * 1897 * @return #GNUNET_YES to continue iteration, #GNUNET_NO to stop
1866 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1867 */ 1898 */
1868static int 1899static int
1869free_direct_neighbors (void *cls, const struct GNUNET_PeerIdentity * key, void *value) 1900free_direct_neighbors (void *cls,
1901 const struct GNUNET_PeerIdentity *key,
1902 void *value)
1870{ 1903{
1871 struct DirectNeighbor *neighbor = value; 1904 struct DirectNeighbor *neighbor = value;
1872 1905
@@ -1883,11 +1916,12 @@ free_direct_neighbors (void *cls, const struct GNUNET_PeerIdentity * key, void *
1883 * @param tc unused 1916 * @param tc unused
1884 */ 1917 */
1885static void 1918static void
1886shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1919shutdown_task (void *cls,
1920 const struct GNUNET_SCHEDULER_TaskContext *tc)
1887{ 1921{
1888 unsigned int i; 1922 unsigned int i;
1889 in_shutdown = GNUNET_YES;
1890 1923
1924 in_shutdown = GNUNET_YES;
1891 GNUNET_assert (NULL != core_api); 1925 GNUNET_assert (NULL != core_api);
1892 GNUNET_CORE_disconnect (core_api); 1926 GNUNET_CORE_disconnect (core_api);
1893 core_api = NULL; 1927 core_api = NULL;
@@ -1909,16 +1943,21 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1909 consensi[i].array_length, 1943 consensi[i].array_length,
1910 0); 1944 0);
1911 } 1945 }
1946 if (GNUNET_SCHEDULER_NO_TASK != rr_task)
1947 {
1948 GNUNET_SCHEDULER_cancel (rr_task);
1949 rr_task = GNUNET_SCHEDULER_NO_TASK;
1950 }
1912} 1951}
1913 1952
1914 1953
1915/** 1954/**
1916 * Notify newly connected client about an existing route. 1955 * Notify newly connected client about an existing route.
1917 * 1956 *
1918 * @param cls the 'struct GNUNET_SERVER_Client' 1957 * @param cls the `struct GNUNET_SERVER_Client *`
1919 * @param key peer identity 1958 * @param key peer identity
1920 * @param value the XXX. 1959 * @param value the `struct Route *`
1921 * @return GNUNET_OK (continue to iterate) 1960 * @return #GNUNET_OK (continue to iterate)
1922 */ 1961 */
1923static int 1962static int
1924add_route (void *cls, 1963add_route (void *cls,