2 This file is part of GNUnet.
3 (C) 2001, 2002, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
23 * @brief code for access to services
24 * @author Christian Grothoff
26 * Generic TCP code for reliable, record-oriented TCP
27 * connections between clients and service providers.
31 #include "gnunet_common.h"
32 #include "gnunet_client_lib.h"
33 #include "gnunet_protocols.h"
34 #include "gnunet_server_lib.h"
35 #include "gnunet_scheduler_lib.h"
37 #define DEBUG_CLIENT GNUNET_NO
41 * How often do we re-try tranmsitting requests before giving up?
42 * Note that if we succeeded transmitting a request but failed to read
43 * a response, we do NOT re-try.
45 #define MAX_ATTEMPTS 10
49 * Handle for a transmission request.
51 struct GNUNET_CLIENT_TransmitHandle
56 struct GNUNET_CLIENT_Connection *sock;
59 * Function to call to get the data for transmission.
61 GNUNET_CONNECTION_TransmitReadyNotify notify;
69 * Handle to the transmission with the underlying
72 struct GNUNET_CONNECTION_TransmitHandle *th;
75 * If we are re-trying and are delaying to do so,
76 * handle to the scheduled task managing the delay.
78 GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
83 struct GNUNET_TIME_Absolute timeout;
86 * Number of bytes requested.
91 * Are we allowed to re-try to connect without telling
92 * the user (of this API) about the connection troubles?
97 * Number of attempts left for transmitting the request. We may
98 * fail the first time (say because the service is not yet up), in
99 * which case (if auto_retry is set) we wait a bit and re-try
100 * (timeout permitting).
102 unsigned int attempts_left;
108 * Context for processing
109 * "GNUNET_CLIENT_transmit_and_get_response" requests.
111 struct TransmitGetResponseContext
116 struct GNUNET_CLIENT_Connection *sock;
119 * Message to transmit; do not free, allocated
120 * right after this struct.
122 const struct GNUNET_MessageHeader *hdr;
127 struct GNUNET_TIME_Absolute timeout;
130 * Function to call when done.
132 GNUNET_CLIENT_MessageHandler rn;
142 * Struct to refer to a GNUnet TCP connection.
143 * This is more than just a socket because if the server
144 * drops the connection, the client automatically tries
145 * to reconnect (and for that needs connection information).
147 struct GNUNET_CLIENT_Connection
151 * the socket handle, NULL if not live
153 struct GNUNET_CONNECTION_Handle *sock;
158 struct GNUNET_SCHEDULER_Handle *sched;
163 struct GNUNET_CONFIGURATION_Handle *cfg;
166 * Name of the service we interact with.
171 * Context of a transmit_and_get_response operation, NULL
172 * if no such operation is pending.
174 struct TransmitGetResponseContext *tag;
177 * Handler for current receiver task.
179 GNUNET_CLIENT_MessageHandler receiver_handler;
182 * Closure for receiver_handler.
184 void *receiver_handler_cls;
187 * Handle for a pending transmission request, NULL if there is
190 struct GNUNET_CLIENT_TransmitHandle *th;
193 * Handler for service test completion (NULL unless in service_test)
195 GNUNET_SCHEDULER_Task test_cb;
198 * If we are re-trying and are delaying to do so,
199 * handle to the scheduled task managing the delay.
201 GNUNET_SCHEDULER_TaskIdentifier receive_task;
204 * Closure for test_cb (NULL unless in service_test)
209 * Buffer for received message.
214 * Timeout for receiving a response (absolute time).
216 struct GNUNET_TIME_Absolute receive_timeout;
219 * Number of bytes in received_buf that are valid.
224 * Size of received_buf.
226 unsigned int received_size;
229 * Do we have a complete response in received_buf?
234 * Are we currently busy doing receive-processing?
235 * GNUNET_YES if so, GNUNET_NO if not.
242 static struct GNUNET_CONNECTION_Handle *
243 do_connect (struct GNUNET_SCHEDULER_Handle *sched,
244 const char *service_name,
245 const struct GNUNET_CONFIGURATION_Handle *cfg)
247 struct GNUNET_CONNECTION_Handle *sock;
249 unsigned long long port;
252 GNUNET_CONFIGURATION_get_value_number (cfg,
258 GNUNET_CONFIGURATION_get_value_string (cfg,
260 "HOSTNAME", &hostname)))
262 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
264 ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
268 if (0 == strlen (hostname))
270 GNUNET_free (hostname);
271 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
272 _("Need a non-empty hostname for service `%s'.\n"),
276 sock = GNUNET_CONNECTION_create_from_connect (sched,
280 GNUNET_SERVER_MAX_MESSAGE_SIZE);
281 GNUNET_free (hostname);
287 * Get a connection with a service.
289 * @param sched scheduler to use
290 * @param service_name name of the service
291 * @param cfg configuration to use
292 * @return NULL on error (service unknown to configuration)
294 struct GNUNET_CLIENT_Connection *
295 GNUNET_CLIENT_connect (struct GNUNET_SCHEDULER_Handle *sched,
296 const char *service_name,
297 const struct GNUNET_CONFIGURATION_Handle *cfg)
299 struct GNUNET_CLIENT_Connection *ret;
300 struct GNUNET_CONNECTION_Handle *sock;
302 sock = do_connect (sched, service_name, cfg);
305 ret = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_Connection));
308 ret->service_name = GNUNET_strdup (service_name);
309 ret->cfg = GNUNET_CONFIGURATION_dup (cfg);
315 * Destroy connection with the service. This will automatically
316 * cancel any pending "receive" request (however, the handler will
317 * *NOT* be called, not even with a NULL message). Any pending
318 * transmission request will also be cancelled UNLESS the callback for
319 * the transmission request has already been called, in which case the
320 * transmission is guaranteed to complete before the socket is fully
321 * destroyed (unless, of course, there is an error with the server
322 * in which case the message may still be lost).
324 * @param sock handle to the service connection
327 GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock)
329 GNUNET_assert (sock->sock != NULL);
330 if (sock->in_receive == GNUNET_YES)
332 GNUNET_CONNECTION_receive_cancel (sock->sock);
333 sock->in_receive = GNUNET_NO;
335 GNUNET_CONNECTION_destroy (sock->sock);
337 if (sock->tag != NULL)
339 GNUNET_free (sock->tag);
342 sock->receiver_handler = NULL;
343 if (sock->th != NULL)
344 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
345 if (sock->receive_task != GNUNET_SCHEDULER_NO_TASK)
347 GNUNET_SCHEDULER_cancel (sock->sched, sock->receive_task);
348 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
350 GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
351 GNUNET_free (sock->service_name);
352 GNUNET_CONFIGURATION_destroy (sock->cfg);
358 * Check if message is complete
361 check_complete (struct GNUNET_CLIENT_Connection *conn)
363 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) &&
364 (conn->received_pos >=
365 ntohs (((const struct GNUNET_MessageHeader *) conn->
366 received_buf)->size)))
367 conn->msg_complete = GNUNET_YES;
372 * Callback function for data received from the network. Note that
373 * both "available" and "errCode" would be 0 if the read simply timed out.
376 * @param buf pointer to received data
377 * @param available number of bytes availabe in "buf",
378 * possibly 0 (on errors)
379 * @param addr address of the sender
380 * @param addrlen size of addr
381 * @param errCode value of errno (on errors receiving)
384 receive_helper (void *cls,
387 const struct sockaddr *addr, socklen_t addrlen, int errCode)
389 struct GNUNET_CLIENT_Connection *conn = cls;
390 struct GNUNET_TIME_Relative remaining;
391 GNUNET_CLIENT_MessageHandler receive_handler;
392 void *receive_handler_cls;
394 GNUNET_assert (conn->msg_complete == GNUNET_NO);
395 conn->in_receive = GNUNET_NO;
396 if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
398 /* signal timeout! */
399 if (NULL != (receive_handler = conn->receiver_handler))
401 receive_handler_cls = conn->receiver_handler_cls;
402 conn->receiver_handler = NULL;
403 receive_handler (receive_handler_cls, NULL);
408 /* FIXME: optimize for common fast case where buf contains the
409 entire message and we need no copying... */
412 /* slow path: append to array */
413 if (conn->received_size < conn->received_pos + available)
414 GNUNET_array_grow (conn->received_buf,
415 conn->received_size, conn->received_pos + available);
416 memcpy (&conn->received_buf[conn->received_pos], buf, available);
417 conn->received_pos += available;
418 check_complete (conn);
419 /* check for timeout */
420 remaining = GNUNET_TIME_absolute_get_remaining (conn->receive_timeout);
421 if (remaining.value == 0)
423 /* signal timeout! */
424 conn->receiver_handler (conn->receiver_handler_cls, NULL);
427 /* back to receive -- either for more data or to call callback! */
428 GNUNET_CLIENT_receive (conn,
429 conn->receiver_handler,
430 conn->receiver_handler_cls, remaining);
435 * Continuation to call the receive callback.
437 * @param cls our handle to the client connection
438 * @param tc scheduler context
441 receive_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
443 struct GNUNET_CLIENT_Connection *sock = cls;
444 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler;
445 const struct GNUNET_MessageHeader *cmsg =
446 (const struct GNUNET_MessageHeader *) sock->received_buf;
447 void *handler_cls = sock->receiver_handler_cls;
448 uint16_t msize = ntohs (cmsg->size);
450 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
452 sock->receive_task = GNUNET_SCHEDULER_NO_TASK;
453 GNUNET_assert (GNUNET_YES == sock->msg_complete);
454 GNUNET_assert (sock->received_pos >= msize);
455 memcpy (msg, cmsg, msize);
456 memmove (sock->received_buf,
457 &sock->received_buf[msize], sock->received_pos - msize);
458 sock->received_pos -= msize;
459 sock->msg_complete = GNUNET_NO;
460 sock->receiver_handler = NULL;
461 check_complete (sock);
463 handler (handler_cls, msg);
468 * Read from the service.
470 * @param sock the service
471 * @param handler function to call with the message
472 * @param handler_cls closure for handler
473 * @param timeout how long to wait until timing out
476 GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
477 GNUNET_CLIENT_MessageHandler handler,
478 void *handler_cls, struct GNUNET_TIME_Relative timeout)
480 if (sock->sock == NULL)
482 /* already disconnected, fail instantly! */
483 GNUNET_break (0); /* this should not happen in well-written code! */
484 handler (handler_cls, NULL);
487 sock->receiver_handler = handler;
488 sock->receiver_handler_cls = handler_cls;
489 sock->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout);
490 if (GNUNET_YES == sock->msg_complete)
492 sock->receive_task = GNUNET_SCHEDULER_add_after (sock->sched,
493 GNUNET_SCHEDULER_NO_TASK,
494 &receive_task, sock);
498 sock->in_receive = GNUNET_YES;
499 GNUNET_CONNECTION_receive (sock->sock,
500 GNUNET_SERVER_MAX_MESSAGE_SIZE,
501 timeout, &receive_helper, sock);
507 * If possible, write a shutdown message to the target
508 * buffer and destroy the client connection.
510 * @param cls the "struct GNUNET_CLIENT_Connection" to destroy
511 * @param size number of bytes available in buf
512 * @param buf NULL on error, otherwise target buffer
513 * @return number of bytes written to buf
516 write_shutdown (void *cls, size_t size, void *buf)
518 struct GNUNET_MessageHeader *msg;
519 struct GNUNET_CLIENT_Connection *sock = cls;
521 GNUNET_CLIENT_disconnect (sock);
522 if (size < sizeof (struct GNUNET_MessageHeader))
524 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
525 _("Failed to transmit shutdown request to client.\n"));
526 return 0; /* client disconnected */
528 msg = (struct GNUNET_MessageHeader *) buf;
529 msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN);
530 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
531 return sizeof (struct GNUNET_MessageHeader);
536 * Request that the service should shutdown.
537 * Afterwards, the connection should be disconnected.
539 * @param sock the socket connected to the service
542 GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock)
544 GNUNET_CONNECTION_notify_transmit_ready (sock->sock,
546 GNUNET_MessageHeader),
547 GNUNET_TIME_UNIT_FOREVER_REL,
548 &write_shutdown, sock);
553 * Report service unavailable.
556 service_test_error (struct GNUNET_SCHEDULER_Handle *s,
557 GNUNET_SCHEDULER_Task task, void *task_cls)
559 GNUNET_SCHEDULER_add_continuation (s,
562 GNUNET_SCHEDULER_REASON_TIMEOUT);
567 * Receive confirmation from test, service is up.
570 * @param msg message received, NULL on timeout or fatal error
573 confirm_handler (void *cls, const struct GNUNET_MessageHeader *msg)
575 struct GNUNET_CLIENT_Connection *conn = cls;
576 /* We may want to consider looking at the reply in more
577 detail in the future, for example, is this the
578 correct service? FIXME! */
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
583 "Received confirmation that service is running.\n");
585 GNUNET_SCHEDULER_add_continuation (conn->sched,
588 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
592 service_test_error (conn->sched, conn->test_cb, conn->test_cb_cls);
594 GNUNET_CLIENT_disconnect (conn);
599 write_test (void *cls, size_t size, void *buf)
601 struct GNUNET_MessageHeader *msg;
603 if (size < sizeof (struct GNUNET_MessageHeader))
606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
607 _("Failure to transmit TEST request.\n"));
609 return 0; /* client disconnected */
612 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
613 "Transmitting `%s' request.\n", "TEST");
615 msg = (struct GNUNET_MessageHeader *) buf;
616 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST);
617 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
618 return sizeof (struct GNUNET_MessageHeader);
623 * Wait until the service is running.
625 * @param sched scheduler to use
626 * @param service name of the service to wait for
627 * @param cfg configuration to use
628 * @param timeout how long to wait at most in ms
629 * @param task task to run if service is running
630 * (reason will be "PREREQ_DONE" (service running)
631 * or "TIMEOUT" (service not known to be running))
632 * @param task_cls closure for task
635 GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched,
637 const struct GNUNET_CONFIGURATION_Handle *cfg,
638 struct GNUNET_TIME_Relative timeout,
639 GNUNET_SCHEDULER_Task task, void *task_cls)
641 struct GNUNET_CLIENT_Connection *conn;
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
645 "Testing if service `%s' is running.\n", service);
647 conn = GNUNET_CLIENT_connect (sched, service, cfg);
650 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
652 ("Could not connect to service `%s', must not be running.\n"),
654 service_test_error (sched, task, task_cls);
657 conn->test_cb = task;
658 conn->test_cb_cls = task_cls;
660 GNUNET_CONNECTION_notify_transmit_ready (conn->sock,
662 GNUNET_MessageHeader),
663 timeout, &write_test, NULL))
665 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
666 _("Failure to transmit request to service `%s'\n"),
668 service_test_error (sched, task, task_cls);
669 GNUNET_CLIENT_disconnect (conn);
672 GNUNET_CLIENT_receive (conn, &confirm_handler, conn, timeout);
677 * Connection notifies us about failure or success of
678 * a transmission request. Either pass it on to our
679 * user or, if possible, retry.
681 * @param cls our "struct GNUNET_CLIENT_TransmissionHandle"
682 * @param size number of bytes available for transmission
683 * @param buf where to write them
684 * @return number of bytes written to buf
686 static size_t client_notify (void *cls, size_t size, void *buf);
690 * This task is run if we should re-try connection to the
691 * service after a while.
693 * @param cls our "struct GNUNET_CLIENT_TransmitHandle" of the request
697 client_delayed_retry (void *cls,
698 const struct GNUNET_SCHEDULER_TaskContext *tc)
700 struct GNUNET_CLIENT_TransmitHandle *th = cls;
702 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
703 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
707 "Transmission failed due to shutdown.\n");
710 th->notify (th->notify_cls, 0, NULL);
714 th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock,
716 GNUNET_TIME_absolute_get_remaining
722 th->notify (th->notify_cls, 0, NULL);
730 * Connection notifies us about failure or success of
731 * a transmission request. Either pass it on to our
732 * user or, if possible, retry.
734 * @param cls our "struct GNUNET_CLIENT_TransmissionHandle"
735 * @param size number of bytes available for transmission
736 * @param buf where to write them
737 * @return number of bytes written to buf
740 client_notify (void *cls, size_t size, void *buf)
742 struct GNUNET_CLIENT_TransmitHandle *th = cls;
744 struct GNUNET_TIME_Relative delay;
750 // FIXME: need a way to check if the
751 // reason is SHUTDOWN (not timeout) and
753 delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
755 if ((GNUNET_YES != th->auto_retry) ||
756 (0 == --th->attempts_left) || (delay.value < 1))
759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
760 "Transmission failed %u times, giving up.\n",
761 MAX_ATTEMPTS - th->attempts_left);
763 GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
768 GNUNET_CONNECTION_destroy (th->sock->sock);
769 th->sock->sock = do_connect (th->sock->sched,
770 th->sock->service_name, th->sock->cfg);
771 GNUNET_assert (NULL != th->sock->sock);
772 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
775 "Transmission failed %u times, trying again in %llums.\n",
776 MAX_ATTEMPTS - th->attempts_left,
777 (unsigned long long) delay.value);
779 th->reconnect_task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
781 &client_delayed_retry,
786 GNUNET_assert (size >= th->size);
787 ret = th->notify (th->notify_cls, size, buf);
794 * Ask the client to call us once the specified number of bytes
795 * are free in the transmission buffer. May call the notify
796 * method immediately if enough space is available.
798 * @param sock connection to the service
799 * @param size number of bytes to send
800 * @param timeout after how long should we give up (and call
801 * notify with buf NULL and size 0)?
802 * @param auto_retry if the connection to the service dies, should we
803 * automatically re-connect and retry (within the timeout period)
804 * or should we immediately fail in this case? Pass GNUNET_YES
805 * if the caller does not care about temporary connection errors,
806 * for example because the protocol is stateless
807 * @param notify function to call
808 * @param notify_cls closure for notify
809 * @return NULL if our buffer will never hold size bytes,
810 * a handle if the notify callback was queued (can be used to cancel)
812 struct GNUNET_CLIENT_TransmitHandle *
813 GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
815 struct GNUNET_TIME_Relative timeout,
817 GNUNET_CONNECTION_TransmitReadyNotify
818 notify, void *notify_cls)
820 struct GNUNET_CLIENT_TransmitHandle *th;
822 if (NULL != sock->th)
824 th = GNUNET_malloc (sizeof (struct GNUNET_CLIENT_TransmitHandle));
827 th->timeout = GNUNET_TIME_relative_to_absolute (timeout);
828 th->auto_retry = auto_retry;
830 th->notify_cls = notify_cls;
831 th->attempts_left = MAX_ATTEMPTS;
832 th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock,
848 * Cancel a request for notification.
850 * @param th handle from the original request.
853 GNUNET_CLIENT_notify_transmit_ready_cancel (struct
854 GNUNET_CLIENT_TransmitHandle *th)
856 if (th->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
858 GNUNET_break (NULL == th->th);
859 GNUNET_SCHEDULER_cancel (th->sock->sched, th->reconnect_task);
860 th->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
864 GNUNET_break (NULL != th->th);
865 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->th);
873 * Function called to notify a client about the socket
874 * begin ready to queue the message. "buf" will be
875 * NULL and "size" zero if the socket was closed for
876 * writing in the meantime.
878 * @param cls closure of type "struct TransmitGetResponseContext*"
879 * @param size number of bytes available in buf
880 * @param buf where the callee should write the message
881 * @return number of bytes written to buf
884 transmit_for_response (void *cls, size_t size, void *buf)
886 struct TransmitGetResponseContext *tc = cls;
889 tc->sock->tag = NULL;
890 msize = ntohs (tc->hdr->size);
893 tc->rn (tc->rn_cls, NULL);
897 GNUNET_assert (size >= msize);
898 memcpy (buf, tc->hdr, msize);
899 GNUNET_CLIENT_receive (tc->sock,
902 GNUNET_TIME_absolute_get_remaining (tc->timeout));
909 * Convenience API that combines sending a request
910 * to the service and waiting for a response.
911 * If either operation times out, the callback
912 * will be called with a "NULL" response (in which
913 * case the connection should probably be destroyed).
915 * @param sock connection to use
916 * @param hdr message to transmit
917 * @param timeout when to give up (for both transmission
918 * and for waiting for a response)
919 * @param auto_retry if the connection to the service dies, should we
920 * automatically re-connect and retry (within the timeout period)
921 * or should we immediately fail in this case? Pass GNUNET_YES
922 * if the caller does not care about temporary connection errors,
923 * for example because the protocol is stateless
924 * @param rn function to call with the response
925 * @param rn_cls closure for rn
926 * @return GNUNET_OK on success, GNUNET_SYSERR if a request
930 GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
932 const struct GNUNET_MessageHeader
934 struct GNUNET_TIME_Relative timeout,
936 GNUNET_CLIENT_MessageHandler rn,
939 struct TransmitGetResponseContext *tc;
942 if (NULL != sock->th)
943 return GNUNET_SYSERR;
944 GNUNET_assert (sock->tag == NULL);
945 msize = ntohs (hdr->size);
946 tc = GNUNET_malloc (sizeof (struct TransmitGetResponseContext) + msize);
948 tc->hdr = (const struct GNUNET_MessageHeader *) &tc[1];
949 memcpy (&tc[1], hdr, msize);
950 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
953 if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock,
957 &transmit_for_response,
962 return GNUNET_SYSERR;
970 /* end of client.c */