diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/transport_api2_core.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/transport/transport_api2_core.c')
-rw-r--r-- | src/transport/transport_api2_core.c | 490 |
1 files changed, 243 insertions, 247 deletions
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c index 20bbf2994..1d2d84bdf 100644 --- a/src/transport/transport_api2_core.c +++ b/src/transport/transport_api2_core.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file transport/transport_api_core.c | 22 | * @file transport/transport_api_core.c |
@@ -32,7 +32,7 @@ | |||
32 | #include "gnunet_transport_core_service.h" | 32 | #include "gnunet_transport_core_service.h" |
33 | #include "transport.h" | 33 | #include "transport.h" |
34 | 34 | ||
35 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-api-core", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * How large to start with for the hashmap of neighbours. | 38 | * How large to start with for the hashmap of neighbours. |
@@ -53,9 +53,7 @@ | |||
53 | /** | 53 | /** |
54 | * Entry in hash table of all of our current (connected) neighbours. | 54 | * Entry in hash table of all of our current (connected) neighbours. |
55 | */ | 55 | */ |
56 | struct Neighbour | 56 | struct Neighbour { |
57 | { | ||
58 | |||
59 | /** | 57 | /** |
60 | * Identity of this neighbour. | 58 | * Identity of this neighbour. |
61 | */ | 59 | */ |
@@ -107,9 +105,7 @@ struct Neighbour | |||
107 | * Handle for the transport service (includes all of the | 105 | * Handle for the transport service (includes all of the |
108 | * state for the transport service). | 106 | * state for the transport service). |
109 | */ | 107 | */ |
110 | struct GNUNET_TRANSPORT_CoreHandle | 108 | struct GNUNET_TRANSPORT_CoreHandle { |
111 | { | ||
112 | |||
113 | /** | 109 | /** |
114 | * Closure for the callbacks. | 110 | * Closure for the callbacks. |
115 | */ | 111 | */ |
@@ -177,7 +173,7 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
177 | * @param h transport service to reconnect | 173 | * @param h transport service to reconnect |
178 | */ | 174 | */ |
179 | static void | 175 | static void |
180 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); | 176 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); |
181 | 177 | ||
182 | 178 | ||
183 | /** | 179 | /** |
@@ -188,10 +184,10 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); | |||
188 | * @return NULL if no such peer entry exists | 184 | * @return NULL if no such peer entry exists |
189 | */ | 185 | */ |
190 | static struct Neighbour * | 186 | static struct Neighbour * |
191 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | 187 | neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, |
192 | const struct GNUNET_PeerIdentity *peer) | 188 | const struct GNUNET_PeerIdentity *peer) |
193 | { | 189 | { |
194 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); | 190 | return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); |
195 | } | 191 | } |
196 | 192 | ||
197 | 193 | ||
@@ -206,27 +202,27 @@ neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | |||
206 | * #GNUNET_NO if not. | 202 | * #GNUNET_NO if not. |
207 | */ | 203 | */ |
208 | static int | 204 | static int |
209 | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 205 | neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
210 | { | 206 | { |
211 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; | 207 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; |
212 | struct Neighbour *n = value; | 208 | struct Neighbour *n = value; |
213 | 209 | ||
214 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 210 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
215 | "Dropping entry for neighbour `%s'.\n", | 211 | "Dropping entry for neighbour `%s'.\n", |
216 | GNUNET_i2s (key)); | 212 | GNUNET_i2s(key)); |
217 | if (NULL != handle->nd_cb) | 213 | if (NULL != handle->nd_cb) |
218 | handle->nd_cb (handle->cls, &n->id, n->handlers_cls); | 214 | handle->nd_cb(handle->cls, &n->id, n->handlers_cls); |
219 | if (NULL != n->env) | 215 | if (NULL != n->env) |
220 | { | 216 | { |
221 | GNUNET_MQ_send_cancel (n->env); | 217 | GNUNET_MQ_send_cancel(n->env); |
222 | n->env = NULL; | 218 | n->env = NULL; |
223 | } | 219 | } |
224 | GNUNET_MQ_destroy (n->mq); | 220 | GNUNET_MQ_destroy(n->mq); |
225 | GNUNET_assert (NULL == n->mq); | 221 | GNUNET_assert(NULL == n->mq); |
226 | GNUNET_assert ( | 222 | GNUNET_assert( |
227 | GNUNET_YES == | 223 | GNUNET_YES == |
228 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); | 224 | GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); |
229 | GNUNET_free (n); | 225 | GNUNET_free(n); |
230 | return GNUNET_YES; | 226 | return GNUNET_YES; |
231 | } | 227 | } |
232 | 228 | ||
@@ -241,13 +237,13 @@ neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
241 | * @param error error code | 237 | * @param error error code |
242 | */ | 238 | */ |
243 | static void | 239 | static void |
244 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 240 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
245 | { | 241 | { |
246 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 242 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
247 | 243 | ||
248 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 244 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
249 | "Error receiving from transport service, disconnecting temporarily.\n"); | 245 | "Error receiving from transport service, disconnecting temporarily.\n"); |
250 | disconnect_and_schedule_reconnect (h); | 246 | disconnect_and_schedule_reconnect(h); |
251 | } | 247 | } |
252 | 248 | ||
253 | 249 | ||
@@ -262,13 +258,13 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
262 | * @param cls the `struct Neighbour` where the message was sent | 258 | * @param cls the `struct Neighbour` where the message was sent |
263 | */ | 259 | */ |
264 | static void | 260 | static void |
265 | notify_send_done (void *cls) | 261 | notify_send_done(void *cls) |
266 | { | 262 | { |
267 | struct Neighbour *n = cls; | 263 | struct Neighbour *n = cls; |
268 | 264 | ||
269 | n->awaiting_done = GNUNET_NO; | 265 | n->awaiting_done = GNUNET_NO; |
270 | n->env = NULL; | 266 | n->env = NULL; |
271 | GNUNET_MQ_impl_send_continue (n->mq); | 267 | GNUNET_MQ_impl_send_continue(n->mq); |
272 | } | 268 | } |
273 | 269 | ||
274 | 270 | ||
@@ -279,18 +275,18 @@ notify_send_done (void *cls) | |||
279 | * @param n neighbour to perform transmission for | 275 | * @param n neighbour to perform transmission for |
280 | */ | 276 | */ |
281 | static void | 277 | static void |
282 | do_send (struct Neighbour *n) | 278 | do_send(struct Neighbour *n) |
283 | { | 279 | { |
284 | GNUNET_assert (0 < n->ready_window); | 280 | GNUNET_assert(0 < n->ready_window); |
285 | GNUNET_assert (NULL != n->env); | 281 | GNUNET_assert(NULL != n->env); |
286 | n->ready_window--; | 282 | n->ready_window--; |
287 | n->awaiting_done = GNUNET_YES; | 283 | n->awaiting_done = GNUNET_YES; |
288 | GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); | 284 | GNUNET_MQ_notify_sent(n->env, ¬ify_send_done, n); |
289 | GNUNET_MQ_send (n->h->mq, n->env); | 285 | GNUNET_MQ_send(n->h->mq, n->env); |
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 286 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
291 | "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", | 287 | "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", |
292 | ntohs (GNUNET_MQ_env_get_msg (n->env)->type), | 288 | ntohs(GNUNET_MQ_env_get_msg(n->env)->type), |
293 | GNUNET_i2s (&n->id)); | 289 | GNUNET_i2s(&n->id)); |
294 | } | 290 | } |
295 | 291 | ||
296 | 292 | ||
@@ -305,44 +301,44 @@ do_send (struct Neighbour *n) | |||
305 | * @param impl_state state of the implementation | 301 | * @param impl_state state of the implementation |
306 | */ | 302 | */ |
307 | static void | 303 | static void |
308 | mq_send_impl (struct GNUNET_MQ_Handle *mq, | 304 | mq_send_impl(struct GNUNET_MQ_Handle *mq, |
309 | const struct GNUNET_MessageHeader *msg, | 305 | const struct GNUNET_MessageHeader *msg, |
310 | void *impl_state) | 306 | void *impl_state) |
311 | { | 307 | { |
312 | struct Neighbour *n = impl_state; | 308 | struct Neighbour *n = impl_state; |
313 | struct OutboundMessage *obm; | 309 | struct OutboundMessage *obm; |
314 | uint16_t msize; | 310 | uint16_t msize; |
315 | 311 | ||
316 | msize = ntohs (msg->size); | 312 | msize = ntohs(msg->size); |
317 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) | 313 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) |
318 | { | 314 | { |
319 | GNUNET_break (0); | 315 | GNUNET_break(0); |
320 | GNUNET_MQ_impl_send_continue (mq); | 316 | GNUNET_MQ_impl_send_continue(mq); |
321 | return; | 317 | return; |
322 | } | 318 | } |
323 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 319 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
324 | "CORE requested transmission of message of type %u to neighbour `%s'.\n", | 320 | "CORE requested transmission of message of type %u to neighbour `%s'.\n", |
325 | ntohs (msg->type), | 321 | ntohs(msg->type), |
326 | GNUNET_i2s (&n->id)); | 322 | GNUNET_i2s(&n->id)); |
327 | 323 | ||
328 | GNUNET_assert (NULL == n->env); | 324 | GNUNET_assert(NULL == n->env); |
329 | n->env = | 325 | n->env = |
330 | GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); | 326 | GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); |
331 | n->env_size = ntohs (msg->size); | 327 | n->env_size = ntohs(msg->size); |
332 | { | 328 | { |
333 | struct GNUNET_MQ_Envelope *env; | 329 | struct GNUNET_MQ_Envelope *env; |
334 | 330 | ||
335 | env = GNUNET_MQ_get_current_envelope (mq); | 331 | env = GNUNET_MQ_get_current_envelope(mq); |
336 | obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); | 332 | obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); |
337 | } | 333 | } |
338 | obm->peer = n->id; | 334 | obm->peer = n->id; |
339 | if (0 == n->ready_window) | 335 | if (0 == n->ready_window) |
340 | { | 336 | { |
341 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 337 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
342 | "Flow control delays transmission to CORE until we see SEND_OK.\n"); | 338 | "Flow control delays transmission to CORE until we see SEND_OK.\n"); |
343 | return; /* can't send yet, need to wait for SEND_OK */ | 339 | return; /* can't send yet, need to wait for SEND_OK */ |
344 | } | 340 | } |
345 | do_send (n); | 341 | do_send(n); |
346 | } | 342 | } |
347 | 343 | ||
348 | 344 | ||
@@ -354,11 +350,11 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
354 | * @param impl_state state of the implementation | 350 | * @param impl_state state of the implementation |
355 | */ | 351 | */ |
356 | static void | 352 | static void |
357 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 353 | mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
358 | { | 354 | { |
359 | struct Neighbour *n = impl_state; | 355 | struct Neighbour *n = impl_state; |
360 | 356 | ||
361 | GNUNET_assert (mq == n->mq); | 357 | GNUNET_assert(mq == n->mq); |
362 | n->mq = NULL; | 358 | n->mq = NULL; |
363 | } | 359 | } |
364 | 360 | ||
@@ -371,22 +367,22 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
371 | * @param impl_state state specific to the implementation | 367 | * @param impl_state state specific to the implementation |
372 | */ | 368 | */ |
373 | static void | 369 | static void |
374 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 370 | mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
375 | { | 371 | { |
376 | struct Neighbour *n = impl_state; | 372 | struct Neighbour *n = impl_state; |
377 | 373 | ||
378 | n->ready_window++; | 374 | n->ready_window++; |
379 | if (GNUNET_YES == n->awaiting_done) | 375 | if (GNUNET_YES == n->awaiting_done) |
380 | { | 376 | { |
381 | GNUNET_MQ_send_cancel (n->env); | 377 | GNUNET_MQ_send_cancel(n->env); |
382 | n->env = NULL; | 378 | n->env = NULL; |
383 | n->awaiting_done = GNUNET_NO; | 379 | n->awaiting_done = GNUNET_NO; |
384 | } | 380 | } |
385 | else | 381 | else |
386 | { | 382 | { |
387 | GNUNET_assert (0 == n->ready_window); | 383 | GNUNET_assert(0 == n->ready_window); |
388 | n->env = NULL; | 384 | n->env = NULL; |
389 | } | 385 | } |
390 | } | 386 | } |
391 | 387 | ||
392 | 388 | ||
@@ -399,11 +395,11 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
399 | * @param error error code | 395 | * @param error error code |
400 | */ | 396 | */ |
401 | static void | 397 | static void |
402 | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 398 | peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
403 | { | 399 | { |
404 | /* struct Neighbour *n = cls; */ | 400 | /* struct Neighbour *n = cls; */ |
405 | 401 | ||
406 | GNUNET_break_op (0); | 402 | GNUNET_break_op(0); |
407 | } | 403 | } |
408 | 404 | ||
409 | 405 | ||
@@ -414,44 +410,44 @@ peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
414 | * @param cim message received | 410 | * @param cim message received |
415 | */ | 411 | */ |
416 | static void | 412 | static void |
417 | handle_connect (void *cls, const struct ConnectInfoMessage *cim) | 413 | handle_connect(void *cls, const struct ConnectInfoMessage *cim) |
418 | { | 414 | { |
419 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 415 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
420 | struct Neighbour *n; | 416 | struct Neighbour *n; |
421 | 417 | ||
422 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 418 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
423 | "Receiving CONNECT message for `%s'\n", | 419 | "Receiving CONNECT message for `%s'\n", |
424 | GNUNET_i2s (&cim->id)); | 420 | GNUNET_i2s(&cim->id)); |
425 | n = neighbour_find (h, &cim->id); | 421 | n = neighbour_find(h, &cim->id); |
426 | if (NULL != n) | 422 | if (NULL != n) |
427 | { | 423 | { |
428 | GNUNET_break (0); | 424 | GNUNET_break(0); |
429 | disconnect_and_schedule_reconnect (h); | 425 | disconnect_and_schedule_reconnect(h); |
430 | return; | 426 | return; |
431 | } | 427 | } |
432 | n = GNUNET_new (struct Neighbour); | 428 | n = GNUNET_new(struct Neighbour); |
433 | n->id = cim->id; | 429 | n->id = cim->id; |
434 | n->h = h; | 430 | n->h = h; |
435 | n->ready_window = SEND_WINDOW_SIZE; | 431 | n->ready_window = SEND_WINDOW_SIZE; |
436 | GNUNET_assert (GNUNET_OK == | 432 | GNUNET_assert(GNUNET_OK == |
437 | GNUNET_CONTAINER_multipeermap_put ( | 433 | GNUNET_CONTAINER_multipeermap_put( |
438 | h->neighbours, | 434 | h->neighbours, |
439 | &n->id, | 435 | &n->id, |
440 | n, | 436 | n, |
441 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 437 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
442 | 438 | ||
443 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, | 439 | n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, |
444 | &mq_destroy_impl, | 440 | &mq_destroy_impl, |
445 | &mq_cancel_impl, | 441 | &mq_cancel_impl, |
446 | n, | 442 | n, |
447 | h->handlers, | 443 | h->handlers, |
448 | &peer_mq_error_handler, | 444 | &peer_mq_error_handler, |
449 | n); | 445 | n); |
450 | if (NULL != h->nc_cb) | 446 | if (NULL != h->nc_cb) |
451 | { | 447 | { |
452 | n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); | 448 | n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); |
453 | GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); | 449 | GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); |
454 | } | 450 | } |
455 | } | 451 | } |
456 | 452 | ||
457 | 453 | ||
@@ -462,23 +458,23 @@ handle_connect (void *cls, const struct ConnectInfoMessage *cim) | |||
462 | * @param dim message received | 458 | * @param dim message received |
463 | */ | 459 | */ |
464 | static void | 460 | static void |
465 | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) | 461 | handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) |
466 | { | 462 | { |
467 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 463 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
468 | struct Neighbour *n; | 464 | struct Neighbour *n; |
469 | 465 | ||
470 | GNUNET_break (ntohl (dim->reserved) == 0); | 466 | GNUNET_break(ntohl(dim->reserved) == 0); |
471 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 467 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
472 | "Receiving DISCONNECT message for `%s'.\n", | 468 | "Receiving DISCONNECT message for `%s'.\n", |
473 | GNUNET_i2s (&dim->peer)); | 469 | GNUNET_i2s(&dim->peer)); |
474 | n = neighbour_find (h, &dim->peer); | 470 | n = neighbour_find(h, &dim->peer); |
475 | if (NULL == n) | 471 | if (NULL == n) |
476 | { | 472 | { |
477 | GNUNET_break (0); | 473 | GNUNET_break(0); |
478 | disconnect_and_schedule_reconnect (h); | 474 | disconnect_and_schedule_reconnect(h); |
479 | return; | 475 | return; |
480 | } | 476 | } |
481 | GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); | 477 | GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); |
482 | } | 478 | } |
483 | 479 | ||
484 | 480 | ||
@@ -489,26 +485,26 @@ handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) | |||
489 | * @param okm message received | 485 | * @param okm message received |
490 | */ | 486 | */ |
491 | static void | 487 | static void |
492 | handle_send_ok (void *cls, const struct SendOkMessage *okm) | 488 | handle_send_ok(void *cls, const struct SendOkMessage *okm) |
493 | { | 489 | { |
494 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 490 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
495 | struct Neighbour *n; | 491 | struct Neighbour *n; |
496 | 492 | ||
497 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 493 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
498 | "Receiving SEND_OK message for transmission to %s\n", | 494 | "Receiving SEND_OK message for transmission to %s\n", |
499 | GNUNET_i2s (&okm->peer)); | 495 | GNUNET_i2s(&okm->peer)); |
500 | n = neighbour_find (h, &okm->peer); | 496 | n = neighbour_find(h, &okm->peer); |
501 | if (NULL == n) | 497 | if (NULL == n) |
502 | { | 498 | { |
503 | /* We should never get a 'SEND_OK' for a peer that we are not | 499 | /* We should never get a 'SEND_OK' for a peer that we are not |
504 | connected to */ | 500 | connected to */ |
505 | GNUNET_break (0); | 501 | GNUNET_break(0); |
506 | disconnect_and_schedule_reconnect (h); | 502 | disconnect_and_schedule_reconnect(h); |
507 | return; | 503 | return; |
508 | } | 504 | } |
509 | n->ready_window++; | 505 | n->ready_window++; |
510 | if ((NULL != n->env) && (1 == n->ready_window)) | 506 | if ((NULL != n->env) && (1 == n->ready_window)) |
511 | do_send (n); | 507 | do_send(n); |
512 | } | 508 | } |
513 | 509 | ||
514 | 510 | ||
@@ -519,23 +515,23 @@ handle_send_ok (void *cls, const struct SendOkMessage *okm) | |||
519 | * @param im message received | 515 | * @param im message received |
520 | */ | 516 | */ |
521 | static int | 517 | static int |
522 | check_recv (void *cls, const struct InboundMessage *im) | 518 | check_recv(void *cls, const struct InboundMessage *im) |
523 | { | 519 | { |
524 | const struct GNUNET_MessageHeader *imm; | 520 | const struct GNUNET_MessageHeader *imm; |
525 | uint16_t size; | 521 | uint16_t size; |
526 | 522 | ||
527 | size = ntohs (im->header.size) - sizeof (*im); | 523 | size = ntohs(im->header.size) - sizeof(*im); |
528 | if (size < sizeof (struct GNUNET_MessageHeader)) | 524 | if (size < sizeof(struct GNUNET_MessageHeader)) |
529 | { | 525 | { |
530 | GNUNET_break (0); | 526 | GNUNET_break(0); |
531 | return GNUNET_SYSERR; | 527 | return GNUNET_SYSERR; |
532 | } | 528 | } |
533 | imm = (const struct GNUNET_MessageHeader *) &im[1]; | 529 | imm = (const struct GNUNET_MessageHeader *)&im[1]; |
534 | if (ntohs (imm->size) != size) | 530 | if (ntohs(imm->size) != size) |
535 | { | 531 | { |
536 | GNUNET_break (0); | 532 | GNUNET_break(0); |
537 | return GNUNET_SYSERR; | 533 | return GNUNET_SYSERR; |
538 | } | 534 | } |
539 | return GNUNET_OK; | 535 | return GNUNET_OK; |
540 | } | 536 | } |
541 | 537 | ||
@@ -547,26 +543,26 @@ check_recv (void *cls, const struct InboundMessage *im) | |||
547 | * @param im message received | 543 | * @param im message received |
548 | */ | 544 | */ |
549 | static void | 545 | static void |
550 | handle_recv (void *cls, const struct InboundMessage *im) | 546 | handle_recv(void *cls, const struct InboundMessage *im) |
551 | { | 547 | { |
552 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 548 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
553 | const struct GNUNET_MessageHeader *imm = | 549 | const struct GNUNET_MessageHeader *imm = |
554 | (const struct GNUNET_MessageHeader *) &im[1]; | 550 | (const struct GNUNET_MessageHeader *)&im[1]; |
555 | struct Neighbour *n; | 551 | struct Neighbour *n; |
556 | 552 | ||
557 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 553 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
558 | "Received message of type %u with %u bytes from `%s'.\n", | 554 | "Received message of type %u with %u bytes from `%s'.\n", |
559 | (unsigned int) ntohs (imm->type), | 555 | (unsigned int)ntohs(imm->type), |
560 | (unsigned int) ntohs (imm->size), | 556 | (unsigned int)ntohs(imm->size), |
561 | GNUNET_i2s (&im->peer)); | 557 | GNUNET_i2s(&im->peer)); |
562 | n = neighbour_find (h, &im->peer); | 558 | n = neighbour_find(h, &im->peer); |
563 | if (NULL == n) | 559 | if (NULL == n) |
564 | { | 560 | { |
565 | GNUNET_break (0); | 561 | GNUNET_break(0); |
566 | disconnect_and_schedule_reconnect (h); | 562 | disconnect_and_schedule_reconnect(h); |
567 | return; | 563 | return; |
568 | } | 564 | } |
569 | GNUNET_MQ_inject_message (n->mq, imm); | 565 | GNUNET_MQ_inject_message(n->mq, imm); |
570 | } | 566 | } |
571 | 567 | ||
572 | 568 | ||
@@ -576,47 +572,47 @@ handle_recv (void *cls, const struct InboundMessage *im) | |||
576 | * @param cls the handle to the transport service | 572 | * @param cls the handle to the transport service |
577 | */ | 573 | */ |
578 | static void | 574 | static void |
579 | reconnect (void *cls) | 575 | reconnect(void *cls) |
580 | { | 576 | { |
581 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 577 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
582 | struct GNUNET_MQ_MessageHandler handlers[] = | 578 | struct GNUNET_MQ_MessageHandler handlers[] = |
583 | {GNUNET_MQ_hd_fixed_size (connect, | 579 | { GNUNET_MQ_hd_fixed_size(connect, |
584 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 580 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, |
585 | struct ConnectInfoMessage, | 581 | struct ConnectInfoMessage, |
586 | h), | 582 | h), |
587 | GNUNET_MQ_hd_fixed_size (disconnect, | 583 | GNUNET_MQ_hd_fixed_size(disconnect, |
588 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | 584 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, |
589 | struct DisconnectInfoMessage, | 585 | struct DisconnectInfoMessage, |
590 | h), | ||
591 | GNUNET_MQ_hd_fixed_size (send_ok, | ||
592 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | ||
593 | struct SendOkMessage, | ||
594 | h), | ||
595 | GNUNET_MQ_hd_var_size (recv, | ||
596 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | ||
597 | struct InboundMessage, | ||
598 | h), | 586 | h), |
599 | GNUNET_MQ_handler_end ()}; | 587 | GNUNET_MQ_hd_fixed_size(send_ok, |
588 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | ||
589 | struct SendOkMessage, | ||
590 | h), | ||
591 | GNUNET_MQ_hd_var_size(recv, | ||
592 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | ||
593 | struct InboundMessage, | ||
594 | h), | ||
595 | GNUNET_MQ_handler_end() }; | ||
600 | struct GNUNET_MQ_Envelope *env; | 596 | struct GNUNET_MQ_Envelope *env; |
601 | struct StartMessage *s; | 597 | struct StartMessage *s; |
602 | uint32_t options; | 598 | uint32_t options; |
603 | 599 | ||
604 | h->reconnect_task = NULL; | 600 | h->reconnect_task = NULL; |
605 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); | 601 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); |
606 | GNUNET_assert (NULL == h->mq); | 602 | GNUNET_assert(NULL == h->mq); |
607 | h->mq = | 603 | h->mq = |
608 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); | 604 | GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); |
609 | if (NULL == h->mq) | 605 | if (NULL == h->mq) |
610 | return; | 606 | return; |
611 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 607 | env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
612 | options = 0; | 608 | options = 0; |
613 | if (h->check_self) | 609 | if (h->check_self) |
614 | options |= 1; | 610 | options |= 1; |
615 | if (NULL != h->handlers) | 611 | if (NULL != h->handlers) |
616 | options |= 2; | 612 | options |= 2; |
617 | s->options = htonl (options); | 613 | s->options = htonl(options); |
618 | s->self = h->self; | 614 | s->self = h->self; |
619 | GNUNET_MQ_send (h->mq, env); | 615 | GNUNET_MQ_send(h->mq, env); |
620 | } | 616 | } |
621 | 617 | ||
622 | 618 | ||
@@ -626,14 +622,14 @@ reconnect (void *cls) | |||
626 | * @param h transport service to reconnect | 622 | * @param h transport service to reconnect |
627 | */ | 623 | */ |
628 | static void | 624 | static void |
629 | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 625 | disconnect(struct GNUNET_TRANSPORT_CoreHandle *h) |
630 | { | 626 | { |
631 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); | 627 | GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); |
632 | if (NULL != h->mq) | 628 | if (NULL != h->mq) |
633 | { | 629 | { |
634 | GNUNET_MQ_destroy (h->mq); | 630 | GNUNET_MQ_destroy(h->mq); |
635 | h->mq = NULL; | 631 | h->mq = NULL; |
636 | } | 632 | } |
637 | } | 633 | } |
638 | 634 | ||
639 | 635 | ||
@@ -644,16 +640,16 @@ disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
644 | * @param h transport service to reconnect | 640 | * @param h transport service to reconnect |
645 | */ | 641 | */ |
646 | static void | 642 | static void |
647 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 643 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) |
648 | { | 644 | { |
649 | GNUNET_assert (NULL == h->reconnect_task); | 645 | GNUNET_assert(NULL == h->reconnect_task); |
650 | disconnect (h); | 646 | disconnect(h); |
651 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 647 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
652 | "Scheduling task to reconnect to transport service in %s.\n", | 648 | "Scheduling task to reconnect to transport service in %s.\n", |
653 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 649 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); |
654 | h->reconnect_task = | 650 | h->reconnect_task = |
655 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 651 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
656 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 652 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
657 | } | 653 | } |
658 | 654 | ||
659 | 655 | ||
@@ -665,12 +661,12 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
665 | * @return NULL if disconnected, otherwise message queue for @a peer | 661 | * @return NULL if disconnected, otherwise message queue for @a peer |
666 | */ | 662 | */ |
667 | struct GNUNET_MQ_Handle * | 663 | struct GNUNET_MQ_Handle * |
668 | GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | 664 | GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, |
669 | const struct GNUNET_PeerIdentity *peer) | 665 | const struct GNUNET_PeerIdentity *peer) |
670 | { | 666 | { |
671 | struct Neighbour *n; | 667 | struct Neighbour *n; |
672 | 668 | ||
673 | n = neighbour_find (handle, peer); | 669 | n = neighbour_find(handle, peer); |
674 | if (NULL == n) | 670 | if (NULL == n) |
675 | return NULL; | 671 | return NULL; |
676 | return n->mq; | 672 | return n->mq; |
@@ -698,21 +694,21 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
698 | * @param pid which peer was the message from that was fully processed by CORE | 694 | * @param pid which peer was the message from that was fully processed by CORE |
699 | */ | 695 | */ |
700 | void | 696 | void |
701 | GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, | 697 | GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, |
702 | const struct GNUNET_PeerIdentity *pid) | 698 | const struct GNUNET_PeerIdentity *pid) |
703 | { | 699 | { |
704 | struct GNUNET_MQ_Envelope *env; | 700 | struct GNUNET_MQ_Envelope *env; |
705 | struct RecvOkMessage *rok; | 701 | struct RecvOkMessage *rok; |
706 | 702 | ||
707 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 703 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
708 | "Message for %s finished CORE processing, sending RECV_OK.\n", | 704 | "Message for %s finished CORE processing, sending RECV_OK.\n", |
709 | GNUNET_i2s (pid)); | 705 | GNUNET_i2s(pid)); |
710 | if (NULL == ch->mq) | 706 | if (NULL == ch->mq) |
711 | return; | 707 | return; |
712 | env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); | 708 | env = GNUNET_MQ_msg(rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); |
713 | rok->increase_window_delta = htonl (1); | 709 | rok->increase_window_delta = htonl(1); |
714 | rok->peer = *pid; | 710 | rok->peer = *pid; |
715 | GNUNET_MQ_send (ch->mq, env); | 711 | GNUNET_MQ_send(ch->mq, env); |
716 | } | 712 | } |
717 | 713 | ||
718 | 714 | ||
@@ -730,46 +726,46 @@ GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, | |||
730 | * @return NULL on error | 726 | * @return NULL on error |
731 | */ | 727 | */ |
732 | struct GNUNET_TRANSPORT_CoreHandle * | 728 | struct GNUNET_TRANSPORT_CoreHandle * |
733 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 729 | GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
734 | const struct GNUNET_PeerIdentity *self, | 730 | const struct GNUNET_PeerIdentity *self, |
735 | const struct GNUNET_MQ_MessageHandler *handlers, | 731 | const struct GNUNET_MQ_MessageHandler *handlers, |
736 | void *cls, | 732 | void *cls, |
737 | GNUNET_TRANSPORT_NotifyConnect nc, | 733 | GNUNET_TRANSPORT_NotifyConnect nc, |
738 | GNUNET_TRANSPORT_NotifyDisconnect nd) | 734 | GNUNET_TRANSPORT_NotifyDisconnect nd) |
739 | { | 735 | { |
740 | struct GNUNET_TRANSPORT_CoreHandle *h; | 736 | struct GNUNET_TRANSPORT_CoreHandle *h; |
741 | unsigned int i; | 737 | unsigned int i; |
742 | 738 | ||
743 | h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); | 739 | h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); |
744 | if (NULL != self) | 740 | if (NULL != self) |
745 | { | 741 | { |
746 | h->self = *self; | 742 | h->self = *self; |
747 | h->check_self = GNUNET_YES; | 743 | h->check_self = GNUNET_YES; |
748 | } | 744 | } |
749 | h->cfg = cfg; | 745 | h->cfg = cfg; |
750 | h->cls = cls; | 746 | h->cls = cls; |
751 | h->nc_cb = nc; | 747 | h->nc_cb = nc; |
752 | h->nd_cb = nd; | 748 | h->nd_cb = nd; |
753 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 749 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
754 | if (NULL != handlers) | 750 | if (NULL != handlers) |
755 | { | 751 | { |
756 | for (i = 0; NULL != handlers[i].cb; i++) | 752 | for (i = 0; NULL != handlers[i].cb; i++) |
757 | ; | 753 | ; |
758 | h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); | 754 | h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); |
759 | GNUNET_memcpy (h->handlers, | 755 | GNUNET_memcpy(h->handlers, |
760 | handlers, | 756 | handlers, |
761 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | 757 | i * sizeof(struct GNUNET_MQ_MessageHandler)); |
762 | } | 758 | } |
763 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); | 759 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); |
764 | reconnect (h); | 760 | reconnect(h); |
765 | if (NULL == h->mq) | 761 | if (NULL == h->mq) |
766 | { | 762 | { |
767 | GNUNET_free_non_null (h->handlers); | 763 | GNUNET_free_non_null(h->handlers); |
768 | GNUNET_free (h); | 764 | GNUNET_free(h); |
769 | return NULL; | 765 | return NULL; |
770 | } | 766 | } |
771 | h->neighbours = | 767 | h->neighbours = |
772 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); | 768 | GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); |
773 | return h; | 769 | return h; |
774 | } | 770 | } |
775 | 771 | ||
@@ -781,22 +777,22 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
781 | * #GNUNET_TRANSPORT_core_connect() | 777 | * #GNUNET_TRANSPORT_core_connect() |
782 | */ | 778 | */ |
783 | void | 779 | void |
784 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | 780 | GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) |
785 | { | 781 | { |
786 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); | 782 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
787 | /* this disconnects all neighbours... */ | 783 | /* this disconnects all neighbours... */ |
788 | disconnect (handle); | 784 | disconnect(handle); |
789 | /* and now we stop trying to connect again... */ | 785 | /* and now we stop trying to connect again... */ |
790 | if (NULL != handle->reconnect_task) | 786 | if (NULL != handle->reconnect_task) |
791 | { | 787 | { |
792 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 788 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); |
793 | handle->reconnect_task = NULL; | 789 | handle->reconnect_task = NULL; |
794 | } | 790 | } |
795 | GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); | 791 | GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); |
796 | handle->neighbours = NULL; | 792 | handle->neighbours = NULL; |
797 | GNUNET_free_non_null (handle->handlers); | 793 | GNUNET_free_non_null(handle->handlers); |
798 | handle->handlers = NULL; | 794 | handle->handlers = NULL; |
799 | GNUNET_free (handle); | 795 | GNUNET_free(handle); |
800 | } | 796 | } |
801 | 797 | ||
802 | 798 | ||