aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-08-23 22:11:49 +0000
committerNils Durner <durner@gnunet.org>2009-08-23 22:11:49 +0000
commit2518cfc0a86865ebe4d0550e0013ed52a494231b (patch)
treee9a130b782597e18bcff24a9fdab6e5c6aae1f9c /src/include
parent2ae973618f3b51fa9bbf5532eaa1352cafc24ecc (diff)
downloadgnunet-2518cfc0a86865ebe4d0550e0013ed52a494231b.tar.gz
gnunet-2518cfc0a86865ebe4d0550e0013ed52a494231b.zip
low level network API
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_client_lib.h2
-rw-r--r--src/include/gnunet_connection_lib.h330
-rw-r--r--src/include/gnunet_disk_lib.h25
-rw-r--r--src/include/gnunet_network_lib.h293
-rw-r--r--src/include/gnunet_scheduler_lib.h84
-rw-r--r--src/include/gnunet_server_lib.h2
-rw-r--r--src/include/gnunet_transport_service.h2
-rw-r--r--src/include/gnunet_util_lib.h1
9 files changed, 498 insertions, 242 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 201deeb4f..69954fd30 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -18,6 +18,7 @@ gnunetinclude_HEADERS = \
18 gnunet_constants.h \ 18 gnunet_constants.h \
19 gnunet_configuration_lib.h \ 19 gnunet_configuration_lib.h \
20 gnunet_container_lib.h \ 20 gnunet_container_lib.h \
21 gnunet_connection_lib.h \
21 gnunet_core_service.h \ 22 gnunet_core_service.h \
22 gnunet_crypto_lib.h \ 23 gnunet_crypto_lib.h \
23 gnunet_datacache_lib.h \ 24 gnunet_datacache_lib.h \
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index b73691b79..eb75e8d1e 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -37,7 +37,7 @@ extern "C"
37 37
38#include "gnunet_common.h" 38#include "gnunet_common.h"
39#include "gnunet_configuration_lib.h" 39#include "gnunet_configuration_lib.h"
40#include "gnunet_network_lib.h" 40#include "gnunet_connection_lib.h"
41#include "gnunet_scheduler_lib.h" 41#include "gnunet_scheduler_lib.h"
42#include "gnunet_time_lib.h" 42#include "gnunet_time_lib.h"
43 43
diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h
new file mode 100644
index 000000000..bc4aeea9b
--- /dev/null
+++ b/src/include/gnunet_connection_lib.h
@@ -0,0 +1,330 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file include/gnunet_connection_lib.h
23 * @brief basic, low-level TCP networking interface
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_NETWORK_LIB_H
27#define GNUNET_NETWORK_LIB_H
28
29#ifdef __cplusplus
30extern "C"
31{
32#if 0 /* keep Emacsens' auto-indent happy */
33}
34#endif
35#endif
36
37#include "gnunet_network_lib.h"
38#include "gnunet_scheduler_lib.h"
39#include "gnunet_time_lib.h"
40
41/**
42 * Timeout we use on TCP connect before trying another
43 * result from the DNS resolver. 5s.
44 */
45#define GNUNET_NETWORK_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
46
47/**
48 * @brief handle for a network connection
49 */
50struct GNUNET_NETWORK_ConnectionHandle;
51
52
53/**
54 * Function to call for access control checks.
55 *
56 * @param cls closure
57 * @param addr address
58 * @param addrlen length of address
59 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
60 * for unknown address family (will be denied).
61 */
62typedef int (*GNUNET_NETWORK_AccessCheck) (void *cls,
63 const struct sockaddr * addr,
64 socklen_t addrlen);
65
66
67/**
68 * Callback function for data received from the network. Note that
69 * both "available" and "err" would be 0 if the read simply timed out.
70 *
71 * @param cls closure
72 * @param buf pointer to received data
73 * @param available number of bytes availabe in "buf",
74 * possibly 0 (on errors)
75 * @param addr address of the sender
76 * @param addrlen size of addr
77 * @param errCode value of errno (on errors receiving)
78 */
79typedef void (*GNUNET_NETWORK_Receiver) (void *cls,
80 const void *buf,
81 size_t available,
82 const struct sockaddr * addr,
83 socklen_t addrlen, int errCode);
84
85
86/**
87 * Create a socket handle by boxing an existing OS socket. The OS
88 * socket should henceforth be no longer used directly.
89 * GNUNET_socket_destroy will close it.
90 *
91 * @param sched scheduler to use
92 * @param osSocket existing socket to box
93 * @param maxbuf maximum write buffer size for the socket (use
94 * 0 for sockets that need no write buffers, such as listen sockets)
95 * @return the boxed socket handle
96 */
97struct GNUNET_NETWORK_ConnectionHandle
98 *GNUNET_NETWORK_connection_create_from_existing (struct
99 GNUNET_SCHEDULER_Handle
100 *sched,
101 struct
102 GNUNET_NETWORK_Descriptor
103 *osSocket, size_t maxbuf);
104
105
106/**
107 * Create a socket handle by accepting on a listen socket. This
108 * function may block if the listen socket has no connection ready.
109 *
110 * @param sched scheduler to use
111 * @param access function to use to check if access is allowed
112 * @param access_cls closure for access
113 * @param lsock listen socket
114 * @param maxbuf maximum write buffer size for the socket (use
115 * 0 for sockets that need no write buffers, such as listen sockets)
116 * @return the socket handle, NULL on error (for example, access refused)
117 */
118struct GNUNET_NETWORK_ConnectionHandle
119 *GNUNET_NETWORK_connection_create_from_accept (struct
120 GNUNET_SCHEDULER_Handle
121 *sched,
122 GNUNET_NETWORK_AccessCheck
123 access, void *access_cls,
124 struct
125 GNUNET_NETWORK_Descriptor
126 *lsock, size_t maxbuf);
127
128
129/**
130 * Create a socket handle by (asynchronously) connecting to a host.
131 * This function returns immediately, even if the connection has not
132 * yet been established. This function only creates TCP connections.
133 *
134 * @param sched scheduler to use
135 * @param hostname name of the host to connect to
136 * @param port port to connect to
137 * @param maxbuf maximum write buffer size for the socket (use
138 * 0 for sockets that need no write buffers, such as listen sockets)
139 * @return the socket handle
140 */
141struct GNUNET_NETWORK_ConnectionHandle
142 *GNUNET_NETWORK_connection_create_from_connect (struct
143 GNUNET_SCHEDULER_Handle
144 *sched,
145 const char *hostname,
146 uint16_t port,
147 size_t maxbuf);
148
149
150
151/**
152 * Create a socket handle by (asynchronously) connecting to a host.
153 * This function returns immediately, even if the connection has not
154 * yet been established. This function only creates TCP connections.
155 *
156 * @param sched scheduler to use
157 * @param af_family address family to use
158 * @param serv_addr server address
159 * @param addrlen length of server address
160 * @param maxbuf maximum write buffer size for the socket (use
161 * 0 for sockets that need no write buffers, such as listen sockets)
162 * @return the socket handle
163 */
164struct GNUNET_NETWORK_ConnectionHandle
165 *GNUNET_NETWORK_connection_create_from_sockaddr (struct
166 GNUNET_SCHEDULER_Handle
167 *sched, int af_family,
168 const struct sockaddr
169 *serv_addr,
170 socklen_t addrlen,
171 size_t maxbuf);
172
173/**
174 * Check if socket is valid (no fatal errors have happened so far).
175 * Note that a socket that is still trying to connect is considered
176 * valid.
177 *
178 * @param sock socket to check
179 * @return GNUNET_YES if valid, GNUNET_NO otherwise
180 */
181int GNUNET_NETWORK_connection_check (struct GNUNET_NETWORK_ConnectionHandle
182 *sock);
183
184
185/**
186 * Obtain the network address of the other party.
187 *
188 * @param sock the client to get the address for
189 * @param addr where to store the address
190 * @param addrlen where to store the length of the address
191 * @return GNUNET_OK on success
192 */
193int GNUNET_NETWORK_connection_get_address (struct
194 GNUNET_NETWORK_ConnectionHandle
195 *sock, void **addr,
196 size_t * addrlen);
197
198/**
199 * Close the socket and free associated resources. Pending
200 * transmissions are simply dropped. A pending receive call will be
201 * called with an error code of "EPIPE".
202 *
203 * @param sock socket to destroy
204 */
205void GNUNET_NETWORK_connection_destroy (struct GNUNET_NETWORK_ConnectionHandle
206 *sock);
207
208
209/**
210 * Receive data from the given socket. Note that this function will
211 * call "receiver" asynchronously using the scheduler. It will
212 * "immediately" return. Note that there MUST only be one active
213 * receive call per socket at any given point in time (so do not
214 * call receive again until the receiver callback has been invoked).
215 *
216 * @param sock socket handle
217 * @param max maximum number of bytes to read
218 * @param timeout maximum amount of time to wait
219 * @param receiver function to call with received data
220 * @param receiver_cls closure for receiver
221 * @return scheduler task ID used for receiving, GNUNET_SCHEDULER_NO_TASK on error
222 */
223GNUNET_SCHEDULER_TaskIdentifier
224GNUNET_NETWORK_connection_receive (struct GNUNET_NETWORK_ConnectionHandle
225 *sock, size_t max,
226 struct GNUNET_TIME_Relative timeout,
227 GNUNET_NETWORK_Receiver receiver,
228 void *receiver_cls);
229
230
231/**
232 * Cancel receive job on the given socket. Note that the
233 * receiver callback must not have been called yet in order
234 * for the cancellation to be valid.
235 *
236 * @param sock socket handle
237 * @param task task identifier returned from the receive call
238 * @return closure of the original receiver callback
239 */
240void *GNUNET_NETWORK_connection_receive_cancel (struct
241 GNUNET_NETWORK_ConnectionHandle
242 *sock,
243 GNUNET_SCHEDULER_TaskIdentifier
244 task);
245
246
247/**
248 * Function called to notify a client about the socket
249 * begin ready to queue more data. "buf" will be
250 * NULL and "size" zero if the socket was closed for
251 * writing in the meantime.
252 *
253 * @param cls closure
254 * @param size number of bytes available in buf
255 * @param buf where the callee should write the message
256 * @return number of bytes written to buf
257 */
258typedef size_t (*GNUNET_NETWORK_TransmitReadyNotify) (void *cls,
259 size_t size, void *buf);
260
261
262/**
263 * Opaque handle that can be used to cancel
264 * a transmit-ready notification.
265 */
266struct GNUNET_NETWORK_TransmitHandle;
267
268/**
269 * Ask the socket to call us once the specified number of bytes
270 * are free in the transmission buffer. May call the notify
271 * method immediately if enough space is available. Note that
272 * this function will abort if "size" is greater than
273 * "maxbuf" (as specified when the socket handle was created).
274 *
275 * Note that "notify" will be called either when enough
276 * buffer space is available OR when the socket is destroyed.
277 * The size parameter given to notify is guaranteed to be
278 * larger or equal to size if the buffer is ready, or zero
279 * if the socket was destroyed (or at least closed for
280 * writing). Finally, any time before 'notify' is called, a
281 * client may call "notify_transmit_ready_cancel" to cancel
282 * the transmission request.
283 *
284 * Only one transmission request can be scheduled at the same
285 * time. Notify will be run with the same scheduler priority
286 * as that of the caller.
287 *
288 * @param sock socket
289 * @param size number of bytes to send
290 * @param timeout after how long should we give up (and call
291 * notify with buf NULL and size 0)?
292 * @param notify function to call when buffer space is available
293 * @param notify_cls closure for notify
294 * @return non-NULL if the notify callback was queued,
295 * NULL if we are already going to notify someone else (busy)
296 */
297struct GNUNET_NETWORK_TransmitHandle
298 *GNUNET_NETWORK_connection_notify_transmit_ready (struct
299 GNUNET_NETWORK_ConnectionHandle
300 *sock, size_t size,
301 struct
302 GNUNET_TIME_Relative
303 timeout,
304 GNUNET_NETWORK_TransmitReadyNotify
305 notify, void *notify_cls);
306
307
308/**
309 * Cancel the specified transmission-ready
310 * notification.
311 *
312 * @param h handle for notification to cancel
313 */
314void
315GNUNET_NETWORK_connection_notify_transmit_ready_cancel (struct
316 GNUNET_NETWORK_TransmitHandle
317 *h);
318
319
320#if 0 /* keep Emacsens' auto-indent happy */
321{
322#endif
323#ifdef __cplusplus
324}
325#endif
326
327
328/* ifndef GNUNET_NETWORK_LIB_H */
329#endif
330/* end of gnunet_connection_lib.h */
diff --git a/src/include/gnunet_disk_lib.h b/src/include/gnunet_disk_lib.h
index 49f2ece48..a5f279f05 100644
--- a/src/include/gnunet_disk_lib.h
+++ b/src/include/gnunet_disk_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) 3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -76,6 +76,8 @@ enum GNUNET_DISK_Seek {GNUNET_SEEK_SET, GNUNET_SEEK_CUR, GNUNET_SEEK_END};
76 76
77struct GNUNET_DISK_FileHandle; 77struct GNUNET_DISK_FileHandle;
78 78
79struct GNUNET_DISK_PipeHandle;
80
79/** 81/**
80 * Get the number of blocks that are left on the partition that 82 * Get the number of blocks that are left on the partition that
81 * contains the given file (for normal users). 83 * contains the given file (for normal users).
@@ -150,6 +152,19 @@ GNUNET_DISK_mktemp (const char *template);
150 */ 152 */
151struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn, int flags, ...); 153struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn, int flags, ...);
152 154
155/**
156 * Creates an interprocess channel
157 * @param blocking creates an asynchronous pipe if set to GNUNET_NO
158 * @return handle to the new pipe, NULL on error
159 */
160struct GNUNET_DISK_PipeHandle *GNUNET_DISK_pipe (int blocking);
161
162/**
163 * Closes an interprocess channel
164 * @param p pipe
165 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
166 */
167int GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p);
153 168
154/** 169/**
155 * Close an open file. 170 * Close an open file.
@@ -159,6 +174,14 @@ struct GNUNET_DISK_FileHandle *GNUNET_DISK_file_open (const char *fn, int flags,
159 */ 174 */
160int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h); 175int GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h);
161 176
177/**
178 * Get the handle to a particular pipe end
179 * @param p pipe
180 * @param n number of the end
181 */
182const struct GNUNET_DISK_FileHandle *GNUNET_DISK_pipe_handle (const struct
183 GNUNET_DISK_PipeHandle
184 *p, int n);
162 185
163/** 186/**
164 * Read the contents of a binary file into a buffer. 187 * Read the contents of a binary file into a buffer.
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 68ca346e5..baba3aba8 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -20,11 +20,12 @@
20 20
21/** 21/**
22 * @file include/gnunet_network_lib.h 22 * @file include/gnunet_network_lib.h
23 * @brief basic, low-level TCP networking interface 23 * @brief basic low-level networking interface
24 * @author Christian Grothoff 24 * @author Nils Durner
25 */ 25 */
26#ifndef GNUNET_NETWORK_LIB_H 26
27#define GNUNET_NETWORK_LIB_H 27#ifndef GNUNET_NETWORK_LIB_H_
28#define GNUNET_NETWORK_LIB_H_
28 29
29#ifdef __cplusplus 30#ifdef __cplusplus
30extern "C" 31extern "C"
@@ -34,265 +35,102 @@ extern "C"
34#endif 35#endif
35#endif 36#endif
36 37
37#include "gnunet_scheduler_lib.h"
38#include "gnunet_time_lib.h" 38#include "gnunet_time_lib.h"
39 39
40/**
41 * Timeout we use on TCP connect before trying another
42 * result from the DNS resolver. 5s.
43 */
44#define GNUNET_NETWORK_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
45 40
46/** 41/**
47 * @brief handle for a network connection 42 * @brief handle to a socket
48 */ 43 */
49struct GNUNET_NETWORK_ConnectionHandle; 44struct GNUNET_NETWORK_Descriptor;
50
51 45
52/** 46/**
53 * Function to call for access control checks. 47 * @brief collection of IO descriptors
54 *
55 * @param cls closure
56 * @param addr address
57 * @param addrlen length of address
58 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
59 * for unknown address family (will be denied).
60 */ 48 */
61typedef int (*GNUNET_NETWORK_AccessCheck) (void *cls, 49struct GNUNET_NETWORK_FDSet;
62 const struct sockaddr * addr,
63 socklen_t addrlen);
64 50
51struct GNUNET_DISK_FileHandle;
65 52
66/** 53struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Descriptor *desc,
67 * Callback function for data received from the network. Note that 54 struct sockaddr *address,
68 * both "available" and "err" would be 0 if the read simply timed out. 55 socklen_t *address_len);
69 *
70 * @param cls closure
71 * @param buf pointer to received data
72 * @param available number of bytes availabe in "buf",
73 * possibly 0 (on errors)
74 * @param addr address of the sender
75 * @param addrlen size of addr
76 * @param errCode value of errno (on errors receiving)
77 */
78typedef void (*GNUNET_NETWORK_Receiver) (void *cls,
79 const void *buf,
80 size_t available,
81 const struct sockaddr * addr,
82 socklen_t addrlen, int errCode);
83 56
57int GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Descriptor *desc,
58 const struct sockaddr *address, socklen_t address_len);
84 59
85/** 60int GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Descriptor *desc);
86 * Create a socket handle by boxing an existing OS socket. The OS
87 * socket should henceforth be no longer used directly.
88 * GNUNET_socket_destroy will close it.
89 *
90 * @param sched scheduler to use
91 * @param osSocket existing socket to box
92 * @param maxbuf maximum write buffer size for the socket (use
93 * 0 for sockets that need no write buffers, such as listen sockets)
94 * @return the boxed socket handle
95 */
96struct GNUNET_NETWORK_ConnectionHandle
97 *GNUNET_NETWORK_connection_create_from_existing (struct GNUNET_SCHEDULER_Handle
98 *sched, int osSocket,
99 size_t maxbuf);
100 61
62int GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Descriptor *desc,
63 const struct sockaddr *address, socklen_t address_len);
101 64
102/** 65int GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Descriptor *desc, int level, int optname,
103 * Create a socket handle by accepting on a listen socket. This 66 void *optval, socklen_t *optlen);
104 * function may block if the listen socket has no connection ready.
105 *
106 * @param sched scheduler to use
107 * @param access function to use to check if access is allowed
108 * @param access_cls closure for access
109 * @param lsock listen socket
110 * @param maxbuf maximum write buffer size for the socket (use
111 * 0 for sockets that need no write buffers, such as listen sockets)
112 * @return the socket handle, NULL on error (for example, access refused)
113 */
114struct GNUNET_NETWORK_ConnectionHandle
115 *GNUNET_NETWORK_connection_create_from_accept (struct GNUNET_SCHEDULER_Handle
116 *sched,
117 GNUNET_NETWORK_AccessCheck
118 access, void *access_cls,
119 int lsock, size_t maxbuf);
120 67
68int GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Descriptor *desc, int backlog);
121 69
122/** 70ssize_t GNUNET_NETWORK_socket_read (const struct GNUNET_NETWORK_Descriptor *desc, void *buf,
123 * Create a socket handle by (asynchronously) connecting to a host. 71 size_t nbyte);
124 * This function returns immediately, even if the connection has not
125 * yet been established. This function only creates TCP connections.
126 *
127 * @param sched scheduler to use
128 * @param hostname name of the host to connect to
129 * @param port port to connect to
130 * @param maxbuf maximum write buffer size for the socket (use
131 * 0 for sockets that need no write buffers, such as listen sockets)
132 * @return the socket handle
133 */
134struct GNUNET_NETWORK_ConnectionHandle
135 *GNUNET_NETWORK_connection_create_from_connect (struct GNUNET_SCHEDULER_Handle
136 *sched, const char *hostname,
137 uint16_t port, size_t maxbuf);
138 72
73ssize_t GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Descriptor *desc, void *buffer,
74 size_t length, int flags);
139 75
76int GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
77 struct GNUNET_NETWORK_FDSet *wfds, struct GNUNET_NETWORK_FDSet *efds,
78 struct GNUNET_TIME_Relative timeout);
140 79
141/** 80/**
142 * Create a socket handle by (asynchronously) connecting to a host. 81 * Set if a socket should use blocking or non-blocking IO.
143 * This function returns immediately, even if the connection has not
144 * yet been established. This function only creates TCP connections.
145 * 82 *
146 * @param sched scheduler to use 83 * @return GNUNET_OK on success, GNUNET_SYSERR on error
147 * @param af_family address family to use
148 * @param serv_addr server address
149 * @param addrlen length of server address
150 * @param maxbuf maximum write buffer size for the socket (use
151 * 0 for sockets that need no write buffers, such as listen sockets)
152 * @return the socket handle
153 */ 84 */
154struct GNUNET_NETWORK_ConnectionHandle 85int GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Descriptor *fd, int doBlock);
155 *GNUNET_NETWORK_connection_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle
156 *sched, int af_family,
157 const struct sockaddr
158 *serv_addr, socklen_t addrlen,
159 size_t maxbuf);
160 86
161/** 87ssize_t GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Descriptor *desc,
162 * Check if socket is valid (no fatal errors have happened so far). 88 const void *buffer, size_t length, int flags);
163 * Note that a socket that is still trying to connect is considered
164 * valid.
165 *
166 * @param sock socket to check
167 * @return GNUNET_YES if valid, GNUNET_NO otherwise
168 */
169int GNUNET_NETWORK_connection_check (struct GNUNET_NETWORK_ConnectionHandle *sock);
170 89
90ssize_t GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Descriptor *desc,
91 const void *message, size_t length, int flags,
92 const struct sockaddr *dest_addr,
93 socklen_t dest_len);
171 94
172/** 95int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Descriptor *fd, int level, int option_name,
173 * Obtain the network address of the other party. 96 const void *option_value, socklen_t option_len);
174 *
175 * @param sock the client to get the address for
176 * @param addr where to store the address
177 * @param addrlen where to store the length of the address
178 * @return GNUNET_OK on success
179 */
180int GNUNET_NETWORK_connection_get_address (struct GNUNET_NETWORK_ConnectionHandle
181 *sock, void **addr, size_t * addrlen);
182 97
183/** 98int GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Descriptor *desc, int how);
184 * Close the socket and free associated resources. Pending
185 * transmissions are simply dropped. A pending receive call will be
186 * called with an error code of "EPIPE".
187 *
188 * @param sock socket to destroy
189 */
190void GNUNET_NETWORK_connection_destroy (struct GNUNET_NETWORK_ConnectionHandle *sock);
191 99
100struct GNUNET_NETWORK_Descriptor *GNUNET_NETWORK_socket_socket (int domain, int type, int protocol);
192 101
193/** 102ssize_t GNUNET_NETWORK_socket_write (const struct GNUNET_NETWORK_Descriptor *desc,
194 * Receive data from the given socket. Note that this function will 103 const void *buf, size_t nbyte);
195 * call "receiver" asynchronously using the scheduler. It will
196 * "immediately" return. Note that there MUST only be one active
197 * receive call per socket at any given point in time (so do not
198 * call receive again until the receiver callback has been invoked).
199 *
200 * @param sock socket handle
201 * @param max maximum number of bytes to read
202 * @param timeout maximum amount of time to wait
203 * @param receiver function to call with received data
204 * @param receiver_cls closure for receiver
205 * @return scheduler task ID used for receiving, GNUNET_SCHEDULER_NO_TASK on error
206 */
207GNUNET_SCHEDULER_TaskIdentifier
208GNUNET_NETWORK_connection_receive (struct GNUNET_NETWORK_ConnectionHandle *sock,
209 size_t max,
210 struct GNUNET_TIME_Relative timeout,
211 GNUNET_NETWORK_Receiver receiver, void *receiver_cls);
212 104
213 105
214/** 106void GNUNET_NETWORK_fdset_zero(struct GNUNET_NETWORK_FDSet *fds);
215 * Cancel receive job on the given socket. Note that the
216 * receiver callback must not have been called yet in order
217 * for the cancellation to be valid.
218 *
219 * @param sock socket handle
220 * @param task task identifier returned from the receive call
221 * @return closure of the original receiver callback
222 */
223void *GNUNET_NETWORK_connection_receive_cancel (struct GNUNET_NETWORK_ConnectionHandle *sock,
224 GNUNET_SCHEDULER_TaskIdentifier task);
225 107
108void GNUNET_NETWORK_fdset_set(struct GNUNET_NETWORK_FDSet *fds,
109 const struct GNUNET_NETWORK_Descriptor *desc);
226 110
227/** 111int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds,
228 * Function called to notify a client about the socket 112 const struct GNUNET_NETWORK_Descriptor *desc);
229 * begin ready to queue more data. "buf" will be
230 * NULL and "size" zero if the socket was closed for
231 * writing in the meantime.
232 *
233 * @param cls closure
234 * @param size number of bytes available in buf
235 * @param buf where the callee should write the message
236 * @return number of bytes written to buf
237 */
238typedef size_t (*GNUNET_NETWORK_TransmitReadyNotify) (void *cls,
239 size_t size, void *buf);
240 113
114void GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
115 const struct GNUNET_NETWORK_FDSet *src);
241 116
242/** 117void GNUNET_NETWORK_fdset_copy(struct GNUNET_NETWORK_FDSet *to,
243 * Opaque handle that can be used to cancel 118 const struct GNUNET_NETWORK_FDSet *from);
244 * a transmit-ready notification.
245 */
246struct GNUNET_NETWORK_TransmitHandle;
247 119
248/** 120void GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, const fd_set *from,
249 * Ask the socket to call us once the specified number of bytes 121 int nfds);
250 * are free in the transmission buffer. May call the notify
251 * method immediately if enough space is available. Note that
252 * this function will abort if "size" is greater than
253 * "maxbuf" (as specified when the socket handle was created).
254 *
255 * Note that "notify" will be called either when enough
256 * buffer space is available OR when the socket is destroyed.
257 * The size parameter given to notify is guaranteed to be
258 * larger or equal to size if the buffer is ready, or zero
259 * if the socket was destroyed (or at least closed for
260 * writing). Finally, any time before 'notify' is called, a
261 * client may call "notify_transmit_ready_cancel" to cancel
262 * the transmission request.
263 *
264 * Only one transmission request can be scheduled at the same
265 * time. Notify will be run with the same scheduler priority
266 * as that of the caller.
267 *
268 * @param sock socket
269 * @param size number of bytes to send
270 * @param timeout after how long should we give up (and call
271 * notify with buf NULL and size 0)?
272 * @param notify function to call when buffer space is available
273 * @param notify_cls closure for notify
274 * @return non-NULL if the notify callback was queued,
275 * NULL if we are already going to notify someone else (busy)
276 */
277struct GNUNET_NETWORK_TransmitHandle
278 *GNUNET_NETWORK_connection_notify_transmit_ready (struct GNUNET_NETWORK_ConnectionHandle
279 *sock, size_t size,
280 struct GNUNET_TIME_Relative timeout,
281 GNUNET_NETWORK_TransmitReadyNotify
282 notify, void *notify_cls);
283 122
123void GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
124 const struct GNUNET_DISK_FileHandle *h);
284 125
285/** 126int GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
286 * Cancel the specified transmission-ready 127 const struct GNUNET_DISK_FileHandle *h);
287 * notification. 128
288 * 129int GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, const struct GNUNET_NETWORK_FDSet *fds2);
289 * @param h handle for notification to cancel
290 */
291void
292GNUNET_NETWORK_connection_notify_transmit_ready_cancel (struct
293 GNUNET_NETWORK_TransmitHandle
294 *h);
295 130
131struct GNUNET_NETWORK_FDSet *GNUNET_NETWORK_fdset_create ();
132
133void GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds);
296 134
297 135
298#if 0 /* keep Emacsens' auto-indent happy */ 136#if 0 /* keep Emacsens' auto-indent happy */
@@ -302,7 +140,4 @@ GNUNET_NETWORK_connection_notify_transmit_ready_cancel (struct
302} 140}
303#endif 141#endif
304 142
305 143#endif /* GNUNET_NETWORK_LIB_H_ */
306/* ifndef GNUNET_NETWORK_LIB_H */
307#endif
308/* end of gnunet_network_lib.h */
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index d4013e630..86f709ed6 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -35,15 +35,15 @@ extern "C"
35#endif 35#endif
36#endif 36#endif
37 37
38#include "gnunet_time_lib.h"
39 38
39#include "gnunet_time_lib.h"
40#include "gnunet_network_lib.h"
40 41
41/** 42/**
42 * Opaque handle for the scheduling service. 43 * Opaque handle for the scheduling service.
43 */ 44 */
44struct GNUNET_SCHEDULER_Handle; 45struct GNUNET_SCHEDULER_Handle;
45 46
46
47/** 47/**
48 * Opaque reference to a task. 48 * Opaque reference to a task.
49 */ 49 */
@@ -173,14 +173,14 @@ struct GNUNET_SCHEDULER_TaskContext
173 * note that additional bits may be set 173 * note that additional bits may be set
174 * that were not in the original request 174 * that were not in the original request
175 */ 175 */
176 const fd_set *read_ready; 176 const struct GNUNET_NETWORK_FDSet *read_ready;
177 177
178 /** 178 /**
179 * Set of file descriptors ready for writing; 179 * Set of file descriptors ready for writing;
180 * note that additional bits may be set 180 * note that additional bits may be set
181 * that were not in the original request. 181 * that were not in the original request.
182 */ 182 */
183 const fd_set *write_ready; 183 const struct GNUNET_NETWORK_FDSet *write_ready;
184 184
185}; 185};
186 186
@@ -345,12 +345,78 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle *sched,
345 * only valid until "main" is started! 345 * only valid until "main" is started!
346 */ 346 */
347GNUNET_SCHEDULER_TaskIdentifier 347GNUNET_SCHEDULER_TaskIdentifier
348GNUNET_SCHEDULER_add_read (struct GNUNET_SCHEDULER_Handle *sched, 348GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle *sched,
349 int run_on_shutdown,
350 enum GNUNET_SCHEDULER_Priority prio,
351 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
352 struct GNUNET_TIME_Relative delay,
353 struct GNUNET_NETWORK_Descriptor *rfd, GNUNET_SCHEDULER_Task main, void *cls);
354
355
356/**
357 * Schedule a new task to be run with a specified delay or when the
358 * specified file descriptor is ready for writing. The delay can be
359 * used as a timeout on the socket being ready. The task will be
360 * scheduled for execution once either the delay has expired or the
361 * socket operation is ready.
362 *
363 * @param sched scheduler to use
364 * @param run_on_shutdown run on shutdown? Set this
365 * argument to GNUNET_NO to skip this task if
366 * the user requested process termination.
367 * @param prio how important is this task?
368 * @param prerequisite_task run this task after the task with the given
369 * task identifier completes (and any of our other
370 * conditions, such as delay, read or write-readyness
371 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
372 * on completion of other tasks.
373 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
374 * @param wfd write file-descriptor
375 * @param main main function of the task
376 * @param cls closure of task
377 * @return unique task identifier for the job
378 * only valid until "main" is started!
379 */
380GNUNET_SCHEDULER_TaskIdentifier
381GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle *sched,
382 int run_on_shutdown,
383 enum GNUNET_SCHEDULER_Priority prio,
384 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
385 struct GNUNET_TIME_Relative delay,
386 struct GNUNET_NETWORK_Descriptor *wfd, GNUNET_SCHEDULER_Task main, void *cls);
387
388
389/**
390 * Schedule a new task to be run with a specified delay or when the
391 * specified file descriptor is ready for reading. The delay can be
392 * used as a timeout on the socket being ready. The task will be
393 * scheduled for execution once either the delay has expired or the
394 * socket operation is ready.
395 *
396 * @param sched scheduler to use
397 * @param run_on_shutdown run on shutdown? Set this
398 * argument to GNUNET_NO to skip this task if
399 * the user requested process termination.
400 * @param prio how important is this task?
401 * @param prerequisite_task run this task after the task with the given
402 * task identifier completes (and any of our other
403 * conditions, such as delay, read or write-readyness
404 * are satisfied). Use GNUNET_SCHEDULER_NO_TASK to not have any dependency
405 * on completion of other tasks.
406 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever"
407 * @param rfd read file-descriptor
408 * @param main main function of the task
409 * @param cls closure of task
410 * @return unique task identifier for the job
411 * only valid until "main" is started!
412 */
413GNUNET_SCHEDULER_TaskIdentifier
414GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle *sched,
349 int run_on_shutdown, 415 int run_on_shutdown,
350 enum GNUNET_SCHEDULER_Priority prio, 416 enum GNUNET_SCHEDULER_Priority prio,
351 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 417 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
352 struct GNUNET_TIME_Relative delay, 418 struct GNUNET_TIME_Relative delay,
353 int rfd, GNUNET_SCHEDULER_Task main, void *cls); 419 struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_Task main, void *cls);
354 420
355 421
356/** 422/**
@@ -378,12 +444,12 @@ GNUNET_SCHEDULER_add_read (struct GNUNET_SCHEDULER_Handle *sched,
378 * only valid until "main" is started! 444 * only valid until "main" is started!
379 */ 445 */
380GNUNET_SCHEDULER_TaskIdentifier 446GNUNET_SCHEDULER_TaskIdentifier
381GNUNET_SCHEDULER_add_write (struct GNUNET_SCHEDULER_Handle *sched, 447GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle *sched,
382 int run_on_shutdown, 448 int run_on_shutdown,
383 enum GNUNET_SCHEDULER_Priority prio, 449 enum GNUNET_SCHEDULER_Priority prio,
384 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 450 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
385 struct GNUNET_TIME_Relative delay, 451 struct GNUNET_TIME_Relative delay,
386 int wfd, GNUNET_SCHEDULER_Task main, void *cls); 452 struct GNUNET_DISK_FileHandle *wfd, GNUNET_SCHEDULER_Task main, void *cls);
387 453
388 454
389/** 455/**
@@ -429,7 +495,7 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle *sched,
429 GNUNET_SCHEDULER_TaskIdentifier 495 GNUNET_SCHEDULER_TaskIdentifier
430 prerequisite_task, 496 prerequisite_task,
431 struct GNUNET_TIME_Relative delay, 497 struct GNUNET_TIME_Relative delay,
432 int nfds, const fd_set * rs, const fd_set * ws, 498 const struct GNUNET_NETWORK_FDSet * rs, const struct GNUNET_NETWORK_FDSet * ws,
433 GNUNET_SCHEDULER_Task main, void *cls); 499 GNUNET_SCHEDULER_Task main, void *cls);
434 500
435#if 0 /* keep Emacsens' auto-indent happy */ 501#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h
index 82085ad0d..092bab40b 100644
--- a/src/include/gnunet_server_lib.h
+++ b/src/include/gnunet_server_lib.h
@@ -37,7 +37,7 @@ extern "C"
37#endif 37#endif
38 38
39#include "gnunet_common.h" 39#include "gnunet_common.h"
40#include "gnunet_network_lib.h" 40#include "gnunet_connection_lib.h"
41#include "gnunet_scheduler_lib.h" 41#include "gnunet_scheduler_lib.h"
42 42
43 43
diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h
index 037a247a2..385bf7cfb 100644
--- a/src/include/gnunet_transport_service.h
+++ b/src/include/gnunet_transport_service.h
@@ -37,7 +37,7 @@ extern "C"
37 37
38#include "gnunet_configuration_lib.h" 38#include "gnunet_configuration_lib.h"
39#include "gnunet_crypto_lib.h" 39#include "gnunet_crypto_lib.h"
40#include "gnunet_network_lib.h" 40#include "gnunet_connection_lib.h"
41#include "gnunet_scheduler_lib.h" 41#include "gnunet_scheduler_lib.h"
42#include "gnunet_time_lib.h" 42#include "gnunet_time_lib.h"
43 43
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 40686b189..fe382be3f 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -39,6 +39,7 @@ extern "C"
39#include "gnunet_common.h" 39#include "gnunet_common.h"
40#include "gnunet_client_lib.h" 40#include "gnunet_client_lib.h"
41#include "gnunet_configuration_lib.h" 41#include "gnunet_configuration_lib.h"
42#include "gnunet_connection_lib.h"
42#include "gnunet_container_lib.h" 43#include "gnunet_container_lib.h"
43#include "gnunet_crypto_lib.h" 44#include "gnunet_crypto_lib.h"
44#include "gnunet_disk_lib.h" 45#include "gnunet_disk_lib.h"