2 This file is part of GNUnet.
3 (C) 2001-2013 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 3, 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 service_name name of the service
53 * @param cfg configuration to use
54 * @return NULL on error (service unknown to configuration)
56 struct GNUNET_CLIENT_Connection *
57 GNUNET_CLIENT_connect (const char *service_name,
58 const struct GNUNET_CONFIGURATION_Handle *cfg);
62 * Destroy connection with the service. This will automatically
63 * cancel any pending "receive" request (however, the handler will
64 * *NOT* be called, not even with a NULL message). Any pending
65 * transmission request will also be cancelled UNLESS the callback for
66 * the transmission request has already been called, in which case the
67 * transmission 'finish_pending_write' argument determines whether or
68 * not the write is guaranteed to complete before the socket is fully
69 * destroyed (unless, of course, there is an error with the server in
70 * which case the message may still be lost).
72 * @param client handle to the service connection
75 GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *client);
79 * Type of a function to call when we receive a message
83 * @param msg message received, NULL on timeout or fatal error
85 typedef void (*GNUNET_CLIENT_MessageHandler) (void *cls,
86 const struct GNUNET_MessageHeader
91 * Read from the service.
93 * @param client connection to the service
94 * @param handler function to call with the message
95 * @param handler_cls closure for handler
96 * @param timeout how long to wait until timing out
99 GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *client,
100 GNUNET_CLIENT_MessageHandler handler, void *handler_cls,
101 struct GNUNET_TIME_Relative timeout);
105 * Transmit handle for client connections.
107 struct GNUNET_CLIENT_TransmitHandle;
111 * Ask the client to call us once the specified number of bytes
112 * are free in the transmission buffer. May call the notify
113 * method immediately if enough space is available.
115 * @param client connection to the service
116 * @param size number of bytes to send
117 * @param timeout after how long should we give up (and call
118 * notify with buf NULL and size 0)?
119 * @param auto_retry if the connection to the service dies, should we
120 * automatically re-connect and retry (within the timeout period)
121 * or should we immediately fail in this case? Pass GNUNET_YES
122 * if the caller does not care about temporary connection errors,
123 * for example because the protocol is stateless
124 * @param notify function to call
125 * @param notify_cls closure for notify
126 * @return NULL if someone else is already waiting to be notified
127 * non-NULL if the notify callback was queued (can be used to cancel
128 * using GNUNET_CONNECTION_notify_transmit_ready_cancel)
130 struct GNUNET_CLIENT_TransmitHandle *
131 GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
133 struct GNUNET_TIME_Relative timeout,
135 GNUNET_CONNECTION_TransmitReadyNotify
136 notify, void *notify_cls);
140 * Cancel a request for notification.
142 * @param th handle from the original request.
145 GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle
150 * Convenience API that combines sending a request
151 * to the service and waiting for a response.
152 * If either operation times out, the callback
153 * will be called with a "NULL" response (in which
154 * case the connection should probably be destroyed).
156 * @param client connection to use
157 * @param hdr message to transmit
158 * @param timeout when to give up (for both transmission
159 * and for waiting for a response)
160 * @param auto_retry if the connection to the service dies, should we
161 * automatically re-connect and retry (within the timeout period)
162 * or should we immediately fail in this case? Pass GNUNET_YES
163 * if the caller does not care about temporary connection errors,
164 * for example because the protocol is stateless
165 * @param rn function to call with the response
166 * @param rn_cls closure for rn
167 * @return GNUNET_OK on success, GNUNET_SYSERR if a request
171 GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *client,
172 const struct GNUNET_MessageHeader *hdr,
173 struct GNUNET_TIME_Relative timeout,
175 GNUNET_CLIENT_MessageHandler rn,
180 * Handle for a test to check if a service is running.
182 struct GNUNET_CLIENT_TestHandle;
185 * Function called with the result on the service test.
188 * @param result GNUNET_YES if the service is running,
189 * GNUNET_NO if the service is not running
190 * GNUNET_SYSERR if the configuration is invalid
192 typedef void (*GNUNET_CLIENT_TestResultCallback)(void *cls,
197 * Test if the service is running. If we are given a UNIXPATH or a
198 * local address, we do this NOT by trying to connect to the service,
199 * but by trying to BIND to the same port. If the BIND fails, we know
200 * the service is running.
202 * @param service name of the service to wait for
203 * @param cfg configuration to use
204 * @param timeout how long to wait at most in ms
205 * @param cb function to call with the result
206 * @param cb_cls closure for 'cb'
207 * @return handle to cancel the test
209 struct GNUNET_CLIENT_TestHandle *
210 GNUNET_CLIENT_service_test (const char *service,
211 const struct GNUNET_CONFIGURATION_Handle *cfg,
212 struct GNUNET_TIME_Relative timeout,
213 GNUNET_CLIENT_TestResultCallback cb, void *cb_cls);
217 * Abort testing for service.
219 * @param th test handle
222 GNUNET_CLIENT_service_test_cancel (struct GNUNET_CLIENT_TestHandle *th);
225 #if 0 /* keep Emacsens' auto-indent happy */
232 /* ifndef GNUNET_CLIENT_LIB_H */
234 /* end of gnunet_client_lib.h */