diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-05 14:24:51 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-02-05 14:24:51 +0000 |
commit | 28f8e239844323e564d63fc8a792cbcbed41ec68 (patch) | |
tree | bce0c4fb0a962e990f410db68f503aa87da8bbb1 /src/testbed/testbed_api_topology.c | |
parent | 01cc59a2f217ca02635beaf533decb1683339dd9 (diff) | |
download | gnunet-28f8e239844323e564d63fc8a792cbcbed41ec68.tar.gz gnunet-28f8e239844323e564d63fc8a792cbcbed41ec68.zip |
add completion callback for overlay topology configure functions
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r-- | src/testbed/testbed_api_topology.c | 160 |
1 files changed, 139 insertions, 21 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index d9666e4df..9618f98dd 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -38,6 +38,12 @@ | |||
38 | 38 | ||
39 | 39 | ||
40 | /** | 40 | /** |
41 | * Default number of retires | ||
42 | */ | ||
43 | #define DEFAULT_RETRY_CNT 3 | ||
44 | |||
45 | |||
46 | /** | ||
41 | * Context information for topology operations | 47 | * Context information for topology operations |
42 | */ | 48 | */ |
43 | struct TopologyContext; | 49 | struct TopologyContext; |
@@ -72,6 +78,25 @@ struct OverlayLink | |||
72 | }; | 78 | }; |
73 | 79 | ||
74 | 80 | ||
81 | struct RetryListEntry | ||
82 | { | ||
83 | /** | ||
84 | * the next pointer for the DLL | ||
85 | */ | ||
86 | struct RetryListEntry *next; | ||
87 | |||
88 | /** | ||
89 | * the prev pointer for the DLL | ||
90 | */ | ||
91 | struct RetryListEntry *prev; | ||
92 | |||
93 | /** | ||
94 | * The link to be retired | ||
95 | */ | ||
96 | struct OverlayLink *link; | ||
97 | }; | ||
98 | |||
99 | |||
75 | /** | 100 | /** |
76 | * Context information for topology operations | 101 | * Context information for topology operations |
77 | */ | 102 | */ |
@@ -93,6 +118,26 @@ struct TopologyContext | |||
93 | void *op_cls; | 118 | void *op_cls; |
94 | 119 | ||
95 | /** | 120 | /** |
121 | * topology generation completion callback | ||
122 | */ | ||
123 | GNUNET_TESTBED_TopologyCompletionCallback comp_cb; | ||
124 | |||
125 | /** | ||
126 | * The closure for the above callback | ||
127 | */ | ||
128 | void *comp_cb_cls; | ||
129 | |||
130 | /** | ||
131 | * DLL head for retry list | ||
132 | */ | ||
133 | struct RetryListEntry *rl_head; | ||
134 | |||
135 | /** | ||
136 | * DLL tail for retry list | ||
137 | */ | ||
138 | struct RetryListEntry *rl_tail; | ||
139 | |||
140 | /** | ||
96 | * The number of peers | 141 | * The number of peers |
97 | */ | 142 | */ |
98 | unsigned int num_peers; | 143 | unsigned int num_peers; |
@@ -103,10 +148,29 @@ struct TopologyContext | |||
103 | unsigned int link_array_size; | 148 | unsigned int link_array_size; |
104 | 149 | ||
105 | /** | 150 | /** |
106 | * should the automatic retry be disabled | 151 | * How many retries to do before we give up |
107 | */ | 152 | */ |
108 | int disable_retry; | 153 | unsigned int retry_cnt; |
109 | 154 | ||
155 | /** | ||
156 | * Number of links to try | ||
157 | */ | ||
158 | unsigned int nlinks; | ||
159 | |||
160 | /** | ||
161 | * How many links have been completed | ||
162 | */ | ||
163 | unsigned int ncompleted; | ||
164 | |||
165 | /** | ||
166 | * Total successfully established overlay connections | ||
167 | */ | ||
168 | unsigned int nsuccess; | ||
169 | |||
170 | /** | ||
171 | * Total failed overlay connections | ||
172 | */ | ||
173 | unsigned int nfailures; | ||
110 | }; | 174 | }; |
111 | 175 | ||
112 | 176 | ||
@@ -198,21 +262,51 @@ overlay_link_completed (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
198 | { | 262 | { |
199 | struct OverlayLink *link = cls; | 263 | struct OverlayLink *link = cls; |
200 | struct TopologyContext *tc; | 264 | struct TopologyContext *tc; |
265 | struct RetryListEntry *retry_entry; | ||
201 | 266 | ||
202 | GNUNET_assert (op == link->op); | 267 | GNUNET_assert (op == link->op); |
203 | GNUNET_TESTBED_operation_done (op); | 268 | GNUNET_TESTBED_operation_done (op); |
204 | link->op = NULL; | 269 | link->op = NULL; |
205 | tc = link->tc; | 270 | tc = link->tc; |
206 | if ((NULL != emsg) && (GNUNET_NO == tc->disable_retry)) | 271 | if (NULL != emsg) |
207 | { | 272 | { |
208 | LOG (GNUNET_ERROR_TYPE_WARNING, | 273 | tc->nfailures++; |
209 | "Error while establishing a link: %s -- Retrying\n", emsg); | 274 | if (0 != tc->retry_cnt) |
210 | link->op = | 275 | { |
211 | GNUNET_TESTBED_overlay_connect (tc->op_cls, &overlay_link_completed, | 276 | LOG (GNUNET_ERROR_TYPE_WARNING, |
212 | link, tc->peers[link->A], | 277 | "Error while establishing a link: %s -- Retrying\n", emsg); |
213 | tc->peers[link->B]); | 278 | retry_entry = GNUNET_malloc (sizeof (struct RetryListEntry)); |
279 | retry_entry->link = link; | ||
280 | GNUNET_CONTAINER_DLL_insert_tail (tc->rl_head, tc->rl_tail, retry_entry); | ||
281 | } | ||
282 | } | ||
283 | else | ||
284 | tc->nsuccess++; | ||
285 | tc->ncompleted++; | ||
286 | if (tc->ncompleted < tc->nlinks) | ||
287 | return; | ||
288 | if ((0 != tc->retry_cnt) && (NULL != tc->rl_head)) | ||
289 | { | ||
290 | tc->retry_cnt--; | ||
291 | tc->ncompleted = 0; | ||
292 | tc->nlinks = 0; | ||
293 | while (NULL != (retry_entry = tc->rl_head)) | ||
294 | { | ||
295 | link = retry_entry->link; | ||
296 | link->op = | ||
297 | GNUNET_TESTBED_overlay_connect (tc->op_cls, &overlay_link_completed, | ||
298 | link, tc->peers[link->A], | ||
299 | tc->peers[link->B]); | ||
300 | tc->nlinks++; | ||
301 | GNUNET_CONTAINER_DLL_remove (tc->rl_head, tc->rl_tail, retry_entry); | ||
302 | GNUNET_free (retry_entry); | ||
303 | } | ||
214 | return; | 304 | return; |
215 | } | 305 | } |
306 | if (NULL != tc->comp_cb) | ||
307 | { | ||
308 | tc->comp_cb (tc->comp_cb_cls, tc->nsuccess, tc->nfailures); | ||
309 | } | ||
216 | } | 310 | } |
217 | 311 | ||
218 | 312 | ||
@@ -228,6 +322,7 @@ opstart_overlay_configure_topology (void *cls) | |||
228 | struct TopologyContext *tc = cls; | 322 | struct TopologyContext *tc = cls; |
229 | unsigned int p; | 323 | unsigned int p; |
230 | 324 | ||
325 | tc->nlinks = tc->link_array_size; | ||
231 | for (p = 0; p < tc->link_array_size; p++) | 326 | for (p = 0; p < tc->link_array_size; p++) |
232 | { | 327 | { |
233 | tc->link_array[p].op = | 328 | tc->link_array[p].op = |
@@ -248,8 +343,14 @@ static void | |||
248 | oprelease_overlay_configure_topology (void *cls) | 343 | oprelease_overlay_configure_topology (void *cls) |
249 | { | 344 | { |
250 | struct TopologyContext *tc = cls; | 345 | struct TopologyContext *tc = cls; |
346 | struct RetryListEntry *retry_entry; | ||
251 | unsigned int p; | 347 | unsigned int p; |
252 | 348 | ||
349 | while (NULL != (retry_entry = tc->rl_head)) | ||
350 | { | ||
351 | GNUNET_CONTAINER_DLL_remove (tc->rl_head, tc->rl_tail, retry_entry); | ||
352 | GNUNET_free (retry_entry); | ||
353 | } | ||
253 | if (NULL != tc->link_array) | 354 | if (NULL != tc->link_array) |
254 | { | 355 | { |
255 | for (p = 0; p < tc->link_array_size; p++) | 356 | for (p = 0; p < tc->link_array_size; p++) |
@@ -741,11 +842,15 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, | |||
741 | * This function then connects the given peers in the P2P overlay | 842 | * This function then connects the given peers in the P2P overlay |
742 | * using the given topology. | 843 | * using the given topology. |
743 | * | 844 | * |
744 | * @param op_cls closure argument to give with the operation event | 845 | * @param op_cls closure argument to give with the peer connect operation events |
846 | * generated through this function | ||
745 | * @param num_peers number of peers in 'peers' | 847 | * @param num_peers number of peers in 'peers' |
746 | * @param peers array of 'num_peers' with the peers to configure | 848 | * @param peers array of 'num_peers' with the peers to configure |
747 | * @param max_connections the maximums number of overlay connections that will | 849 | * @param max_connections the maximums number of overlay connections that will |
748 | * be made to achieve the given topology | 850 | * be made to achieve the given topology |
851 | * @param comp_cb the completion callback to call when the topology generation | ||
852 | * is completed | ||
853 | * @param comp_cb_cls closure for the above completion callback | ||
749 | * @param topo desired underlay topology to use | 854 | * @param topo desired underlay topology to use |
750 | * @param va topology-specific options | 855 | * @param va topology-specific options |
751 | * @return handle to the operation, NULL if connecting these | 856 | * @return handle to the operation, NULL if connecting these |
@@ -755,11 +860,13 @@ GNUNET_TESTBED_underlay_configure_topology (void *op_cls, | |||
755 | struct GNUNET_TESTBED_Operation * | 860 | struct GNUNET_TESTBED_Operation * |
756 | GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | 861 | GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, |
757 | unsigned int num_peers, | 862 | unsigned int num_peers, |
758 | struct GNUNET_TESTBED_Peer | 863 | struct GNUNET_TESTBED_Peer **peers, |
759 | **peers, | ||
760 | unsigned int *max_connections, | 864 | unsigned int *max_connections, |
761 | enum GNUNET_TESTBED_TopologyOption | 865 | GNUNET_TESTBED_TopologyCompletionCallback |
762 | topo, va_list va) | 866 | comp_cb, |
867 | void *comp_cb_cls, | ||
868 | enum GNUNET_TESTBED_TopologyOption topo, | ||
869 | va_list va) | ||
763 | { | 870 | { |
764 | struct TopologyContext *tc; | 871 | struct TopologyContext *tc; |
765 | struct GNUNET_TESTBED_Operation *op; | 872 | struct GNUNET_TESTBED_Operation *op; |
@@ -774,6 +881,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
774 | tc->peers = peers; | 881 | tc->peers = peers; |
775 | tc->num_peers = num_peers; | 882 | tc->num_peers = num_peers; |
776 | tc->op_cls = op_cls; | 883 | tc->op_cls = op_cls; |
884 | tc->retry_cnt = DEFAULT_RETRY_CNT; | ||
777 | switch (topo) | 885 | switch (topo) |
778 | { | 886 | { |
779 | case GNUNET_TESTBED_TOPOLOGY_LINE: | 887 | case GNUNET_TESTBED_TOPOLOGY_LINE: |
@@ -847,8 +955,8 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
847 | 955 | ||
848 | switch (secondary_option) | 956 | switch (secondary_option) |
849 | { | 957 | { |
850 | case GNUNET_TESTBED_TOPOLOGY_DISABLE_AUTO_RETRY: | 958 | case GNUNET_TESTBED_TOPOLOGY_RETRY_CNT: |
851 | tc->disable_retry = GNUNET_YES; | 959 | tc->retry_cnt = va_arg (va, unsigned int); |
852 | break; | 960 | break; |
853 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: | 961 | case GNUNET_TESTBED_TOPOLOGY_OPTION_END: |
854 | break; | 962 | break; |
@@ -880,11 +988,15 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
880 | * This function then connects the given peers in the P2P overlay | 988 | * This function then connects the given peers in the P2P overlay |
881 | * using the given topology. | 989 | * using the given topology. |
882 | * | 990 | * |
883 | * @param op_cls closure argument to give with the operation event | 991 | * @param op_cls closure argument to give with the peer connect operation events |
992 | * generated through this function | ||
884 | * @param num_peers number of peers in 'peers' | 993 | * @param num_peers number of peers in 'peers' |
885 | * @param peers array of 'num_peers' with the peers to configure | 994 | * @param peers array of 'num_peers' with the peers to configure |
886 | * @param max_connections the maximums number of overlay connections that will | 995 | * @param max_connections the maximums number of overlay connections that will |
887 | * be made to achieve the given topology | 996 | * be made to achieve the given topology |
997 | * @param comp_cb the completion callback to call when the topology generation | ||
998 | * is completed | ||
999 | * @param comp_cb_cls closure for the above completion callback | ||
888 | * @param topo desired underlay topology to use | 1000 | * @param topo desired underlay topology to use |
889 | * @param ... topology-specific options | 1001 | * @param ... topology-specific options |
890 | * @return handle to the operation, NULL if connecting these | 1002 | * @return handle to the operation, NULL if connecting these |
@@ -892,11 +1004,15 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
892 | * not running or underlay disallows) or if num_peers is less than 2 | 1004 | * not running or underlay disallows) or if num_peers is less than 2 |
893 | */ | 1005 | */ |
894 | struct GNUNET_TESTBED_Operation * | 1006 | struct GNUNET_TESTBED_Operation * |
895 | GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers, | 1007 | GNUNET_TESTBED_overlay_configure_topology (void *op_cls, |
1008 | unsigned int num_peers, | ||
896 | struct GNUNET_TESTBED_Peer **peers, | 1009 | struct GNUNET_TESTBED_Peer **peers, |
897 | unsigned int *max_connections, | 1010 | unsigned int *max_connections, |
898 | enum GNUNET_TESTBED_TopologyOption | 1011 | GNUNET_TESTBED_TopologyCompletionCallback |
899 | topo, ...) | 1012 | comp_cb, |
1013 | void *comp_cb_cls, | ||
1014 | enum GNUNET_TESTBED_TopologyOption topo, | ||
1015 | ...) | ||
900 | { | 1016 | { |
901 | struct GNUNET_TESTBED_Operation *op; | 1017 | struct GNUNET_TESTBED_Operation *op; |
902 | va_list vargs; | 1018 | va_list vargs; |
@@ -904,7 +1020,9 @@ GNUNET_TESTBED_overlay_configure_topology (void *op_cls, unsigned int num_peers, | |||
904 | GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); | 1020 | GNUNET_assert (topo < GNUNET_TESTBED_TOPOLOGY_OPTION_END); |
905 | va_start (vargs, topo); | 1021 | va_start (vargs, topo); |
906 | op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers, | 1022 | op = GNUNET_TESTBED_overlay_configure_topology_va (op_cls, num_peers, peers, |
907 | max_connections, topo, | 1023 | max_connections, |
1024 | comp_cb, comp_cb_cls, | ||
1025 | topo, | ||
908 | vargs); | 1026 | vargs); |
909 | va_end (vargs); | 1027 | va_end (vargs); |
910 | return op; | 1028 | return op; |