aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-25 20:33:57 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-25 20:33:57 +0000
commit93cf4031938ca0f3d13ce491ba9be2c77763ffae (patch)
treef19ff21d13772eedc42d4f86d1b844891c3e3055 /src/testbed
parent98764c99d4e56c8520ac5d1f3a056649fa2137fc (diff)
downloadgnunet-93cf4031938ca0f3d13ce491ba9be2c77763ffae.tar.gz
gnunet-93cf4031938ca0f3d13ce491ba9be2c77763ffae.zip
remove global variable for barriers, move into controller
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/testbed_api.c113
-rw-r--r--src/testbed/testbed_api.h76
-rw-r--r--src/testbed/testbed_api_barriers.c181
-rw-r--r--src/testbed/testbed_api_barriers.h20
-rw-r--r--src/testbed/testbed_api_hosts.c4
-rw-r--r--src/testbed/testbed_api_operations.c2
6 files changed, 194 insertions, 202 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 90b0e06c8..d946b7082 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -36,6 +36,7 @@
36 36
37#include "testbed.h" 37#include "testbed.h"
38#include "testbed_api.h" 38#include "testbed_api.h"
39#include "testbed_api_barriers.h"
39#include "testbed_api_hosts.h" 40#include "testbed_api_hosts.h"
40#include "testbed_api_peers.h" 41#include "testbed_api_peers.h"
41#include "testbed_api_operations.h" 42#include "testbed_api_operations.h"
@@ -1047,6 +1048,118 @@ handle_link_controllers_result (void *cls,
1047 1048
1048 1049
1049/** 1050/**
1051 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
1052 *
1053 * @param cls the controller handle to determine the connection this message
1054 * belongs to
1055 * @param msg the barrier status message
1056 * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
1057 * down signalling an error (message malformed)
1058 */
1059static int
1060check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
1061 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1062{
1063 uint16_t msize;
1064 uint16_t name_len;
1065 int status;
1066 const char *name;
1067 size_t emsg_len;
1068
1069 msize = ntohs (msg->header.size);
1070 name = msg->data;
1071 name_len = ntohs (msg->name_len);
1072
1073 if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
1074 {
1075 GNUNET_break_op (0);
1076 return GNUNET_SYSERR;
1077 }
1078 if ('\0' != name[name_len])
1079 {
1080 GNUNET_break_op (0);
1081 return GNUNET_SYSERR;
1082 }
1083 status = ntohs (msg->status);
1084 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
1085 {
1086 emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
1087 + 1); /* +1!? */
1088 if (0 == emsg_len)
1089 {
1090 GNUNET_break_op (0);
1091 return GNUNET_SYSERR;
1092 }
1093 }
1094 return GNUNET_OK;
1095}
1096
1097
1098/**
1099 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages
1100 *
1101 * @param c the controller handle to determine the connection this message
1102 * belongs to
1103 * @param msg the barrier status message
1104 */
1105static void
1106handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
1107 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
1108{
1109 struct GNUNET_TESTBED_Barrier *barrier;
1110 char *emsg;
1111 const char *name;
1112 struct GNUNET_HashCode key;
1113 size_t emsg_len;
1114 int status;
1115 uint16_t msize;
1116 uint16_t name_len;
1117
1118 emsg = NULL;
1119 barrier = NULL;
1120 msize = ntohs (msg->header.size);
1121 name = msg->data;
1122 name_len = ntohs (msg->name_len);
1123 LOG_DEBUG ("Received BARRIER_STATUS msg\n");
1124 status = ntohs (msg->status);
1125 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
1126 {
1127 status = -1;
1128 emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
1129 + 1);
1130 emsg = GNUNET_malloc (emsg_len + 1);
1131 memcpy (emsg,
1132 msg->data + name_len + 1,
1133 emsg_len);
1134 }
1135 if (NULL == c->barrier_map)
1136 {
1137 GNUNET_break_op (0);
1138 goto cleanup;
1139 }
1140 GNUNET_CRYPTO_hash (name, name_len, &key);
1141 barrier = GNUNET_CONTAINER_multihashmap_get (c->barrier_map, &key);
1142 if (NULL == barrier)
1143 {
1144 GNUNET_break_op (0);
1145 goto cleanup;
1146 }
1147 GNUNET_assert (NULL != barrier->cb);
1148 if ((GNUNET_YES == barrier->echo) &&
1149 (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
1150 GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
1151 barrier->cb (barrier->cls, name, barrier, status, emsg);
1152 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
1153 return; /* just initialised; skip cleanup */
1154
1155 cleanup:
1156 GNUNET_free_non_null (emsg);
1157 if (NULL != barrier)
1158 GNUNET_TESTBED_barrier_remove_ (barrier);
1159}
1160
1161
1162/**
1050 * Handler for messages from controller (testbed service) 1163 * Handler for messages from controller (testbed service)
1051 * 1164 *
1052 * @param cls the controller handler 1165 * @param cls the controller handler
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index cf39e3415..7a8e6539a 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -183,7 +183,8 @@ struct OperationContext
183 * 183 *
184 * @param cls closure 184 * @param cls closure
185 */ 185 */
186typedef void (*TESTBED_opcq_empty_cb) (void *cls); 186typedef void
187(*TESTBED_opcq_empty_cb) (void *cls);
187 188
188 189
189/** 190/**
@@ -274,6 +275,12 @@ struct GNUNET_TESTBED_Controller
274 struct OperationQueue *opq_parallel_topology_config_operations; 275 struct OperationQueue *opq_parallel_topology_config_operations;
275 276
276 /** 277 /**
278 * handle for hashtable of barrier handles, values are
279 * of type `struct GNUNET_TESTBED_Barrier`.
280 */
281 struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
282
283 /**
277 * The controller event mask 284 * The controller event mask
278 */ 285 */
279 uint64_t event_mask; 286 uint64_t event_mask;
@@ -292,6 +299,44 @@ struct GNUNET_TESTBED_Controller
292 299
293 300
294/** 301/**
302 * Handle for barrier
303 */
304struct GNUNET_TESTBED_Barrier
305{
306 /**
307 * hashcode identifying this barrier in the hashmap
308 */
309 struct GNUNET_HashCode key;
310
311 /**
312 * The controller handle given while initiliasing this barrier
313 */
314 struct GNUNET_TESTBED_Controller *c;
315
316 /**
317 * The name of the barrier
318 */
319 char *name;
320
321 /**
322 * The continuation callback to call when we have a status update on this
323 */
324 GNUNET_TESTBED_barrier_status_cb cb;
325
326 /**
327 * the closure for the above callback
328 */
329 void *cls;
330
331 /**
332 * Should the barrier crossed status message be echoed back to the controller?
333 */
334 int echo;
335};
336
337
338
339/**
295 * Queues a message in send queue for sending to the service 340 * Queues a message in send queue for sending to the service
296 * 341 *
297 * @param controller the handle to the controller 342 * @param controller the handle to the controller
@@ -460,34 +505,5 @@ GNUNET_TESTBED_get_slave_config_ (void *op_cls,
460 uint32_t slave_host_id); 505 uint32_t slave_host_id);
461 506
462 507
463/**
464 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
465 *
466 * @param cls the controller handle to determine the connection this message
467 * belongs to
468 * @param msg the barrier status message
469 * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
470 * down signalling an error (message malformed)
471 */
472int
473check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
474 const struct GNUNET_TESTBED_BarrierStatusMsg *msg);
475
476
477/**
478 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages. This
479 * function is defined in @file testbed_api_barriers.c
480 *
481 * @param c the controller handle to determine the connection this message
482 * belongs to
483 * @param msg the barrier status message
484 */
485void
486handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
487 const struct GNUNET_TESTBED_BarrierStatusMsg *msg);
488
489
490
491
492#endif 508#endif
493/* end of testbed_api.h */ 509/* end of testbed_api.h */
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c
index 824dbcdba..0163c0ce4 100644
--- a/src/testbed/testbed_api_barriers.c
+++ b/src/testbed/testbed_api_barriers.c
@@ -41,48 +41,6 @@
41#define LOG_DEBUG(...) \ 41#define LOG_DEBUG(...) \
42 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); 42 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__);
43 43
44/**
45 * Handle for barrier
46 */
47struct GNUNET_TESTBED_Barrier
48{
49 /**
50 * hashcode identifying this barrier in the hashmap
51 */
52 struct GNUNET_HashCode key;
53
54 /**
55 * The controller handle given while initiliasing this barrier
56 */
57 struct GNUNET_TESTBED_Controller *c;
58
59 /**
60 * The name of the barrier
61 */
62 char *name;
63
64 /**
65 * The continuation callback to call when we have a status update on this
66 */
67 GNUNET_TESTBED_barrier_status_cb cb;
68
69 /**
70 * the closure for the above callback
71 */
72 void *cls;
73
74 /**
75 * Should the barrier crossed status message be echoed back to the controller?
76 */
77 int echo;
78};
79
80
81/**
82 * handle for hashtable of barrier handles
83 */
84static struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
85
86 44
87/** 45/**
88 * Remove a barrier and it was the last one in the barrier hash map, destroy the 46 * Remove a barrier and it was the last one in the barrier hash map, destroy the
@@ -90,133 +48,23 @@ static struct GNUNET_CONTAINER_MultiHashMap *barrier_map;
90 * 48 *
91 * @param barrier the barrier to remove 49 * @param barrier the barrier to remove
92 */ 50 */
93static void 51void
94barrier_remove (struct GNUNET_TESTBED_Barrier *barrier) 52GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier)
95{ 53{
96 GNUNET_assert (NULL != barrier_map); /* No barriers present */ 54 struct GNUNET_TESTBED_Controller *c = barrier->c;
55
56 GNUNET_assert (NULL != c->barrier_map); /* No barriers present */
97 GNUNET_assert (GNUNET_OK == 57 GNUNET_assert (GNUNET_OK ==
98 GNUNET_CONTAINER_multihashmap_remove (barrier_map, 58 GNUNET_CONTAINER_multihashmap_remove (c->barrier_map,
99 &barrier->key, 59 &barrier->key,
100 barrier)); 60 barrier));
101 GNUNET_free (barrier->name); 61 GNUNET_free (barrier->name);
102 GNUNET_free (barrier); 62 GNUNET_free (barrier);
103 if (0 == GNUNET_CONTAINER_multihashmap_size (barrier_map)) 63 if (0 == GNUNET_CONTAINER_multihashmap_size (c->barrier_map))
104 { 64 {
105 GNUNET_CONTAINER_multihashmap_destroy (barrier_map); 65 GNUNET_CONTAINER_multihashmap_destroy (c->barrier_map);
106 barrier_map = NULL; 66 c->barrier_map = NULL;
107 }
108}
109
110
111/**
112 * Validate #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS message.
113 *
114 * @param cls the controller handle to determine the connection this message
115 * belongs to
116 * @param msg the barrier status message
117 * @return #GNUNET_OK if the message is valid; #GNUNET_SYSERR to tear it
118 * down signalling an error (message malformed)
119 */
120int
121check_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
122 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
123{
124 uint16_t msize;
125 uint16_t name_len;
126 int status;
127 const char *name;
128 size_t emsg_len;
129
130 msize = ntohs (msg->header.size);
131 name = msg->data;
132 name_len = ntohs (msg->name_len);
133
134 if (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len + 1 > msize)
135 {
136 GNUNET_break_op (0);
137 return GNUNET_SYSERR;
138 }
139 if ('\0' != name[name_len])
140 {
141 GNUNET_break_op (0);
142 return GNUNET_SYSERR;
143 }
144 status = ntohs (msg->status);
145 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
146 {
147 emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
148 + 1); /* +1!? */
149 if (0 == emsg_len)
150 {
151 GNUNET_break_op (0);
152 return GNUNET_SYSERR;
153 }
154 }
155 return GNUNET_OK;
156}
157
158
159/**
160 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages
161 *
162 * @param c the controller handle to determine the connection this message
163 * belongs to
164 * @param msg the barrier status message
165 */
166void
167handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c,
168 const struct GNUNET_TESTBED_BarrierStatusMsg *msg)
169{
170 struct GNUNET_TESTBED_Barrier *barrier;
171 char *emsg;
172 const char *name;
173 struct GNUNET_HashCode key;
174 size_t emsg_len;
175 int status;
176 uint16_t msize;
177 uint16_t name_len;
178
179 emsg = NULL;
180 barrier = NULL;
181 msize = ntohs (msg->header.size);
182 name = msg->data;
183 name_len = ntohs (msg->name_len);
184 LOG_DEBUG ("Received BARRIER_STATUS msg\n");
185 status = ntohs (msg->status);
186 if (GNUNET_TESTBED_BARRIERSTATUS_ERROR == status)
187 {
188 status = -1;
189 emsg_len = msize - (sizeof (struct GNUNET_TESTBED_BarrierStatusMsg) + name_len
190 + 1);
191 emsg = GNUNET_malloc (emsg_len + 1);
192 memcpy (emsg,
193 msg->data + name_len + 1,
194 emsg_len);
195 }
196 if (NULL == barrier_map)
197 {
198 GNUNET_break_op (0);
199 goto cleanup;
200 }
201 GNUNET_CRYPTO_hash (name, name_len, &key);
202 barrier = GNUNET_CONTAINER_multihashmap_get (barrier_map, &key);
203 if (NULL == barrier)
204 {
205 GNUNET_break_op (0);
206 goto cleanup;
207 } 67 }
208 GNUNET_assert (NULL != barrier->cb);
209 if ((GNUNET_YES == barrier->echo) &&
210 (GNUNET_TESTBED_BARRIERSTATUS_CROSSED == status))
211 GNUNET_TESTBED_queue_message_ (c, GNUNET_copy_message (&msg->header));
212 barrier->cb (barrier->cls, name, barrier, status, emsg);
213 if (GNUNET_TESTBED_BARRIERSTATUS_INITIALISED == status)
214 return; /* just initialised; skip cleanup */
215
216 cleanup:
217 GNUNET_free_non_null (emsg);
218 if (NULL != barrier)
219 barrier_remove (barrier);
220} 68}
221 69
222 70
@@ -254,10 +102,11 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
254 name_len = strlen (name); 102 name_len = strlen (name);
255 GNUNET_assert (0 < name_len); 103 GNUNET_assert (0 < name_len);
256 GNUNET_CRYPTO_hash (name, name_len, &key); 104 GNUNET_CRYPTO_hash (name, name_len, &key);
257 if (NULL == barrier_map) 105 if (NULL == controller->barrier_map)
258 barrier_map = GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES); 106 controller->barrier_map = GNUNET_CONTAINER_multihashmap_create (3, GNUNET_YES);
259 if (GNUNET_YES == 107 if (GNUNET_YES ==
260 GNUNET_CONTAINER_multihashmap_contains (barrier_map, &key)) 108 GNUNET_CONTAINER_multihashmap_contains (controller->barrier_map,
109 &key))
261 { 110 {
262 GNUNET_break (0); 111 GNUNET_break (0);
263 return NULL; 112 return NULL;
@@ -271,7 +120,7 @@ GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
271 barrier->echo = echo; 120 barrier->echo = echo;
272 (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode)); 121 (void) memcpy (&barrier->key, &key, sizeof (struct GNUNET_HashCode));
273 GNUNET_assert (GNUNET_OK == 122 GNUNET_assert (GNUNET_OK ==
274 GNUNET_CONTAINER_multihashmap_put (barrier_map, 123 GNUNET_CONTAINER_multihashmap_put (controller->barrier_map,
275 &barrier->key, 124 &barrier->key,
276 barrier, 125 barrier,
277 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 126 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
@@ -328,7 +177,7 @@ GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier)
328 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL); 177 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_CANCEL);
329 (void) memcpy (msg->name, barrier->name, strlen (barrier->name)); 178 (void) memcpy (msg->name, barrier->name, strlen (barrier->name));
330 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header); 179 GNUNET_TESTBED_queue_message_ (barrier->c, &msg->header);
331 barrier_remove (barrier); 180 GNUNET_TESTBED_barrier_remove_ (barrier);
332} 181}
333 182
334 183
diff --git a/src/testbed/testbed_api_barriers.h b/src/testbed/testbed_api_barriers.h
index 9aa988f9e..b839a4ce4 100644
--- a/src/testbed/testbed_api_barriers.h
+++ b/src/testbed/testbed_api_barriers.h
@@ -24,6 +24,8 @@
24 * exposed as user API) 24 * exposed as user API)
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in> 25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 */ 26 */
27#ifndef TESTBED_API_BARRIERS_H
28#define TESTBED_API_BARRIERS_H
27 29
28#include "gnunet_testbed_service.h" 30#include "gnunet_testbed_service.h"
29 31
@@ -40,7 +42,7 @@
40 * @param cb the callback to call when the barrier is reached or upon error. 42 * @param cb the callback to call when the barrier is reached or upon error.
41 * Cannot be NULL. 43 * Cannot be NULL.
42 * @param cls closure for the above callback 44 * @param cls closure for the above callback
43 * @param echo GNUNET_YES to echo the barrier crossed status message back to the 45 * @param echo #GNUNET_YES to echo the barrier crossed status message back to the
44 * controller 46 * controller
45 * @return barrier handle; NULL upon error 47 * @return barrier handle; NULL upon error
46 */ 48 */
@@ -48,5 +50,19 @@ struct GNUNET_TESTBED_Barrier *
48GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller, 50GNUNET_TESTBED_barrier_init_ (struct GNUNET_TESTBED_Controller *controller,
49 const char *name, 51 const char *name,
50 unsigned int quorum, 52 unsigned int quorum,
51 GNUNET_TESTBED_barrier_status_cb cb, void *cls, 53 GNUNET_TESTBED_barrier_status_cb cb,
54 void *cls,
52 int echo); 55 int echo);
56
57
58/**
59 * Remove a barrier and it was the last one in the barrier hash map, destroy the
60 * hash map
61 *
62 * @param barrier the barrier to remove
63 */
64void
65GNUNET_TESTBED_barrier_remove_ (struct GNUNET_TESTBED_Barrier *barrier);
66
67
68#endif
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index d371108ec..5b1df615e 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -202,8 +202,7 @@ GNUNET_TESTBED_host_lookup_by_id_ (uint32_t id)
202 */ 202 */
203struct GNUNET_TESTBED_Host * 203struct GNUNET_TESTBED_Host *
204GNUNET_TESTBED_host_create_by_id_ (uint32_t id, 204GNUNET_TESTBED_host_create_by_id_ (uint32_t id,
205 const struct GNUNET_CONFIGURATION_Handle 205 const struct GNUNET_CONFIGURATION_Handle *cfg)
206 *cfg)
207{ 206{
208 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0); 207 return GNUNET_TESTBED_host_create_with_id (id, NULL, NULL, cfg, 0);
209} 208}
@@ -395,7 +394,6 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
395 *cfg, 394 *cfg,
396 struct GNUNET_TESTBED_Host ***hosts) 395 struct GNUNET_TESTBED_Host ***hosts)
397{ 396{
398 //struct GNUNET_TESTBED_Host **host_array;
399 struct GNUNET_TESTBED_Host *starting_host; 397 struct GNUNET_TESTBED_Host *starting_host;
400 char *data; 398 char *data;
401 char *buf; 399 char *buf;
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c
index 7f5aaa873..542f35b3c 100644
--- a/src/testbed/testbed_api_operations.c
+++ b/src/testbed/testbed_api_operations.c
@@ -400,7 +400,7 @@ static unsigned int n_expired_opqs;
400/** 400/**
401 * The id of the task to process the ready queue 401 * The id of the task to process the ready queue
402 */ 402 */
403struct GNUNET_SCHEDULER_Task * process_rq_task_id; 403struct GNUNET_SCHEDULER_Task *process_rq_task_id;
404 404
405 405
406/** 406/**