diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-28 09:36:25 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-28 09:36:25 +0000 |
commit | e52bc40e93e7fa51bd0ffef1e1ac5b502050dd14 (patch) | |
tree | 42618c7777b40bffe3e1bdf0ff2fcf2ab9c97b46 /src/testbed/testbed_api_topology.c | |
parent | 0010ac4bcb273072fcf7ac8f5507e5c21d238dd8 (diff) | |
download | gnunet-e52bc40e93e7fa51bd0ffef1e1ac5b502050dd14.tar.gz gnunet-e52bc40e93e7fa51bd0ffef1e1ac5b502050dd14.zip |
implemented generic topology overlay connections
Diffstat (limited to 'src/testbed/testbed_api_topology.c')
-rw-r--r-- | src/testbed/testbed_api_topology.c | 99 |
1 files changed, 85 insertions, 14 deletions
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c index 45209fb65..04fea74b3 100644 --- a/src/testbed/testbed_api_topology.c +++ b/src/testbed/testbed_api_topology.c | |||
@@ -36,14 +36,14 @@ | |||
36 | struct OverlayLink | 36 | struct OverlayLink |
37 | { | 37 | { |
38 | /** | 38 | /** |
39 | * Peer A | 39 | * position of peer A's handle in peers array |
40 | */ | 40 | */ |
41 | struct GNUNET_TESTBED_Peer *A; | 41 | uint32_t A; |
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Peer B | 44 | * position of peer B's handle in peers array |
45 | */ | 45 | */ |
46 | struct GNUNET_TESTBED_Peer *B; | 46 | uint32_t B; |
47 | 47 | ||
48 | }; | 48 | }; |
49 | 49 | ||
@@ -54,34 +54,102 @@ struct OverlayLink | |||
54 | struct TopologyContext | 54 | struct TopologyContext |
55 | { | 55 | { |
56 | /** | 56 | /** |
57 | * An array of links | 57 | * The array of peers |
58 | */ | ||
59 | struct GNUNET_TESTBED_Peer **peers; | ||
60 | |||
61 | /** | ||
62 | * An array of links; this array is of size link_array_size | ||
58 | */ | 63 | */ |
59 | struct OverlayLink *link_array; | 64 | struct OverlayLink *link_array; |
65 | |||
66 | /** | ||
67 | * An array of operations resulting from the links we try to establish; the | ||
68 | * number of operations in this array is equal to link_array_size (1 link = 1 | ||
69 | * operation) | ||
70 | */ | ||
71 | struct GNUNET_TESTBED_Operation **link_ops; | ||
72 | |||
73 | /** | ||
74 | * The size of the link array | ||
75 | */ | ||
76 | unsigned int link_array_size; | ||
60 | 77 | ||
61 | }; | 78 | }; |
62 | 79 | ||
63 | 80 | ||
64 | /** | 81 | /** |
82 | * Callback to be called when an overlay_link operation complete | ||
83 | * | ||
84 | * @param cls element of the link_op array which points to the corresponding operation | ||
85 | * @param op the operation that has been finished | ||
86 | * @param emsg error message in case the operation has failed; will be NULL if | ||
87 | * operation has executed successfully. | ||
88 | */ | ||
89 | static void | ||
90 | overlay_link_completed (void *cls, | ||
91 | struct GNUNET_TESTBED_Operation *op, | ||
92 | const char *emsg) | ||
93 | { | ||
94 | struct GNUNET_TESTBED_Operation **link_op = cls; | ||
95 | |||
96 | GNUNET_assert (*link_op == op); | ||
97 | GNUNET_TESTBED_operation_done (op); | ||
98 | *link_op = NULL; | ||
99 | if (NULL != emsg) | ||
100 | { | ||
101 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
102 | "Error while establishing a link: %s\n", emsg); | ||
103 | return; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | |||
108 | |||
109 | /** | ||
65 | * Function called when a overlay connect operation is ready | 110 | * Function called when a overlay connect operation is ready |
66 | * | 111 | * |
67 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 112 | * @param cls the Topology context |
68 | */ | 113 | */ |
69 | static void | 114 | static void |
70 | opstart_overlay_configure_topology (void *cls) | 115 | opstart_overlay_configure_topology (void *cls) |
71 | { | 116 | { |
72 | GNUNET_break (0); | 117 | struct TopologyContext *tc = cls; |
118 | unsigned int p; | ||
119 | |||
120 | tc->link_ops = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operations *) | ||
121 | * tc->link_array_size); | ||
122 | for (p = 0; p < tc->link_array_size; p++) | ||
123 | { | ||
124 | tc->link_ops[p] = | ||
125 | GNUNET_TESTBED_overlay_connect (NULL, &overlay_link_completed, | ||
126 | &tc->link_ops[p], | ||
127 | tc->peers[tc->link_array[p].A], | ||
128 | tc->peers[tc->link_array[p].B]); | ||
129 | } | ||
73 | } | 130 | } |
74 | 131 | ||
75 | 132 | ||
76 | /** | 133 | /** |
77 | * Callback which will be called when overlay connect operation is released | 134 | * Callback which will be called when overlay connect operation is released |
78 | * | 135 | * |
79 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 136 | * @param cls the Topology context |
80 | */ | 137 | */ |
81 | static void | 138 | static void |
82 | oprelease_overlay_configure_topology (void *cls) | 139 | oprelease_overlay_configure_topology (void *cls) |
83 | { | 140 | { |
84 | GNUNET_break (0); | 141 | struct TopologyContext *tc = cls; |
142 | unsigned int p; | ||
143 | |||
144 | if (NULL != tc->link_ops) | ||
145 | { | ||
146 | for (p = 0; p < tc->link_array_size; p++) | ||
147 | if (NULL != tc->link_ops[p]) | ||
148 | GNUNET_TESTBED_operation_cancel (tc->link_ops[p]); | ||
149 | GNUNET_free (tc->link_ops); | ||
150 | } | ||
151 | GNUNET_free_non_null (tc->link_array); | ||
152 | GNUNET_free (tc); | ||
85 | } | 153 | } |
86 | 154 | ||
87 | 155 | ||
@@ -154,7 +222,7 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
154 | enum GNUNET_TESTBED_TopologyOption | 222 | enum GNUNET_TESTBED_TopologyOption |
155 | topo, va_list va) | 223 | topo, va_list va) |
156 | { | 224 | { |
157 | struct OverlayLink *link_array; | 225 | struct TopologyContext *tc; |
158 | struct GNUNET_TESTBED_Operation *op; | 226 | struct GNUNET_TESTBED_Operation *op; |
159 | struct GNUNET_TESTBED_Controller *c; | 227 | struct GNUNET_TESTBED_Controller *c; |
160 | unsigned int p; | 228 | unsigned int p; |
@@ -162,21 +230,24 @@ GNUNET_TESTBED_overlay_configure_topology_va (void *op_cls, | |||
162 | if (num_peers < 2) | 230 | if (num_peers < 2) |
163 | return NULL; | 231 | return NULL; |
164 | c = peers[0]->controller; | 232 | c = peers[0]->controller; |
233 | tc = GNUNET_malloc (sizeof (struct TopologyContext)); | ||
165 | switch (topo) | 234 | switch (topo) |
166 | { | 235 | { |
167 | case GNUNET_TESTBED_TOPOLOGY_LINE: | 236 | case GNUNET_TESTBED_TOPOLOGY_LINE: |
168 | link_array = GNUNET_malloc (sizeof (struct OverlayLink) * (num_peers - 1)); | 237 | tc->link_array_size = num_peers - 1; |
238 | tc->link_array = GNUNET_malloc (sizeof (struct OverlayLink) * | ||
239 | tc->link_array_size); | ||
169 | for (p=1; p < num_peers; p++) | 240 | for (p=1; p < num_peers; p++) |
170 | { | 241 | { |
171 | link_array[p-1].A = peers[p-1]; | 242 | tc->link_array[p-1].A = p-1; |
172 | link_array[p-1].B = peers[p]; | 243 | tc->link_array[p-1].B = p; |
173 | } | 244 | } |
174 | break; | 245 | break; |
175 | default: | 246 | default: |
176 | GNUNET_break (0); | 247 | GNUNET_break (0); |
177 | return NULL; | 248 | return NULL; |
178 | } | 249 | } |
179 | op = GNUNET_TESTBED_operation_create_ (link_array, | 250 | op = GNUNET_TESTBED_operation_create_ (tc, |
180 | &opstart_overlay_configure_topology, | 251 | &opstart_overlay_configure_topology, |
181 | &oprelease_overlay_configure_topology); | 252 | &oprelease_overlay_configure_topology); |
182 | GNUNET_TESTBED_operation_queue_insert_ | 253 | GNUNET_TESTBED_operation_queue_insert_ |