diff options
Diffstat (limited to 'src/transport/transport_api_core.c')
-rw-r--r-- | src/transport/transport_api_core.c | 603 |
1 files changed, 300 insertions, 303 deletions
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c index 224af5de2..d88461d5a 100644 --- a/src/transport/transport_api_core.c +++ b/src/transport/transport_api_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_service.h" | 32 | #include "gnunet_transport_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 | * If we could not send any payload to a peer for this amount of | 38 | * If we could not send any payload to a peer for this amount of |
@@ -49,8 +49,7 @@ | |||
49 | /** | 49 | /** |
50 | * Entry in hash table of all of our current (connected) neighbours. | 50 | * Entry in hash table of all of our current (connected) neighbours. |
51 | */ | 51 | */ |
52 | struct Neighbour | 52 | struct Neighbour { |
53 | { | ||
54 | /** | 53 | /** |
55 | * Overall transport handle. | 54 | * Overall transport handle. |
56 | */ | 55 | */ |
@@ -119,9 +118,7 @@ struct Neighbour | |||
119 | * Handle for the transport service (includes all of the | 118 | * Handle for the transport service (includes all of the |
120 | * state for the transport service). | 119 | * state for the transport service). |
121 | */ | 120 | */ |
122 | struct GNUNET_TRANSPORT_CoreHandle | 121 | struct GNUNET_TRANSPORT_CoreHandle { |
123 | { | ||
124 | |||
125 | /** | 122 | /** |
126 | * Closure for the callbacks. | 123 | * Closure for the callbacks. |
127 | */ | 124 | */ |
@@ -203,7 +200,7 @@ struct GNUNET_TRANSPORT_CoreHandle | |||
203 | * @param h transport service to reconnect | 200 | * @param h transport service to reconnect |
204 | */ | 201 | */ |
205 | static void | 202 | static void |
206 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); | 203 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h); |
207 | 204 | ||
208 | 205 | ||
209 | /** | 206 | /** |
@@ -214,10 +211,10 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); | |||
214 | * @return NULL if no such peer entry exists | 211 | * @return NULL if no such peer entry exists |
215 | */ | 212 | */ |
216 | static struct Neighbour * | 213 | static struct Neighbour * |
217 | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | 214 | neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, |
218 | const struct GNUNET_PeerIdentity *peer) | 215 | const struct GNUNET_PeerIdentity *peer) |
219 | { | 216 | { |
220 | return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); | 217 | return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer); |
221 | } | 218 | } |
222 | 219 | ||
223 | 220 | ||
@@ -228,17 +225,17 @@ neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, | |||
228 | * @param cls the `struct Neighbour` that has excess bandwidth | 225 | * @param cls the `struct Neighbour` that has excess bandwidth |
229 | */ | 226 | */ |
230 | static void | 227 | static void |
231 | notify_excess_cb (void *cls) | 228 | notify_excess_cb(void *cls) |
232 | { | 229 | { |
233 | struct Neighbour *n = cls; | 230 | struct Neighbour *n = cls; |
234 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; | 231 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; |
235 | 232 | ||
236 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 233 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
237 | "Notifying CORE that more bandwidth is available for %s\n", | 234 | "Notifying CORE that more bandwidth is available for %s\n", |
238 | GNUNET_i2s (&n->id)); | 235 | GNUNET_i2s(&n->id)); |
239 | 236 | ||
240 | if (NULL != h->neb_cb) | 237 | if (NULL != h->neb_cb) |
241 | h->neb_cb (h->cls, &n->id, n->handlers_cls); | 238 | h->neb_cb(h->cls, &n->id, n->handlers_cls); |
242 | } | 239 | } |
243 | 240 | ||
244 | 241 | ||
@@ -253,33 +250,33 @@ notify_excess_cb (void *cls) | |||
253 | * #GNUNET_NO if not. | 250 | * #GNUNET_NO if not. |
254 | */ | 251 | */ |
255 | static int | 252 | static int |
256 | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 253 | neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
257 | { | 254 | { |
258 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; | 255 | struct GNUNET_TRANSPORT_CoreHandle *handle = cls; |
259 | struct Neighbour *n = value; | 256 | struct Neighbour *n = value; |
260 | 257 | ||
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 258 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
262 | "Dropping entry for neighbour `%s'.\n", | 259 | "Dropping entry for neighbour `%s'.\n", |
263 | GNUNET_i2s (key)); | 260 | GNUNET_i2s(key)); |
264 | GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); | 261 | GNUNET_BANDWIDTH_tracker_notification_stop(&n->out_tracker); |
265 | if (NULL != handle->nd_cb) | 262 | if (NULL != handle->nd_cb) |
266 | handle->nd_cb (handle->cls, &n->id, n->handlers_cls); | 263 | handle->nd_cb(handle->cls, &n->id, n->handlers_cls); |
267 | if (NULL != n->timeout_task) | 264 | if (NULL != n->timeout_task) |
268 | { | 265 | { |
269 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 266 | GNUNET_SCHEDULER_cancel(n->timeout_task); |
270 | n->timeout_task = NULL; | 267 | n->timeout_task = NULL; |
271 | } | 268 | } |
272 | if (NULL != n->env) | 269 | if (NULL != n->env) |
273 | { | 270 | { |
274 | GNUNET_MQ_send_cancel (n->env); | 271 | GNUNET_MQ_send_cancel(n->env); |
275 | n->env = NULL; | 272 | n->env = NULL; |
276 | } | 273 | } |
277 | GNUNET_MQ_destroy (n->mq); | 274 | GNUNET_MQ_destroy(n->mq); |
278 | GNUNET_assert (NULL == n->mq); | 275 | GNUNET_assert(NULL == n->mq); |
279 | GNUNET_assert ( | 276 | GNUNET_assert( |
280 | GNUNET_YES == | 277 | GNUNET_YES == |
281 | GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); | 278 | GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n)); |
282 | GNUNET_free (n); | 279 | GNUNET_free(n); |
283 | return GNUNET_YES; | 280 | return GNUNET_YES; |
284 | } | 281 | } |
285 | 282 | ||
@@ -294,14 +291,14 @@ neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
294 | * @param error error code | 291 | * @param error error code |
295 | */ | 292 | */ |
296 | static void | 293 | static void |
297 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 294 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
298 | { | 295 | { |
299 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 296 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
300 | 297 | ||
301 | LOG (GNUNET_ERROR_TYPE_ERROR, | 298 | LOG(GNUNET_ERROR_TYPE_ERROR, |
302 | "Error receiving from transport service (%d), disconnecting temporarily.\n", | 299 | "Error receiving from transport service (%d), disconnecting temporarily.\n", |
303 | error); | 300 | error); |
304 | disconnect_and_schedule_reconnect (h); | 301 | disconnect_and_schedule_reconnect(h); |
305 | } | 302 | } |
306 | 303 | ||
307 | 304 | ||
@@ -313,16 +310,16 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
313 | * @return #GNUNET_OK if message is well-formed | 310 | * @return #GNUNET_OK if message is well-formed |
314 | */ | 311 | */ |
315 | static int | 312 | static int |
316 | check_hello (void *cls, const struct GNUNET_MessageHeader *msg) | 313 | check_hello(void *cls, const struct GNUNET_MessageHeader *msg) |
317 | { | 314 | { |
318 | struct GNUNET_PeerIdentity me; | 315 | struct GNUNET_PeerIdentity me; |
319 | 316 | ||
320 | if (GNUNET_OK != | 317 | if (GNUNET_OK != |
321 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me)) | 318 | GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, &me)) |
322 | { | 319 | { |
323 | GNUNET_break (0); | 320 | GNUNET_break(0); |
324 | return GNUNET_SYSERR; | 321 | return GNUNET_SYSERR; |
325 | } | 322 | } |
326 | return GNUNET_OK; | 323 | return GNUNET_OK; |
327 | } | 324 | } |
328 | 325 | ||
@@ -334,7 +331,7 @@ check_hello (void *cls, const struct GNUNET_MessageHeader *msg) | |||
334 | * @param msg message received | 331 | * @param msg message received |
335 | */ | 332 | */ |
336 | static void | 333 | static void |
337 | handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) | 334 | handle_hello(void *cls, const struct GNUNET_MessageHeader *msg) |
338 | { | 335 | { |
339 | /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ | 336 | /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ |
340 | } | 337 | } |
@@ -349,13 +346,13 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) | |||
349 | * @param cls the `struct Neighbour` where the message was sent | 346 | * @param cls the `struct Neighbour` where the message was sent |
350 | */ | 347 | */ |
351 | static void | 348 | static void |
352 | notify_send_done_fin (void *cls) | 349 | notify_send_done_fin(void *cls) |
353 | { | 350 | { |
354 | struct Neighbour *n = cls; | 351 | struct Neighbour *n = cls; |
355 | 352 | ||
356 | n->timeout_task = NULL; | 353 | n->timeout_task = NULL; |
357 | n->is_ready = GNUNET_YES; | 354 | n->is_ready = GNUNET_YES; |
358 | GNUNET_MQ_impl_send_continue (n->mq); | 355 | GNUNET_MQ_impl_send_continue(n->mq); |
359 | } | 356 | } |
360 | 357 | ||
361 | 358 | ||
@@ -368,31 +365,31 @@ notify_send_done_fin (void *cls) | |||
368 | * @param cls the `struct Neighbour` where the message was sent | 365 | * @param cls the `struct Neighbour` where the message was sent |
369 | */ | 366 | */ |
370 | static void | 367 | static void |
371 | notify_send_done (void *cls) | 368 | notify_send_done(void *cls) |
372 | { | 369 | { |
373 | struct Neighbour *n = cls; | 370 | struct Neighbour *n = cls; |
374 | struct GNUNET_TIME_Relative delay; | 371 | struct GNUNET_TIME_Relative delay; |
375 | 372 | ||
376 | n->timeout_task = NULL; | 373 | n->timeout_task = NULL; |
377 | if (NULL != n->env) | 374 | if (NULL != n->env) |
378 | { | 375 | { |
379 | GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, | 376 | GNUNET_BANDWIDTH_tracker_consume(&n->out_tracker, |
380 | n->env_size + n->traffic_overhead); | 377 | n->env_size + n->traffic_overhead); |
381 | n->env = NULL; | 378 | n->env = NULL; |
382 | n->traffic_overhead = 0; | 379 | n->traffic_overhead = 0; |
383 | } | 380 | } |
384 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); | 381 | delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); |
385 | if (0 == delay.rel_value_us) | 382 | if (0 == delay.rel_value_us) |
386 | { | 383 | { |
387 | n->is_ready = GNUNET_YES; | 384 | n->is_ready = GNUNET_YES; |
388 | GNUNET_MQ_impl_send_continue (n->mq); | 385 | GNUNET_MQ_impl_send_continue(n->mq); |
389 | return; | 386 | return; |
390 | } | 387 | } |
391 | GNUNET_MQ_impl_send_in_flight (n->mq); | 388 | GNUNET_MQ_impl_send_in_flight(n->mq); |
392 | /* cannot send even a small message without violating | 389 | /* cannot send even a small message without violating |
393 | quota, wait a before allowing MQ to send next message */ | 390 | quota, wait a before allowing MQ to send next message */ |
394 | n->timeout_task = | 391 | n->timeout_task = |
395 | GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done_fin, n); | 392 | GNUNET_SCHEDULER_add_delayed(delay, ¬ify_send_done_fin, n); |
396 | } | 393 | } |
397 | 394 | ||
398 | 395 | ||
@@ -407,44 +404,44 @@ notify_send_done (void *cls) | |||
407 | * @param impl_state state of the implementation | 404 | * @param impl_state state of the implementation |
408 | */ | 405 | */ |
409 | static void | 406 | static void |
410 | mq_send_impl (struct GNUNET_MQ_Handle *mq, | 407 | mq_send_impl(struct GNUNET_MQ_Handle *mq, |
411 | const struct GNUNET_MessageHeader *msg, | 408 | const struct GNUNET_MessageHeader *msg, |
412 | void *impl_state) | 409 | void *impl_state) |
413 | { | 410 | { |
414 | struct Neighbour *n = impl_state; | 411 | struct Neighbour *n = impl_state; |
415 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; | 412 | struct GNUNET_TRANSPORT_CoreHandle *h = n->h; |
416 | struct OutboundMessage *obm; | 413 | struct OutboundMessage *obm; |
417 | uint16_t msize; | 414 | uint16_t msize; |
418 | 415 | ||
419 | GNUNET_assert (GNUNET_YES == n->is_ready); | 416 | GNUNET_assert(GNUNET_YES == n->is_ready); |
420 | msize = ntohs (msg->size); | 417 | msize = ntohs(msg->size); |
421 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) | 418 | if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm)) |
422 | { | 419 | { |
423 | GNUNET_break (0); | 420 | GNUNET_break(0); |
424 | GNUNET_MQ_impl_send_continue (mq); | 421 | GNUNET_MQ_impl_send_continue(mq); |
425 | return; | 422 | return; |
426 | } | 423 | } |
427 | GNUNET_assert (NULL == n->env); | 424 | GNUNET_assert(NULL == n->env); |
428 | n->env = | 425 | n->env = |
429 | GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); | 426 | GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); |
430 | { | 427 | { |
431 | struct GNUNET_MQ_Envelope *env; | 428 | struct GNUNET_MQ_Envelope *env; |
432 | 429 | ||
433 | env = GNUNET_MQ_get_current_envelope (mq); | 430 | env = GNUNET_MQ_get_current_envelope(mq); |
434 | obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); | 431 | obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env)); |
435 | } | 432 | } |
436 | obm->timeout = GNUNET_TIME_relative_hton ( | 433 | obm->timeout = GNUNET_TIME_relative_hton( |
437 | GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ | 434 | GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ |
438 | obm->peer = n->id; | 435 | obm->peer = n->id; |
439 | GNUNET_assert (NULL == n->timeout_task); | 436 | GNUNET_assert(NULL == n->timeout_task); |
440 | n->is_ready = GNUNET_NO; | 437 | n->is_ready = GNUNET_NO; |
441 | n->env_size = ntohs (msg->size); | 438 | n->env_size = ntohs(msg->size); |
442 | GNUNET_MQ_notify_sent (n->env, ¬ify_send_done, n); | 439 | GNUNET_MQ_notify_sent(n->env, ¬ify_send_done, n); |
443 | GNUNET_MQ_send (h->mq, n->env); | 440 | GNUNET_MQ_send(h->mq, n->env); |
444 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 441 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
445 | "Queued message of type %u for neighbour `%s'.\n", | 442 | "Queued message of type %u for neighbour `%s'.\n", |
446 | ntohs (msg->type), | 443 | ntohs(msg->type), |
447 | GNUNET_i2s (&n->id)); | 444 | GNUNET_i2s(&n->id)); |
448 | } | 445 | } |
449 | 446 | ||
450 | 447 | ||
@@ -456,11 +453,11 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq, | |||
456 | * @param impl_state state of the implementation | 453 | * @param impl_state state of the implementation |
457 | */ | 454 | */ |
458 | static void | 455 | static void |
459 | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 456 | mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
460 | { | 457 | { |
461 | struct Neighbour *n = impl_state; | 458 | struct Neighbour *n = impl_state; |
462 | 459 | ||
463 | GNUNET_assert (mq == n->mq); | 460 | GNUNET_assert(mq == n->mq); |
464 | n->mq = NULL; | 461 | n->mq = NULL; |
465 | } | 462 | } |
466 | 463 | ||
@@ -473,16 +470,16 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
473 | * @param impl_state state specific to the implementation | 470 | * @param impl_state state specific to the implementation |
474 | */ | 471 | */ |
475 | static void | 472 | static void |
476 | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | 473 | mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state) |
477 | { | 474 | { |
478 | struct Neighbour *n = impl_state; | 475 | struct Neighbour *n = impl_state; |
479 | 476 | ||
480 | GNUNET_assert (GNUNET_NO == n->is_ready); | 477 | GNUNET_assert(GNUNET_NO == n->is_ready); |
481 | if (NULL != n->env) | 478 | if (NULL != n->env) |
482 | { | 479 | { |
483 | GNUNET_MQ_send_cancel (n->env); | 480 | GNUNET_MQ_send_cancel(n->env); |
484 | n->env = NULL; | 481 | n->env = NULL; |
485 | } | 482 | } |
486 | 483 | ||
487 | n->is_ready = GNUNET_YES; | 484 | n->is_ready = GNUNET_YES; |
488 | } | 485 | } |
@@ -497,11 +494,11 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
497 | * @param error error code | 494 | * @param error error code |
498 | */ | 495 | */ |
499 | static void | 496 | static void |
500 | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 497 | peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
501 | { | 498 | { |
502 | /* struct Neighbour *n = cls; */ | 499 | /* struct Neighbour *n = cls; */ |
503 | 500 | ||
504 | GNUNET_break_op (0); | 501 | GNUNET_break_op(0); |
505 | } | 502 | } |
506 | 503 | ||
507 | 504 | ||
@@ -512,16 +509,16 @@ peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
512 | * @param cls the `struct Neighbour` for which the timeout changed | 509 | * @param cls the `struct Neighbour` for which the timeout changed |
513 | */ | 510 | */ |
514 | static void | 511 | static void |
515 | outbound_bw_tracker_update (void *cls) | 512 | outbound_bw_tracker_update(void *cls) |
516 | { | 513 | { |
517 | struct Neighbour *n = cls; | 514 | struct Neighbour *n = cls; |
518 | struct GNUNET_TIME_Relative delay; | 515 | struct GNUNET_TIME_Relative delay; |
519 | 516 | ||
520 | if (NULL == n->timeout_task) | 517 | if (NULL == n->timeout_task) |
521 | return; | 518 | return; |
522 | delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); | 519 | delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128); |
523 | GNUNET_SCHEDULER_cancel (n->timeout_task); | 520 | GNUNET_SCHEDULER_cancel(n->timeout_task); |
524 | n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, ¬ify_send_done, n); | 521 | n->timeout_task = GNUNET_SCHEDULER_add_delayed(delay, ¬ify_send_done, n); |
525 | } | 522 | } |
526 | 523 | ||
527 | 524 | ||
@@ -532,54 +529,54 @@ outbound_bw_tracker_update (void *cls) | |||
532 | * @param cim message received | 529 | * @param cim message received |
533 | */ | 530 | */ |
534 | static void | 531 | static void |
535 | handle_connect (void *cls, const struct ConnectInfoMessage *cim) | 532 | handle_connect(void *cls, const struct ConnectInfoMessage *cim) |
536 | { | 533 | { |
537 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 534 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
538 | struct Neighbour *n; | 535 | struct Neighbour *n; |
539 | 536 | ||
540 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 537 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
541 | "Receiving CONNECT message for `%s' with quota %u\n", | 538 | "Receiving CONNECT message for `%s' with quota %u\n", |
542 | GNUNET_i2s (&cim->id), | 539 | GNUNET_i2s(&cim->id), |
543 | ntohl (cim->quota_out.value__)); | 540 | ntohl(cim->quota_out.value__)); |
544 | n = neighbour_find (h, &cim->id); | 541 | n = neighbour_find(h, &cim->id); |
545 | if (NULL != n) | 542 | if (NULL != n) |
546 | { | 543 | { |
547 | GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */ | 544 | GNUNET_break(0); /* FIXME: this assertion seems to fail sometimes!? */ |
548 | disconnect_and_schedule_reconnect (h); | 545 | disconnect_and_schedule_reconnect(h); |
549 | return; | 546 | return; |
550 | } | 547 | } |
551 | n = GNUNET_new (struct Neighbour); | 548 | n = GNUNET_new(struct Neighbour); |
552 | n->id = cim->id; | 549 | n->id = cim->id; |
553 | n->h = h; | 550 | n->h = h; |
554 | n->is_ready = GNUNET_YES; | 551 | n->is_ready = GNUNET_YES; |
555 | n->traffic_overhead = 0; | 552 | n->traffic_overhead = 0; |
556 | GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker, | 553 | GNUNET_BANDWIDTH_tracker_init2(&n->out_tracker, |
557 | &outbound_bw_tracker_update, | 554 | &outbound_bw_tracker_update, |
558 | n, | 555 | n, |
559 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, | 556 | GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, |
560 | MAX_BANDWIDTH_CARRY_S, | 557 | MAX_BANDWIDTH_CARRY_S, |
561 | ¬ify_excess_cb, | 558 | ¬ify_excess_cb, |
562 | n); | 559 | n); |
563 | GNUNET_assert (GNUNET_OK == | 560 | GNUNET_assert(GNUNET_OK == |
564 | GNUNET_CONTAINER_multipeermap_put ( | 561 | GNUNET_CONTAINER_multipeermap_put( |
565 | h->neighbours, | 562 | h->neighbours, |
566 | &n->id, | 563 | &n->id, |
567 | n, | 564 | n, |
568 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 565 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
569 | 566 | ||
570 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); | 567 | GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, cim->quota_out); |
571 | n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, | 568 | n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl, |
572 | &mq_destroy_impl, | 569 | &mq_destroy_impl, |
573 | &mq_cancel_impl, | 570 | &mq_cancel_impl, |
574 | n, | 571 | n, |
575 | h->handlers, | 572 | h->handlers, |
576 | &peer_mq_error_handler, | 573 | &peer_mq_error_handler, |
577 | n); | 574 | n); |
578 | if (NULL != h->nc_cb) | 575 | if (NULL != h->nc_cb) |
579 | { | 576 | { |
580 | n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); | 577 | n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq); |
581 | GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); | 578 | GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls); |
582 | } | 579 | } |
583 | } | 580 | } |
584 | 581 | ||
585 | 582 | ||
@@ -590,23 +587,23 @@ handle_connect (void *cls, const struct ConnectInfoMessage *cim) | |||
590 | * @param dim message received | 587 | * @param dim message received |
591 | */ | 588 | */ |
592 | static void | 589 | static void |
593 | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) | 590 | handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim) |
594 | { | 591 | { |
595 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 592 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
596 | struct Neighbour *n; | 593 | struct Neighbour *n; |
597 | 594 | ||
598 | GNUNET_break (ntohl (dim->reserved) == 0); | 595 | GNUNET_break(ntohl(dim->reserved) == 0); |
599 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 596 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
600 | "Receiving DISCONNECT message for `%s'.\n", | 597 | "Receiving DISCONNECT message for `%s'.\n", |
601 | GNUNET_i2s (&dim->peer)); | 598 | GNUNET_i2s(&dim->peer)); |
602 | n = neighbour_find (h, &dim->peer); | 599 | n = neighbour_find(h, &dim->peer); |
603 | if (NULL == n) | 600 | if (NULL == n) |
604 | { | 601 | { |
605 | GNUNET_break (0); | 602 | GNUNET_break(0); |
606 | disconnect_and_schedule_reconnect (h); | 603 | disconnect_and_schedule_reconnect(h); |
607 | return; | 604 | return; |
608 | } | 605 | } |
609 | GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); | 606 | GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n)); |
610 | } | 607 | } |
611 | 608 | ||
612 | 609 | ||
@@ -617,36 +614,36 @@ handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) | |||
617 | * @param okm message received | 614 | * @param okm message received |
618 | */ | 615 | */ |
619 | static void | 616 | static void |
620 | handle_send_ok (void *cls, const struct SendOkMessage *okm) | 617 | handle_send_ok(void *cls, const struct SendOkMessage *okm) |
621 | { | 618 | { |
622 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 619 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
623 | struct Neighbour *n; | 620 | struct Neighbour *n; |
624 | uint32_t bytes_msg; | 621 | uint32_t bytes_msg; |
625 | uint32_t bytes_physical; | 622 | uint32_t bytes_physical; |
626 | 623 | ||
627 | bytes_msg = ntohl (okm->bytes_msg); | 624 | bytes_msg = ntohl(okm->bytes_msg); |
628 | bytes_physical = ntohl (okm->bytes_physical); | 625 | bytes_physical = ntohl(okm->bytes_physical); |
629 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 626 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
630 | "Receiving SEND_OK message, transmission to %s %s.\n", | 627 | "Receiving SEND_OK message, transmission to %s %s.\n", |
631 | GNUNET_i2s (&okm->peer), | 628 | GNUNET_i2s(&okm->peer), |
632 | ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); | 629 | ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed"); |
633 | n = neighbour_find (h, &okm->peer); | 630 | n = neighbour_find(h, &okm->peer); |
634 | if (NULL == n) | 631 | if (NULL == n) |
635 | { | 632 | { |
636 | /* We should never get a 'SEND_OK' for a peer that we are not | 633 | /* We should never get a 'SEND_OK' for a peer that we are not |
637 | connected to */ | 634 | connected to */ |
638 | GNUNET_break (0); | 635 | GNUNET_break(0); |
639 | disconnect_and_schedule_reconnect (h); | 636 | disconnect_and_schedule_reconnect(h); |
640 | return; | 637 | return; |
641 | } | 638 | } |
642 | if (bytes_physical > bytes_msg) | 639 | if (bytes_physical > bytes_msg) |
643 | { | 640 | { |
644 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 641 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
645 | "Overhead for %u byte message was %u\n", | 642 | "Overhead for %u byte message was %u\n", |
646 | bytes_msg, | 643 | bytes_msg, |
647 | bytes_physical - bytes_msg); | 644 | bytes_physical - bytes_msg); |
648 | n->traffic_overhead += bytes_physical - bytes_msg; | 645 | n->traffic_overhead += bytes_physical - bytes_msg; |
649 | } | 646 | } |
650 | } | 647 | } |
651 | 648 | ||
652 | 649 | ||
@@ -657,23 +654,23 @@ handle_send_ok (void *cls, const struct SendOkMessage *okm) | |||
657 | * @param im message received | 654 | * @param im message received |
658 | */ | 655 | */ |
659 | static int | 656 | static int |
660 | check_recv (void *cls, const struct InboundMessage *im) | 657 | check_recv(void *cls, const struct InboundMessage *im) |
661 | { | 658 | { |
662 | const struct GNUNET_MessageHeader *imm; | 659 | const struct GNUNET_MessageHeader *imm; |
663 | uint16_t size; | 660 | uint16_t size; |
664 | 661 | ||
665 | size = ntohs (im->header.size) - sizeof (*im); | 662 | size = ntohs(im->header.size) - sizeof(*im); |
666 | if (size < sizeof (struct GNUNET_MessageHeader)) | 663 | if (size < sizeof(struct GNUNET_MessageHeader)) |
667 | { | 664 | { |
668 | GNUNET_break (0); | 665 | GNUNET_break(0); |
669 | return GNUNET_SYSERR; | 666 | return GNUNET_SYSERR; |
670 | } | 667 | } |
671 | imm = (const struct GNUNET_MessageHeader *) &im[1]; | 668 | imm = (const struct GNUNET_MessageHeader *)&im[1]; |
672 | if (ntohs (imm->size) != size) | 669 | if (ntohs(imm->size) != size) |
673 | { | 670 | { |
674 | GNUNET_break (0); | 671 | GNUNET_break(0); |
675 | return GNUNET_SYSERR; | 672 | return GNUNET_SYSERR; |
676 | } | 673 | } |
677 | return GNUNET_OK; | 674 | return GNUNET_OK; |
678 | } | 675 | } |
679 | 676 | ||
@@ -685,27 +682,27 @@ check_recv (void *cls, const struct InboundMessage *im) | |||
685 | * @param im message received | 682 | * @param im message received |
686 | */ | 683 | */ |
687 | static void | 684 | static void |
688 | handle_recv (void *cls, const struct InboundMessage *im) | 685 | handle_recv(void *cls, const struct InboundMessage *im) |
689 | { | 686 | { |
690 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 687 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
691 | const struct GNUNET_MessageHeader *imm = | 688 | const struct GNUNET_MessageHeader *imm = |
692 | (const struct GNUNET_MessageHeader *) &im[1]; | 689 | (const struct GNUNET_MessageHeader *)&im[1]; |
693 | struct Neighbour *n; | 690 | struct Neighbour *n; |
694 | 691 | ||
695 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 692 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
696 | "Received message of type %u with %u bytes from `%s'.\n", | 693 | "Received message of type %u with %u bytes from `%s'.\n", |
697 | (unsigned int) ntohs (imm->type), | 694 | (unsigned int)ntohs(imm->type), |
698 | (unsigned int) ntohs (imm->size), | 695 | (unsigned int)ntohs(imm->size), |
699 | GNUNET_i2s (&im->peer)); | 696 | GNUNET_i2s(&im->peer)); |
700 | n = neighbour_find (h, &im->peer); | 697 | n = neighbour_find(h, &im->peer); |
701 | if (NULL == n) | 698 | if (NULL == n) |
702 | { | 699 | { |
703 | GNUNET_break (0); | 700 | GNUNET_break(0); |
704 | disconnect_and_schedule_reconnect (h); | 701 | disconnect_and_schedule_reconnect(h); |
705 | return; | 702 | return; |
706 | } | 703 | } |
707 | h->rom_pending++; | 704 | h->rom_pending++; |
708 | GNUNET_MQ_inject_message (n->mq, imm); | 705 | GNUNET_MQ_inject_message(n->mq, imm); |
709 | } | 706 | } |
710 | 707 | ||
711 | 708 | ||
@@ -716,24 +713,24 @@ handle_recv (void *cls, const struct InboundMessage *im) | |||
716 | * @param msg message received | 713 | * @param msg message received |
717 | */ | 714 | */ |
718 | static void | 715 | static void |
719 | handle_set_quota (void *cls, const struct QuotaSetMessage *qm) | 716 | handle_set_quota(void *cls, const struct QuotaSetMessage *qm) |
720 | { | 717 | { |
721 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 718 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
722 | struct Neighbour *n; | 719 | struct Neighbour *n; |
723 | 720 | ||
724 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 721 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
725 | "Receiving SET_QUOTA message for `%s' with quota %u\n", | 722 | "Receiving SET_QUOTA message for `%s' with quota %u\n", |
726 | GNUNET_i2s (&qm->peer), | 723 | GNUNET_i2s(&qm->peer), |
727 | ntohl (qm->quota.value__)); | 724 | ntohl(qm->quota.value__)); |
728 | n = neighbour_find (h, &qm->peer); | 725 | n = neighbour_find(h, &qm->peer); |
729 | if (NULL == n) | 726 | if (NULL == n) |
730 | { | 727 | { |
731 | GNUNET_break ( | 728 | GNUNET_break( |
732 | 0); /* FIXME: julius reports this assertion fails sometimes? */ | 729 | 0); /* FIXME: julius reports this assertion fails sometimes? */ |
733 | disconnect_and_schedule_reconnect (h); | 730 | disconnect_and_schedule_reconnect(h); |
734 | return; | 731 | return; |
735 | } | 732 | } |
736 | GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota); | 733 | GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, qm->quota); |
737 | } | 734 | } |
738 | 735 | ||
739 | 736 | ||
@@ -743,55 +740,55 @@ handle_set_quota (void *cls, const struct QuotaSetMessage *qm) | |||
743 | * @param cls the handle to the transport service | 740 | * @param cls the handle to the transport service |
744 | */ | 741 | */ |
745 | static void | 742 | static void |
746 | reconnect (void *cls) | 743 | reconnect(void *cls) |
747 | { | 744 | { |
748 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; | 745 | struct GNUNET_TRANSPORT_CoreHandle *h = cls; |
749 | struct GNUNET_MQ_MessageHandler handlers[] = | 746 | struct GNUNET_MQ_MessageHandler handlers[] = |
750 | {GNUNET_MQ_hd_var_size (hello, | 747 | { GNUNET_MQ_hd_var_size(hello, |
751 | GNUNET_MESSAGE_TYPE_HELLO, | 748 | GNUNET_MESSAGE_TYPE_HELLO, |
752 | struct GNUNET_MessageHeader, | 749 | struct GNUNET_MessageHeader, |
750 | h), | ||
751 | GNUNET_MQ_hd_fixed_size(connect, | ||
752 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | ||
753 | struct ConnectInfoMessage, | ||
754 | h), | ||
755 | GNUNET_MQ_hd_fixed_size(disconnect, | ||
756 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | ||
757 | struct DisconnectInfoMessage, | ||
753 | h), | 758 | h), |
754 | GNUNET_MQ_hd_fixed_size (connect, | 759 | GNUNET_MQ_hd_fixed_size(send_ok, |
755 | GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, | 760 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, |
756 | struct ConnectInfoMessage, | 761 | struct SendOkMessage, |
757 | h), | ||
758 | GNUNET_MQ_hd_fixed_size (disconnect, | ||
759 | GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, | ||
760 | struct DisconnectInfoMessage, | ||
761 | h), | ||
762 | GNUNET_MQ_hd_fixed_size (send_ok, | ||
763 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, | ||
764 | struct SendOkMessage, | ||
765 | h), | ||
766 | GNUNET_MQ_hd_var_size (recv, | ||
767 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, | ||
768 | struct InboundMessage, | ||
769 | h), | 762 | h), |
770 | GNUNET_MQ_hd_fixed_size (set_quota, | 763 | GNUNET_MQ_hd_var_size(recv, |
771 | GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, | 764 | GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, |
772 | struct QuotaSetMessage, | 765 | struct InboundMessage, |
773 | h), | 766 | h), |
774 | GNUNET_MQ_handler_end ()}; | 767 | GNUNET_MQ_hd_fixed_size(set_quota, |
768 | GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, | ||
769 | struct QuotaSetMessage, | ||
770 | h), | ||
771 | GNUNET_MQ_handler_end() }; | ||
775 | struct GNUNET_MQ_Envelope *env; | 772 | struct GNUNET_MQ_Envelope *env; |
776 | struct StartMessage *s; | 773 | struct StartMessage *s; |
777 | uint32_t options; | 774 | uint32_t options; |
778 | 775 | ||
779 | h->reconnect_task = NULL; | 776 | h->reconnect_task = NULL; |
780 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); | 777 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); |
781 | GNUNET_assert (NULL == h->mq); | 778 | GNUNET_assert(NULL == h->mq); |
782 | h->mq = | 779 | h->mq = |
783 | GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); | 780 | GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h); |
784 | if (NULL == h->mq) | 781 | if (NULL == h->mq) |
785 | return; | 782 | return; |
786 | env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 783 | env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
787 | options = 0; | 784 | options = 0; |
788 | if (h->check_self) | 785 | if (h->check_self) |
789 | options |= 1; | 786 | options |= 1; |
790 | if (NULL != h->handlers) | 787 | if (NULL != h->handlers) |
791 | options |= 2; | 788 | options |= 2; |
792 | s->options = htonl (options); | 789 | s->options = htonl(options); |
793 | s->self = h->self; | 790 | s->self = h->self; |
794 | GNUNET_MQ_send (h->mq, env); | 791 | GNUNET_MQ_send(h->mq, env); |
795 | } | 792 | } |
796 | 793 | ||
797 | 794 | ||
@@ -802,22 +799,22 @@ reconnect (void *cls) | |||
802 | * @param h transport service to reconnect | 799 | * @param h transport service to reconnect |
803 | */ | 800 | */ |
804 | static void | 801 | static void |
805 | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | 802 | disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h) |
806 | { | 803 | { |
807 | GNUNET_assert (NULL == h->reconnect_task); | 804 | GNUNET_assert(NULL == h->reconnect_task); |
808 | /* Forget about all neighbours that we used to be connected to */ | 805 | /* Forget about all neighbours that we used to be connected to */ |
809 | GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); | 806 | GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h); |
810 | if (NULL != h->mq) | 807 | if (NULL != h->mq) |
811 | { | 808 | { |
812 | GNUNET_MQ_destroy (h->mq); | 809 | GNUNET_MQ_destroy(h->mq); |
813 | h->mq = NULL; | 810 | h->mq = NULL; |
814 | } | 811 | } |
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 812 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
816 | "Scheduling task to reconnect to transport service in %s.\n", | 813 | "Scheduling task to reconnect to transport service in %s.\n", |
817 | GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); | 814 | GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES)); |
818 | h->reconnect_task = | 815 | h->reconnect_task = |
819 | GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); | 816 | GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h); |
820 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); | 817 | h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay); |
821 | } | 818 | } |
822 | 819 | ||
823 | 820 | ||
@@ -829,12 +826,12 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) | |||
829 | * @return NULL if disconnected, otherwise message queue for @a peer | 826 | * @return NULL if disconnected, otherwise message queue for @a peer |
830 | */ | 827 | */ |
831 | struct GNUNET_MQ_Handle * | 828 | struct GNUNET_MQ_Handle * |
832 | GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | 829 | GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, |
833 | const struct GNUNET_PeerIdentity *peer) | 830 | const struct GNUNET_PeerIdentity *peer) |
834 | { | 831 | { |
835 | struct Neighbour *n; | 832 | struct Neighbour *n; |
836 | 833 | ||
837 | n = neighbour_find (handle, peer); | 834 | n = neighbour_find(handle, peer); |
838 | if (NULL == n) | 835 | if (NULL == n) |
839 | return NULL; | 836 | return NULL; |
840 | return n->mq; | 837 | return n->mq; |
@@ -856,23 +853,23 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, | |||
856 | * @return NULL on error | 853 | * @return NULL on error |
857 | */ | 854 | */ |
858 | struct GNUNET_TRANSPORT_CoreHandle * | 855 | struct GNUNET_TRANSPORT_CoreHandle * |
859 | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 856 | GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, |
860 | const struct GNUNET_PeerIdentity *self, | 857 | const struct GNUNET_PeerIdentity *self, |
861 | const struct GNUNET_MQ_MessageHandler *handlers, | 858 | const struct GNUNET_MQ_MessageHandler *handlers, |
862 | void *cls, | 859 | void *cls, |
863 | GNUNET_TRANSPORT_NotifyConnect nc, | 860 | GNUNET_TRANSPORT_NotifyConnect nc, |
864 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 861 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
865 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) | 862 | GNUNET_TRANSPORT_NotifyExcessBandwidth neb) |
866 | { | 863 | { |
867 | struct GNUNET_TRANSPORT_CoreHandle *h; | 864 | struct GNUNET_TRANSPORT_CoreHandle *h; |
868 | unsigned int i; | 865 | unsigned int i; |
869 | 866 | ||
870 | h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); | 867 | h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle); |
871 | if (NULL != self) | 868 | if (NULL != self) |
872 | { | 869 | { |
873 | h->self = *self; | 870 | h->self = *self; |
874 | h->check_self = GNUNET_YES; | 871 | h->check_self = GNUNET_YES; |
875 | } | 872 | } |
876 | h->cfg = cfg; | 873 | h->cfg = cfg; |
877 | h->cls = cls; | 874 | h->cls = cls; |
878 | h->nc_cb = nc; | 875 | h->nc_cb = nc; |
@@ -880,24 +877,24 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
880 | h->neb_cb = neb; | 877 | h->neb_cb = neb; |
881 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; | 878 | h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; |
882 | if (NULL != handlers) | 879 | if (NULL != handlers) |
883 | { | 880 | { |
884 | for (i = 0; NULL != handlers[i].cb; i++) | 881 | for (i = 0; NULL != handlers[i].cb; i++) |
885 | ; | 882 | ; |
886 | h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); | 883 | h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler); |
887 | GNUNET_memcpy (h->handlers, | 884 | GNUNET_memcpy(h->handlers, |
888 | handlers, | 885 | handlers, |
889 | i * sizeof (struct GNUNET_MQ_MessageHandler)); | 886 | i * sizeof(struct GNUNET_MQ_MessageHandler)); |
890 | } | 887 | } |
891 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); | 888 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); |
892 | reconnect (h); | 889 | reconnect(h); |
893 | if (NULL == h->mq) | 890 | if (NULL == h->mq) |
894 | { | 891 | { |
895 | GNUNET_free_non_null (h->handlers); | 892 | GNUNET_free_non_null(h->handlers); |
896 | GNUNET_free (h); | 893 | GNUNET_free(h); |
897 | return NULL; | 894 | return NULL; |
898 | } | 895 | } |
899 | h->neighbours = | 896 | h->neighbours = |
900 | GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); | 897 | GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES); |
901 | return h; | 898 | return h; |
902 | } | 899 | } |
903 | 900 | ||
@@ -909,23 +906,23 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
909 | * #GNUNET_TRANSPORT_core_connect() | 906 | * #GNUNET_TRANSPORT_core_connect() |
910 | */ | 907 | */ |
911 | void | 908 | void |
912 | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | 909 | GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle) |
913 | { | 910 | { |
914 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); | 911 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); |
915 | /* this disconnects all neighbours... */ | 912 | /* this disconnects all neighbours... */ |
916 | if (NULL == handle->reconnect_task) | 913 | if (NULL == handle->reconnect_task) |
917 | disconnect_and_schedule_reconnect (handle); | 914 | disconnect_and_schedule_reconnect(handle); |
918 | /* and now we stop trying to connect again... */ | 915 | /* and now we stop trying to connect again... */ |
919 | if (NULL != handle->reconnect_task) | 916 | if (NULL != handle->reconnect_task) |
920 | { | 917 | { |
921 | GNUNET_SCHEDULER_cancel (handle->reconnect_task); | 918 | GNUNET_SCHEDULER_cancel(handle->reconnect_task); |
922 | handle->reconnect_task = NULL; | 919 | handle->reconnect_task = NULL; |
923 | } | 920 | } |
924 | GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); | 921 | GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours); |
925 | handle->neighbours = NULL; | 922 | handle->neighbours = NULL; |
926 | GNUNET_free_non_null (handle->handlers); | 923 | GNUNET_free_non_null(handle->handlers); |
927 | handle->handlers = NULL; | 924 | handle->handlers = NULL; |
928 | GNUNET_free (handle); | 925 | GNUNET_free(handle); |
929 | } | 926 | } |
930 | 927 | ||
931 | 928 | ||
@@ -950,18 +947,18 @@ GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) | |||
950 | * @param pid which peer was the message from that was fully processed by CORE | 947 | * @param pid which peer was the message from that was fully processed by CORE |
951 | */ | 948 | */ |
952 | void | 949 | void |
953 | GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, | 950 | GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch, |
954 | const struct GNUNET_PeerIdentity *pid) | 951 | const struct GNUNET_PeerIdentity *pid) |
955 | { | 952 | { |
956 | struct RecvOkMessage *rom; | 953 | struct RecvOkMessage *rom; |
957 | struct GNUNET_MQ_Envelope *env; | 954 | struct GNUNET_MQ_Envelope *env; |
958 | 955 | ||
959 | GNUNET_assert (ch->rom_pending > 0); | 956 | GNUNET_assert(ch->rom_pending > 0); |
960 | ch->rom_pending--; | 957 | ch->rom_pending--; |
961 | env = GNUNET_MQ_msg (rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); | 958 | env = GNUNET_MQ_msg(rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); |
962 | rom->increase_window_delta = htonl (1); | 959 | rom->increase_window_delta = htonl(1); |
963 | rom->peer = *pid; | 960 | rom->peer = *pid; |
964 | GNUNET_MQ_send (ch->mq, env); | 961 | GNUNET_MQ_send(ch->mq, env); |
965 | } | 962 | } |
966 | 963 | ||
967 | 964 | ||