diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-22 15:52:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-22 15:52:40 +0000 |
commit | 48436941449d867ef9a32ddf29439c5017d37775 (patch) | |
tree | a34b1230ba7e4d2e9deea743dcfdb283f7f7b605 /src | |
parent | 87487477c67697355c79d2fe079d23a5b31c7ab6 (diff) | |
download | gnunet-48436941449d867ef9a32ddf29439c5017d37775.tar.gz gnunet-48436941449d867ef9a32ddf29439c5017d37775.zip |
stuff
Diffstat (limited to 'src')
-rw-r--r-- | src/core/core_api.c | 66 | ||||
-rw-r--r-- | src/core/gnunet-service-core.c | 233 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs.c | 46 | ||||
-rw-r--r-- | src/include/gnunet_server_lib.h | 20 | ||||
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 17 | ||||
-rw-r--r-- | src/statistics/gnunet-service-statistics.c | 15 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 8 | ||||
-rw-r--r-- | src/util/gnunet-service-resolver.c | 48 | ||||
-rw-r--r-- | src/util/server_tc.c | 29 |
9 files changed, 159 insertions, 323 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c index e7e958bd7..a23313499 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c | |||
@@ -87,9 +87,14 @@ struct GNUNET_CORE_Handle | |||
87 | const struct GNUNET_CORE_MessageHandler *handlers; | 87 | const struct GNUNET_CORE_MessageHandler *handlers; |
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Our connection to the service. | 90 | * Our connection to the service for notifications. |
91 | */ | 91 | */ |
92 | struct GNUNET_CLIENT_Connection *client; | 92 | struct GNUNET_CLIENT_Connection *client_notifications; |
93 | |||
94 | /** | ||
95 | * Our connection to the service for normal requests. | ||
96 | */ | ||
97 | struct GNUNET_CLIENT_Connection *client_requests; | ||
93 | 98 | ||
94 | /** | 99 | /** |
95 | * Handle for our current transmission request. | 100 | * Handle for our current transmission request. |
@@ -263,10 +268,10 @@ static size_t transmit_start (void *cls, size_t size, void *buf); | |||
263 | static void | 268 | static void |
264 | reconnect (struct GNUNET_CORE_Handle *h) | 269 | reconnect (struct GNUNET_CORE_Handle *h) |
265 | { | 270 | { |
266 | GNUNET_CLIENT_disconnect (h->client); | 271 | GNUNET_CLIENT_disconnect (h->client_notifications); |
267 | h->currently_down = GNUNET_YES; | 272 | h->currently_down = GNUNET_YES; |
268 | h->client = GNUNET_CLIENT_connect (h->sched, "core", h->cfg); | 273 | h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg); |
269 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 274 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications, |
270 | sizeof (struct InitMessage) + | 275 | sizeof (struct InitMessage) + |
271 | sizeof (uint16_t) * h->hcnt, | 276 | sizeof (uint16_t) * h->hcnt, |
272 | GNUNET_TIME_UNIT_SECONDS, | 277 | GNUNET_TIME_UNIT_SECONDS, |
@@ -346,6 +351,7 @@ static void | |||
346 | trigger_next_request (struct GNUNET_CORE_Handle *h) | 351 | trigger_next_request (struct GNUNET_CORE_Handle *h) |
347 | { | 352 | { |
348 | struct GNUNET_CORE_TransmitHandle *th; | 353 | struct GNUNET_CORE_TransmitHandle *th; |
354 | |||
349 | if (h->currently_down) | 355 | if (h->currently_down) |
350 | return; /* connection temporarily down */ | 356 | return; /* connection temporarily down */ |
351 | if (NULL == (th = h->pending_head)) | 357 | if (NULL == (th = h->pending_head)) |
@@ -356,7 +362,7 @@ trigger_next_request (struct GNUNET_CORE_Handle *h) | |||
356 | GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task); | 362 | GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task); |
357 | th->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 363 | th->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
358 | } | 364 | } |
359 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, | 365 | h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_requests, |
360 | th->msize, | 366 | th->msize, |
361 | GNUNET_TIME_absolute_get_remaining | 367 | GNUNET_TIME_absolute_get_remaining |
362 | (th->timeout), | 368 | (th->timeout), |
@@ -367,20 +373,19 @@ trigger_next_request (struct GNUNET_CORE_Handle *h) | |||
367 | 373 | ||
368 | 374 | ||
369 | /** | 375 | /** |
370 | * Handler for most messages received from the core. | 376 | * Handler for notification messages received from the core. |
371 | * | 377 | * |
372 | * @param cls our "struct GNUNET_CORE_Handle" | 378 | * @param cls our "struct GNUNET_CORE_Handle" |
373 | * @param msg the message received from the core service | 379 | * @param msg the message received from the core service |
374 | */ | 380 | */ |
375 | static void | 381 | static void |
376 | main_handler (void *cls, const struct GNUNET_MessageHeader *msg) | 382 | main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg) |
377 | { | 383 | { |
378 | struct GNUNET_CORE_Handle *h = cls; | 384 | struct GNUNET_CORE_Handle *h = cls; |
379 | unsigned int hpos; | 385 | unsigned int hpos; |
380 | const struct ConnectNotifyMessage *cnm; | 386 | const struct ConnectNotifyMessage *cnm; |
381 | const struct DisconnectNotifyMessage *dnm; | 387 | const struct DisconnectNotifyMessage *dnm; |
382 | const struct NotifyTrafficMessage *ntm; | 388 | const struct NotifyTrafficMessage *ntm; |
383 | const struct ConfigurationInfoMessage *cim; | ||
384 | const struct GNUNET_MessageHeader *em; | 389 | const struct GNUNET_MessageHeader *em; |
385 | uint16_t msize; | 390 | uint16_t msize; |
386 | uint16_t et; | 391 | uint16_t et; |
@@ -524,38 +529,15 @@ main_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
524 | GNUNET_TIME_relative_ntoh (ntm->latency), | 529 | GNUNET_TIME_relative_ntoh (ntm->latency), |
525 | ntohl (ntm->distance)); | 530 | ntohl (ntm->distance)); |
526 | break; | 531 | break; |
527 | case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO: | ||
528 | if (msize != sizeof (struct ConfigurationInfoMessage)) | ||
529 | { | ||
530 | GNUNET_break (0); | ||
531 | break; | ||
532 | } | ||
533 | if (NULL == h->submitted) | ||
534 | break; | ||
535 | cim = (const struct ConfigurationInfoMessage *) msg; | ||
536 | |||
537 | /* process configuration data */ | ||
538 | if (h->submitted->info != NULL) | ||
539 | h->submitted->info (h->submitted->info_cls, | ||
540 | &h->submitted->peer, | ||
541 | ntohl (cim->bpm_in), | ||
542 | ntohl (cim->bpm_out), | ||
543 | (int) ntohl (cim->reserved_amount), | ||
544 | cim->preference); | ||
545 | /* done, clean up! */ | ||
546 | GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH? | ||
547 | trigger_next_request (h); | ||
548 | break; | ||
549 | default: | 532 | default: |
550 | GNUNET_break (0); | 533 | GNUNET_break (0); |
551 | break; | 534 | break; |
552 | } | 535 | } |
553 | GNUNET_CLIENT_receive (h->client, | 536 | GNUNET_CLIENT_receive (h->client_notifications, |
554 | &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); | 537 | &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); |
555 | } | 538 | } |
556 | 539 | ||
557 | 540 | ||
558 | |||
559 | /** | 541 | /** |
560 | * Function called when we are ready to transmit our | 542 | * Function called when we are ready to transmit our |
561 | * "START" message (or when this operation timed out). | 543 | * "START" message (or when this operation timed out). |
@@ -606,8 +588,8 @@ init_reply_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
606 | #endif | 588 | #endif |
607 | h->currently_down = GNUNET_NO; | 589 | h->currently_down = GNUNET_NO; |
608 | trigger_next_request (h); | 590 | trigger_next_request (h); |
609 | GNUNET_CLIENT_receive (h->client, | 591 | GNUNET_CLIENT_receive (h->client_notifications, |
610 | &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); | 592 | &main_notify_handler, h, GNUNET_TIME_UNIT_FOREVER_REL); |
611 | if (NULL != (init = h->init)) | 593 | if (NULL != (init = h->init)) |
612 | { | 594 | { |
613 | /* mark so we don't call init on reconnect */ | 595 | /* mark so we don't call init on reconnect */ |
@@ -710,7 +692,7 @@ transmit_start (void *cls, size_t size, void *buf) | |||
710 | ts = (uint16_t *) & init[1]; | 692 | ts = (uint16_t *) & init[1]; |
711 | for (hpos = 0; hpos < h->hcnt; hpos++) | 693 | for (hpos = 0; hpos < h->hcnt; hpos++) |
712 | ts[hpos] = htons (h->handlers[hpos].type); | 694 | ts[hpos] = htons (h->handlers[hpos].type); |
713 | GNUNET_CLIENT_receive (h->client, | 695 | GNUNET_CLIENT_receive (h->client_notifications, |
714 | &init_reply_handler, | 696 | &init_reply_handler, |
715 | h, | 697 | h, |
716 | GNUNET_TIME_absolute_get_remaining | 698 | GNUNET_TIME_absolute_get_remaining |
@@ -774,8 +756,8 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
774 | h->inbound_hdr_only = inbound_hdr_only; | 756 | h->inbound_hdr_only = inbound_hdr_only; |
775 | h->outbound_hdr_only = outbound_hdr_only; | 757 | h->outbound_hdr_only = outbound_hdr_only; |
776 | h->handlers = handlers; | 758 | h->handlers = handlers; |
777 | h->client = GNUNET_CLIENT_connect (sched, "core", cfg); | 759 | h->client_notifications = GNUNET_CLIENT_connect (sched, "core", cfg); |
778 | if (h->client == NULL) | 760 | if (h->client_notifications == NULL) |
779 | { | 761 | { |
780 | GNUNET_free (h); | 762 | GNUNET_free (h); |
781 | return NULL; | 763 | return NULL; |
@@ -793,7 +775,7 @@ GNUNET_CORE_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
793 | timeout.value); | 775 | timeout.value); |
794 | #endif | 776 | #endif |
795 | h->th = | 777 | h->th = |
796 | GNUNET_CLIENT_notify_transmit_ready (h->client, | 778 | GNUNET_CLIENT_notify_transmit_ready (h->client_notifications, |
797 | sizeof (struct InitMessage) + | 779 | sizeof (struct InitMessage) + |
798 | sizeof (uint16_t) * h->hcnt, timeout, | 780 | sizeof (uint16_t) * h->hcnt, timeout, |
799 | GNUNET_YES, | 781 | GNUNET_YES, |
@@ -816,7 +798,9 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) | |||
816 | GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req); | 798 | GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req); |
817 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) | 799 | if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) |
818 | GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task); | 800 | GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task); |
819 | GNUNET_CLIENT_disconnect (handle->client); | 801 | GNUNET_CLIENT_disconnect (handle->client_notifications); |
802 | if (handle->client_requests != NULL) | ||
803 | GNUNET_CLIENT_disconnect (handle->client_requests); | ||
820 | GNUNET_free_non_null (handle->solicit_buffer); | 804 | GNUNET_free_non_null (handle->solicit_buffer); |
821 | GNUNET_free (handle); | 805 | GNUNET_free (handle); |
822 | } | 806 | } |
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 915217ea1..842197fb1 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -539,31 +539,6 @@ struct Neighbour | |||
539 | 539 | ||
540 | 540 | ||
541 | /** | 541 | /** |
542 | * Events are messages for clients. The struct | ||
543 | * itself is followed by the actual message. | ||
544 | */ | ||
545 | struct Event | ||
546 | { | ||
547 | /** | ||
548 | * This is a linked list. | ||
549 | */ | ||
550 | struct Event *next; | ||
551 | |||
552 | /** | ||
553 | * Size of the message. | ||
554 | */ | ||
555 | size_t size; | ||
556 | |||
557 | /** | ||
558 | * Could this event be dropped if this queue | ||
559 | * is getting too large? (NOT YET USED!) | ||
560 | */ | ||
561 | int can_drop; | ||
562 | |||
563 | }; | ||
564 | |||
565 | |||
566 | /** | ||
567 | * Data structure for each client connected to the core service. | 542 | * Data structure for each client connected to the core service. |
568 | */ | 543 | */ |
569 | struct Client | 544 | struct Client |
@@ -579,23 +554,6 @@ struct Client | |||
579 | struct GNUNET_SERVER_Client *client_handle; | 554 | struct GNUNET_SERVER_Client *client_handle; |
580 | 555 | ||
581 | /** | 556 | /** |
582 | * Linked list of messages we still need to deliver to | ||
583 | * this client. | ||
584 | */ | ||
585 | struct Event *event_head; | ||
586 | |||
587 | /** | ||
588 | * Tail of the linked list of events. | ||
589 | */ | ||
590 | struct Event *event_tail; | ||
591 | |||
592 | /** | ||
593 | * Current transmit handle, NULL if no transmission request | ||
594 | * is pending. | ||
595 | */ | ||
596 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
597 | |||
598 | /** | ||
599 | * Array of the types of messages this peer cares | 557 | * Array of the types of messages this peer cares |
600 | * about (with "tcnt" entries). Allocated as part | 558 | * about (with "tcnt" entries). Allocated as part |
601 | * of this client struct, do not free! | 559 | * of this client struct, do not free! |
@@ -658,6 +616,11 @@ static struct GNUNET_TRANSPORT_Handle *transport; | |||
658 | static struct Client *clients; | 616 | static struct Client *clients; |
659 | 617 | ||
660 | /** | 618 | /** |
619 | * Context for notifications we need to send to our clients. | ||
620 | */ | ||
621 | static struct GNUNET_SERVER_NotificationContext *notifier; | ||
622 | |||
623 | /** | ||
661 | * We keep neighbours in a linked list (for now). | 624 | * We keep neighbours in a linked list (for now). |
662 | */ | 625 | */ |
663 | static struct Neighbour *neighbours; | 626 | static struct Neighbour *neighbours; |
@@ -762,110 +725,6 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
762 | 725 | ||
763 | 726 | ||
764 | /** | 727 | /** |
765 | * Find the entry for the given client. | ||
766 | * | ||
767 | * @param client handle for the client | ||
768 | * @return NULL if we are not connected, otherwise the | ||
769 | * client's struct. | ||
770 | */ | ||
771 | static struct Client * | ||
772 | find_client (const struct GNUNET_SERVER_Client *client) | ||
773 | { | ||
774 | struct Client *ret; | ||
775 | |||
776 | ret = clients; | ||
777 | while ((ret != NULL) && (client != ret->client_handle)) | ||
778 | ret = ret->next; | ||
779 | return ret; | ||
780 | } | ||
781 | |||
782 | |||
783 | /** | ||
784 | * If necessary, initiate a request with the server to | ||
785 | * transmit messages from the queue of the given client. | ||
786 | * @param client who to transfer messages to | ||
787 | */ | ||
788 | static void request_transmit (struct Client *client); | ||
789 | |||
790 | |||
791 | /** | ||
792 | * Client is ready to receive data, provide it. | ||
793 | * | ||
794 | * @param cls closure | ||
795 | * @param size number of bytes available in buf | ||
796 | * @param buf where the callee should write the message | ||
797 | * @return number of bytes written to buf | ||
798 | */ | ||
799 | static size_t | ||
800 | do_client_transmit (void *cls, size_t size, void *buf) | ||
801 | { | ||
802 | struct Client *client = cls; | ||
803 | struct Event *e; | ||
804 | char *tgt; | ||
805 | size_t ret; | ||
806 | |||
807 | client->th = NULL; | ||
808 | #if DEBUG_CORE_CLIENT | ||
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
810 | "Client ready to receive %u bytes.\n", size); | ||
811 | #endif | ||
812 | if (buf == NULL) | ||
813 | { | ||
814 | #if DEBUG_CORE | ||
815 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
816 | "Failed to transmit data to client (disconnect)?\n"); | ||
817 | #endif | ||
818 | return 0; /* we'll surely get a disconnect soon... */ | ||
819 | } | ||
820 | tgt = buf; | ||
821 | ret = 0; | ||
822 | while ((NULL != (e = client->event_head)) && (e->size <= size)) | ||
823 | { | ||
824 | memcpy (&tgt[ret], &e[1], e->size); | ||
825 | size -= e->size; | ||
826 | ret += e->size; | ||
827 | client->event_head = e->next; | ||
828 | GNUNET_free (e); | ||
829 | } | ||
830 | GNUNET_assert (ret > 0); | ||
831 | if (client->event_head == NULL) | ||
832 | client->event_tail = NULL; | ||
833 | #if DEBUG_CORE_CLIENT | ||
834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
835 | "Transmitting %u bytes to client\n", ret); | ||
836 | #endif | ||
837 | request_transmit (client); | ||
838 | return ret; | ||
839 | } | ||
840 | |||
841 | |||
842 | /** | ||
843 | * If necessary, initiate a request with the server to | ||
844 | * transmit messages from the queue of the given client. | ||
845 | * @param client who to transfer messages to | ||
846 | */ | ||
847 | static void | ||
848 | request_transmit (struct Client *client) | ||
849 | { | ||
850 | |||
851 | if (NULL != client->th) | ||
852 | return; /* already pending */ | ||
853 | if (NULL == client->event_head) | ||
854 | return; /* no more events pending */ | ||
855 | #if DEBUG_CORE_CLIENT | ||
856 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
857 | "Asking server to transmit %u bytes to client\n", | ||
858 | client->event_head->size); | ||
859 | #endif | ||
860 | client->th | ||
861 | = GNUNET_SERVER_notify_transmit_ready (client->client_handle, | ||
862 | client->event_head->size, | ||
863 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
864 | &do_client_transmit, client); | ||
865 | } | ||
866 | |||
867 | |||
868 | /** | ||
869 | * Send a message to one of our clients. | 728 | * Send a message to one of our clients. |
870 | * | 729 | * |
871 | * @param client target for the message | 730 | * @param client target for the message |
@@ -875,51 +734,28 @@ request_transmit (struct Client *client) | |||
875 | */ | 734 | */ |
876 | static void | 735 | static void |
877 | send_to_client (struct Client *client, | 736 | send_to_client (struct Client *client, |
878 | const struct GNUNET_MessageHeader *msg, int can_drop) | 737 | const struct GNUNET_MessageHeader *msg, |
738 | int can_drop) | ||
879 | { | 739 | { |
880 | struct Event *e; | ||
881 | unsigned int queue_size; | ||
882 | uint16_t msize; | ||
883 | |||
884 | #if DEBUG_CORE_CLIENT | 740 | #if DEBUG_CORE_CLIENT |
885 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 741 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
886 | "Preparing to send message of type %u to client.\n", | 742 | "Preparing to send message of type %u to client.\n", |
887 | ntohs (msg->type)); | 743 | ntohs (msg->type)); |
888 | #endif | 744 | #endif |
889 | queue_size = 0; | 745 | GNUNET_SERVER_notification_context_unicast (notifier, |
890 | e = client->event_head; | 746 | client->client_handle, |
891 | while (e != NULL) | 747 | msg, |
892 | { | 748 | can_drop); |
893 | queue_size++; | ||
894 | e = e->next; | ||
895 | } | ||
896 | if ( (queue_size >= MAX_CLIENT_QUEUE_SIZE) && | ||
897 | (can_drop == GNUNET_YES) ) | ||
898 | { | ||
899 | #if DEBUG_CORE | ||
900 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
901 | "Too many messages in queue for the client, dropping the new message.\n"); | ||
902 | #endif | ||
903 | return; | ||
904 | } | ||
905 | |||
906 | msize = ntohs (msg->size); | ||
907 | e = GNUNET_malloc (sizeof (struct Event) + msize); | ||
908 | /* append */ | ||
909 | if (client->event_tail != NULL) | ||
910 | client->event_tail->next = e; | ||
911 | else | ||
912 | client->event_head = e; | ||
913 | client->event_tail = e; | ||
914 | e->can_drop = can_drop; | ||
915 | e->size = msize; | ||
916 | memcpy (&e[1], msg, msize); | ||
917 | request_transmit (client); | ||
918 | } | 749 | } |
919 | 750 | ||
920 | 751 | ||
921 | /** | 752 | /** |
922 | * Send a message to all of our current clients. | 753 | * Send a message to all of our current clients that have |
754 | * the right options set. | ||
755 | * | ||
756 | * @param msg message to multicast | ||
757 | * @param can_drop can this message be discarded if the queue is too long | ||
758 | * @param options mask to use | ||
923 | */ | 759 | */ |
924 | static void | 760 | static void |
925 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, | 761 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, |
@@ -978,6 +814,7 @@ handle_client_init (void *cls, | |||
978 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 814 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
979 | return; | 815 | return; |
980 | } | 816 | } |
817 | GNUNET_SERVER_notification_context_add (notifier, client); | ||
981 | im = (const struct InitMessage *) message; | 818 | im = (const struct InitMessage *) message; |
982 | types = (const uint16_t *) &im[1]; | 819 | types = (const uint16_t *) &im[1]; |
983 | msize -= sizeof (struct InitMessage); | 820 | msize -= sizeof (struct InitMessage); |
@@ -1017,7 +854,6 @@ handle_client_init (void *cls, | |||
1017 | send_to_client (c, &cnm.header, GNUNET_NO); | 854 | send_to_client (c, &cnm.header, GNUNET_NO); |
1018 | n = n->next; | 855 | n = n->next; |
1019 | } | 856 | } |
1020 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1021 | } | 857 | } |
1022 | 858 | ||
1023 | 859 | ||
@@ -1032,7 +868,6 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1032 | { | 868 | { |
1033 | struct Client *pos; | 869 | struct Client *pos; |
1034 | struct Client *prev; | 870 | struct Client *prev; |
1035 | struct Event *e; | ||
1036 | 871 | ||
1037 | if (client == NULL) | 872 | if (client == NULL) |
1038 | return; | 873 | return; |
@@ -1050,13 +885,6 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1050 | clients = pos->next; | 885 | clients = pos->next; |
1051 | else | 886 | else |
1052 | prev->next = pos->next; | 887 | prev->next = pos->next; |
1053 | if (pos->th != NULL) | ||
1054 | GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); | ||
1055 | while (NULL != (e = pos->event_head)) | ||
1056 | { | ||
1057 | pos->event_head = e->next; | ||
1058 | GNUNET_free (e); | ||
1059 | } | ||
1060 | GNUNET_free (pos); | 888 | GNUNET_free (pos); |
1061 | return; | 889 | return; |
1062 | } | 890 | } |
@@ -1072,15 +900,15 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1072 | */ | 900 | */ |
1073 | static void | 901 | static void |
1074 | handle_client_request_info (void *cls, | 902 | handle_client_request_info (void *cls, |
1075 | struct GNUNET_SERVER_Client *client, | 903 | struct GNUNET_SERVER_Client *client, |
1076 | const struct GNUNET_MessageHeader *message) | 904 | const struct GNUNET_MessageHeader *message) |
1077 | { | 905 | { |
1078 | const struct RequestInfoMessage *rcm; | 906 | const struct RequestInfoMessage *rcm; |
1079 | struct Neighbour *n; | 907 | struct Neighbour *n; |
1080 | struct ConfigurationInfoMessage cim; | 908 | struct ConfigurationInfoMessage cim; |
1081 | struct Client *c; | ||
1082 | int reserv; | 909 | int reserv; |
1083 | unsigned long long old_preference; | 910 | unsigned long long old_preference; |
911 | struct GNUNET_SERVER_TransmitContext *tc; | ||
1084 | 912 | ||
1085 | #if DEBUG_CORE_CLIENT | 913 | #if DEBUG_CORE_CLIENT |
1086 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 914 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1128,17 +956,15 @@ handle_client_request_info (void *cls, | |||
1128 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); | 956 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); |
1129 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); | 957 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); |
1130 | cim.peer = rcm->peer; | 958 | cim.peer = rcm->peer; |
1131 | c = find_client (client); | 959 | |
1132 | if (c == NULL) | ||
1133 | { | ||
1134 | GNUNET_break (0); | ||
1135 | return; | ||
1136 | } | ||
1137 | #if DEBUG_CORE_CLIENT | 960 | #if DEBUG_CORE_CLIENT |
1138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1139 | "Sending `%s' message to client.\n", "CONFIGURATION_INFO"); | 962 | "Sending `%s' message to client.\n", "CONFIGURATION_INFO"); |
1140 | #endif | 963 | #endif |
1141 | send_to_client (c, &cim.header, GNUNET_NO); | 964 | tc = GNUNET_SERVER_transmit_context_create (client); |
965 | GNUNET_SERVER_transmit_context_append_message (tc, &cim.header); | ||
966 | GNUNET_SERVER_transmit_context_run (tc, | ||
967 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1142 | } | 968 | } |
1143 | 969 | ||
1144 | 970 | ||
@@ -3252,6 +3078,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
3252 | neighbour_count--; | 3078 | neighbour_count--; |
3253 | free_neighbour (n); | 3079 | free_neighbour (n); |
3254 | } | 3080 | } |
3081 | GNUNET_SERVER_notification_context_destroy (notifier); | ||
3082 | notifier = NULL; | ||
3255 | while (NULL != (c = clients)) | 3083 | while (NULL != (c = clients)) |
3256 | handle_client_disconnect (NULL, c->client_handle); | 3084 | handle_client_disconnect (NULL, c->client_handle); |
3257 | if (my_private_key != NULL) | 3085 | if (my_private_key != NULL) |
@@ -3281,7 +3109,7 @@ run (void *cls, | |||
3281 | char *keyfile; | 3109 | char *keyfile; |
3282 | 3110 | ||
3283 | sched = s; | 3111 | sched = s; |
3284 | cfg = c; | 3112 | cfg = c; |
3285 | /* parse configuration */ | 3113 | /* parse configuration */ |
3286 | if ( | 3114 | if ( |
3287 | (GNUNET_OK != | 3115 | (GNUNET_OK != |
@@ -3330,6 +3158,7 @@ run (void *cls, | |||
3330 | sizeof (my_public_key), &my_identity.hashPubKey); | 3158 | sizeof (my_public_key), &my_identity.hashPubKey); |
3331 | /* setup notification */ | 3159 | /* setup notification */ |
3332 | server = serv; | 3160 | server = serv; |
3161 | notifier = GNUNET_SERVER_notification_context_create (server, 0); | ||
3333 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 3162 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
3334 | /* setup transport connection */ | 3163 | /* setup transport connection */ |
3335 | transport = GNUNET_TRANSPORT_connect (sched, | 3164 | transport = GNUNET_TRANSPORT_connect (sched, |
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index b8855632c..fa83eb889 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -961,9 +961,9 @@ signal_index_ok (struct IndexInfo *ii) | |||
961 | ii->filename, | 961 | ii->filename, |
962 | (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, | 962 | (const char*) GNUNET_CONTAINER_multihashmap_get (ifm, |
963 | &ii->file_id)); | 963 | &ii->file_id)); |
964 | GNUNET_SERVER_transmit_context_append (ii->tc, | 964 | GNUNET_SERVER_transmit_context_append_data (ii->tc, |
965 | NULL, 0, | 965 | NULL, 0, |
966 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); | 966 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); |
967 | GNUNET_SERVER_transmit_context_run (ii->tc, | 967 | GNUNET_SERVER_transmit_context_run (ii->tc, |
968 | GNUNET_TIME_UNIT_MINUTES); | 968 | GNUNET_TIME_UNIT_MINUTES); |
969 | GNUNET_free (ii); | 969 | GNUNET_free (ii); |
@@ -972,9 +972,9 @@ signal_index_ok (struct IndexInfo *ii) | |||
972 | ii->next = indexed_files; | 972 | ii->next = indexed_files; |
973 | indexed_files = ii; | 973 | indexed_files = ii; |
974 | write_index_list (); | 974 | write_index_list (); |
975 | GNUNET_SERVER_transmit_context_append (ii->tc, | 975 | GNUNET_SERVER_transmit_context_append_data (ii->tc, |
976 | NULL, 0, | 976 | NULL, 0, |
977 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); | 977 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK); |
978 | GNUNET_SERVER_transmit_context_run (ii->tc, | 978 | GNUNET_SERVER_transmit_context_run (ii->tc, |
979 | GNUNET_TIME_UNIT_MINUTES); | 979 | GNUNET_TIME_UNIT_MINUTES); |
980 | ii->tc = NULL; | 980 | ii->tc = NULL; |
@@ -1009,9 +1009,9 @@ hash_for_index_val (void *cls, | |||
1009 | "Wanted `%s'\n", | 1009 | "Wanted `%s'\n", |
1010 | GNUNET_h2s (&ii->file_id)); | 1010 | GNUNET_h2s (&ii->file_id)); |
1011 | #endif | 1011 | #endif |
1012 | GNUNET_SERVER_transmit_context_append (ii->tc, | 1012 | GNUNET_SERVER_transmit_context_append_data (ii->tc, |
1013 | NULL, 0, | 1013 | NULL, 0, |
1014 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); | 1014 | GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED); |
1015 | GNUNET_SERVER_transmit_context_run (ii->tc, | 1015 | GNUNET_SERVER_transmit_context_run (ii->tc, |
1016 | GNUNET_TIME_UNIT_MINUTES); | 1016 | GNUNET_TIME_UNIT_MINUTES); |
1017 | GNUNET_free (ii); | 1017 | GNUNET_free (ii); |
@@ -1110,17 +1110,13 @@ handle_index_list_get (void *cls, | |||
1110 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; | 1110 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; |
1111 | size_t slen; | 1111 | size_t slen; |
1112 | const char *fn; | 1112 | const char *fn; |
1113 | struct GNUNET_MessageHeader *msg; | ||
1114 | struct IndexInfo *pos; | 1113 | struct IndexInfo *pos; |
1115 | 1114 | ||
1116 | tc = GNUNET_SERVER_transmit_context_create (client); | 1115 | tc = GNUNET_SERVER_transmit_context_create (client); |
1117 | iim = (struct IndexInfoMessage*) buf; | 1116 | iim = (struct IndexInfoMessage*) buf; |
1118 | msg = &iim->header; | ||
1119 | pos = indexed_files; | 1117 | pos = indexed_files; |
1120 | while (NULL != pos) | 1118 | while (NULL != pos) |
1121 | { | 1119 | { |
1122 | iim->reserved = 0; | ||
1123 | iim->file_id = pos->file_id; | ||
1124 | fn = pos->filename; | 1120 | fn = pos->filename; |
1125 | slen = strlen (fn) + 1; | 1121 | slen = strlen (fn) + 1; |
1126 | if (slen + sizeof (struct IndexInfoMessage) > | 1122 | if (slen + sizeof (struct IndexInfoMessage) > |
@@ -1129,18 +1125,18 @@ handle_index_list_get (void *cls, | |||
1129 | GNUNET_break (0); | 1125 | GNUNET_break (0); |
1130 | break; | 1126 | break; |
1131 | } | 1127 | } |
1128 | iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | ||
1129 | iim->header.size = htons (slen + sizeof (struct IndexInfoMessage)); | ||
1130 | iim->reserved = 0; | ||
1131 | iim->file_id = pos->file_id; | ||
1132 | memcpy (&iim[1], fn, slen); | 1132 | memcpy (&iim[1], fn, slen); |
1133 | GNUNET_SERVER_transmit_context_append | 1133 | GNUNET_SERVER_transmit_context_append_message (tc, |
1134 | (tc, | 1134 | &iim->header); |
1135 | &msg[1], | ||
1136 | sizeof (struct IndexInfoMessage) | ||
1137 | - sizeof (struct GNUNET_MessageHeader) + slen, | ||
1138 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY); | ||
1139 | pos = pos->next; | 1135 | pos = pos->next; |
1140 | } | 1136 | } |
1141 | GNUNET_SERVER_transmit_context_append (tc, | 1137 | GNUNET_SERVER_transmit_context_append_data (tc, |
1142 | NULL, 0, | 1138 | NULL, 0, |
1143 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); | 1139 | GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END); |
1144 | GNUNET_SERVER_transmit_context_run (tc, | 1140 | GNUNET_SERVER_transmit_context_run (tc, |
1145 | GNUNET_TIME_UNIT_MINUTES); | 1141 | GNUNET_TIME_UNIT_MINUTES); |
1146 | } | 1142 | } |
@@ -1198,9 +1194,9 @@ handle_unindex (void *cls, | |||
1198 | if (GNUNET_YES == found) | 1194 | if (GNUNET_YES == found) |
1199 | write_index_list (); | 1195 | write_index_list (); |
1200 | tc = GNUNET_SERVER_transmit_context_create (client); | 1196 | tc = GNUNET_SERVER_transmit_context_create (client); |
1201 | GNUNET_SERVER_transmit_context_append (tc, | 1197 | GNUNET_SERVER_transmit_context_append_data (tc, |
1202 | NULL, 0, | 1198 | NULL, 0, |
1203 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); | 1199 | GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK); |
1204 | GNUNET_SERVER_transmit_context_run (tc, | 1200 | GNUNET_SERVER_transmit_context_run (tc, |
1205 | GNUNET_TIME_UNIT_MINUTES); | 1201 | GNUNET_TIME_UNIT_MINUTES); |
1206 | } | 1202 | } |
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h index 5609d7a9e..351c0a7c1 100644 --- a/src/include/gnunet_server_lib.h +++ b/src/include/gnunet_server_lib.h | |||
@@ -492,9 +492,23 @@ struct GNUNET_SERVER_TransmitContext | |||
492 | * @param type type of the message | 492 | * @param type type of the message |
493 | */ | 493 | */ |
494 | void | 494 | void |
495 | GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext | 495 | GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext |
496 | *tc, const void *data, size_t length, | 496 | *tc, const void *data, size_t length, |
497 | uint16_t type); | 497 | uint16_t type); |
498 | |||
499 | |||
500 | /** | ||
501 | * Append a message to the transmission context. | ||
502 | * All messages in the context will be sent by | ||
503 | * the transmit_context_run method. | ||
504 | * | ||
505 | * @param tc context to use | ||
506 | * @param msg message to append | ||
507 | */ | ||
508 | void | ||
509 | GNUNET_SERVER_transmit_context_append_message (struct GNUNET_SERVER_TransmitContext | ||
510 | *tc, const struct GNUNET_MessageHeader *msg); | ||
511 | |||
498 | 512 | ||
499 | /** | 513 | /** |
500 | * Execute a transmission context. If there is | 514 | * Execute a transmission context. If there is |
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 5b2b999d6..9ac38ea9f 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -470,7 +470,6 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
470 | { | 470 | { |
471 | struct HostEntry *pos; | 471 | struct HostEntry *pos; |
472 | struct InfoMessage *im; | 472 | struct InfoMessage *im; |
473 | const struct GNUNET_MessageHeader *end; | ||
474 | uint16_t hs; | 473 | uint16_t hs; |
475 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; | 474 | char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; |
476 | struct GNUNET_SERVER_TransmitContext *tc; | 475 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -487,6 +486,8 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
487 | change_host_trust (&pos->identity, trust_change); | 486 | change_host_trust (&pos->identity, trust_change); |
488 | hs = 0; | 487 | hs = 0; |
489 | im = (struct InfoMessage *) buf; | 488 | im = (struct InfoMessage *) buf; |
489 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | ||
490 | im->header.size = htons (sizeof (struct InfoMessage) + hs); | ||
490 | if (pos->hello != NULL) | 491 | if (pos->hello != NULL) |
491 | { | 492 | { |
492 | hs = GNUNET_HELLO_size (pos->hello); | 493 | hs = GNUNET_HELLO_size (pos->hello); |
@@ -497,19 +498,13 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
497 | } | 498 | } |
498 | im->trust = htonl (pos->trust); | 499 | im->trust = htonl (pos->trust); |
499 | im->peer = pos->identity; | 500 | im->peer = pos->identity; |
500 | end = &im->header; | 501 | GNUNET_SERVER_transmit_context_append_message (tc, |
501 | GNUNET_SERVER_transmit_context_append (tc, | 502 | &im->header); |
502 | &end[1], | ||
503 | hs + | ||
504 | sizeof (struct InfoMessage) - | ||
505 | sizeof (struct | ||
506 | GNUNET_MessageHeader), | ||
507 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | ||
508 | } | 503 | } |
509 | pos = pos->next; | 504 | pos = pos->next; |
510 | } | 505 | } |
511 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, | 506 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
512 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 507 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
513 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 508 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
514 | } | 509 | } |
515 | 510 | ||
diff --git a/src/statistics/gnunet-service-statistics.c b/src/statistics/gnunet-service-statistics.c index c90038e03..428ce932f 100644 --- a/src/statistics/gnunet-service-statistics.c +++ b/src/statistics/gnunet-service-statistics.c | |||
@@ -218,16 +218,15 @@ transmit (struct GNUNET_SERVER_TransmitContext *tc, | |||
218 | const struct StatsEntry *e) | 218 | const struct StatsEntry *e) |
219 | { | 219 | { |
220 | struct GNUNET_STATISTICS_ReplyMessage *m; | 220 | struct GNUNET_STATISTICS_ReplyMessage *m; |
221 | struct GNUNET_MessageHeader *h; | ||
222 | size_t size; | 221 | size_t size; |
223 | uint16_t msize; | ||
224 | 222 | ||
225 | size = | 223 | size = |
226 | sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1 + | 224 | sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1 + |
227 | strlen (e->name) + 1; | 225 | strlen (e->name) + 1; |
228 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); | 226 | GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); |
229 | msize = size - sizeof (struct GNUNET_MessageHeader); | ||
230 | m = GNUNET_malloc (size); | 227 | m = GNUNET_malloc (size); |
228 | m->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_VALUE); | ||
229 | m->header.size = htons (size); | ||
231 | m->uid = htonl (e->uid); | 230 | m->uid = htonl (e->uid); |
232 | if (e->persistent) | 231 | if (e->persistent) |
233 | m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); | 232 | m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT); |
@@ -241,11 +240,7 @@ transmit (struct GNUNET_SERVER_TransmitContext *tc, | |||
241 | "Transmitting value for `%s:%s': %llu\n", | 240 | "Transmitting value for `%s:%s': %llu\n", |
242 | e->service, e->name, e->value); | 241 | e->service, e->name, e->value); |
243 | #endif | 242 | #endif |
244 | h = &m->header; | 243 | GNUNET_SERVER_transmit_context_append_message (tc, &m->header); |
245 | GNUNET_SERVER_transmit_context_append (tc, | ||
246 | &h[1], | ||
247 | msize, | ||
248 | GNUNET_MESSAGE_TYPE_STATISTICS_VALUE); | ||
249 | GNUNET_free (m); | 244 | GNUNET_free (m); |
250 | } | 245 | } |
251 | 246 | ||
@@ -303,8 +298,8 @@ handle_get (void *cls, | |||
303 | transmit (tc, pos); | 298 | transmit (tc, pos); |
304 | pos = pos->next; | 299 | pos = pos->next; |
305 | } | 300 | } |
306 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, | 301 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
307 | GNUNET_MESSAGE_TYPE_STATISTICS_END); | 302 | GNUNET_MESSAGE_TYPE_STATISTICS_END); |
308 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 303 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
309 | } | 304 | } |
310 | 305 | ||
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index fe8b5043e..4251e7890 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -2587,8 +2587,8 @@ transmit_address_to_client (void *cls, const char *address) | |||
2587 | slen = 0; | 2587 | slen = 0; |
2588 | else | 2588 | else |
2589 | slen = strlen (address) + 1; | 2589 | slen = strlen (address) + 1; |
2590 | GNUNET_SERVER_transmit_context_append (tc, address, slen, | 2590 | GNUNET_SERVER_transmit_context_append_data (tc, address, slen, |
2591 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 2591 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); |
2592 | if (NULL == address) | 2592 | if (NULL == address) |
2593 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 2593 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
2594 | } | 2594 | } |
@@ -2644,8 +2644,8 @@ handle_address_lookup (void *cls, | |||
2644 | if (NULL == lsPlugin) | 2644 | if (NULL == lsPlugin) |
2645 | { | 2645 | { |
2646 | tc = GNUNET_SERVER_transmit_context_create (client); | 2646 | tc = GNUNET_SERVER_transmit_context_create (client); |
2647 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, | 2647 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
2648 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | 2648 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); |
2649 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); | 2649 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); |
2650 | return; | 2650 | return; |
2651 | } | 2651 | } |
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c index b3e40b889..59d4c1d97 100644 --- a/src/util/gnunet-service-resolver.c +++ b/src/util/gnunet-service-resolver.c | |||
@@ -227,12 +227,12 @@ get_ip_as_string (struct GNUNET_SERVER_Client *client, | |||
227 | } | 227 | } |
228 | tc = GNUNET_SERVER_transmit_context_create (client); | 228 | tc = GNUNET_SERVER_transmit_context_create (client); |
229 | if (cache->addr != NULL) | 229 | if (cache->addr != NULL) |
230 | GNUNET_SERVER_transmit_context_append (tc, | 230 | GNUNET_SERVER_transmit_context_append_data (tc, |
231 | cache->addr, | 231 | cache->addr, |
232 | strlen (cache->addr) + 1, | 232 | strlen (cache->addr) + 1, |
233 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 233 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
234 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, | 234 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
235 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 235 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
236 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 236 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
237 | } | 237 | } |
238 | 238 | ||
@@ -280,10 +280,10 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
280 | pos = result; | 280 | pos = result; |
281 | while (pos != NULL) | 281 | while (pos != NULL) |
282 | { | 282 | { |
283 | GNUNET_SERVER_transmit_context_append (tc, | 283 | GNUNET_SERVER_transmit_context_append_data (tc, |
284 | result->ai_addr, | 284 | result->ai_addr, |
285 | result->ai_addrlen, | 285 | result->ai_addrlen, |
286 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 286 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
287 | pos = pos->ai_next; | 287 | pos = pos->ai_next; |
288 | } | 288 | } |
289 | freeaddrinfo (result); | 289 | freeaddrinfo (result); |
@@ -327,10 +327,10 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
327 | memset (&a4, 0, sizeof (a4)); | 327 | memset (&a4, 0, sizeof (a4)); |
328 | a4.sin_family = AF_INET; | 328 | a4.sin_family = AF_INET; |
329 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); | 329 | memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length); |
330 | GNUNET_SERVER_transmit_context_append (tc, | 330 | GNUNET_SERVER_transmit_context_append_data (tc, |
331 | &a4, | 331 | &a4, |
332 | sizeof (a4), | 332 | sizeof (a4), |
333 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 333 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
334 | } | 334 | } |
335 | else | 335 | else |
336 | { | 336 | { |
@@ -338,10 +338,10 @@ gethostbyname2_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
338 | memset (&a6, 0, sizeof (a6)); | 338 | memset (&a6, 0, sizeof (a6)); |
339 | a6.sin6_family = AF_INET6; | 339 | a6.sin6_family = AF_INET6; |
340 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); | 340 | memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length); |
341 | GNUNET_SERVER_transmit_context_append (tc, | 341 | GNUNET_SERVER_transmit_context_append_data (tc, |
342 | &a6, | 342 | &a6, |
343 | sizeof (a6), | 343 | sizeof (a6), |
344 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 344 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
345 | } | 345 | } |
346 | return GNUNET_OK; | 346 | return GNUNET_OK; |
347 | } | 347 | } |
@@ -372,10 +372,10 @@ gethostbyname_resolve (struct GNUNET_SERVER_TransmitContext *tc, | |||
372 | memset (&addr, 0, sizeof (addr)); | 372 | memset (&addr, 0, sizeof (addr)); |
373 | addr.sin_family = AF_INET; | 373 | addr.sin_family = AF_INET; |
374 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); | 374 | memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length); |
375 | GNUNET_SERVER_transmit_context_append (tc, | 375 | GNUNET_SERVER_transmit_context_append_data (tc, |
376 | &addr, | 376 | &addr, |
377 | sizeof (addr), | 377 | sizeof (addr), |
378 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 378 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
379 | return GNUNET_OK; | 379 | return GNUNET_OK; |
380 | } | 380 | } |
381 | #endif | 381 | #endif |
@@ -409,8 +409,8 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client, | |||
409 | if ((ret == GNUNET_NO) && ((domain == AF_UNSPEC) || (domain == PF_INET))) | 409 | if ((ret == GNUNET_NO) && ((domain == AF_UNSPEC) || (domain == PF_INET))) |
410 | gethostbyname_resolve (tc, hostname); | 410 | gethostbyname_resolve (tc, hostname); |
411 | #endif | 411 | #endif |
412 | GNUNET_SERVER_transmit_context_append (tc, NULL, 0, | 412 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, |
413 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); | 413 | GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE); |
414 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 414 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
415 | } | 415 | } |
416 | 416 | ||
diff --git a/src/util/server_tc.c b/src/util/server_tc.c index bffb892b1..7514b0cd3 100644 --- a/src/util/server_tc.c +++ b/src/util/server_tc.c | |||
@@ -149,9 +149,9 @@ GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client) | |||
149 | * @param type type of the message | 149 | * @param type type of the message |
150 | */ | 150 | */ |
151 | void | 151 | void |
152 | GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext | 152 | GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext |
153 | *tc, const void *data, size_t length, | 153 | *tc, const void *data, size_t length, |
154 | uint16_t type) | 154 | uint16_t type) |
155 | { | 155 | { |
156 | struct GNUNET_MessageHeader *msg; | 156 | struct GNUNET_MessageHeader *msg; |
157 | size_t size; | 157 | size_t size; |
@@ -169,6 +169,29 @@ GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext | |||
169 | 169 | ||
170 | 170 | ||
171 | /** | 171 | /** |
172 | * Append a message to the transmission context. | ||
173 | * All messages in the context will be sent by | ||
174 | * the transmit_context_run method. | ||
175 | * | ||
176 | * @param tc context to use | ||
177 | * @param msg message to append | ||
178 | */ | ||
179 | void | ||
180 | GNUNET_SERVER_transmit_context_append_message(struct GNUNET_SERVER_TransmitContext | ||
181 | *tc, const struct GNUNET_MessageHeader *msg) | ||
182 | { | ||
183 | struct GNUNET_MessageHeader *m; | ||
184 | uint16_t size; | ||
185 | |||
186 | size = ntohs (msg->size); | ||
187 | tc->buf = GNUNET_realloc (tc->buf, tc->total + size); | ||
188 | m = (struct GNUNET_MessageHeader *) &tc->buf[tc->total]; | ||
189 | tc->total += size; | ||
190 | memcpy (m, msg, size); | ||
191 | } | ||
192 | |||
193 | |||
194 | /** | ||
172 | * Execute a transmission context. If there is | 195 | * Execute a transmission context. If there is |
173 | * an error in the transmission, the receive_done | 196 | * an error in the transmission, the receive_done |
174 | * method will be called with an error code (GNUNET_SYSERR), | 197 | * method will be called with an error code (GNUNET_SYSERR), |