2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 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.
22 * @file include/gnunet_client_lib.h
23 * @brief functions related to accessing services
24 * @author Christian Grothoff
27 #ifndef GNUNET_CLIENT_LIB_H
28 #define GNUNET_CLIENT_LIB_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_common.h"
39 #include "gnunet_configuration_lib.h"
40 #include "gnunet_connection_lib.h"
41 #include "gnunet_scheduler_lib.h"
42 #include "gnunet_time_lib.h"
45 * Opaque handle for a connection to a service.
47 struct GNUNET_CLIENT_Connection;
50 * Get a connection with a service.
52 * @param sched scheduler to use
53 * @param service_name name of the service
54 * @param cfg configuration to use
55 * @return NULL on error (service unknown to configuration)
57 struct GNUNET_CLIENT_Connection *GNUNET_CLIENT_connect (struct
58 GNUNET_SCHEDULER_Handle
63 GNUNET_CONFIGURATION_Handle
68 * Configure this connection to ignore shutdown signals.
70 * @param h client handle
71 * @param do_ignore GNUNET_YES to ignore, GNUNET_NO to restore default
74 GNUNET_CLIENT_ignore_shutdown (struct GNUNET_CLIENT_Connection *h,
80 * Destroy connection with the service. This will automatically
81 * cancel any pending "receive" request (however, the handler will
82 * *NOT* be called, not even with a NULL message). Any pending
83 * transmission request will also be cancelled UNLESS the callback for
84 * the transmission request has already been called, in which case the
85 * transmission 'finish_pending_write' argument determines whether or
86 * not the write is guaranteed to complete before the socket is fully
87 * destroyed (unless, of course, there is an error with the server in
88 * which case the message may still be lost).
90 * @param sock handle to the service connection
91 * @param finish_pending_write should a transmission already passed to the
92 * handle be completed?
94 void GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock,
95 int finish_pending_write);
98 * Type of a function to call when we receive a message
102 * @param msg message received, NULL on timeout or fatal error
104 typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls,
106 GNUNET_MessageHeader * msg);
109 * Read from the service.
111 * @param sock the service
112 * @param handler function to call with the message
113 * @param handler_cls closure for handler
114 * @param timeout how long to wait until timing out
116 void GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
117 GNUNET_CLIENT_MessageHandler handler,
119 struct GNUNET_TIME_Relative timeout);
123 * Transmit handle for client connections.
125 struct GNUNET_CLIENT_TransmitHandle;
129 * Ask the client to call us once the specified number of bytes
130 * are free in the transmission buffer. May call the notify
131 * method immediately if enough space is available.
133 * @param sock connection to the service
134 * @param size number of bytes to send
135 * @param timeout after how long should we give up (and call
136 * notify with buf NULL and size 0)?
137 * @param auto_retry if the connection to the service dies, should we
138 * automatically re-connect and retry (within the timeout period)
139 * or should we immediately fail in this case? Pass GNUNET_YES
140 * if the caller does not care about temporary connection errors,
141 * for example because the protocol is stateless
142 * @param notify function to call
143 * @param notify_cls closure for notify
144 * @return NULL if someone else is already waiting to be notified
145 * non-NULL if the notify callback was queued (can be used to cancel
146 * using GNUNET_CONNECTION_notify_transmit_ready_cancel)
148 struct GNUNET_CLIENT_TransmitHandle
149 *GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
151 struct GNUNET_TIME_Relative timeout,
153 GNUNET_CONNECTION_TransmitReadyNotify
159 * Cancel a request for notification.
161 * @param th handle from the original request.
164 GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th);
168 * Convenience API that combines sending a request
169 * to the service and waiting for a response.
170 * If either operation times out, the callback
171 * will be called with a "NULL" response (in which
172 * case the connection should probably be destroyed).
174 * @param sock connection to use
175 * @param hdr message to transmit
176 * @param timeout when to give up (for both transmission
177 * and for waiting for a response)
178 * @param auto_retry if the connection to the service dies, should we
179 * automatically re-connect and retry (within the timeout period)
180 * or should we immediately fail in this case? Pass GNUNET_YES
181 * if the caller does not care about temporary connection errors,
182 * for example because the protocol is stateless
183 * @param rn function to call with the response
184 * @param rn_cls closure for rn
185 * @return GNUNET_OK on success, GNUNET_SYSERR if a request
189 GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock,
190 const struct GNUNET_MessageHeader *hdr,
191 struct GNUNET_TIME_Relative timeout,
193 GNUNET_CLIENT_MessageHandler rn,
199 * Request that the service should shutdown.
200 * Afterwards, the connection will automatically be
201 * disconnected. Hence the "sock" shoud not
202 * be used by the caller after this call
203 * (calling this function frees "sock" after a while).
205 * @param sock the socket connected to the service
207 void GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock);
211 * Wait until the service is running.
213 * @param sched scheduler to use
214 * @param service name of the service to wait for
215 * @param cfg configuration to use
216 * @param timeout how long to wait at most in ms
217 * @param task task to run if service is running
218 * (reason will be "PREREQ_DONE" (service running)
219 * or "TIMEOUT" (service not known to be running))
220 * @param task_cls closure for task
222 void GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched,
224 const struct GNUNET_CONFIGURATION_Handle *cfg,
225 struct GNUNET_TIME_Relative timeout,
226 GNUNET_SCHEDULER_Task task, void *task_cls);
229 #if 0 /* keep Emacsens' auto-indent happy */
236 /* ifndef GNUNET_CLIENT_LIB_H */
238 /* end of gnunet_client_lib.h */