diff options
Diffstat (limited to 'src/testbed/testbed_api_barriers.c')
-rw-r--r-- | src/testbed/testbed_api_barriers.c | 205 |
1 files changed, 103 insertions, 102 deletions
diff --git a/src/testbed/testbed_api_barriers.c b/src/testbed/testbed_api_barriers.c index 7e38b4297..988fa7a1e 100644 --- a/src/testbed/testbed_api_barriers.c +++ b/src/testbed/testbed_api_barriers.c | |||
@@ -31,19 +31,20 @@ | |||
31 | * Logging shorthand | 31 | * Logging shorthand |
32 | */ | 32 | */ |
33 | #define LOG(type, ...) \ | 33 | #define LOG(type, ...) \ |
34 | GNUNET_log_from(type, "testbed-api-barriers", __VA_ARGS__); | 34 | GNUNET_log_from (type, "testbed-api-barriers", __VA_ARGS__); |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Debug logging shorthand | 37 | * Debug logging shorthand |
38 | */ | 38 | */ |
39 | #define LOG_DEBUG(...) \ | 39 | #define LOG_DEBUG(...) \ |
40 | LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); | 40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Barrier wait handle | 44 | * Barrier wait handle |
45 | */ | 45 | */ |
46 | struct GNUNET_TESTBED_BarrierWaitHandle { | 46 | struct GNUNET_TESTBED_BarrierWaitHandle |
47 | { | ||
47 | /** | 48 | /** |
48 | * The name of the barrier | 49 | * The name of the barrier |
49 | */ | 50 | */ |
@@ -80,8 +81,8 @@ struct GNUNET_TESTBED_BarrierWaitHandle { | |||
80 | * @return #GNUNET_OK if the message is well-formed. | 81 | * @return #GNUNET_OK if the message is well-formed. |
81 | */ | 82 | */ |
82 | static int | 83 | static int |
83 | check_status(void *cls, | 84 | check_status (void *cls, |
84 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 85 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
85 | { | 86 | { |
86 | /* FIXME: this fails to actually check that the message | 87 | /* FIXME: this fails to actually check that the message |
87 | follows the protocol spec (0-terminations!). However, | 88 | follows the protocol spec (0-terminations!). However, |
@@ -99,43 +100,43 @@ check_status(void *cls, | |||
99 | * @param msg received message | 100 | * @param msg received message |
100 | */ | 101 | */ |
101 | static void | 102 | static void |
102 | handle_status(void *cls, | 103 | handle_status (void *cls, |
103 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 104 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
104 | { | 105 | { |
105 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 106 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
106 | 107 | ||
107 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
108 | "Got barrier status %d\n", | 109 | "Got barrier status %d\n", |
109 | (int)ntohs(msg->status)); | 110 | (int) ntohs (msg->status)); |
110 | switch (ntohs(msg->status)) | 111 | switch (ntohs (msg->status)) |
111 | { | 112 | { |
112 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: | 113 | case GNUNET_TESTBED_BARRIERSTATUS_ERROR: |
113 | h->cb(h->cb_cls, | 114 | h->cb (h->cb_cls, |
114 | h->name, | 115 | h->name, |
115 | GNUNET_SYSERR); | 116 | GNUNET_SYSERR); |
116 | break; | 117 | break; |
117 | 118 | ||
118 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: | 119 | case GNUNET_TESTBED_BARRIERSTATUS_INITIALISED: |
119 | h->cb(h->cb_cls, | 120 | h->cb (h->cb_cls, |
120 | h->name, | 121 | h->name, |
121 | GNUNET_SYSERR); | 122 | GNUNET_SYSERR); |
122 | GNUNET_break(0); | 123 | GNUNET_break (0); |
123 | break; | 124 | break; |
124 | 125 | ||
125 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: | 126 | case GNUNET_TESTBED_BARRIERSTATUS_CROSSED: |
126 | h->cb(h->cb_cls, | 127 | h->cb (h->cb_cls, |
127 | h->name, | 128 | h->name, |
128 | GNUNET_OK); | 129 | GNUNET_OK); |
129 | break; | 130 | break; |
130 | 131 | ||
131 | default: | 132 | default: |
132 | GNUNET_break_op(0); | 133 | GNUNET_break_op (0); |
133 | h->cb(h->cb_cls, | 134 | h->cb (h->cb_cls, |
134 | h->name, | 135 | h->name, |
135 | GNUNET_SYSERR); | 136 | GNUNET_SYSERR); |
136 | break; | 137 | break; |
137 | } | 138 | } |
138 | GNUNET_TESTBED_barrier_wait_cancel(h); | 139 | GNUNET_TESTBED_barrier_wait_cancel (h); |
139 | } | 140 | } |
140 | 141 | ||
141 | 142 | ||
@@ -148,15 +149,15 @@ handle_status(void *cls, | |||
148 | * @param error error code | 149 | * @param error error code |
149 | */ | 150 | */ |
150 | static void | 151 | static void |
151 | mq_error_handler(void *cls, | 152 | mq_error_handler (void *cls, |
152 | enum GNUNET_MQ_Error error) | 153 | enum GNUNET_MQ_Error error) |
153 | { | 154 | { |
154 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; | 155 | struct GNUNET_TESTBED_BarrierWaitHandle *h = cls; |
155 | 156 | ||
156 | h->cb(h->cb_cls, | 157 | h->cb (h->cb_cls, |
157 | h->name, | 158 | h->name, |
158 | GNUNET_SYSERR); | 159 | GNUNET_SYSERR); |
159 | GNUNET_TESTBED_barrier_wait_cancel(h); | 160 | GNUNET_TESTBED_barrier_wait_cancel (h); |
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
@@ -172,72 +173,72 @@ mq_error_handler(void *cls, | |||
172 | * anytime before the callback is called. NULL upon error. | 173 | * anytime before the callback is called. NULL upon error. |
173 | */ | 174 | */ |
174 | struct GNUNET_TESTBED_BarrierWaitHandle * | 175 | struct GNUNET_TESTBED_BarrierWaitHandle * |
175 | GNUNET_TESTBED_barrier_wait(const char *name, | 176 | GNUNET_TESTBED_barrier_wait (const char *name, |
176 | GNUNET_TESTBED_barrier_wait_cb cb, | 177 | GNUNET_TESTBED_barrier_wait_cb cb, |
177 | void *cb_cls) | 178 | void *cb_cls) |
178 | { | 179 | { |
179 | struct GNUNET_TESTBED_BarrierWaitHandle *h | 180 | struct GNUNET_TESTBED_BarrierWaitHandle *h |
180 | = GNUNET_new(struct GNUNET_TESTBED_BarrierWaitHandle); | 181 | = GNUNET_new (struct GNUNET_TESTBED_BarrierWaitHandle); |
181 | struct GNUNET_MQ_MessageHandler handlers[] = { | 182 | struct GNUNET_MQ_MessageHandler handlers[] = { |
182 | GNUNET_MQ_hd_var_size(status, | 183 | GNUNET_MQ_hd_var_size (status, |
183 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | 184 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, |
184 | struct GNUNET_TESTBED_BarrierStatusMsg, | 185 | struct GNUNET_TESTBED_BarrierStatusMsg, |
185 | h), | 186 | h), |
186 | GNUNET_MQ_handler_end() | 187 | GNUNET_MQ_handler_end () |
187 | }; | 188 | }; |
188 | struct GNUNET_MQ_Envelope *env; | 189 | struct GNUNET_MQ_Envelope *env; |
189 | struct GNUNET_TESTBED_BarrierWait *msg; | 190 | struct GNUNET_TESTBED_BarrierWait *msg; |
190 | const char *cfg_filename; | 191 | const char *cfg_filename; |
191 | size_t name_len; | 192 | size_t name_len; |
192 | 193 | ||
193 | GNUNET_assert(NULL != cb); | 194 | GNUNET_assert (NULL != cb); |
194 | cfg_filename = getenv(ENV_TESTBED_CONFIG); | 195 | cfg_filename = getenv (ENV_TESTBED_CONFIG); |
195 | if (NULL == cfg_filename) | 196 | if (NULL == cfg_filename) |
196 | { | 197 | { |
197 | LOG(GNUNET_ERROR_TYPE_ERROR, | 198 | LOG (GNUNET_ERROR_TYPE_ERROR, |
198 | "Are you running under testbed?\n"); | 199 | "Are you running under testbed?\n"); |
199 | GNUNET_free(h); | 200 | GNUNET_free (h); |
200 | return NULL; | 201 | return NULL; |
201 | } | 202 | } |
202 | h->cfg = GNUNET_CONFIGURATION_create(); | 203 | h->cfg = GNUNET_CONFIGURATION_create (); |
203 | if (GNUNET_OK != | 204 | if (GNUNET_OK != |
204 | GNUNET_CONFIGURATION_load(h->cfg, | 205 | GNUNET_CONFIGURATION_load (h->cfg, |
205 | cfg_filename)) | 206 | cfg_filename)) |
206 | { | 207 | { |
207 | LOG(GNUNET_ERROR_TYPE_ERROR, | 208 | LOG (GNUNET_ERROR_TYPE_ERROR, |
208 | "Unable to load configuration from file `%s'\n", | 209 | "Unable to load configuration from file `%s'\n", |
209 | cfg_filename); | 210 | cfg_filename); |
210 | GNUNET_CONFIGURATION_destroy(h->cfg); | 211 | GNUNET_CONFIGURATION_destroy (h->cfg); |
211 | GNUNET_free(h); | 212 | GNUNET_free (h); |
212 | return NULL; | 213 | return NULL; |
213 | } | 214 | } |
214 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 215 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
215 | "Waiting on barrier `%s'\n", | 216 | "Waiting on barrier `%s'\n", |
216 | name); | 217 | name); |
217 | h->name = GNUNET_strdup(name); | 218 | h->name = GNUNET_strdup (name); |
218 | h->cb = cb; | 219 | h->cb = cb; |
219 | h->cb_cls = cb_cls; | 220 | h->cb_cls = cb_cls; |
220 | h->mq = GNUNET_CLIENT_connect(h->cfg, | 221 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
221 | "testbed-barrier", | 222 | "testbed-barrier", |
222 | handlers, | 223 | handlers, |
223 | &mq_error_handler, | 224 | &mq_error_handler, |
224 | h); | 225 | h); |
225 | if (NULL == h->mq) | 226 | if (NULL == h->mq) |
226 | { | 227 | { |
227 | LOG(GNUNET_ERROR_TYPE_ERROR, | 228 | LOG (GNUNET_ERROR_TYPE_ERROR, |
228 | "Unable to connect to local testbed-barrier service\n"); | 229 | "Unable to connect to local testbed-barrier service\n"); |
229 | GNUNET_TESTBED_barrier_wait_cancel(h); | 230 | GNUNET_TESTBED_barrier_wait_cancel (h); |
230 | return NULL; | 231 | return NULL; |
231 | } | 232 | } |
232 | name_len = strlen(name); /* NOTE: unusual to not have 0-termination, change? */ | 233 | name_len = strlen (name); /* NOTE: unusual to not have 0-termination, change? */ |
233 | env = GNUNET_MQ_msg_extra(msg, | 234 | env = GNUNET_MQ_msg_extra (msg, |
234 | name_len, | 235 | name_len, |
235 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); | 236 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_WAIT); |
236 | GNUNET_memcpy(msg->name, | 237 | GNUNET_memcpy (msg->name, |
237 | name, | 238 | name, |
238 | name_len); | 239 | name_len); |
239 | GNUNET_MQ_send(h->mq, | 240 | GNUNET_MQ_send (h->mq, |
240 | env); | 241 | env); |
241 | return h; | 242 | return h; |
242 | } | 243 | } |
243 | 244 | ||
@@ -248,16 +249,16 @@ GNUNET_TESTBED_barrier_wait(const char *name, | |||
248 | * @param h the barrier wait handle | 249 | * @param h the barrier wait handle |
249 | */ | 250 | */ |
250 | void | 251 | void |
251 | GNUNET_TESTBED_barrier_wait_cancel(struct GNUNET_TESTBED_BarrierWaitHandle *h) | 252 | GNUNET_TESTBED_barrier_wait_cancel (struct GNUNET_TESTBED_BarrierWaitHandle *h) |
252 | { | 253 | { |
253 | if (NULL != h->mq) | 254 | if (NULL != h->mq) |
254 | { | 255 | { |
255 | GNUNET_MQ_destroy(h->mq); | 256 | GNUNET_MQ_destroy (h->mq); |
256 | h->mq = NULL; | 257 | h->mq = NULL; |
257 | } | 258 | } |
258 | GNUNET_free(h->name); | 259 | GNUNET_free (h->name); |
259 | GNUNET_CONFIGURATION_destroy(h->cfg); | 260 | GNUNET_CONFIGURATION_destroy (h->cfg); |
260 | GNUNET_free(h); | 261 | GNUNET_free (h); |
261 | } | 262 | } |
262 | 263 | ||
263 | /* end of testbed_api_barriers.c */ | 264 | /* end of testbed_api_barriers.c */ |