diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-27 14:43:43 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-27 14:43:43 +0000 |
commit | b0474eb7a6aa570c04e4d76fd664caa406b3dd30 (patch) | |
tree | 3c75a22df7f927addeb3b6ca51c266088b6978fd /src/testbed | |
parent | 6f9c566127d0737ecd529f458dc28b7fc02e6eb9 (diff) | |
download | gnunet-b0474eb7a6aa570c04e4d76fd664caa406b3dd30.tar.gz gnunet-b0474eb7a6aa570c04e4d76fd664caa406b3dd30.zip |
convert testbed_api_barriers to new MQ API
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/test_testbed_api.c | 77 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_template.conf | 2 | ||||
-rw-r--r-- | src/testbed/testbed.h | 4 | ||||
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 205 |
4 files changed, 151 insertions, 137 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index 83203e71e..19e95f2c2 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -90,7 +90,7 @@ static struct GNUNET_ARM_Handle *arm_handle; | |||
90 | /** | 90 | /** |
91 | * Abort task identifier | 91 | * Abort task identifier |
92 | */ | 92 | */ |
93 | static struct GNUNET_SCHEDULER_Task * abort_task; | 93 | static struct GNUNET_SCHEDULER_Task *abort_task; |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * The testing result | 96 | * The testing result |
@@ -103,25 +103,25 @@ static int result; | |||
103 | */ | 103 | */ |
104 | enum Test | 104 | enum Test |
105 | { | 105 | { |
106 | /** | 106 | /** |
107 | * Test cases which are not covered by the below ones | 107 | * Test cases which are not covered by the below ones |
108 | */ | 108 | */ |
109 | OTHER, | 109 | OTHER, |
110 | 110 | ||
111 | /** | 111 | /** |
112 | * Test where we get a peer config from controller | 112 | * Test where we get a peer config from controller |
113 | */ | 113 | */ |
114 | PEER_GETCONFIG, | 114 | PEER_GETCONFIG, |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * Test where we connect to a service running on the peer | 117 | * Test where we connect to a service running on the peer |
118 | */ | 118 | */ |
119 | PEER_SERVICE_CONNECT, | 119 | PEER_SERVICE_CONNECT, |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Test where we get a peer's identity from controller | 122 | * Test where we get a peer's identity from controller |
123 | */ | 123 | */ |
124 | PEER_DESTROY, | 124 | PEER_DESTROY |
125 | }; | 125 | }; |
126 | 126 | ||
127 | /** | 127 | /** |
@@ -197,7 +197,8 @@ do_abort (void *cls) | |||
197 | * @return service handle to return in 'op_result', NULL on error | 197 | * @return service handle to return in 'op_result', NULL on error |
198 | */ | 198 | */ |
199 | static void * | 199 | static void * |
200 | arm_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 200 | arm_connect_adapter (void *cls, |
201 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
201 | { | 202 | { |
202 | FAIL_TEST (NULL == cls, return NULL); | 203 | FAIL_TEST (NULL == cls, return NULL); |
203 | FAIL_TEST (OTHER == sub_test, return NULL); | 204 | FAIL_TEST (OTHER == sub_test, return NULL); |
@@ -215,7 +216,8 @@ arm_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
215 | * @param op_result service handle returned from the connect adapter | 216 | * @param op_result service handle returned from the connect adapter |
216 | */ | 217 | */ |
217 | static void | 218 | static void |
218 | arm_disconnect_adapter (void *cls, void *op_result) | 219 | arm_disconnect_adapter (void *cls, |
220 | void *op_result) | ||
219 | { | 221 | { |
220 | FAIL_TEST (NULL != op_result, return); | 222 | FAIL_TEST (NULL != op_result, return); |
221 | FAIL_TEST (op_result == arm_handle, return); | 223 | FAIL_TEST (op_result == arm_handle, return); |
@@ -238,8 +240,10 @@ arm_disconnect_adapter (void *cls, void *op_result) | |||
238 | * operation has executed successfully. | 240 | * operation has executed successfully. |
239 | */ | 241 | */ |
240 | static void | 242 | static void |
241 | service_connect_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 243 | service_connect_comp_cb (void *cls, |
242 | void *ca_result, const char *emsg) | 244 | struct GNUNET_TESTBED_Operation *op, |
245 | void *ca_result, | ||
246 | const char *emsg) | ||
243 | { | 247 | { |
244 | switch (sub_test) | 248 | switch (sub_test) |
245 | { | 249 | { |
@@ -268,7 +272,8 @@ service_connect_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
268 | * operation is successfull | 272 | * operation is successfull |
269 | */ | 273 | */ |
270 | static void | 274 | static void |
271 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | 275 | peerinfo_cb (void *cb_cls, |
276 | struct GNUNET_TESTBED_Operation *op, | ||
272 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 277 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
273 | const char *emsg) | 278 | const char *emsg) |
274 | { | 279 | { |
@@ -299,7 +304,8 @@ peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | |||
299 | * @param event information about the event | 304 | * @param event information about the event |
300 | */ | 305 | */ |
301 | static void | 306 | static void |
302 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 307 | controller_cb (void *cls, |
308 | const struct GNUNET_TESTBED_EventInformation *event) | ||
303 | { | 309 | { |
304 | switch (event->type) | 310 | switch (event->type) |
305 | { | 311 | { |
@@ -365,7 +371,9 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
365 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 371 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
366 | */ | 372 | */ |
367 | static void | 373 | static void |
368 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 374 | peer_create_cb (void *cls, |
375 | struct GNUNET_TESTBED_Peer *peer, | ||
376 | const char *emsg) | ||
369 | { | 377 | { |
370 | struct GNUNET_TESTBED_Peer **peer_ptr; | 378 | struct GNUNET_TESTBED_Peer **peer_ptr; |
371 | 379 | ||
@@ -374,7 +382,10 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
374 | FAIL_TEST (NULL != peer_ptr, return); | 382 | FAIL_TEST (NULL != peer_ptr, return); |
375 | *peer_ptr = peer; | 383 | *peer_ptr = peer; |
376 | GNUNET_TESTBED_operation_done (operation); | 384 | GNUNET_TESTBED_operation_done (operation); |
377 | operation = GNUNET_TESTBED_peer_start (NULL, peer, NULL, NULL); | 385 | operation = GNUNET_TESTBED_peer_start (NULL, |
386 | peer, | ||
387 | NULL, | ||
388 | NULL); | ||
378 | FAIL_TEST (NULL != operation, return); | 389 | FAIL_TEST (NULL != operation, return); |
379 | } | 390 | } |
380 | 391 | ||
@@ -386,12 +397,16 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
386 | * @param emsg the error message; NULL if host registration is successful | 397 | * @param emsg the error message; NULL if host registration is successful |
387 | */ | 398 | */ |
388 | static void | 399 | static void |
389 | registration_comp (void *cls, const char *emsg) | 400 | registration_comp (void *cls, |
401 | const char *emsg) | ||
390 | { | 402 | { |
391 | FAIL_TEST (cls == neighbour, return); | 403 | FAIL_TEST (cls == neighbour, return); |
392 | reg_handle = NULL; | 404 | reg_handle = NULL; |
393 | operation = | 405 | operation = |
394 | GNUNET_TESTBED_peer_create (controller, host, cfg, &peer_create_cb, | 406 | GNUNET_TESTBED_peer_create (controller, |
407 | host, | ||
408 | cfg, | ||
409 | &peer_create_cb, | ||
395 | &peer); | 410 | &peer); |
396 | FAIL_TEST (NULL != operation, return); | 411 | FAIL_TEST (NULL != operation, return); |
397 | } | 412 | } |
@@ -402,12 +417,14 @@ registration_comp (void *cls, const char *emsg) | |||
402 | * | 417 | * |
403 | * @param cls the closure from GNUNET_TESTBED_controller_start() | 418 | * @param cls the closure from GNUNET_TESTBED_controller_start() |
404 | * @param cfg the configuration with which the controller has been started; | 419 | * @param cfg the configuration with which the controller has been started; |
405 | * NULL if status is not GNUNET_OK | 420 | * NULL if status is not #GNUNET_OK |
406 | * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, | 421 | * @param status #GNUNET_OK if the startup is successfull; #GNUNET_SYSERR if not, |
407 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | 422 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case |
408 | */ | 423 | */ |
409 | static void | 424 | static void |
410 | status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status) | 425 | status_cb (void *cls, |
426 | const struct GNUNET_CONFIGURATION_Handle *cfg_, | ||
427 | int status) | ||
411 | { | 428 | { |
412 | uint64_t event_mask; | 429 | uint64_t event_mask; |
413 | 430 | ||
@@ -440,12 +457,14 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, int status | |||
440 | * Main run function. | 457 | * Main run function. |
441 | * | 458 | * |
442 | * @param cls NULL | 459 | * @param cls NULL |
443 | * @param args arguments passed to GNUNET_PROGRAM_run | 460 | * @param args arguments passed to #GNUNET_PROGRAM_run() |
444 | * @param cfgfile the path to configuration file | 461 | * @param cfgfile the path to configuration file |
445 | * @param cfg the configuration file handle | 462 | * @param cfg the configuration file handle |
446 | */ | 463 | */ |
447 | static void | 464 | static void |
448 | run (void *cls, char *const *args, const char *cfgfile, | 465 | run (void *cls, |
466 | char *const *args, | ||
467 | const char *cfgfile, | ||
449 | const struct GNUNET_CONFIGURATION_Handle *config) | 468 | const struct GNUNET_CONFIGURATION_Handle *config) |
450 | { | 469 | { |
451 | cfg = GNUNET_CONFIGURATION_dup (config); | 470 | cfg = GNUNET_CONFIGURATION_dup (config); |
diff --git a/src/testbed/test_testbed_api_template.conf b/src/testbed/test_testbed_api_template.conf index 296c2b0dc..35317fd1c 100644 --- a/src/testbed/test_testbed_api_template.conf +++ b/src/testbed/test_testbed_api_template.conf | |||
@@ -1,3 +1,5 @@ | |||
1 | @INLINE@ ../../contrib/no_forcestart.conf | ||
2 | @INLINE@ ../../contrib/no_autostart_above_core.conf | ||
1 | [testbed] | 3 | [testbed] |
2 | AUTOSTART = NO | 4 | AUTOSTART = NO |
3 | PORT = 12113 | 5 | PORT = 12113 |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index bc93ed8a8..b6119e98f 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -877,8 +877,8 @@ struct GNUNET_TESTBED_BarrierStatusMsg | |||
877 | uint16_t name_len GNUNET_PACKED; | 877 | uint16_t name_len GNUNET_PACKED; |
878 | 878 | ||
879 | /** | 879 | /** |
880 | * the barrier name (NULL terminated) concatenated with an error message (NULL | 880 | * the barrier name (0-terminated) concatenated with an error message |
881 | * terminated) if the status were to indicate an error | 881 | * (0-terminated) if the status were to indicate an error |
882 | */ | 882 | */ |
883 | char data[0]; | 883 | char data[0]; |
884 | }; | 884 | }; |
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index 3ec4a905e..74139cc53 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -56,19 +56,9 @@ struct GNUNET_TESTBED_BarrierWaitHandle | |||
56 | struct GNUNET_CONFIGURATION_Handle *cfg; | 56 | struct GNUNET_CONFIGURATION_Handle *cfg; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * The client connection | 59 | * The testbed-barrier service message queue. |
60 | */ | 60 | */ |
61 | struct GNUNET_CLIENT_Connection *conn; | 61 | struct GNUNET_MQ_Handle *mq; |
62 | |||
63 | /** | ||
64 | * Transmit handle | ||
65 | */ | ||
66 | struct GNUNET_CLIENT_TransmitHandle *tx; | ||
67 | |||
68 | /** | ||
69 | * The message to transmit with tx | ||
70 | */ | ||
71 | struct GNUNET_MessageHeader *msg; | ||
72 | 62 | ||
73 | /** | 63 | /** |
74 | * The barrier wait callback | 64 | * The barrier wait callback |
@@ -76,98 +66,92 @@ struct GNUNET_TESTBED_BarrierWaitHandle | |||
76 | GNUNET_TESTBED_barrier_wait_cb cb; | 66 | GNUNET_TESTBED_barrier_wait_cb cb; |
77 | 67 | ||
78 | /** | 68 | /** |
79 | * The closure for the above callback | 69 | * The closure for @e cb. |
80 | */ | 70 | */ |
81 | void *cls; | 71 | void *cb_cls; |
82 | }; | 72 | }; |
83 | 73 | ||
84 | 74 | ||
85 | 75 | ||
86 | /** | 76 | /** |
77 | * Check if barrier status message is well-formed. | ||
78 | * | ||
79 | * @param cls closure | ||
80 | * @param msg received message | ||
81 | * @return #GNUNET_OK if the message is well-formed. | ||
82 | */ | ||
83 | static int | ||
84 | check_status (void *cls, | ||
85 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | ||
86 | { | ||
87 | /* FIXME: this fails to actually check that the message | ||
88 | follows the protocol spec (0-terminations!). However, | ||
89 | not critical as #handle_status() doesn't interpret the | ||
90 | variable-size part anyway right now. */ | ||
91 | return GNUNET_OK; | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
87 | * Type of a function to call when we receive a message | 96 | * Type of a function to call when we receive a message |
88 | * from the service. | 97 | * from the service. |
89 | * | 98 | * |
90 | * @param cls closure | 99 | * @param cls closure |
91 | * @param message received message; NULL on timeout or fatal error | 100 | * @param msg received message |
92 | */ | 101 | */ |
93 | static void | 102 | static void |
94 | receive_handler (void *cls, | 103 | handle_status (void *cls, |
95 | const struct GNUNET_MessageHeader *message) | 104 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
96 | { | 105 | { |
97 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 106 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
98 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg; | ||
99 | uint16_t msize; | ||
100 | 107 | ||
101 | if (NULL == message) | ||
102 | { | ||
103 | GNUNET_break_op (0); | ||
104 | goto fail; | ||
105 | } | ||
106 | if (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS != ntohs (message->type)) | ||
107 | { | ||
108 | GNUNET_break_op (0); | ||
109 | goto fail; | ||
110 | } | ||
111 | msize = ntohs (message->size); | ||
112 | if (msize <= sizeof (struct GNUNET_TESTBED_BarrierStatusMsg)) | ||
113 | { | ||
114 | GNUNET_break_op (0); | ||
115 | goto fail; | ||
116 | } | ||
117 | msg = (const struct GNUNET_TESTBED_BarrierStatusMsg *) message; | ||
118 | switch (ntohs (msg->status)) | 108 | switch (ntohs (msg->status)) |
119 | { | 109 | { |
120 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 110 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
121 | goto fail; | 111 | h->cb (h->cb_cls, |
112 | h->name, | ||
113 | GNUNET_SYSERR); | ||
114 | break; | ||
122 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 115 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
116 | h->cb (h->cb_cls, | ||
117 | h->name, | ||
118 | GNUNET_SYSERR); | ||
123 | GNUNET_break (0); | 119 | GNUNET_break (0); |
124 | goto fail; | 120 | break; |
125 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 121 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
126 | h->cb (h->cls, h->name, GNUNET_OK); | 122 | h->cb (h->cb_cls, |
127 | goto destroy; | 123 | h->name, |
124 | GNUNET_OK); | ||
125 | break; | ||
128 | default: | 126 | default: |
129 | GNUNET_break_op (0); | 127 | GNUNET_break_op (0); |
128 | h->cb (h->cb_cls, | ||
129 | h->name, | ||
130 | GNUNET_SYSERR); | ||
131 | break; | ||
130 | } | 132 | } |
131 | |||
132 | fail: | ||
133 | h->cb (h->cls, h->name, GNUNET_SYSERR); | ||
134 | |||
135 | destroy: | ||
136 | GNUNET_TESTBED_barrier_wait_cancel (h); | 133 | GNUNET_TESTBED_barrier_wait_cancel (h); |
137 | } | 134 | } |
138 | 135 | ||
139 | 136 | ||
140 | /** | 137 | /** |
141 | * Function called to notify a client about the connection | 138 | * Generic error handler, called with the appropriate error code and |
142 | * begin ready to queue more data. "buf" will be | 139 | * the same closure specified at the creation of the message queue. |
143 | * NULL and "size" zero if the connection was closed for | 140 | * Not every message queue implementation supports an error handler. |
144 | * writing in the meantime. | ||
145 | * | 141 | * |
146 | * @param cls closure | 142 | * @param cls closure with the `struct GNUNET_TESTBED_BarrierWaitHandle *` |
147 | * @param size number of bytes available in buf | 143 | * @param error error code |
148 | * @param buf where the callee should write the message | ||
149 | * @return number of bytes written to buf | ||
150 | */ | 144 | */ |
151 | static size_t | 145 | static void |
152 | transmit_notify (void *cls, size_t size, void *buf) | 146 | mq_error_handler (void *cls, |
147 | enum GNUNET_MQ_Error error) | ||
153 | { | 148 | { |
154 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 149 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
155 | uint16_t msize; | ||
156 | 150 | ||
157 | h->tx = NULL; | 151 | h->cb (h->cb_cls, |
158 | if ((0 == size) || (NULL == buf)) | 152 | h->name, |
159 | { | 153 | GNUNET_SYSERR); |
160 | h->cb (h->cls, h->name, GNUNET_SYSERR); | 154 | GNUNET_TESTBED_barrier_wait_cancel (h); |
161 | GNUNET_TESTBED_barrier_wait_cancel (h); | ||
162 | return 0; | ||
163 | } | ||
164 | msize = htons (h->msg->size); | ||
165 | GNUNET_assert (msize <= size); | ||
166 | (void) memcpy (buf, h->msg, msize); | ||
167 | GNUNET_free (h->msg); | ||
168 | h->msg = NULL; | ||
169 | GNUNET_CLIENT_receive (h->conn, &receive_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); | ||
170 | return msize; | ||
171 | } | 155 | } |
172 | 156 | ||
173 | 157 | ||
@@ -178,64 +162,74 @@ transmit_notify (void *cls, size_t size, void *buf) | |||
178 | * | 162 | * |
179 | * @param name the name of the barrier | 163 | * @param name the name of the barrier |
180 | * @param cb the barrier wait callback | 164 | * @param cb the barrier wait callback |
181 | * @param cls the closure for the above callback | 165 | * @param cb_cls the closure for @a cb |
182 | * @return barrier wait handle which can be used to cancel the waiting at | 166 | * @return barrier wait handle which can be used to cancel the waiting at |
183 | * anytime before the callback is called. NULL upon error. | 167 | * anytime before the callback is called. NULL upon error. |
184 | */ | 168 | */ |
185 | struct GNUNET_TESTBED_BarrierWaitHandle * | 169 | struct GNUNET_TESTBED_BarrierWaitHandle * |
186 | GNUNET_TESTBED_barrier_wait (const char *name, | 170 | GNUNET_TESTBED_barrier_wait (const char *name, |
187 | GNUNET_TESTBED_barrier_wait_cb cb, | 171 | GNUNET_TESTBED_barrier_wait_cb cb, |
188 | void *cls) | 172 | void *cb_cls) |
189 | { | 173 | { |
174 | GNUNET_MQ_hd_var_size (status, | ||
175 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | ||
176 | struct GNUNET_TESTBED_BarrierStatusMsg); | ||
177 | struct GNUNET_TESTBED_BarrierWaitHandle *h | ||
178 | = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); | ||
179 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
180 | make_status_handler (h), | ||
181 | GNUNET_MQ_handler_end () | ||
182 | }; | ||
183 | struct GNUNET_MQ_Envelope *env; | ||
190 | struct GNUNET_TESTBED_BarrierWait *msg; | 184 | struct GNUNET_TESTBED_BarrierWait *msg; |
191 | struct GNUNET_CONFIGURATION_Handle *cfg; | 185 | const char *cfg_filename; |
192 | struct GNUNET_TESTBED_BarrierWaitHandle *h; | ||
193 | char *cfg_filename; | ||
194 | size_t name_len; | 186 | size_t name_len; |
195 | uint16_t msize; | ||
196 | 187 | ||
197 | GNUNET_assert (NULL != cb); | 188 | GNUNET_assert (NULL != cb); |
198 | GNUNET_assert (NULL != name); | ||
199 | cfg_filename = getenv (ENV_TESTBED_CONFIG); | 189 | cfg_filename = getenv (ENV_TESTBED_CONFIG); |
200 | if (NULL == cfg_filename) | 190 | if (NULL == cfg_filename) |
201 | { | 191 | { |
202 | LOG (GNUNET_ERROR_TYPE_ERROR, "Are you running under testbed?\n"); | 192 | LOG (GNUNET_ERROR_TYPE_ERROR, |
193 | "Are you running under testbed?\n"); | ||
194 | GNUNET_free (h); | ||
203 | return NULL; | 195 | return NULL; |
204 | } | 196 | } |
205 | cfg = GNUNET_CONFIGURATION_create (); | 197 | h->cfg = GNUNET_CONFIGURATION_create (); |
206 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_filename)) | 198 | if (GNUNET_OK != |
199 | GNUNET_CONFIGURATION_load (h->cfg, | ||
200 | cfg_filename)) | ||
207 | { | 201 | { |
208 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to load configuration from file `%s'\n", | 202 | LOG (GNUNET_ERROR_TYPE_ERROR, |
203 | "Unable to load configuration from file `%s'\n", | ||
209 | cfg_filename); | 204 | cfg_filename); |
210 | GNUNET_CONFIGURATION_destroy (cfg); | 205 | GNUNET_CONFIGURATION_destroy (h->cfg); |
206 | GNUNET_free (h); | ||
211 | return NULL; | 207 | return NULL; |
212 | } | 208 | } |
213 | h = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); | ||
214 | h->name = GNUNET_strdup (name); | 209 | h->name = GNUNET_strdup (name); |
215 | h->cfg = cfg; | ||
216 | h->conn = GNUNET_CLIENT_connect ("testbed-barrier", h->cfg); | ||
217 | h->cb = cb; | 210 | h->cb = cb; |
218 | h->cls = cls; | 211 | h->cb_cls = cb_cls; |
219 | if (NULL == h->conn) | 212 | h->mq = GNUNET_CLIENT_connecT (h->cfg, |
213 | "testbed-barrier", | ||
214 | handlers, | ||
215 | &mq_error_handler, | ||
216 | h); | ||
217 | if (NULL == h->mq) | ||
220 | { | 218 | { |
221 | LOG (GNUNET_ERROR_TYPE_ERROR, | 219 | LOG (GNUNET_ERROR_TYPE_ERROR, |
222 | "Unable to connect to local testbed-barrier service\n"); | 220 | "Unable to connect to local testbed-barrier service\n"); |
223 | GNUNET_TESTBED_barrier_wait_cancel (h); | 221 | GNUNET_TESTBED_barrier_wait_cancel (h); |
224 | return NULL; | 222 | return NULL; |
225 | } | 223 | } |
226 | name_len = strlen (name); | 224 | name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */ |
227 | msize = sizeof (struct GNUNET_TESTBED_BarrierWait) + name_len; | 225 | env = GNUNET_MQ_msg_extra (msg, |
228 | msg = GNUNET_malloc (msize); | 226 | name_len, |
229 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); | 227 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); |
230 | msg->header.size = htons (msize); | 228 | memcpy (msg->name, |
231 | (void) memcpy (msg->name, name, name_len); | 229 | name, |
232 | h->msg = &msg->header; | 230 | name_len); |
233 | h->tx = | 231 | GNUNET_MQ_send (h->mq, |
234 | GNUNET_CLIENT_notify_transmit_ready (h->conn, msize, | 232 | env); |
235 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
236 | GNUNET_NO, | ||
237 | &transmit_notify, | ||
238 | h); | ||
239 | return h; | 233 | return h; |
240 | } | 234 | } |
241 | 235 | ||
@@ -248,13 +242,12 @@ GNUNET_TESTBED_barrier_wait (const char *name, | |||
248 | void | 242 | void |
249 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) | 243 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) |
250 | { | 244 | { |
245 | if (NULL != h->mq) | ||
246 | { | ||
247 | GNUNET_MQ_destroy (h->mq); | ||
248 | h->mq = NULL; | ||
249 | } | ||
251 | GNUNET_free (h->name); | 250 | GNUNET_free (h->name); |
252 | if (NULL != h->tx) | ||
253 | GNUNET_CLIENT_notify_transmit_ready_cancel (h->tx); | ||
254 | if (NULL != h->conn) | ||
255 | GNUNET_CLIENT_disconnect (h->conn); | ||
256 | if (NULL != h->msg) | ||
257 | GNUNET_free (h->msg); | ||
258 | GNUNET_CONFIGURATION_destroy (h->cfg); | 251 | GNUNET_CONFIGURATION_destroy (h->cfg); |
259 | GNUNET_free (h); | 252 | GNUNET_free (h); |
260 | } | 253 | } |