diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-07 09:29:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-07 09:29:33 +0000 |
commit | 50ada5687201159d94ff49c6961df8ffe527f6bc (patch) | |
tree | 892bbb22ba512403dc6d9934a4dbeece3a53be3e /src/transport/gnunet-service-transport_neighbours.c | |
parent | 91f7d85580d5f763f276e8d43bc40e958685c640 (diff) | |
download | gnunet-50ada5687201159d94ff49c6961df8ffe527f6bc.tar.gz gnunet-50ada5687201159d94ff49c6961df8ffe527f6bc.zip |
more neighbours code
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours.c')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours.c | 113 |
1 files changed, 42 insertions, 71 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index d915261ec..6f6b366c2 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c | |||
@@ -397,76 +397,6 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) | |||
397 | 397 | ||
398 | 398 | ||
399 | /** | 399 | /** |
400 | * Send the specified message to the specified peer. | ||
401 | * | ||
402 | * @param client source of the transmission request (can be NULL) | ||
403 | * @param peer_address ForeignAddressList where we should send this message | ||
404 | * @param priority how important is the message | ||
405 | * @param timeout how long do we have to transmit? | ||
406 | * @param message_buf message(s) to send GNUNET_MessageHeader(s) | ||
407 | * @param message_buf_size total size of all messages in message_buf | ||
408 | * @param is_internal is this an internal message; these are pre-pended and | ||
409 | * also do not count for plugins being "ready" to transmit | ||
410 | * @param neighbour handle to the neighbour for transmission | ||
411 | */ | ||
412 | static void | ||
413 | transmit_to_peer (struct TransportClient *client, | ||
414 | struct ForeignAddressList *peer_address, | ||
415 | unsigned int priority, | ||
416 | struct GNUNET_TIME_Relative timeout, | ||
417 | const char *message_buf, | ||
418 | size_t message_buf_size, | ||
419 | int is_internal, struct NeighbourMapEntry *neighbour) | ||
420 | { | ||
421 | struct MessageQueue *mq; | ||
422 | |||
423 | #if EXTRA_CHECKS | ||
424 | if (client != NULL) | ||
425 | { | ||
426 | /* check for duplicate submission */ | ||
427 | mq = neighbour->messages_head; | ||
428 | while (NULL != mq) | ||
429 | { | ||
430 | if (mq->client == client) | ||
431 | { | ||
432 | /* client transmitted to same peer twice | ||
433 | before getting SEND_OK! */ | ||
434 | GNUNET_break (0); | ||
435 | return; | ||
436 | } | ||
437 | mq = mq->next; | ||
438 | } | ||
439 | } | ||
440 | #endif | ||
441 | GNUNET_STATISTICS_update (stats, | ||
442 | gettext_noop ("# bytes in message queue for other peers"), | ||
443 | message_buf_size, | ||
444 | GNUNET_NO); | ||
445 | mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size); | ||
446 | mq->specific_address = peer_address; | ||
447 | mq->client = client; | ||
448 | /* FIXME: this memcpy can be up to 7% of our total runtime! */ | ||
449 | memcpy (&mq[1], message_buf, message_buf_size); | ||
450 | mq->message_buf = (const char*) &mq[1]; | ||
451 | mq->message_buf_size = message_buf_size; | ||
452 | memcpy(&mq->neighbour_id, &neighbour->id, sizeof(struct GNUNET_PeerIdentity)); | ||
453 | mq->internal_msg = is_internal; | ||
454 | mq->priority = priority; | ||
455 | mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
456 | if (is_internal) | ||
457 | GNUNET_CONTAINER_DLL_insert (neighbour->messages_head, | ||
458 | neighbour->messages_tail, | ||
459 | mq); | ||
460 | else | ||
461 | GNUNET_CONTAINER_DLL_insert_after (neighbour->messages_head, | ||
462 | neighbour->messages_tail, | ||
463 | neighbour->messages_tail, | ||
464 | mq); | ||
465 | try_transmission_to_peer (neighbour); | ||
466 | } | ||
467 | |||
468 | |||
469 | /** | ||
470 | * Create a fresh entry in our neighbour list for the given peer. | 400 | * Create a fresh entry in our neighbour list for the given peer. |
471 | * Will try to transmit our current HELLO to the new neighbour. | 401 | * Will try to transmit our current HELLO to the new neighbour. |
472 | * Do not call this function directly, use 'setup_peer_check_blacklist. | 402 | * Do not call this function directly, use 'setup_peer_check_blacklist. |
@@ -670,7 +600,13 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target) | |||
670 | int | 600 | int |
671 | GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) | 601 | GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) |
672 | { | 602 | { |
673 | return GNUNET_NO; | 603 | struct NeighbourMapEntry *n; |
604 | |||
605 | n = lookup_neighbour (target); | ||
606 | if ( (NULL == n) || | ||
607 | (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value == 0) ) | ||
608 | return GNUNET_NO; /* not connected */ | ||
609 | return GNUNET_YES; | ||
674 | } | 610 | } |
675 | 611 | ||
676 | 612 | ||
@@ -679,15 +615,50 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) | |||
679 | * | 615 | * |
680 | * @param target destination | 616 | * @param target destination |
681 | * @param msg message to send | 617 | * @param msg message to send |
618 | * @param timeout when to fail with timeout | ||
682 | * @param cont function to call when done | 619 | * @param cont function to call when done |
683 | * @param cont_cls closure for 'cont' | 620 | * @param cont_cls closure for 'cont' |
684 | */ | 621 | */ |
685 | void | 622 | void |
686 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, | 623 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, |
687 | const struct GNUNET_MessageHeader *msg, | 624 | const struct GNUNET_MessageHeader *msg, |
625 | struct GNUNET_TIME_Relative timeout, | ||
688 | GST_NeighbourSendContinuation cont, | 626 | GST_NeighbourSendContinuation cont, |
689 | void *cont_cls) | 627 | void *cont_cls) |
690 | { | 628 | { |
629 | struct NeighbourMapEntry *n; | ||
630 | struct MessageQueue *mq; | ||
631 | uint16_t message_buf_size; | ||
632 | |||
633 | n = lookup_neighbour (target); | ||
634 | if ( (n == NULL) || | ||
635 | (GNUNET_TIME_absolute_get_remaining (n->peer_timeout).rel_value == 0) ) | ||
636 | { | ||
637 | GNUNET_STATISTICS_update (GST_stats, | ||
638 | gettext_noop ("# SET QUOTA messages ignored (no such peer)"), | ||
639 | 1, | ||
640 | GNUNET_NO); | ||
641 | if (NULL != cont) | ||
642 | cont (cont_cls, | ||
643 | GNUNET_SYSERR); | ||
644 | return; | ||
645 | } | ||
646 | message_buf_size = ntohs (msg->size); | ||
647 | GNUNET_assert (message_buf_size >= sizeof (struct GNUNET_MessageHeader)); | ||
648 | GNUNET_STATISTICS_update (GST_stats, | ||
649 | gettext_noop ("# bytes in message queue for other peers"), | ||
650 | message_buf_size, | ||
651 | GNUNET_NO); | ||
652 | mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size); | ||
653 | /* FIXME: this memcpy can be up to 7% of our total runtime! */ | ||
654 | memcpy (&mq[1], msg, message_buf_size); | ||
655 | mq->message_buf = (const char*) &mq[1]; | ||
656 | mq->message_buf_size = message_buf_size; | ||
657 | mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
658 | GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, | ||
659 | n->messages_tail, | ||
660 | mq); | ||
661 | // try_transmission_to_peer (n); | ||
691 | } | 662 | } |
692 | 663 | ||
693 | 664 | ||