aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/Makefile.am2
-rw-r--r--src/include/gnunet_arm_service.h18
-rw-r--r--src/include/gnunet_bandwidth_lib.h14
-rw-r--r--src/include/gnunet_cadet_service.h523
-rw-r--r--src/include/gnunet_configuration_lib.h7
-rw-r--r--src/include/gnunet_connection_lib.h400
-rw-r--r--src/include/gnunet_constants.h2
-rw-r--r--src/include/gnunet_core_service.h53
-rw-r--r--src/include/gnunet_datastore_plugin.h41
-rw-r--r--src/include/gnunet_datastore_service.h47
-rw-r--r--src/include/gnunet_fs_service.h47
-rw-r--r--src/include/gnunet_getopt_lib.h349
-rw-r--r--src/include/gnunet_helper_lib.h8
-rw-r--r--src/include/gnunet_json_lib.h20
-rw-r--r--src/include/gnunet_mq_lib.h1
-rw-r--r--src/include/gnunet_multicast_service.h4
-rw-r--r--src/include/gnunet_peerstore_service.h4
-rw-r--r--src/include/gnunet_server_lib.h887
-rw-r--r--src/include/gnunet_service_lib.h107
-rw-r--r--src/include/gnunet_sq_lib.h35
-rw-r--r--src/include/gnunet_util_lib.h17
-rw-r--r--src/include/platform.h1
22 files changed, 496 insertions, 2091 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 4fb2577fd..b745da125 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -38,7 +38,6 @@ gnunetinclude_HEADERS = \
38 gnunet_common.h \ 38 gnunet_common.h \
39 gnunet_constants.h \ 39 gnunet_constants.h \
40 gnunet_configuration_lib.h \ 40 gnunet_configuration_lib.h \
41 gnunet_connection_lib.h \
42 gnunet_consensus_service.h \ 41 gnunet_consensus_service.h \
43 gnunet_container_lib.h \ 42 gnunet_container_lib.h \
44 gnunet_conversation_service.h \ 43 gnunet_conversation_service.h \
@@ -107,7 +106,6 @@ gnunetinclude_HEADERS = \
107 gnunet_scalarproduct_service.h \ 106 gnunet_scalarproduct_service.h \
108 gnunet_scheduler_lib.h \ 107 gnunet_scheduler_lib.h \
109 gnunet_secretsharing_service.h \ 108 gnunet_secretsharing_service.h \
110 gnunet_server_lib.h \
111 gnunet_service_lib.h \ 109 gnunet_service_lib.h \
112 gnunet_set_service.h \ 110 gnunet_set_service.h \
113 gnunet_signal_lib.h \ 111 gnunet_signal_lib.h \
diff --git a/src/include/gnunet_arm_service.h b/src/include/gnunet_arm_service.h
index 7fb14d3ac..f8d71bd8b 100644
--- a/src/include/gnunet_arm_service.h
+++ b/src/include/gnunet_arm_service.h
@@ -62,25 +62,9 @@ enum GNUNET_ARM_RequestStatus
62 GNUNET_ARM_REQUEST_SENT_OK = 0, 62 GNUNET_ARM_REQUEST_SENT_OK = 0,
63 63
64 /** 64 /**
65 * Misconfiguration (can't connect to the ARM service).
66 */
67 GNUNET_ARM_REQUEST_CONFIGURATION_ERROR = 1,
68
69 /**
70 * We disconnected from ARM, and request was not sent. 65 * We disconnected from ARM, and request was not sent.
71 */ 66 */
72 GNUNET_ARM_REQUEST_DISCONNECTED = 2, 67 GNUNET_ARM_REQUEST_DISCONNECTED = 2
73
74 /**
75 * ARM API is busy (probably trying to connect to ARM),
76 * and request was not sent. Try again later.
77 */
78 GNUNET_ARM_REQUEST_BUSY = 3,
79
80 /**
81 * Request time ran out before we had a chance to send it.
82 */
83 GNUNET_ARM_REQUEST_TIMEOUT = 5
84 68
85}; 69};
86 70
diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h
index 178ddaaac..967d50dea 100644
--- a/src/include/gnunet_bandwidth_lib.h
+++ b/src/include/gnunet_bandwidth_lib.h
@@ -133,7 +133,7 @@ struct GNUNET_BANDWIDTH_Tracker
133 /** 133 /**
134 * Maximum number of seconds over which bandwidth may "accumulate". 134 * Maximum number of seconds over which bandwidth may "accumulate".
135 * Note that additionally, we also always allow at least 135 * Note that additionally, we also always allow at least
136 * #GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. 136 * #GNUNET_MAX_MESSAGE_SIZE to accumulate.
137 */ 137 */
138 uint32_t max_carry_s__; 138 uint32_t max_carry_s__;
139}; 139};
@@ -214,10 +214,10 @@ GNUNET_BANDWIDTH_value_max (struct GNUNET_BANDWIDTH_Value32NBO b1,
214/** 214/**
215 * Initialize bandwidth tracker. Note that in addition to the 215 * Initialize bandwidth tracker. Note that in addition to the
216 * 'max_carry_s' limit, we also always allow at least 216 * 'max_carry_s' limit, we also always allow at least
217 * #GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the 217 * #GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the
218 * bytes-per-second limit is so small that within 'max_carry_s' not 218 * bytes-per-second limit is so small that within 'max_carry_s' not
219 * even #GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is 219 * even #GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is
220 * ignored and replaced by #GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in 220 * ignored and replaced by #GNUNET_MAX_MESSAGE_SIZE (which is in
221 * bytes). 221 * bytes).
222 * 222 *
223 * @param av tracker to initialize 223 * @param av tracker to initialize
@@ -238,10 +238,10 @@ GNUNET_BANDWIDTH_tracker_init (struct GNUNET_BANDWIDTH_Tracker *av,
238/** 238/**
239 * Initialize bandwidth tracker. Note that in addition to the 239 * Initialize bandwidth tracker. Note that in addition to the
240 * 'max_carry_s' limit, we also always allow at least 240 * 'max_carry_s' limit, we also always allow at least
241 * GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the 241 * GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the
242 * bytes-per-second limit is so small that within 'max_carry_s' not 242 * bytes-per-second limit is so small that within 'max_carry_s' not
243 * even GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is 243 * even GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is
244 * ignored and replaced by GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in 244 * ignored and replaced by GNUNET_MAX_MESSAGE_SIZE (which is in
245 * bytes). 245 * bytes).
246 * 246 *
247 * @param av tracker to initialize 247 * @param av tracker to initialize
diff --git a/src/include/gnunet_cadet_service.h b/src/include/gnunet_cadet_service.h
index fd838df8d..f76f17a51 100644
--- a/src/include/gnunet_cadet_service.h
+++ b/src/include/gnunet_cadet_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2014 GNUnet e.V. 3 Copyright (C) 2009-2017 GNUnet e.V.
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
@@ -49,7 +49,7 @@ extern "C"
49/** 49/**
50 * Version number of GNUnet-cadet API. 50 * Version number of GNUnet-cadet API.
51 */ 51 */
52#define GNUNET_CADET_VERSION 0x00000004 52#define GNUNET_CADET_VERSION 0x00000005
53 53
54 54
55/** 55/**
@@ -69,6 +69,33 @@ struct GNUNET_CADET_Port;
69 69
70 70
71/** 71/**
72 * Hash uniquely identifying a connection below a tunnel.
73 */
74struct GNUNET_CADET_ConnectionTunnelIdentifier
75{
76 struct GNUNET_ShortHashCode connection_of_tunnel;
77};
78
79
80/**
81 * Number identifying a CADET channel within a tunnel.
82 */
83struct GNUNET_CADET_ChannelTunnelNumber
84{
85 /**
86 * Which number does this channel have that uniquely identfies
87 * it within its tunnel, in network byte order.
88 *
89 * Given two peers, both may initiate channels over the same tunnel.
90 * The @e cn must be greater or equal to 0x80000000 (high-bit set)
91 * for tunnels initiated with the peer that has the larger peer
92 * identity as compared using #GNUNET_CRYPTO_cmp_peer_identity().
93 */
94 uint32_t cn GNUNET_PACKED;
95};
96
97
98/**
72 * Channel options. Second line indicates filed in the 99 * Channel options. Second line indicates filed in the
73 * CadetChannelInfo union carrying the answer. 100 * CadetChannelInfo union carrying the answer.
74 */ 101 */
@@ -108,118 +135,67 @@ enum GNUNET_CADET_ChannelOption
108 135
109 136
110/** 137/**
111 * Functions with this signature are called whenever a message is 138 * Method called whenever a peer connects to a port in MQ-based CADET.
112 * received.
113 *
114 * Each time the function must call #GNUNET_CADET_receive_done on the channel
115 * in order to receive the next message. This doesn't need to be immediate:
116 * can be delayed if some processing is done on the message.
117 * 139 *
118 * @param cls Closure (set from #GNUNET_CADET_connect). 140 * @param cls Closure from #GNUNET_CADET_open_port.
119 * @param channel Connection to the other end. 141 * @param channel New handle to the channel.
120 * @param channel_ctx Place to store local state associated with the channel. 142 * @param source Peer that started this channel.
121 * @param message The actual message. 143 * @return Closure for the incoming @a channel. It's given to:
122 * @return #GNUNET_OK to keep the channel open, 144 * - The #GNUNET_CADET_DisconnectEventHandler (given to
123 * #GNUNET_SYSERR to close it (signal serious error). 145 * #GNUNET_CADET_open_port) when the channel dies.
124 */ 146 * - Each the #GNUNET_MQ_MessageCallback handlers for each message
125typedef int 147 * received on the @a channel.
126(*GNUNET_CADET_MessageCallback) (void *cls,
127 struct GNUNET_CADET_Channel *channel,
128 void **channel_ctx,
129 const struct GNUNET_MessageHeader *message);
130
131
132/**
133 * Message handler. Each struct specifies how to handle on particular
134 * type of message received.
135 */ 148 */
136struct GNUNET_CADET_MessageHandler 149typedef void *
137{ 150(*GNUNET_CADET_ConnectEventHandler) (void *cls,
138 /** 151 struct GNUNET_CADET_Channel *channel,
139 * Function to call for messages of type @e type. 152 const struct GNUNET_PeerIdentity *source);
140 */
141 GNUNET_CADET_MessageCallback callback;
142
143 /**
144 * Type of the message this handler covers.
145 */
146 uint16_t type;
147
148 /**
149 * Expected size of messages of this type. Use 0 for variable-size.
150 * If non-zero, messages of the given type will be discarded if they
151 * do not have the right size.
152 */
153 uint16_t expected_size;
154};
155 153
156 154
157/** 155/**
158 * Method called whenever another peer has added us to a channel 156 * Function called whenever an MQ-channel is destroyed, even if the destruction
159 * the other peer initiated. 157 * was requested by #GNUNET_CADET_channel_destroy.
160 * Only called (once) upon reception of data with a message type which was 158 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
161 * subscribed to in #GNUNET_CADET_connect.
162 *
163 * A call to #GNUNET_CADET_channel_destroy causes te channel to be ignored. In
164 * this case the handler MUST return NULL.
165 * 159 *
166 * @param cls closure 160 * It should clean up any associated state, including cancelling any pending
167 * @param channel new handle to the channel 161 * transmission on this channel.
168 * @param initiator peer that started the channel
169 * @param port Port this channel is for.
170 * @param options CadetOption flag field, with all active option bits set to 1.
171 * 162 *
172 * @return initial channel context for the channel 163 * @param cls Channel closure.
173 * (can be NULL -- that's not an error) 164 * @param channel Connection to the other end (henceforth invalid).
174 */ 165 */
175typedef void * 166typedef void
176(GNUNET_CADET_InboundChannelNotificationHandler) (void *cls, 167(*GNUNET_CADET_DisconnectEventHandler) (void *cls,
177 struct GNUNET_CADET_Channel *channel, 168 const struct GNUNET_CADET_Channel *channel);
178 const struct GNUNET_PeerIdentity *initiator,
179 const struct GNUNET_HashCode *port,
180 enum GNUNET_CADET_ChannelOption options);
181 169
182 170
183/** 171/**
184 * Function called whenever a channel is destroyed. Should clean up 172 * Function called whenever an MQ-channel's transmission window size changes.
185 * any associated state, including cancelling any pending transmission on this
186 * channel.
187 * 173 *
188 * It must NOT call #GNUNET_CADET_channel_destroy on the channel. 174 * The first callback in an outgoing channel will be with a non-zero value
175 * and will mean the channel is connected to the destination.
176 *
177 * For an incoming channel it will be called immediately after the
178 * #GNUNET_CADET_ConnectEventHandler, also with a non-zero value.
189 * 179 *
190 * @param cls closure (set from #GNUNET_CADET_connect) 180 * @param cls Channel closure.
191 * @param channel connection to the other end (henceforth invalid) 181 * @param channel Connection to the other end --- FIXME: drop?
192 * @param channel_ctx place where local state associated 182 * @param window_size New window size. If the is more messages than buffer size
193 * with the channel is stored 183 * this value will be negative. -- FIXME: make unsigned, we never call negative?
194 */ 184 */
195typedef void 185typedef void
196(GNUNET_CADET_ChannelEndHandler) (void *cls, 186(*GNUNET_CADET_WindowSizeEventHandler) (void *cls,
197 const struct GNUNET_CADET_Channel *channel, 187 const struct GNUNET_CADET_Channel *channel,
198 void *channel_ctx); 188 int window_size);
199 189
200 190
201/** 191/**
202 * Connect to the cadet service. 192 * Connect to the MQ-based cadet service.
203 * 193 *
204 * @param cfg Configuration to use. 194 * @param cfg Configuration to use.
205 * @param cls Closure for the various callbacks that follow (including 195 * @return Handle to the cadet service NULL on error.
206 * handlers in the handlers array).
207 * @param cleaner Function called when a channel is destroyed.
208 * It is called immediately if #GNUNET_CADET_channel_destroy
209 * is called on the channel.
210 * @param handlers Callbacks for messages we care about, NULL-terminated. Each
211 * one must call #GNUNET_CADET_receive_done on the channel to
212 * receive the next message. Messages of a type that is not
213 * in the handlers array are ignored if received.
214 *
215 * @return handle to the cadet service NULL on error
216 * (in this case, init is never called)
217 */ 196 */
218struct GNUNET_CADET_Handle * 197struct GNUNET_CADET_Handle *
219GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 198GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
220 void *cls,
221 GNUNET_CADET_ChannelEndHandler cleaner,
222 const struct GNUNET_CADET_MessageHandler *handlers);
223 199
224 200
225/** 201/**
@@ -233,21 +209,29 @@ GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
233void 209void
234GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle); 210GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle);
235 211
212
236/** 213/**
237 * Open a port to receive incomming channels. 214 * Open a port to receive incomming MQ-based channels.
238 * 215 *
239 * @param h CADET handle. 216 * @param h CADET handle.
240 * @param port Hash representing the port number. 217 * @param port Hash identifying the port.
241 * @param new_channel Function called when an channel is received. 218 * @param connects Function called when an incoming channel is connected.
242 * @param new_channel_cls Closure for @a new_channel. 219 * @param connects_cls Closure for the @a connects handler.
243 * 220 * @param window_changes Function called when the transmit window size changes.
221 * Can be NULL.
222 * @param disconnects Function called when a channel is disconnected.
223 * @param handlers Callbacks for messages we care about, NULL-terminated.
244 * @return Port handle. 224 * @return Port handle.
245 */ 225 */
246struct GNUNET_CADET_Port * 226struct GNUNET_CADET_Port *
247GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, 227GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
248 const struct GNUNET_HashCode *port, 228 const struct GNUNET_HashCode *port,
249 GNUNET_CADET_InboundChannelNotificationHandler new_channel, 229 GNUNET_CADET_ConnectEventHandler connects,
250 void *new_channel_cls); 230 void *connects_cls,
231 GNUNET_CADET_WindowSizeEventHandler window_changes,
232 GNUNET_CADET_DisconnectEventHandler disconnects,
233 const struct GNUNET_MQ_MessageHandler *handlers);
234
251 235
252/** 236/**
253 * Close a port opened with @a GNUNET_CADET_open_port. 237 * Close a port opened with @a GNUNET_CADET_open_port.
@@ -258,27 +242,38 @@ GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h,
258void 242void
259GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p); 243GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p);
260 244
245
261/** 246/**
262 * Create a new channel towards a remote peer. 247 * Create a new channel towards a remote peer.
263 * 248 *
264 * If the destination port is not open by any peer or the destination peer 249 * If the destination port is not open by any peer or the destination peer
265 * does not accept the channel, #GNUNET_CADET_ChannelEndHandler will be called 250 * does not accept the channel, @a disconnects will be called
266 * for this channel. 251 * for this channel.
267 * 252 *
268 * @param h cadet handle 253 * @param h CADET handle.
269 * @param channel_ctx client's channel context to associate with the channel 254 * @param channel_cls Closure for the channel. It's given to:
270 * @param peer peer identity the channel should go to 255 * - The management handler @a window_changes.
271 * @param port Port hash (port number). 256 * - The disconnect handler @a disconnects
257 * - Each message type callback in @a handlers
258 * @param destination Peer identity the channel should go to.
259 * @param port Identification of the destination port.
272 * @param options CadetOption flag field, with all desired option bits set to 1. 260 * @param options CadetOption flag field, with all desired option bits set to 1.
273 * 261 * @param window_changes Function called when the transmit window size changes.
274 * @return handle to the channel 262 * Can be NULL if this data is of no interest.
263 * TODO Not yet implemented.
264 * @param disconnects Function called when the channel is disconnected.
265 * @param handlers Callbacks for messages we care about, NULL-terminated.
266 * @return Handle to the channel.
275 */ 267 */
276struct GNUNET_CADET_Channel * 268struct GNUNET_CADET_Channel *
277GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, 269GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h,
278 void *channel_ctx, 270 void *channel_cls,
279 const struct GNUNET_PeerIdentity *peer, 271 const struct GNUNET_PeerIdentity *destination,
280 const struct GNUNET_HashCode *port, 272 const struct GNUNET_HashCode *port,
281 enum GNUNET_CADET_ChannelOption options); 273 enum GNUNET_CADET_ChannelOption options,
274 GNUNET_CADET_WindowSizeEventHandler window_changes,
275 GNUNET_CADET_DisconnectEventHandler disconnects,
276 const struct GNUNET_MQ_MessageHandler *handlers);
282 277
283 278
284/** 279/**
@@ -295,6 +290,52 @@ GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel);
295 290
296 291
297/** 292/**
293 * Obtain the message queue for a connected channel.
294 *
295 * @param channel The channel handle from which to get the MQ.
296 * @return The message queue of the channel.
297 */
298struct GNUNET_MQ_Handle *
299GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel);
300
301
302/**
303 * Indicate readiness to receive the next message on a channel.
304 *
305 * Should only be called once per handler called.
306 *
307 * @param channel Channel that will be allowed to call another handler.
308 */
309void
310GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel);
311
312
313/******************************************************************************/
314/******************** MONITORING /DEBUG API *************************/
315/******************************************************************************/
316/* The following calls are not useful for normal CADET operation, but for */
317/* debug and monitoring of the cadet state. They can be safely ignored. */
318/* The API can change at any point without notice. */
319/* Please contact the developer if you consider any of this calls useful for */
320/* normal cadet applications. */
321/******************************************************************************/
322
323
324/**
325 * Transitional function to convert an unsigned int port to a hash value.
326 * WARNING: local static value returned, NOT reentrant!
327 * WARNING: do not use this function for new code!
328 *
329 * @param port Numerical port (unsigned int format).
330 *
331 * @return A GNUNET_HashCode usable for the new CADET API.
332 */
333const struct GNUNET_HashCode *
334GC_u2h (uint32_t port);
335
336
337
338/**
298 * Struct to retrieve info about a channel. 339 * Struct to retrieve info about a channel.
299 */ 340 */
300union GNUNET_CADET_ChannelInfo 341union GNUNET_CADET_ChannelInfo
@@ -327,76 +368,6 @@ GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel,
327 368
328 369
329/** 370/**
330 * Handle for a transmission request.
331 */
332struct GNUNET_CADET_TransmitHandle;
333
334
335/**
336 * Ask the cadet to call @a notify once it is ready to transmit the
337 * given number of bytes to the specified channel.
338 * Only one call can be active at any time, to issue another request,
339 * wait for the callback or cancel the current request.
340 *
341 * @param channel channel to use for transmission
342 * @param cork is corking allowed for this transmission?
343 * @param maxdelay how long can the message wait?
344 * @param notify_size how many bytes of buffer space does notify want?
345 * @param notify function to call when buffer space is available;
346 * will be called with NULL on timeout or if the overall queue
347 * for this peer is larger than queue_size and this is currently
348 * the message with the lowest priority
349 * @param notify_cls closure for @a notify
350 * @return non-NULL if the notify callback was queued,
351 * NULL if we can not even queue the request (insufficient
352 * memory); if NULL is returned, @a notify will NOT be called.
353 */
354struct GNUNET_CADET_TransmitHandle *
355GNUNET_CADET_notify_transmit_ready (struct GNUNET_CADET_Channel *channel,
356 int cork,
357 struct GNUNET_TIME_Relative maxdelay,
358 size_t notify_size,
359 GNUNET_CONNECTION_TransmitReadyNotify notify,
360 void *notify_cls);
361
362
363/**
364 * Cancel the specified transmission-ready notification.
365 *
366 * #DEPRECATED
367 * Since soon we will send immediately with mq (via request_data),
368 * there will be time or need to cancel a "pending" transmission.
369 *
370 * @param th handle that was returned by "notify_transmit_ready".
371 */
372void
373GNUNET_CADET_notify_transmit_ready_cancel (struct GNUNET_CADET_TransmitHandle *th);
374
375
376/**
377 * Indicate readiness to receive the next message on a channel.
378 *
379 * Should only be called once per handler called.
380 *
381 * @param channel Channel that will be allowed to call another handler.
382 */
383void
384GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel);
385
386
387
388/******************************************************************************/
389/******************** MONITORING /DEBUG API *************************/
390/******************************************************************************/
391/* The following calls are not useful for normal CADET operation, but for */
392/* debug and monitoring of the cadet state. They can be safely ignored. */
393/* The API can change at any point without notice. */
394/* Please contact the developer if you consider any of this calls useful for */
395/* normal cadet applications. */
396/******************************************************************************/
397
398
399/**
400 * Method called to retrieve information about a specific channel the cadet peer 371 * Method called to retrieve information about a specific channel the cadet peer
401 * is aware of, including all transit nodes. 372 * is aware of, including all transit nodes.
402 * 373 *
@@ -482,33 +453,6 @@ typedef void
482 453
483 454
484/** 455/**
485 * Hash uniquely identifying a connection below a tunnel.
486 */
487struct GNUNET_CADET_ConnectionTunnelIdentifier
488{
489 struct GNUNET_ShortHashCode connection_of_tunnel;
490};
491
492
493/**
494 * Number identifying a CADET channel within a tunnel.
495 */
496struct GNUNET_CADET_ChannelTunnelNumber
497{
498 /**
499 * Which number does this channel have that uniquely identfies
500 * it within its tunnel, in network byte order.
501 *
502 * Given two peers, both may initiate channels over the same tunnel.
503 * The @e cn must be greater or equal to 0x80000000 (high-bit set)
504 * for tunnels initiated with the peer that has the larger peer
505 * identity as compared using #GNUNET_CRYPTO_cmp_peer_identity().
506 */
507 uint32_t cn GNUNET_PACKED;
508};
509
510
511/**
512 * Method called to retrieve information about a specific tunnel the cadet peer 456 * Method called to retrieve information about a specific tunnel the cadet peer
513 * has established, o`r is trying to establish. 457 * has established, o`r is trying to establish.
514 * 458 *
@@ -667,169 +611,6 @@ GNUNET_CADET_get_tunnel (struct GNUNET_CADET_Handle *h,
667 void *callback_cls); 611 void *callback_cls);
668 612
669 613
670/**
671 * Create a message queue for a cadet channel.
672 * The message queue can only be used to transmit messages,
673 * not to receive them.
674 *
675 * @param channel the channel to create the message qeue for
676 * @return a message queue to messages over the channel
677 */
678struct GNUNET_MQ_Handle *
679GNUNET_CADET_mq_create (struct GNUNET_CADET_Channel *channel);
680
681
682/**
683 * Transitional function to convert an unsigned int port to a hash value.
684 * WARNING: local static value returned, NOT reentrant!
685 * WARNING: do not use this function for new code!
686 *
687 * @param port Numerical port (unsigned int format).
688 *
689 * @return A GNUNET_HashCode usable for the new CADET API.
690 */
691const struct GNUNET_HashCode *
692GC_u2h (uint32_t port);
693
694
695/******************************************************************************/
696/******************************* MQ-BASED API *********************************/
697/******************************************************************************/
698
699/**
700 * Method called whenever a peer connects to a port in MQ-based CADET.
701 *
702 * @param cls Closure from #GNUNET_CADET_open_porT.
703 * @param channel New handle to the channel.
704 * @param source Peer that started this channel.
705 * @return Closure for the incoming @a channel. It's given to:
706 * - The #GNUNET_CADET_DisconnectEventHandler (given to
707 * #GNUNET_CADET_open_porT) when the channel dies.
708 * - Each the #GNUNET_MQ_MessageCallback handlers for each message
709 * received on the @a channel.
710 */
711typedef void *
712(*GNUNET_CADET_ConnectEventHandler) (void *cls,
713 struct GNUNET_CADET_Channel *channel,
714 const struct GNUNET_PeerIdentity *source);
715
716
717/**
718 * Function called whenever an MQ-channel is destroyed, even if the destruction
719 * was requested by #GNUNET_CADET_channel_destroy.
720 * It must NOT call #GNUNET_CADET_channel_destroy on the channel.
721 *
722 * It should clean up any associated state, including cancelling any pending
723 * transmission on this channel.
724 *
725 * @param cls Channel closure.
726 * @param channel Connection to the other end (henceforth invalid).
727 */
728typedef void
729(*GNUNET_CADET_DisconnectEventHandler) (void *cls,
730 const struct GNUNET_CADET_Channel *channel);
731
732
733/**
734 * Function called whenever an MQ-channel's transmission window size changes.
735 *
736 * The first callback in an outgoing channel will be with a non-zero value
737 * and will mean the channel is connected to the destination.
738 *
739 * For an incoming channel it will be called immediately after the
740 * #GNUNET_CADET_ConnectEventHandler, also with a non-zero value.
741 *
742 * @param cls Channel closure.
743 * @param channel Connection to the other end --- FIXME: drop?
744 * @param window_size New window size. If the is more messages than buffer size
745 * this value will be negative. -- FIXME: make unsigned, we never call negative?
746 */
747typedef void
748(*GNUNET_CADET_WindowSizeEventHandler) (void *cls,
749 const struct GNUNET_CADET_Channel *channel,
750 int window_size);
751
752
753/**
754 * Connect to the MQ-based cadet service.
755 *
756 * @param cfg Configuration to use.
757 * @return Handle to the cadet service NULL on error.
758 */
759struct GNUNET_CADET_Handle *
760GNUNET_CADET_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg);
761
762
763/**
764 * Open a port to receive incomming MQ-based channels.
765 *
766 * @param h CADET handle.
767 * @param port Hash identifying the port.
768 * @param connects Function called when an incoming channel is connected.
769 * @param connects_cls Closure for the @a connects handler.
770 * @param window_changes Function called when the transmit window size changes.
771 * Can be NULL.
772 * @param disconnects Function called when a channel is disconnected.
773 * @param handlers Callbacks for messages we care about, NULL-terminated.
774 * @return Port handle.
775 */
776struct GNUNET_CADET_Port *
777GNUNET_CADET_open_porT (struct GNUNET_CADET_Handle *h,
778 const struct GNUNET_HashCode *port,
779 GNUNET_CADET_ConnectEventHandler connects,
780 void *connects_cls,
781 GNUNET_CADET_WindowSizeEventHandler window_changes,
782 GNUNET_CADET_DisconnectEventHandler disconnects,
783 const struct GNUNET_MQ_MessageHandler *handlers);
784
785/**
786 * Create a new channel towards a remote peer.
787 *
788 * If the destination port is not open by any peer or the destination peer
789 * does not accept the channel, #GNUNET_CADET_ChannelEndHandler will be called
790 * for this channel.
791 *
792 * @param h CADET handle.
793 * @param channel_cls Closure for the channel. It's given to:
794 * - The management handler @a window_changes.
795 * - The disconnect handler @a disconnects
796 * - Each message type callback in @a handlers
797 * @param destination Peer identity the channel should go to.
798 * @param port Identification of the destination port.
799 * @param options CadetOption flag field, with all desired option bits set to 1.
800 * @param window_changes Function called when the transmit window size changes.
801 * Can be NULL if this data is of no interest.
802 * TODO Not yet implemented.
803 * @param disconnects Function called when the channel is disconnected.
804 * @param handlers Callbacks for messages we care about, NULL-terminated.
805 * @return Handle to the channel.
806 */
807struct GNUNET_CADET_Channel *
808GNUNET_CADET_channel_creatE (struct GNUNET_CADET_Handle *h,
809 void *channel_cls,
810 const struct GNUNET_PeerIdentity *destination,
811 const struct GNUNET_HashCode *port,
812 enum GNUNET_CADET_ChannelOption options,
813 GNUNET_CADET_WindowSizeEventHandler window_changes,
814 GNUNET_CADET_DisconnectEventHandler disconnects,
815 const struct GNUNET_MQ_MessageHandler *handlers);
816
817
818/**
819 * Obtain the message queue for a connected channel.
820 *
821 * @param channel The channel handle from which to get the MQ.
822 * @return The message queue of the channel.
823 */
824struct GNUNET_MQ_Handle *
825GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel);
826
827
828/******************************************************************************/
829/******************************* MQ-BASED API *********************************/
830/******************************************************************************/
831
832
833 614
834#if 0 /* keep Emacsens' auto-indent happy */ 615#if 0 /* keep Emacsens' auto-indent happy */
835{ 616{
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 746dea61f..c1537e4f8 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -281,8 +281,8 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
281 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 281 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
282 */ 282 */
283int 283int
284GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle 284GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
285 *cfg, const char *section, 285 const char *section,
286 const char *option, 286 const char *option,
287 float *number); 287 float *number);
288 288
@@ -454,9 +454,6 @@ GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg,
454 size_t buf_size); 454 size_t buf_size);
455 455
456 456
457
458
459
460/** 457/**
461 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" 458 * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR"
462 * where either in the "PATHS" section or the environtment "FOO" is 459 * where either in the "PATHS" section or the environtment "FOO" is
diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h
deleted file mode 100644
index e9dd95d1b..000000000
--- a/src/include/gnunet_connection_lib.h
+++ /dev/null
@@ -1,400 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009 GNUnet e.V.
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 3, 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file include/gnunet_connection_lib.h
25 * Basic, low-level TCP networking interface
26 *
27 * @defgroup connection Connection library
28 * Basic, low-level TCP networking interface
29 * @{
30 */
31#ifndef GNUNET_CONNECTION_LIB_H
32#define GNUNET_CONNECTION_LIB_H
33
34#ifdef __cplusplus
35extern "C"
36{
37#if 0 /* keep Emacsens' auto-indent happy */
38}
39#endif
40#endif
41
42#include "gnunet_network_lib.h"
43#include "gnunet_scheduler_lib.h"
44#include "gnunet_time_lib.h"
45
46/**
47 * Timeout we use on TCP connect before trying another
48 * result from the DNS resolver. Actual value used
49 * is this value divided by the number of address families.
50 * Default is 5s.
51 */
52#define GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
53
54/**
55 * @brief handle for a network connection
56 */
57struct GNUNET_CONNECTION_Handle;
58
59
60/**
61 * Credentials for UNIX domain sockets.
62 */
63struct GNUNET_CONNECTION_Credentials
64{
65 /**
66 * UID of the other end of the connection.
67 */
68 uid_t uid;
69
70 /**
71 * GID of the other end of the connection.
72 */
73 gid_t gid;
74};
75
76
77/**
78 * Function to call for access control checks.
79 *
80 * @param cls closure
81 * @param ucred credentials, if available, otherwise NULL
82 * @param addr address
83 * @param addrlen length of address
84 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
85 * for unknown address family (will be denied).
86 */
87typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls,
88 const struct
89 GNUNET_CONNECTION_Credentials *
90 ucred,
91 const struct sockaddr * addr,
92 socklen_t addrlen);
93
94
95/**
96 * Callback function for data received from the network. Note that
97 * both "available" and "err" would be 0 if the read simply timed out.
98 *
99 * @param cls closure
100 * @param buf pointer to received data
101 * @param available number of bytes availabe in "buf",
102 * possibly 0 (on errors)
103 * @param addr address of the sender
104 * @param addrlen size of addr
105 * @param errCode value of errno (on errors receiving)
106 */
107typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf,
108 size_t available,
109 const struct sockaddr * addr,
110 socklen_t addrlen, int errCode);
111
112/**
113 * Set the persist option on this connection handle. Indicates
114 * that the underlying socket or fd should never really be closed.
115 * Used for indicating process death.
116 *
117 * @param connection the connection to set persistent
118 */
119void
120GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection);
121
122/**
123 * Disable the "CORK" feature for communication with the given socket,
124 * forcing the OS to immediately flush the buffer on transmission
125 * instead of potentially buffering multiple messages. Essentially
126 * reduces the OS send buffers to zero.
127 * Used to make sure that the last messages sent through the connection
128 * reach the other side before the process is terminated.
129 *
130 * @param connection the connection to make flushing and blocking
131 * @return #GNUNET_OK on success
132 */
133int
134GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection);
135
136
137/**
138 * Create a connection handle by (asynchronously) connecting to a host.
139 * This function returns immediately, even if the connection has not
140 * yet been established. This function only creates TCP connections.
141 *
142 * @param s socket to connect
143 * @param serv_addr server address
144 * @param addrlen length of server address
145 * @return the connection handle
146 */
147struct GNUNET_CONNECTION_Handle *
148GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
149 const struct sockaddr *serv_addr,
150 socklen_t addrlen);
151
152
153/**
154 * Create a connection handle by boxing an existing OS socket. The OS
155 * socket should henceforth be no longer used directly.
156 * #GNUNET_CONNECTION_destroy() will close it.
157 *
158 * @param osSocket existing socket to box
159 * @return the boxed socket handle
160 */
161struct GNUNET_CONNECTION_Handle *
162GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket);
163
164
165/**
166 * Create a connection handle by accepting on a listen socket. This
167 * function may block if the listen socket has no connection ready.
168 *
169 * @param access_cb function to use to check if access is allowed
170 * @param access_cb_cls closure for @a access_cb
171 * @param lsock listen socket
172 * @return the connection handle, NULL on error (for example, access refused)
173 */
174struct GNUNET_CONNECTION_Handle *
175GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
176 void *access_cb_cls,
177 struct GNUNET_NETWORK_Handle *lsock);
178
179
180/**
181 * Create a connection handle by (asynchronously) connecting to a host.
182 * This function returns immediately, even if the connection has not
183 * yet been established. This function only creates TCP connections.
184 *
185 * @param cfg configuration to use
186 * @param hostname name of the host to connect to
187 * @param port port to connect to
188 * @return the connection handle
189 */
190struct GNUNET_CONNECTION_Handle *
191GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle
192 *cfg, const char *hostname,
193 uint16_t port);
194
195
196/**
197 * Create a connection handle by connecting to a UNIX domain service.
198 * This function returns immediately, even if the connection has not
199 * yet been established. This function only creates UNIX connections.
200 *
201 * @param cfg configuration to use
202 * @param unixpath path to connect to)
203 * @return the connection handle, NULL on systems without UNIX support
204 */
205struct GNUNET_CONNECTION_Handle *
206GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct
207 GNUNET_CONFIGURATION_Handle
208 *cfg, const char *unixpath);
209
210
211
212
213/**
214 * Create a connection handle by (asynchronously) connecting to a host.
215 * This function returns immediately, even if the connection has not
216 * yet been established. This function only creates TCP connections.
217 *
218 * @param af_family address family to use
219 * @param serv_addr server address
220 * @param addrlen length of server address
221 * @return the connection handle
222 */
223struct GNUNET_CONNECTION_Handle *
224GNUNET_CONNECTION_create_from_sockaddr (int af_family,
225 const struct sockaddr *serv_addr,
226 socklen_t addrlen);
227
228/**
229 * Check if connection is valid (no fatal errors have happened so far).
230 * Note that a connection that is still trying to connect is considered
231 * valid.
232 *
233 * @param connection handle to check
234 * @return GNUNET_YES if valid, GNUNET_NO otherwise
235 */
236int
237GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection);
238
239
240/**
241 * Obtain the network address of the other party.
242 *
243 * @param connection the client to get the address for
244 * @param addr where to store the address
245 * @param addrlen where to store the length of the address
246 * @return GNUNET_OK on success
247 */
248int
249GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection,
250 void **addr, size_t * addrlen);
251
252
253/**
254 * Close the connection and free associated resources. There must
255 * not be any pending requests for reading or writing to the
256 * connection at this time.
257 *
258 * @param connection connection to destroy
259 */
260void
261GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection);
262
263
264/**
265 * Receive data from the given connection. Note that this function will
266 * call "receiver" asynchronously using the scheduler. It will
267 * "immediately" return. Note that there MUST only be one active
268 * receive call per connection at any given point in time (so do not
269 * call receive again until the receiver callback has been invoked).
270 *
271 * @param connection connection handle
272 * @param max maximum number of bytes to read
273 * @param timeout maximum amount of time to wait
274 * @param receiver function to call with received data
275 * @param receiver_cls closure for receiver
276 */
277void
278GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max,
279 struct GNUNET_TIME_Relative timeout,
280 GNUNET_CONNECTION_Receiver receiver,
281 void *receiver_cls);
282
283
284/**
285 * Cancel receive job on the given connection. Note that the
286 * receiver callback must not have been called yet in order
287 * for the cancellation to be valid.
288 *
289 * @param connection connection handle
290 * @return closure of the original receiver callback closure
291 */
292void *
293GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection);
294
295
296/**
297 * Function called to notify a client about the connection begin ready
298 * to queue more data. @a buf will be NULL and @a size zero if the
299 * connection was closed for writing in the meantime.
300 *
301 * @param cls closure
302 * @param size number of bytes available in @a buf
303 * @param buf where the callee should write the message
304 * @return number of bytes written to @a buf
305 */
306typedef size_t
307(*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls,
308 size_t size,
309 void *buf);
310
311
312/**
313 * Opaque handle that can be used to cancel
314 * a transmit-ready notification.
315 */
316struct GNUNET_CONNECTION_TransmitHandle;
317
318/**
319 * Ask the connection to call us once the specified number of bytes
320 * are free in the transmission buffer. Will never call the @a notify
321 * callback in this task, but always first go into the scheduler. Note that
322 * this function will abort if "size" is greater than
323 * #GNUNET_SERVER_MAX_MESSAGE_SIZE.
324 *
325 * Note that "notify" will be called either when enough
326 * buffer space is available OR when the connection is destroyed.
327 * The size parameter given to notify is guaranteed to be
328 * larger or equal to size if the buffer is ready, or zero
329 * if the connection was destroyed (or at least closed for
330 * writing). Finally, any time before 'notify' is called, a
331 * client may call "notify_transmit_ready_cancel" to cancel
332 * the transmission request.
333 *
334 * Only one transmission request can be scheduled at the same
335 * time. Notify will be run with the same scheduler priority
336 * as that of the caller.
337 *
338 * @param connection connection
339 * @param size number of bytes to send
340 * @param timeout after how long should we give up (and call
341 * notify with buf NULL and size 0)?
342 * @param notify function to call when buffer space is available
343 * @param notify_cls closure for notify
344 * @return non-NULL if the notify callback was queued,
345 * NULL if we are already going to notify someone else (busy)
346 */
347struct GNUNET_CONNECTION_TransmitHandle *
348GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection,
349 size_t size,
350 struct GNUNET_TIME_Relative timeout,
351 GNUNET_CONNECTION_TransmitReadyNotify
352 notify, void *notify_cls);
353
354
355/**
356 * Cancel the specified transmission-ready
357 * notification.
358 *
359 * @param th handle for notification to cancel
360 */
361void
362GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
363 GNUNET_CONNECTION_TransmitHandle
364 *th);
365
366
367/**
368 * Create a connection to be proxied using a given connection.
369 *
370 * @param cph connection to proxy server
371 * @return connection to be proxied
372 */
373struct GNUNET_CONNECTION_Handle *
374GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph);
375
376
377/**
378 * Activate proxied connection and destroy initial proxy handshake connection.
379 * There must not be any pending requests for reading or writing to the
380 * proxy hadshake connection at this time.
381 *
382 * @param proxied connection connection to proxy server
383 */
384void
385GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied);
386
387
388#if 0 /* keep Emacsens' auto-indent happy */
389{
390#endif
391#ifdef __cplusplus
392}
393#endif
394
395/* ifndef GNUNET_CONNECTION_LIB_H */
396#endif
397
398/** @} */ /* end of group */
399
400/* end of gnunet_connection_lib.h */
diff --git a/src/include/gnunet_constants.h b/src/include/gnunet_constants.h
index 1d0232cea..1c48298a0 100644
--- a/src/include/gnunet_constants.h
+++ b/src/include/gnunet_constants.h
@@ -40,6 +40,8 @@ extern "C"
40#endif 40#endif
41#endif 41#endif
42 42
43
44
43/** 45/**
44 * Bandwidth (in/out) to assume initially (before either peer has 46 * Bandwidth (in/out) to assume initially (before either peer has
45 * communicated any particular preference). Should be rather low; set 47 * communicated any particular preference). Should be rather low; set
diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h
index 8136770b7..ace223c11 100644
--- a/src/include/gnunet_core_service.h
+++ b/src/include/gnunet_core_service.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2014, 2016 GNUnet e.V. 3 Copyright (C) 2009-2017 GNUnet e.V.
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
@@ -197,57 +197,6 @@ GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h,
197 197
198 198
199/** 199/**
200 * Handle for a transmission request.
201 */
202struct GNUNET_CORE_TransmitHandle;
203
204
205/**
206 * Ask the core to call @a notify once it is ready to transmit the
207 * given number of bytes to the specified @a target. Must only be
208 * called after a connection to the respective peer has been
209 * established (and the client has been informed about this). You may
210 * have one request of this type pending for each connected peer at
211 * any time. If a peer disconnects, the application MUST call
212 * #GNUNET_CORE_notify_transmit_ready_cancel() on the respective
213 * transmission request, if one such request is pending.
214 *
215 * @param handle connection to core service
216 * @param cork is corking allowed for this transmission?
217 * @param priority how important is the message?
218 * @param maxdelay how long can the message wait? Only effective if @a cork is #GNUNET_YES
219 * @param target who should receive the message, never NULL (can be this peer's identity for loopback)
220 * @param notify_size how many bytes of buffer space does @a notify want?
221 * @param notify function to call when buffer space is available;
222 * will be called with NULL on timeout; clients MUST cancel
223 * all pending transmission requests DURING the disconnect
224 * handler
225 * @param notify_cls closure for @a notify
226 * @return non-NULL if the notify callback was queued,
227 * NULL if we can not even queue the request (request already pending);
228 * if NULL is returned, @a notify will NOT be called.
229 */
230struct GNUNET_CORE_TransmitHandle *
231GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
232 int cork,
233 enum GNUNET_CORE_Priority priority,
234 struct GNUNET_TIME_Relative maxdelay,
235 const struct GNUNET_PeerIdentity *target,
236 size_t notify_size,
237 GNUNET_CONNECTION_TransmitReadyNotify notify,
238 void *notify_cls);
239
240
241/**
242 * Cancel the specified transmission-ready notification.
243 *
244 * @param th handle that was returned by #GNUNET_CORE_notify_transmit_ready().
245 */
246void
247GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th);
248
249
250/**
251 * Handle to a CORE monitoring operation. 200 * Handle to a CORE monitoring operation.
252 */ 201 */
253struct GNUNET_CORE_MonitorHandle; 202struct GNUNET_CORE_MonitorHandle;
diff --git a/src/include/gnunet_datastore_plugin.h b/src/include/gnunet_datastore_plugin.h
index 2295d4e72..b1c9cb7c3 100644
--- a/src/include/gnunet_datastore_plugin.h
+++ b/src/include/gnunet_datastore_plugin.h
@@ -204,9 +204,9 @@ typedef void
204 * Get one of the results for a particular key in the datastore. 204 * Get one of the results for a particular key in the datastore.
205 * 205 *
206 * @param cls closure 206 * @param cls closure
207 * @param offset offset of the result (modulo num-results); 207 * @param next_uid return the result with lowest uid >= next_uid
208 * specific ordering does not matter for the offset 208 * @param random if true, return a random result instead of using next_uid
209 * @param key key to match, never NULL 209 * @param key maybe NULL (to match all entries)
210 * @param vhash hash of the value, maybe NULL (to 210 * @param vhash hash of the value, maybe NULL (to
211 * match all values that have the right key). 211 * match all values that have the right key).
212 * Note that for DBlocks there is no difference 212 * Note that for DBlocks there is no difference
@@ -215,17 +215,18 @@ typedef void
215 * @param type entries of which type are relevant? 215 * @param type entries of which type are relevant?
216 * Use 0 for any type. 216 * Use 0 for any type.
217 * @param proc function to call on the matching value; 217 * @param proc function to call on the matching value;
218 * proc should be called with NULL if there is no result 218 * will be called with NULL if nothing matches
219 * @param proc_cls closure for @a proc 219 * @param proc_cls closure for @a proc
220 */ 220 */
221typedef void 221typedef void
222(*PluginGetKey) (void *cls, 222(*PluginGetKey) (void *cls,
223 uint64_t offset, 223 uint64_t next_uid,
224 const struct GNUNET_HashCode *key, 224 bool random,
225 const struct GNUNET_HashCode *vhash, 225 const struct GNUNET_HashCode *key,
226 enum GNUNET_BLOCK_Type type, 226 const struct GNUNET_HashCode *vhash,
227 PluginDatumProcessor proc, 227 enum GNUNET_BLOCK_Type type,
228 void *proc_cls); 228 PluginDatumProcessor proc,
229 void *proc_cls);
229 230
230 231
231/** 232/**
@@ -285,23 +286,22 @@ typedef void
285 286
286 287
287/** 288/**
288 * Select a single item from the datastore at the specified offset 289 * Select a single item from the datastore (among those applicable).
289 * (among those applicable).
290 * 290 *
291 * @param cls closure 291 * @param cls closure
292 * @param offset offset of the result (modulo num-results); 292 * @param next_uid return the result with lowest uid >= next_uid
293 * specific ordering does not matter for the offset
294 * @param type entries of which type should be considered? 293 * @param type entries of which type should be considered?
295 * Must not be zero (ANY). 294 * Must not be zero (ANY).
296 * @param proc function to call on the matching value 295 * @param proc function to call on the matching value;
296 * will be called with NULL if no value matches
297 * @param proc_cls closure for @a proc 297 * @param proc_cls closure for @a proc
298 */ 298 */
299typedef void 299typedef void
300(*PluginGetType) (void *cls, 300(*PluginGetType) (void *cls,
301 uint64_t offset, 301 uint64_t next_uid,
302 enum GNUNET_BLOCK_Type type, 302 enum GNUNET_BLOCK_Type type,
303 PluginDatumProcessor proc, 303 PluginDatumProcessor proc,
304 void *proc_cls); 304 void *proc_cls);
305 305
306 306
307/** 307/**
@@ -354,9 +354,6 @@ struct GNUNET_DATASTORE_PluginFunctions
354 354
355 /** 355 /**
356 * Get datum (of the specified type) with anonymity level zero. 356 * Get datum (of the specified type) with anonymity level zero.
357 * This function is allowed to ignore the 'offset' argument
358 * and instead return a random result (with zero anonymity of
359 * the correct type) if implementing an offset is expensive.
360 */ 357 */
361 PluginGetType get_zero_anonymity; 358 PluginGetType get_zero_anonymity;
362 359
diff --git a/src/include/gnunet_datastore_service.h b/src/include/gnunet_datastore_service.h
index f594d8fa6..830e7da86 100644
--- a/src/include/gnunet_datastore_service.h
+++ b/src/include/gnunet_datastore_service.h
@@ -201,33 +201,6 @@ GNUNET_DATASTORE_release_reserve (struct GNUNET_DATASTORE_Handle *h,
201 201
202 202
203/** 203/**
204 * Update a value in the datastore.
205 *
206 * @param h handle to the datastore
207 * @param uid identifier for the value
208 * @param priority how much to increase the priority of the value
209 * @param expiration new expiration value should be MAX of existing and this argument
210 * @param queue_priority ranking of this request in the priority queue
211 * @param max_queue_size at what queue size should this request be dropped
212 * (if other requests of higher priority are in the queue)
213 * @param cont continuation to call when done
214 * @param cont_cls closure for @a cont
215 * @return NULL if the entry was not queued, otherwise a handle that can be used to
216 * cancel; note that even if NULL is returned, the callback will be invoked
217 * (or rather, will already have been invoked)
218 */
219struct GNUNET_DATASTORE_QueueEntry *
220GNUNET_DATASTORE_update (struct GNUNET_DATASTORE_Handle *h,
221 uint64_t uid,
222 uint32_t priority,
223 struct GNUNET_TIME_Absolute expiration,
224 unsigned int queue_priority,
225 unsigned int max_queue_size,
226 GNUNET_DATASTORE_ContinuationWithStatus cont,
227 void *cont_cls);
228
229
230/**
231 * Explicitly remove some content from the database. @a cont will be 204 * Explicitly remove some content from the database. @a cont will be
232 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if 205 * called with status #GNUNET_OK if content was removed, #GNUNET_NO if
233 * no matching entry was found and #GNUNET_SYSERR on all other types 206 * no matching entry was found and #GNUNET_SYSERR on all other types
@@ -288,10 +261,8 @@ typedef void
288 * will only be called once. 261 * will only be called once.
289 * 262 *
290 * @param h handle to the datastore 263 * @param h handle to the datastore
291 * @param offset offset of the result (modulo num-results); set to 264 * @param next_uid return the result with lowest uid >= next_uid
292 * a random 64-bit value initially; then increment by 265 * @param random if true, return a random result instead of using next_uid
293 * one each time; detect that all results have been found by uid
294 * being again the first uid ever returned.
295 * @param key maybe NULL (to match all entries) 266 * @param key maybe NULL (to match all entries)
296 * @param type desired type, 0 for any 267 * @param type desired type, 0 for any
297 * @param queue_priority ranking of this request in the priority queue 268 * @param queue_priority ranking of this request in the priority queue
@@ -305,7 +276,8 @@ typedef void
305 */ 276 */
306struct GNUNET_DATASTORE_QueueEntry * 277struct GNUNET_DATASTORE_QueueEntry *
307GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h, 278GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
308 uint64_t offset, 279 uint64_t next_uid,
280 bool random,
309 const struct GNUNET_HashCode *key, 281 const struct GNUNET_HashCode *key,
310 enum GNUNET_BLOCK_Type type, 282 enum GNUNET_BLOCK_Type type,
311 unsigned int queue_priority, 283 unsigned int queue_priority,
@@ -316,16 +288,9 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
316 288
317/** 289/**
318 * Get a single zero-anonymity value from the datastore. 290 * Get a single zero-anonymity value from the datastore.
319 * Note that some implementations can ignore the 'offset' and
320 * instead return a random zero-anonymity value. In that case,
321 * detecting the wrap-around based on a repeating UID is at best
322 * probabilistic.
323 * 291 *
324 * @param h handle to the datastore 292 * @param h handle to the datastore
325 * @param offset offset of the result (modulo num-results); set to 293 * @param next_uid return the result with lowest uid >= next_uid
326 * a random 64-bit value initially; then increment by
327 * one each time; detect that all results have been found by uid
328 * being again the first uid ever returned.
329 * @param queue_priority ranking of this request in the priority queue 294 * @param queue_priority ranking of this request in the priority queue
330 * @param max_queue_size at what queue size should this request be dropped 295 * @param max_queue_size at what queue size should this request be dropped
331 * (if other requests of higher priority are in the queue) 296 * (if other requests of higher priority are in the queue)
@@ -339,7 +304,7 @@ GNUNET_DATASTORE_get_key (struct GNUNET_DATASTORE_Handle *h,
339 */ 304 */
340struct GNUNET_DATASTORE_QueueEntry * 305struct GNUNET_DATASTORE_QueueEntry *
341GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h, 306GNUNET_DATASTORE_get_zero_anonymity (struct GNUNET_DATASTORE_Handle *h,
342 uint64_t offset, 307 uint64_t next_uid,
343 unsigned int queue_priority, 308 unsigned int queue_priority,
344 unsigned int max_queue_size, 309 unsigned int max_queue_size,
345 enum GNUNET_BLOCK_Type type, 310 enum GNUNET_BLOCK_Type type,
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index a9c7e8944..ac418072e 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -438,23 +438,36 @@ GNUNET_FS_uri_ksk_create_from_meta_data (const struct GNUNET_CONTAINER_MetaData
438/* ******************** command-line option parsing API *********************** */ 438/* ******************** command-line option parsing API *********************** */
439 439
440/** 440/**
441 * Command-line option parser function that allows the user 441 * Allow user to specify keywords.
442 * to specify one or more '-k' options with keywords. Each 442 *
443 * specified keyword will be added to the URI. A pointer to 443 * @param shortName short name of the option
444 * the URI must be passed as the "scls" argument. 444 * @param name long name of the option
445 * 445 * @param argumentHelp help text for the option argument
446 * @param ctx command line processor context 446 * @param description long help text for the option
447 * @param scls must be of type "struct GNUNET_FS_Uri **" 447 * @param[out] topKeywords set to the desired value
448 * @param option name of the option (typically 'k') 448 */
449 * @param value command line argument given 449struct GNUNET_GETOPT_CommandLineOption
450 * @return #GNUNET_OK on success 450GNUNET_FS_GETOPT_KEYWORDS (char shortName,
451 */ 451 const char *name,
452int 452 const char *argumentHelp,
453GNUNET_FS_getopt_set_keywords (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 453 const char *description,
454 void *scls, 454 struct GNUNET_FS_Uri **topKeywords);
455 const char *option, 455
456 const char *value); 456/**
457 457 * Allow user to specify metadata.
458 *
459 * @param shortName short name of the option
460 * @param name long name of the option
461 * @param argumentHelp help text for the option argument
462 * @param description long help text for the option
463 * @param[out] metadata set to the desired value
464 */
465struct GNUNET_GETOPT_CommandLineOption
466GNUNET_FS_GETOPT_METADATA (char shortName,
467 const char *name,
468 const char *argumentHelp,
469 const char *description,
470 struct GNUNET_CONTAINER_MetaData **meta);
458 471
459/** 472/**
460 * Command-line option parser function that allows the user to specify 473 * Command-line option parser function that allows the user to specify
diff --git a/src/include/gnunet_getopt_lib.h b/src/include/gnunet_getopt_lib.h
index b04020a70..c2bd72340 100644
--- a/src/include/gnunet_getopt_lib.h
+++ b/src/include/gnunet_getopt_lib.h
@@ -97,6 +97,7 @@ typedef int
97 const char *option, 97 const char *option,
98 const char *value); 98 const char *value);
99 99
100
100/** 101/**
101 * @brief Definition of a command line option. 102 * @brief Definition of a command line option.
102 */ 103 */
@@ -130,255 +131,301 @@ struct GNUNET_GETOPT_CommandLineOption
130 int require_argument; 131 int require_argument;
131 132
132 /** 133 /**
134 * Is the presence of this option mandatory?
135 */
136 int option_mandatory;
137
138 /**
133 * Handler for the option. 139 * Handler for the option.
134 */ 140 */
135 GNUNET_GETOPT_CommandLineOptionProcessor processor; 141 GNUNET_GETOPT_CommandLineOptionProcessor processor;
136 142
137 /** 143 /**
144 * Function to call on @e scls to clean up after processing all
145 * the arguments. Can be NULL.
146 */
147 void (*cleaner)(void *cls);
148
149 /**
138 * Specific closure to pass to the processor. 150 * Specific closure to pass to the processor.
139 */ 151 */
140 void *scls; 152 void *scls;
141 153
142}; 154};
143 155
156
144/** 157/**
145 * Macro defining the option to print the command line 158 * Defining the option to print the command line
146 * help text (-h option). 159 * help text (-h option).
147 * 160 *
148 * @param about string with brief description of the application 161 * @param about string with brief description of the application
149 */ 162 */
150#define GNUNET_GETOPT_OPTION_HELP(about) \ 163struct GNUNET_GETOPT_CommandLineOption
151 { 'h', "help", (const char *) NULL, gettext_noop("print this help"), 0, &GNUNET_GETOPT_format_help_, (void *) about } 164GNUNET_GETOPT_OPTION_HELP (const char *about);
152 165
153 166
154/** 167/**
155 * Macro defining the option to print the version of 168 * Define the option to print the version of
156 * the application (-v option) 169 * the application (-v option)
157 * 170 *
158 * @param version string with the version number 171 * @param version string with the version number
159 */ 172 */
160#define GNUNET_GETOPT_OPTION_VERSION(version) \ 173struct GNUNET_GETOPT_CommandLineOption
161 { 'v', "version", (const char *) NULL, gettext_noop("print the version number"), 0, &GNUNET_GETOPT_print_version_, (void *) version } 174GNUNET_GETOPT_OPTION_VERSION (const char *version);
175
162 176
163 177
164/** 178/**
165 * Allow user to specify log file name (-l option) 179 * Allow user to specify log file name (-l option)
166 * 180 *
167 * @param logfn set to the name of the logfile 181 * @param[out] logfn set to the name of the logfile
168 */ 182 */
169#define GNUNET_GETOPT_OPTION_LOGFILE(logfn) \ 183struct GNUNET_GETOPT_CommandLineOption
170 { 'l', "logfile", "LOGFILE", gettext_noop("configure logging to write logs to LOGFILE"), 1, &GNUNET_GETOPT_set_string, (void *) logfn } 184GNUNET_GETOPT_OPTION_LOGFILE (char **logfn);
171 185
172 186
173/** 187/**
174 * Allow user to specify log level (-L option) 188 * Allow user to specify a string.
175 * 189 *
176 * @param loglev set to the log level 190 * @param shortName short name of the option
191 * @param name long name of the option
192 * @param argumentHelp help text for the option argument
193 * @param description long help text for the option
194 * @param[out] str set to the string
177 */ 195 */
178#define GNUNET_GETOPT_OPTION_LOGLEVEL(loglev) \ 196struct GNUNET_GETOPT_CommandLineOption
179 { 'L', "log", "LOGLEVEL", gettext_noop("configure logging to use LOGLEVEL"), 1, &GNUNET_GETOPT_set_string, (void *) loglev } 197GNUNET_GETOPT_OPTION_STRING (char shortName,
198 const char *name,
199 const char *argumentHelp,
200 const char *description,
201 char **str);
202
203/**
204 * Allow user to specify a filename (automatically path expanded).
205 *
206 * @param shortName short name of the option
207 * @param name long name of the option
208 * @param argumentHelp help text for the option argument
209 * @param description long help text for the option
210 * @param[out] str set to the string
211 */
212struct GNUNET_GETOPT_CommandLineOption
213GNUNET_GETOPT_OPTION_FILENAME (char shortName,
214 const char *name,
215 const char *argumentHelp,
216 const char *description,
217 char **str);
180 218
181 219
182/** 220/**
183 * Get number of verbose (-V) flags 221 * Allow user to specify a binary value using Crockford
222 * Base32 encoding.
184 * 223 *
185 * @param level where to store the verbosity level (should be an 'int') 224 * @param shortName short name of the option
225 * @param name long name of the option
226 * @param argumentHelp help text for the option argument
227 * @param description long help text for the option
228 * @param[out] val binary value decoded from Crockford Base32-encoded argument
229 * @param val_size size of @a val in bytes
186 */ 230 */
187#define GNUNET_GETOPT_OPTION_VERBOSE(level) \ 231struct GNUNET_GETOPT_CommandLineOption
188 { 'V', "verbose", (const char *) NULL, gettext_noop("be verbose"), 0, &GNUNET_GETOPT_increment_value, (void *) level } 232GNUNET_GETOPT_OPTION_SET_BASE32_FIXED_SIZE (char shortName,
233 const char *name,
234 const char *argumentHelp,
235 const char *description,
236 void *val,
237 size_t val_size);
189 238
190 239
191/** 240/**
192 * Get configuration file name (-c option) 241 * Allow user to specify a binary value using Crockford
242 * Base32 encoding where the size of the binary value is
243 * automatically determined from its type.
193 * 244 *
194 * @param fn set to the configuration file name 245 * @param shortName short name of the option
246 * @param name long name of the option
247 * @param argumentHelp help text for the option argument
248 * @param description long help text for the option
249 * @param[out] val binary value decoded from Crockford Base32-encoded argument;
250 * size is determined by type (sizeof (*val)).
195 */ 251 */
196#define GNUNET_GETOPT_OPTION_CFG_FILE(fn) \ 252#define GNUNET_GETOPT_OPTION_SET_BASE32_AUTO(shortName,name,argumentHelp,description,val) \
197 { 'c', "config", "FILENAME", gettext_noop("use configuration file FILENAME"), 1, &GNUNET_GETOPT_set_string, (void *) fn } 253 GNUNET_GETOPT_OPTION_SET_BASE32_FIXED_SIZE(shortName,name,argumentHelp,description,val,sizeof(*val))
198 254
199 255
200/** 256/**
201 * Marker for the end of the list of options. 257 * Allow user to specify a flag (which internally means setting
258 * an integer to 1/#GNUNET_YES/#GNUNET_OK.
259 *
260 * @param shortName short name of the option
261 * @param name long name of the option
262 * @param description long help text for the option
263 * @param[out] val set to 1 if the option is present
202 */ 264 */
203#define GNUNET_GETOPT_OPTION_END \ 265struct GNUNET_GETOPT_CommandLineOption
204 { '\0', NULL, NULL, NULL, 0, NULL, NULL } 266GNUNET_GETOPT_OPTION_SET_ONE (char shortName,
267 const char *name,
268 const char *description,
269 int *val);
205 270
206 271
207/** 272/**
208 * Parse the command line. 273 * Allow user to specify an `unsigned int`.
209 * 274 *
210 * @param binaryOptions Name of application with option summary 275 * @param shortName short name of the option
211 * @param allOptions defined options and handlers 276 * @param name long name of the option
212 * @param argc number of arguments in @a argv 277 * @param argumentHelp help text for the option argument
213 * @param argv actual arguments 278 * @param description long help text for the option
214 * @return index into argv with first non-option 279 * @param[out] val set to the value specified at the command line
215 * argument, or #GNUNET_SYSERR on error
216 */ 280 */
217int 281struct GNUNET_GETOPT_CommandLineOption
218GNUNET_GETOPT_run (const char *binaryOptions, 282GNUNET_GETOPT_OPTION_SET_UINT (char shortName,
219 const struct GNUNET_GETOPT_CommandLineOption *allOptions, 283 const char *name,
220 unsigned int argc, char *const *argv); 284 const char *argumentHelp,
285 const char *description,
286 unsigned int *val);
221 287
222 288
223/** 289/**
224 * Set an option of type 'unsigned long long' from the command line. 290 * Allow user to specify an `unsigned long long`.
225 * A pointer to this function should be passed as part of the
226 * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options
227 * of this type. It should be followed by a pointer to a value of
228 * type `unsigned long long`.
229 * 291 *
230 * @param ctx command line processing context 292 * @param shortName short name of the option
231 * @param scls additional closure (will point to the 'unsigned long long') 293 * @param name long name of the option
232 * @param option name of the option 294 * @param argumentHelp help text for the option argument
233 * @param value actual value of the option as a string. 295 * @param description long help text for the option
234 * @return #GNUNET_OK if parsing the value worked 296 * @param[out] val set to the value specified at the command line
235 */ 297 */
236int 298struct GNUNET_GETOPT_CommandLineOption
237GNUNET_GETOPT_set_ulong (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 299GNUNET_GETOPT_OPTION_SET_ULONG (char shortName,
238 void *scls, const char *option, const char *value); 300 const char *name,
301 const char *argumentHelp,
302 const char *description,
303 unsigned long long *val);
239 304
240 305
241/** 306/**
242 * Set an option of type 'struct GNUNET_TIME_Relative' from the command line. 307 * Allow user to specify a `struct GNUNET_TIME_Relative`
243 * A pointer to this function should be passed as part of the 308 * (using human-readable "fancy" time).
244 * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options
245 * of this type. It should be followed by a pointer to a value of
246 * type `struct GNUNET_TIME_Relative`.
247 * 309 *
248 * @param ctx command line processing context 310 * @param shortName short name of the option
249 * @param scls additional closure (will point to the 'struct GNUNET_TIME_Relative') 311 * @param name long name of the option
250 * @param option name of the option 312 * @param argumentHelp help text for the option argument
251 * @param value actual value of the option as a string. 313 * @param description long help text for the option
252 * @return #GNUNET_OK if parsing the value worked 314 * @param[out] val set to the time specified at the command line
253 */ 315 */
254int 316struct GNUNET_GETOPT_CommandLineOption
255GNUNET_GETOPT_set_relative_time (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 317GNUNET_GETOPT_OPTION_SET_RELATIVE_TIME (char shortName,
256 void *scls, const char *option, const char *value); 318 const char *name,
319 const char *argumentHelp,
320 const char *description,
321 struct GNUNET_TIME_Relative *val);
257 322
258 323
259/** 324/**
260 * Set an option of type 'unsigned int' from the command line. 325 * Allow user to specify a `struct GNUNET_TIME_Absolute`
261 * A pointer to this function should be passed as part of the 326 * (using human-readable "fancy" time).
262 * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options
263 * of this type. It should be followed by a pointer to a value of
264 * type `unsigned int`.
265 * 327 *
266 * @param ctx command line processing context 328 * @param shortName short name of the option
267 * @param scls additional closure (will point to the 'unsigned int') 329 * @param name long name of the option
268 * @param option name of the option 330 * @param argumentHelp help text for the option argument
269 * @param value actual value of the option as a string. 331 * @param description long help text for the option
270 * @return #GNUNET_OK if parsing the value worked 332 * @param[out] val set to the time specified at the command line
271 */ 333 */
272int 334struct GNUNET_GETOPT_CommandLineOption
273GNUNET_GETOPT_set_uint (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 335GNUNET_GETOPT_OPTION_SET_ABSOLUTE_TIME (char shortName,
274 void *scls, const char *option, const char *value); 336 const char *name,
337 const char *argumentHelp,
338 const char *description,
339 struct GNUNET_TIME_Absolute *val);
275 340
276 341
277/** 342/**
278 * Set an option of type 'int' from the command line to 1 if the 343 * Increment @a val each time the option flag is given by one.
279 * given option is present.
280 * A pointer to this function should be passed as part of the
281 * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options
282 * of this type. It should be followed by a pointer to a value of
283 * type `int`.
284 * 344 *
285 * @param ctx command line processing context 345 * @param shortName short name of the option
286 * @param scls additional closure (will point to the `int`) 346 * @param name long name of the option
287 * @param option name of the option 347 * @param argumentHelp help text for the option argument
288 * @param value not used (NULL) 348 * @param description long help text for the option
289 * @return #GNUNET_OK (always) 349 * @param[out] val set to 1 if the option is present
290 */ 350 */
291int 351struct GNUNET_GETOPT_CommandLineOption
292GNUNET_GETOPT_set_one (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 352GNUNET_GETOPT_OPTION_INCREMENT_VALUE (char shortName,
293 void *scls, const char *option, const char *value); 353 const char *name,
354 const char *description,
355 unsigned int *val);
294 356
295 357
296/** 358/**
297 * Set an option of type 'char *' from the command line. 359 * Define the '-L' log level option. Note that we do not check
298 * A pointer to this function should be passed as part of the 360 * that the log level is valid here.
299 * `struct GNUNET_GETOPT_CommandLineOption` array to initialize options
300 * of this type. It should be followed by a pointer to a value of
301 * type `char *`, which will be allocated with the requested string.
302 * 361 *
303 * @param ctx command line processing context 362 * @param[out] level set to the log level
304 * @param scls additional closure (will point to the `char *`,
305 * which will be allocated)
306 * @param option name of the option
307 * @param value actual value of the option (a string)
308 * @return #GNUNET_OK (always)
309 */ 363 */
310int 364struct GNUNET_GETOPT_CommandLineOption
311GNUNET_GETOPT_set_string (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 365GNUNET_GETOPT_OPTION_LOGLEVEL (char **level);
312 void *scls, const char *option, const char *value);
313 366
314 367
315/** 368/**
316 * Set an option of type 'char *' from the command line doing fs expansion. 369 * Define the '-V' verbosity option. Using the option more
317 * A pointer to this function should be passed as part of the 370 * than once increments @a level each time.
318 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
319 * of this type. It should be followed by a pointer to a value of
320 * type 'char *', which will be allocated with the requested string.
321 * 371 *
322 * @param ctx command line processing context 372 * @param[out] level set to the verbosity level
323 * @param scls additional closure (will point to the 'char *',
324 * which will be allocated)
325 * @param option name of the option
326 * @param value actual value of the option (a string)
327 * @return #GNUNET_OK (always)
328 */ 373 */
329int 374struct GNUNET_GETOPT_CommandLineOption
330GNUNET_GETOPT_set_filename (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx, 375GNUNET_GETOPT_OPTION_VERBOSE (unsigned int *level);
331 void *scls, const char *option, const char *value); 376
332 377
333/** 378/**
334 * Set an option of type 'unsigned int' from the command line. Each 379 * Allow user to specify log file name (-l option)
335 * time the option flag is given, the value is incremented by one.
336 * A pointer to this function should be passed as part of the
337 * 'struct GNUNET_GETOPT_CommandLineOption' array to initialize options
338 * of this type. It should be followed by a pointer to a value of
339 * type 'int'.
340 * 380 *
341 * @param ctx command line processing context 381 * @param[out] logfn set to the name of the logfile
342 * @param scls additional closure (will point to the 'int')
343 * @param option name of the option
344 * @param value not used (NULL)
345 * @return #GNUNET_OK (always)
346 */ 382 */
347int 383struct GNUNET_GETOPT_CommandLineOption
348GNUNET_GETOPT_increment_value (struct GNUNET_GETOPT_CommandLineProcessorContext 384GNUNET_GETOPT_OPTION_LOGFILE (char **logfn);
349 *ctx, void *scls, const char *option,
350 const char *value);
351 385
352 386
353/* *************** internal prototypes - use macros above! ************* */ 387/**
388 * Allow user to specify configuration file name (-c option)
389 *
390 * @param[out] fn set to the name of the configuration file
391 */
392struct GNUNET_GETOPT_CommandLineOption
393GNUNET_GETOPT_OPTION_CFG_FILE (char **fn);
394
354 395
355/** 396/**
356 * Print out details on command line options (implements --help). 397 * Make the given option mandatory.
357 * 398 *
358 * @param ctx command line processing context 399 * @param opt option to modify
359 * @param scls additional closure (points to about text) 400 * @return @a opt with the mandatory flag set.
360 * @param option name of the option
361 * @param value not used (NULL)
362 * @return #GNUNET_NO (do not continue, not an error)
363 */ 401 */
364int 402struct GNUNET_GETOPT_CommandLineOption
365GNUNET_GETOPT_format_help_ (struct GNUNET_GETOPT_CommandLineProcessorContext 403GNUNET_GETOPT_OPTION_MANDATORY (struct GNUNET_GETOPT_CommandLineOption opt);
366 *ctx, void *scls, const char *option, 404
367 const char *value);
368 405
369/** 406/**
370 * Print out program version (implements --version). 407 * Marker for the end of the list of options.
408 */
409#define GNUNET_GETOPT_OPTION_END \
410 { '\0', NULL, NULL, NULL, 0, 0, NULL, NULL, NULL }
411
412
413/**
414 * Parse the command line.
371 * 415 *
372 * @param ctx command line processing context 416 * @param binaryOptions Name of application with option summary
373 * @param scls additional closure (points to version string) 417 * @param allOptions defined options and handlers
374 * @param option name of the option 418 * @param argc number of arguments in @a argv
375 * @param value not used (NULL) 419 * @param argv actual arguments
376 * @return #GNUNET_NO (do not continue, not an error) 420 * @return index into argv with first non-option
421 * argument, or #GNUNET_SYSERR on error
377 */ 422 */
378int 423int
379GNUNET_GETOPT_print_version_ (struct GNUNET_GETOPT_CommandLineProcessorContext 424GNUNET_GETOPT_run (const char *binaryOptions,
380 *ctx, void *scls, const char *option, 425 const struct GNUNET_GETOPT_CommandLineOption *allOptions,
381 const char *value); 426 unsigned int argc,
427 char *const *argv);
428
382 429
383#if 0 /* keep Emacsens' auto-indent happy */ 430#if 0 /* keep Emacsens' auto-indent happy */
384{ 431{
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h
index db0ca98aa..60b3ff681 100644
--- a/src/include/gnunet_helper_lib.h
+++ b/src/include/gnunet_helper_lib.h
@@ -38,7 +38,8 @@
38#define GNUNET_HELPER_LIB_H 38#define GNUNET_HELPER_LIB_H
39 39
40#include "gnunet_scheduler_lib.h" 40#include "gnunet_scheduler_lib.h"
41#include "gnunet_server_lib.h" 41#include "gnunet_mst_lib.h"
42
42 43
43/** 44/**
44 * The handle to a helper process. 45 * The handle to a helper process.
@@ -52,7 +53,8 @@ struct GNUNET_HELPER_Handle;
52 * 53 *
53 * @param cls the closure from GNUNET_HELPER_start() 54 * @param cls the closure from GNUNET_HELPER_start()
54 */ 55 */
55typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls); 56typedef void
57(*GNUNET_HELPER_ExceptionCallback) (void *cls);
56 58
57 59
58/** 60/**
@@ -75,7 +77,7 @@ struct GNUNET_HELPER_Handle *
75GNUNET_HELPER_start (int with_control_pipe, 77GNUNET_HELPER_start (int with_control_pipe,
76 const char *binary_name, 78 const char *binary_name,
77 char *const binary_argv[], 79 char *const binary_argv[],
78 GNUNET_SERVER_MessageTokenizerCallback cb, 80 GNUNET_MessageTokenizerCallback cb,
79 GNUNET_HELPER_ExceptionCallback exp_cb, 81 GNUNET_HELPER_ExceptionCallback exp_cb,
80 void *cb_cls); 82 void *cb_cls);
81 83
diff --git a/src/include/gnunet_json_lib.h b/src/include/gnunet_json_lib.h
index 9e5f9e284..ce721d8d8 100644
--- a/src/include/gnunet_json_lib.h
+++ b/src/include/gnunet_json_lib.h
@@ -427,6 +427,26 @@ void
427GNUNET_JSON_post_parser_cleanup (void *con_cls); 427GNUNET_JSON_post_parser_cleanup (void *con_cls);
428 428
429 429
430/* ****************** GETOPT JSON helper ******************* */
431
432
433/**
434 * Allow user to specify a JSON input value.
435 *
436 * @param shortName short name of the option
437 * @param name long name of the option
438 * @param argumentHelp help text for the option argument
439 * @param description long help text for the option
440 * @param[out] val set to the JSON specified at the command line
441 */
442struct GNUNET_GETOPT_CommandLineOption
443GNUNET_JSON_getopt (char shortName,
444 const char *name,
445 const char *argumentHelp,
446 const char *description,
447 json_t **json);
448
449
430#endif 450#endif
431 451
432/* end of gnunet_json_lib.h */ 452/* end of gnunet_json_lib.h */
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h
index b05128ccc..ecee1b223 100644
--- a/src/include/gnunet_mq_lib.h
+++ b/src/include/gnunet_mq_lib.h
@@ -35,6 +35,7 @@
35#ifndef GNUNET_MQ_LIB_H 35#ifndef GNUNET_MQ_LIB_H
36#define GNUNET_MQ_LIB_H 36#define GNUNET_MQ_LIB_H
37 37
38#include "gnunet_scheduler_lib.h"
38 39
39/** 40/**
40 * Allocate an envelope, with extra space allocated after the space needed 41 * Allocate an envelope, with extra space allocated after the space needed
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h
index 3829a7040..5645207dd 100644
--- a/src/include/gnunet_multicast_service.h
+++ b/src/include/gnunet_multicast_service.h
@@ -617,6 +617,7 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
617 * data. If 0 is returned in @a data_size the transmission is paused, 617 * data. If 0 is returned in @a data_size the transmission is paused,
618 * and can be resumed with GNUNET_MULTICAST_origin_to_all_resume(). 618 * and can be resumed with GNUNET_MULTICAST_origin_to_all_resume().
619 * #GNUNET_YES if this completes the transmission (all data supplied) 619 * #GNUNET_YES if this completes the transmission (all data supplied)
620 * @deprecated should move to MQ-style API!
620 */ 621 */
621typedef int 622typedef int
622(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls, 623(*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls,
@@ -647,6 +648,7 @@ struct GNUNET_MULTICAST_OriginTransmitHandle;
647 * Closure for @a notify. 648 * Closure for @a notify.
648 * 649 *
649 * @return NULL on error (i.e. request already pending). 650 * @return NULL on error (i.e. request already pending).
651 * @deprecated should move to MQ-style API!
650 */ 652 */
651struct GNUNET_MULTICAST_OriginTransmitHandle * 653struct GNUNET_MULTICAST_OriginTransmitHandle *
652GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin, 654GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
@@ -854,6 +856,7 @@ GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member,
854 * data. If 0 is returned in @a data_size the transmission is paused, 856 * data. If 0 is returned in @a data_size the transmission is paused,
855 * and can be resumed with GNUNET_MULTICAST_member_to_origin_resume(). 857 * and can be resumed with GNUNET_MULTICAST_member_to_origin_resume().
856 * #GNUNET_YES if this completes the transmission (all data supplied) 858 * #GNUNET_YES if this completes the transmission (all data supplied)
859 * @deprecated should move to MQ-style API!
857 */ 860 */
858typedef int 861typedef int
859(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls, 862(*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls,
@@ -880,6 +883,7 @@ struct GNUNET_MULTICAST_MemberTransmitHandle;
880 * Closure for @a notify. 883 * Closure for @a notify.
881 * 884 *
882 * @return Handle to cancel request, NULL on error (i.e. request already pending). 885 * @return Handle to cancel request, NULL on error (i.e. request already pending).
886 * @deprecated should move to MQ-style API!
883 */ 887 */
884struct GNUNET_MULTICAST_MemberTransmitHandle * 888struct GNUNET_MULTICAST_MemberTransmitHandle *
885GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member, 889GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 3cafe70b8..c636447c2 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -86,7 +86,7 @@ struct GNUNET_PEERSTORE_Record
86 /** 86 /**
87 * Peer Identity 87 * Peer Identity
88 */ 88 */
89 struct GNUNET_PeerIdentity *peer; 89 struct GNUNET_PeerIdentity peer;
90 90
91 /** 91 /**
92 * Record key string 92 * Record key string
@@ -106,7 +106,7 @@ struct GNUNET_PEERSTORE_Record
106 /** 106 /**
107 * Expiry time of entry 107 * Expiry time of entry
108 */ 108 */
109 struct GNUNET_TIME_Absolute *expiry; 109 struct GNUNET_TIME_Absolute expiry;
110 110
111 /** 111 /**
112 * Client from which this record originated. 112 * Client from which this record originated.
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h
deleted file mode 100644
index 5da31bcd7..000000000
--- a/src/include/gnunet_server_lib.h
+++ /dev/null
@@ -1,887 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013 GNUnet e.V.
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 3, 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21/**
22 * @author Christian Grothoff
23 *
24 * @file
25 * Library for building GNUnet network servers
26
27 * @defgroup server Server library
28 * Library for building GNUnet network servers
29 *
30 * Provides functions for a server that communicates with clients.
31 *
32 * @see [Documentation](https://gnunet.org/ipc)
33 *
34 * @{
35 */
36
37#ifndef GNUNET_SERVER_LIB_H
38#define GNUNET_SERVER_LIB_H
39
40#ifdef __cplusplus
41extern "C"
42{
43#if 0 /* keep Emacsens' auto-indent happy */
44}
45#endif
46#endif
47
48#include "gnunet_common.h"
49#include "gnunet_connection_lib.h"
50
51
52/**
53 * Largest supported message (to be precise, one byte more
54 * than the largest possible message, so tests involving
55 * this value should check for messages being smaller than
56 * this value).
57 */
58#define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536
59
60/**
61 * Smallest supported message.
62 */
63#define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
64
65/**
66 * @brief handle for a server
67 */
68struct GNUNET_SERVER_Handle;
69
70/**
71 * @brief opaque handle for a client of the server
72 */
73struct GNUNET_SERVER_Client;
74
75/**
76 * @brief opaque handle server returns for aborting transmission to a client.
77 */
78struct GNUNET_SERVER_TransmitHandle;
79
80
81/**
82 * Functions with this signature are called whenever a message is
83 * received.
84 *
85 * @param cls closure
86 * @param client identification of the client
87 * @param message the actual message
88 */
89typedef void
90(*GNUNET_SERVER_MessageCallback) (void *cls,
91 struct GNUNET_SERVER_Client *client,
92 const struct GNUNET_MessageHeader *message);
93
94
95/**
96 * Message handler. Each struct specifies how to handle on particular
97 * type of message received.
98 */
99struct GNUNET_SERVER_MessageHandler
100{
101 /**
102 * Function to call for messages of "type".
103 */
104 GNUNET_SERVER_MessageCallback callback;
105
106 /**
107 * Closure argument for @e callback.
108 */
109 void *callback_cls;
110
111 /**
112 * Type of the message this handler covers.
113 */
114 uint16_t type;
115
116 /**
117 * Expected size of messages of this type. Use 0 for
118 * variable-size. If non-zero, messages of the given
119 * type will be discarded (and the connection closed)
120 * if they do not have the right size.
121 */
122 uint16_t expected_size;
123
124};
125
126
127/**
128 * Create a new server.
129 *
130 * @param access_cb function for access control
131 * @param access_cb_cls closure for @a access_cb
132 * @param lsocks NULL-terminated array of listen sockets
133 * @param idle_timeout after how long should we timeout idle connections?
134 * @param require_found if #GNUNET_YES, connections sending messages of unknown type
135 * will be closed
136 * @return handle for the new server, NULL on error
137 * (typically, "port" already in use)
138 */
139struct GNUNET_SERVER_Handle *
140GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb,
141 void *access_cb_cls,
142 struct GNUNET_NETWORK_Handle **lsocks,
143 struct GNUNET_TIME_Relative idle_timeout,
144 int require_found);
145
146/**
147 * Create a new server.
148 *
149 * @param access_cb function for access control
150 * @param access_cb_cls closure for @a access_cb
151 * @param server_addr address toes listen on (including port), NULL terminated array
152 * @param socklen lengths of respective @a server_addr
153 * @param idle_timeout after how long should we timeout idle connections?
154 * @param require_found if #GNUNET_YES, connections sending messages of unknown type
155 * will be closed
156 * @return handle for the new server, NULL on error
157 * (typically, "port" already in use)
158 */
159struct GNUNET_SERVER_Handle *
160GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
161 void *access_cb_cls,
162 struct sockaddr *const *server_addr,
163 const socklen_t *socklen,
164 struct GNUNET_TIME_Relative idle_timeout,
165 int require_found);
166
167
168/**
169 * Suspend accepting connections from the listen socket temporarily.
170 * Resume activity using #GNUNET_SERVER_resume.
171 *
172 * @param server server to stop accepting connections.
173 */
174void
175GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server);
176
177
178/**
179 * Resume accepting connections from the listen socket.
180 *
181 * @param server server to resume accepting connections.
182 */
183void
184GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server);
185
186
187/**
188 * Stop the listen socket and get ready to shutdown the server once
189 * only clients marked using #GNUNET_SERVER_client_mark_monitor are
190 * left.
191 *
192 * @param server server to stop listening on
193 */
194void
195GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server);
196
197
198/**
199 * Free resources held by this server.
200 *
201 * @param server server to destroy
202 */
203void
204GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server);
205
206
207/**
208 * Add additional handlers to an existing server.
209 *
210 * @param server the server to add handlers to
211 * @param handlers array of message handlers for
212 * incoming messages; the last entry must
213 * have "NULL" for the "callback"; multiple
214 * entries for the same type are allowed,
215 * they will be called in order of occurence.
216 * These handlers can be removed later;
217 * the handlers array must exist until removed
218 * (or server is destroyed).
219 */
220void
221GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
222 const struct GNUNET_SERVER_MessageHandler *handlers);
223
224
225/**
226 * Notify us when the server has enough space to transmit
227 * a message of the given size to the given client.
228 *
229 * @param client client to transmit message to
230 * @param size requested amount of buffer space
231 * @param timeout after how long should we give up (and call
232 * notify with buf NULL and size 0)?
233 * @param callback function to call when space is available
234 * @param callback_cls closure for @a callback
235 * @return non-NULL if the notify callback was queued; can be used
236 * to cancel the request using
237 * #GNUNET_SERVER_notify_transmit_ready_cancel.
238 * NULL if we are already going to notify someone else (busy)
239 */
240struct GNUNET_SERVER_TransmitHandle *
241GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
242 size_t size,
243 struct GNUNET_TIME_Relative timeout,
244 GNUNET_CONNECTION_TransmitReadyNotify callback,
245 void *callback_cls);
246
247
248/**
249 * Abort transmission request.
250 *
251 * @param th request to abort
252 */
253void
254GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th);
255
256
257/**
258 * Set the 'monitor' flag on this client. Clients which have been
259 * marked as 'monitors' won't prevent the server from shutting down
260 * once #GNUNET_SERVER_stop_listening has been invoked. The idea is
261 * that for "normal" clients we likely want to allow them to process
262 * their requests; however, monitor-clients are likely to 'never'
263 * disconnect during shutdown and thus will not be considered when
264 * determining if the server should continue to exist after
265 * #GNUNET_SERVER_destroy has been called.
266 *
267 * @param client the client to set the 'monitor' flag on
268 */
269void
270GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client);
271
272
273/**
274 * Set the persistent flag on this client, used to setup client
275 * connection to only be killed when the process of the service it's
276 * connected to is actually dead. This API is used during shutdown
277 * signalling within ARM, and it is not expected that typical users
278 * of the API would need this function.
279 *
280 * @param client the client to set the persistent flag on
281 */
282void
283GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client);
284
285
286/**
287 * Resume receiving from this client, we are done processing the
288 * current request. This function must be called from within each
289 * #GNUNET_SERVER_MessageCallback (or its respective continuations).
290 *
291 * @param client client we were processing a message of
292 * @param success #GNUNET_OK to keep the connection open and
293 * continue to receive
294 * #GNUNET_NO to close the connection (normal behavior)
295 * #GNUNET_SYSERR to close the connection (signal
296 * serious error)
297 */
298void
299GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
300 int success);
301
302
303/**
304 * Change the timeout for a particular client. Decreasing the timeout
305 * may not go into effect immediately (only after the previous timeout
306 * times out or activity happens on the socket).
307 *
308 * @param client the client to update
309 * @param timeout new timeout for activities on the socket
310 */
311void
312GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
313 struct GNUNET_TIME_Relative timeout);
314
315
316/**
317 * Return user context associated with the given client.
318 * Note: you should probably use the macro (call without the underscore).
319 *
320 * @param client client to query
321 * @param size number of bytes in user context struct (for verification only)
322 * @return pointer to user context
323 */
324void *
325GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
326 size_t size);
327
328
329/**
330 * Set user context to be associated with the given client.
331 * Note: you should probably use the macro (call without the underscore).
332 *
333 * @param client client to query
334 * @param ptr pointer to user context
335 * @param size number of bytes in user context struct (for verification only)
336 */
337void
338GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
339 void *ptr,
340 size_t size);
341
342
343/**
344 * Return user context associated with the given client.
345 *
346 * @param client client to query
347 * @param type expected return type (i.e. 'struct Foo')
348 * @return pointer to user context of type 'type *'.
349 */
350#define GNUNET_SERVER_client_get_user_context(client,type) \
351 (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type))
352
353/**
354 * Set user context to be associated with the given client.
355 *
356 * @param client client to query
357 * @param value pointer to user context
358 */
359#define GNUNET_SERVER_client_set_user_context(client,value) \
360 GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value))
361
362
363/**
364 * Disable the warning the server issues if a message is not acknowledged
365 * in a timely fashion. Use this call if a client is intentionally delayed
366 * for a while. Only applies to the current message.
367 *
368 * @param client client for which to disable the warning
369 */
370void
371GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client
372 *client);
373
374
375/**
376 * Inject a message into the server, pretend it came
377 * from the specified client. Delivery of the message
378 * will happen instantly (if a handler is installed;
379 * otherwise the call does nothing).
380 *
381 * @param server the server receiving the message
382 * @param sender the "pretended" sender of the message
383 * can be NULL!
384 * @param message message to transmit
385 * @return #GNUNET_OK if the message was OK and the
386 * connection can stay open
387 * #GNUNET_SYSERR if the connection to the
388 * client should be shut down
389 */
390int
391GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
392 struct GNUNET_SERVER_Client *sender,
393 const struct GNUNET_MessageHeader *message);
394
395
396/**
397 * Add a TCP socket-based connection to the set of handles managed by
398 * this server. Use this function for outgoing (P2P) connections that
399 * we initiated (and where this server should process incoming
400 * messages).
401 *
402 * @param server the server to use
403 * @param connection the connection to manage (client must
404 * stop using this connection from now on)
405 * @return the client handle
406 */
407struct GNUNET_SERVER_Client *
408GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
409 struct GNUNET_CONNECTION_Handle *connection);
410
411
412/**
413 * Notify the server that the given client handle should
414 * be kept (keeps the connection up if possible, increments
415 * the internal reference counter).
416 *
417 * @param client the client to keep
418 */
419void
420GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client);
421
422
423/**
424 * Notify the server that the given client handle is no
425 * longer required. Decrements the reference counter. If
426 * that counter reaches zero an inactive connection maybe
427 * closed.
428 *
429 * @param client the client to drop
430 */
431void
432GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client);
433
434
435/**
436 * Obtain the network address of the other party.
437 *
438 * @param client the client to get the address for
439 * @param addr where to store the address
440 * @param addrlen where to store the length of @a addr
441 * @return #GNUNET_OK on success
442 */
443int
444GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
445 void **addr, size_t *addrlen);
446
447
448/**
449 * Functions with this signature are called whenever a client
450 * is disconnected on the network level.
451 *
452 * @param cls closure
453 * @param client identification of the client; NULL
454 * for the last call when the server is destroyed
455 */
456typedef void
457(*GNUNET_SERVER_DisconnectCallback) (void *cls,
458 struct GNUNET_SERVER_Client *client);
459
460
461/**
462 * Functions with this signature are called whenever a client
463 * is connected on the network level.
464 *
465 * @param cls closure
466 * @param client identification of the client
467 */
468typedef void
469(*GNUNET_SERVER_ConnectCallback) (void *cls,
470 struct GNUNET_SERVER_Client *client);
471
472
473/**
474 * Ask the server to notify us whenever a client disconnects.
475 * This function is called whenever the actual network connection
476 * is closed; the reference count may be zero or larger than zero
477 * at this point. If the server is destroyed before this
478 * notification is explicitly cancelled, the 'callback' will
479 * once be called with a 'client' argument of NULL to indicate
480 * that the server itself is now gone (and that the callback
481 * won't be called anymore and also can no longer be cancelled).
482 *
483 * @param server the server manageing the clients
484 * @param callback function to call on disconnect
485 * @param callback_cls closure for @a callback
486 */
487void
488GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
489 GNUNET_SERVER_DisconnectCallback callback,
490 void *callback_cls);
491
492
493/**
494 * Ask the server to notify us whenever a client connects.
495 * This function is called whenever the actual network connection
496 * is opened. If the server is destroyed before this
497 * notification is explicitly cancelled, the @a callback will
498 * once be called with a 'client' argument of NULL to indicate
499 * that the server itself is now gone (and that the callback
500 * won't be called anymore and also can no longer be cancelled).
501 *
502 * @param server the server manageing the clients
503 * @param callback function to call on sconnect
504 * @param callback_cls closure for @a callback
505 */
506void
507GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
508 GNUNET_SERVER_ConnectCallback callback,
509 void *callback_cls);
510
511
512/**
513 * Ask the server to stop notifying us whenever a client disconnects.
514 * Arguments must match exactly those given to
515 * #GNUNET_SERVER_disconnect_notify. It is not necessary to call this
516 * function during shutdown of the server; in fact, most applications
517 * will never use this function.
518 *
519 * @param server the server manageing the clients
520 * @param callback function to call on disconnect
521 * @param callback_cls closure for @a callback
522 */
523void
524GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
525 GNUNET_SERVER_DisconnectCallback callback,
526 void *callback_cls);
527
528
529/**
530 * Ask the server to stop notifying us whenever a client connects.
531 * Arguments must match exactly those given to
532 * #GNUNET_SERVER_connect_notify. It is not necessary to call this
533 * function during shutdown of the server; in fact, most applications
534 * will never use this function.
535 *
536 * @param server the server manageing the clients
537 * @param callback function to call on connect
538 * @param callback_cls closure for @a callback
539 */
540void
541GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
542 GNUNET_SERVER_ConnectCallback callback,
543 void *callback_cls);
544
545
546/**
547 * Ask the server to disconnect from the given client. This is the
548 * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done,
549 * except that it allows dropping of a client even when not handling a
550 * message from that client.
551 *
552 * @param client the client to disconnect from
553 */
554void
555GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client);
556
557
558/**
559 * Disable the "CORK" feature for communication with the given client,
560 * forcing the OS to immediately flush the buffer on transmission
561 * instead of potentially buffering multiple messages.
562 *
563 * @param client handle to the client
564 * @return #GNUNET_OK on success
565 */
566int
567GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client);
568
569
570/**
571 * The tansmit context is the key datastructure for a conveniance API
572 * used for transmission of complex results to the client followed
573 * ONLY by signaling receive_done with success or error
574 */
575struct GNUNET_SERVER_TransmitContext;
576
577
578/**
579 * Create a new transmission context for the given client.
580 *
581 * @param client client to create the context for.
582 * @return NULL on error
583 */
584struct GNUNET_SERVER_TransmitContext *
585GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client);
586
587
588/**
589 * Append a message to the transmission context.
590 * All messages in the context will be sent by
591 * the #GNUNET_SERVER_transmit_context_run method.
592 *
593 * @param tc context to use
594 * @param data what to append to the result message
595 * @param length length of @a data
596 * @param type type of the message
597 */
598void
599GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext *tc,
600 const void *data,
601 size_t length, uint16_t type);
602
603
604/**
605 * Append a message to the transmission context.
606 * All messages in the context will be sent by
607 * the transmit_context_run method.
608 *
609 * @param tc context to use
610 * @param msg message to append
611 */
612void
613GNUNET_SERVER_transmit_context_append_message (struct GNUNET_SERVER_TransmitContext *tc,
614 const struct GNUNET_MessageHeader *msg);
615
616
617/**
618 * Execute a transmission context. If there is an error in the
619 * transmission, the receive_done method will be called with an error
620 * code (#GNUNET_SYSERR), otherwise with #GNUNET_OK.
621 *
622 * @param tc transmission context to use
623 * @param timeout when to time out and abort the transmission
624 */
625void
626GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
627 struct GNUNET_TIME_Relative timeout);
628
629
630/**
631 * Destroy a transmission context. This function must not be called
632 * after #GNUNET_SERVER_transmit_context_run.
633 *
634 * @param tc transmission context to destroy
635 * @param success code to give to #GNUNET_SERVER_receive_done for
636 * the client: #GNUNET_OK to keep the connection open and
637 * continue to receive
638 * #GNUNET_NO to close the connection (normal behavior)
639 * #GNUNET_SYSERR to close the connection (signal
640 * serious error)
641 */
642void
643GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext *tc,
644 int success);
645
646
647/**
648 * The notification context is the key datastructure for a conveniance
649 * API used for transmission of notifications to the client until the
650 * client disconnects or is disconnected (or the notification context
651 * is destroyed, in which case we disconnect these clients).
652 * Essentially, all (notification) messages are queued up until the
653 * client is able to read them.
654 */
655struct GNUNET_SERVER_NotificationContext;
656
657
658/**
659 * Create a new notification context.
660 *
661 * @param server server for which this function creates the context
662 * @param queue_length maximum number of messages to keep in
663 * the notification queue; optional messages are dropped
664 * if the queue gets longer than this number of messages
665 * @return handle to the notification context
666 */
667struct GNUNET_SERVER_NotificationContext *
668GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
669 unsigned int queue_length);
670
671
672/**
673 * Destroy the context, force disconnect for all clients.
674 *
675 * @param nc context to destroy.
676 */
677void
678GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationContext *nc);
679
680
681/**
682 * Add a client to the notification context.
683 *
684 * @param nc context to modify
685 * @param client client to add
686 */
687void
688GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext *nc,
689 struct GNUNET_SERVER_Client *client);
690
691
692/**
693 * Send a message to a particular client; must have
694 * already been added to the notification context.
695 *
696 * @param nc context to modify
697 * @param client client to transmit to
698 * @param msg message to send
699 * @param can_drop can this message be dropped due to queue length limitations
700 */
701void
702GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationContext *nc,
703 struct GNUNET_SERVER_Client *client,
704 const struct GNUNET_MessageHeader *msg,
705 int can_drop);
706
707
708/**
709 * Send a message to all clients of this context.
710 *
711 * @param nc context to modify
712 * @param msg message to send
713 * @param can_drop can this message be dropped due to queue length limitations
714 */
715void
716GNUNET_SERVER_notification_context_broadcast (struct GNUNET_SERVER_NotificationContext *nc,
717 const struct GNUNET_MessageHeader *msg,
718 int can_drop);
719
720
721/**
722 * Return active number of subscribers in this context.
723 *
724 * @param nc context to query
725 * @return number of current subscribers
726 */
727unsigned int
728GNUNET_SERVER_notification_context_get_size (struct GNUNET_SERVER_NotificationContext *nc);
729
730
731/**
732 * Create a message queue for a server's client.
733 *
734 * @param client the client
735 * @return the message queue
736 */
737struct GNUNET_MQ_Handle *
738GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client);
739
740
741/**
742 * Handle to a message stream tokenizer.
743 */
744struct GNUNET_SERVER_MessageStreamTokenizer;
745
746
747/**
748 * Functions with this signature are called whenever a
749 * complete message is received by the tokenizer.
750 *
751 * Do not call #GNUNET_SERVER_mst_destroy from within
752 * the scope of this callback.
753 *
754 * @param cls closure
755 * @param client identification of the client
756 * @param message the actual message
757 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
758 */
759typedef int
760(*GNUNET_SERVER_MessageTokenizerCallback) (void *cls,
761 void *client,
762 const struct GNUNET_MessageHeader *message);
763
764
765/**
766 * Create a message stream tokenizer.
767 *
768 * @param cb function to call on completed messages
769 * @param cb_cls closure for @a cb
770 * @return handle to tokenizer
771 */
772struct GNUNET_SERVER_MessageStreamTokenizer *
773GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
774 void *cb_cls);
775
776
777/**
778 * Add incoming data to the receive buffer and call the
779 * callback for all complete messages.
780 *
781 * @param mst tokenizer to use
782 * @param client_identity ID of client for which this is a buffer,
783 * can be NULL (will be passed back to 'cb')
784 * @param buf input data to add
785 * @param size number of bytes in @a buf
786 * @param purge should any excess bytes in the buffer be discarded
787 * (i.e. for packet-based services like UDP)
788 * @param one_shot only call callback once, keep rest of message in buffer
789 * @return #GNUNET_OK if we are done processing (need more data)
790 * #GNUNET_NO if one_shot was set and we have another message ready
791 * #GNUNET_SYSERR if the data stream is corrupt
792 */
793int
794GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
795 void *client_identity,
796 const char *buf, size_t size,
797 int purge, int one_shot);
798
799
800/**
801 * Destroys a tokenizer.
802 *
803 * @param mst tokenizer to destroy
804 */
805void
806GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
807
808
809/**
810 * Signature of a function to create a custom tokenizer.
811 *
812 * @param cls closure from #GNUNET_SERVER_set_callbacks
813 * @param client handle to client the tokenzier will be used for
814 * @return handle to custom tokenizer ('mst')
815 */
816typedef void*
817(*GNUNET_SERVER_MstCreateCallback) (void *cls,
818 struct GNUNET_SERVER_Client *client);
819
820
821/**
822 * Signature of a function to destroy a custom tokenizer.
823 *
824 * @param cls closure from #GNUNET_SERVER_set_callbacks
825 * @param mst custom tokenizer handle
826 */
827typedef void
828(*GNUNET_SERVER_MstDestroyCallback) (void *cls,
829 void *mst);
830
831
832/**
833 * Signature of a function to receive data for a custom tokenizer.
834 *
835 * @param cls closure from #GNUNET_SERVER_set_callbacks
836 * @param mst custom tokenizer handle
837 * @param client_identity ID of client for which this is a buffer,
838 * can be NULL (will be passed back to 'cb')
839 * @param buf input data to add
840 * @param size number of bytes in @a buf
841 * @param purge should any excess bytes in the buffer be discarded
842 * (i.e. for packet-based services like UDP)
843 * @param one_shot only call callback once, keep rest of message in buffer
844 * @return #GNUNET_OK if we are done processing (need more data)
845 * #GNUNET_NO if one_shot was set and we have another message ready
846 * #GNUNET_SYSERR if the data stream is corrupt
847 */
848typedef int
849(*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst,
850 struct GNUNET_SERVER_Client *client,
851 const char *buf,
852 size_t size,
853 int purge,
854 int one_shot);
855
856
857/**
858 * Change functions used by the server to tokenize the message stream.
859 * (very rarely used).
860 *
861 * @param server server to modify
862 * @param create new tokenizer initialization function
863 * @param destroy new tokenizer destruction function
864 * @param receive new tokenizer receive function
865 * @param cls closure for @a create, @a receive and @a destroy
866 */
867void
868GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
869 GNUNET_SERVER_MstCreateCallback create,
870 GNUNET_SERVER_MstDestroyCallback destroy,
871 GNUNET_SERVER_MstReceiveCallback receive,
872 void *cls);
873
874
875#if 0 /* keep Emacsens' auto-indent happy */
876{
877#endif
878#ifdef __cplusplus
879}
880#endif
881
882/* ifndef GNUNET_SERVER_LIB_H */
883#endif
884
885/** @} */ /* end of group server */
886
887/* end of gnunet_server_lib.h */
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h
index 75b880530..aacafe956 100644
--- a/src/include/gnunet_service_lib.h
+++ b/src/include/gnunet_service_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016 GNUnet e.V. 3 Copyright (C) 2009-2013, 2016, 2017 GNUnet e.V.
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
@@ -44,25 +44,10 @@ extern "C"
44#endif 44#endif
45 45
46#include "gnunet_configuration_lib.h" 46#include "gnunet_configuration_lib.h"
47#include "gnunet_server_lib.h"
48#include "gnunet_mq_lib.h" 47#include "gnunet_mq_lib.h"
49 48
50 49
51/** 50/**
52 * Function called by the service's run
53 * method to run service-specific setup code.
54 *
55 * @param cls closure
56 * @param server the initialized server
57 * @param cfg configuration to use
58 */
59typedef void
60(*GNUNET_SERVICE_Main) (void *cls,
61 struct GNUNET_SERVER_Handle *server,
62 const struct GNUNET_CONFIGURATION_Handle *cfg);
63
64
65/**
66 * Options for the service (bitmask). 51 * Options for the service (bitmask).
67 */ 52 */
68enum GNUNET_SERVICE_Options 53enum GNUNET_SERVICE_Options
@@ -88,84 +73,6 @@ enum GNUNET_SERVICE_Options
88}; 73};
89 74
90 75
91/**
92 * Run a standard GNUnet service startup sequence (initialize loggers
93 * and configuration, parse options).
94 *
95 * @param argc number of command line arguments in @a argv
96 * @param argv command line arguments
97 * @param service_name our service name
98 * @param options service options
99 * @param task main task of the service
100 * @param task_cls closure for @a task
101 * @return #GNUNET_SYSERR on error, #GNUNET_OK
102 * if we shutdown nicely
103 * @deprecated
104 */
105int
106GNUNET_SERVICE_run (int argc,
107 char *const *argv,
108 const char *service_name,
109 enum GNUNET_SERVICE_Options options,
110 GNUNET_SERVICE_Main task,
111 void *task_cls);
112
113
114/**
115 * Opaque handle for a service.
116 */
117struct GNUNET_SERVICE_Context;
118
119
120/**
121 * Run a service startup sequence within an existing
122 * initialized system.
123 *
124 * @param service_name our service name
125 * @param cfg configuration to use
126 * @param options service options
127 * @return NULL on error, service handle
128 * @deprecated
129 */
130struct GNUNET_SERVICE_Context *
131GNUNET_SERVICE_start (const char *service_name,
132 const struct GNUNET_CONFIGURATION_Handle *cfg,
133 enum GNUNET_SERVICE_Options options);
134
135
136/**
137 * Obtain the server used by a service. Note that the server must NOT
138 * be destroyed by the caller.
139 *
140 * @param ctx the service context returned from the start function
141 * @return handle to the server for this service, NULL if there is none
142 * @deprecated
143 */
144struct GNUNET_SERVER_Handle *
145GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx);
146
147
148/**
149 * Get the NULL-terminated array of listen sockets for this service.
150 *
151 * @param ctx service context to query
152 * @return NULL if there are no listen sockets, otherwise NULL-terminated
153 * array of listen sockets.
154 * @deprecated
155 */
156struct GNUNET_NETWORK_Handle *const *
157GNUNET_SERVICE_get_listen_sockets (struct GNUNET_SERVICE_Context *ctx);
158
159
160/**
161 * Stop a service that was started with #GNUNET_SERVICE_start.
162 *
163 * @param sctx the service context returned from the start function
164 * @deprecated
165 */
166void
167GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx);
168
169 76
170/* **************** NEW SERVICE API ********************** */ 77/* **************** NEW SERVICE API ********************** */
171 78
@@ -245,7 +152,7 @@ typedef void
245 * dropped. Additionally, clients can be dropped at any time using 152 * dropped. Additionally, clients can be dropped at any time using
246 * #GNUNET_SERVICE_client_drop(). 153 * #GNUNET_SERVICE_client_drop().
247 * 154 *
248 * The service must be stopped using #GNUNET_SERVICE_stoP(). 155 * The service must be stopped using #GNUNET_SERVICE_stop().
249 * 156 *
250 * @param service_name name of the service to run 157 * @param service_name name of the service to run
251 * @param cfg configuration to use 158 * @param cfg configuration to use
@@ -258,7 +165,7 @@ typedef void
258 * @return NULL on error 165 * @return NULL on error
259 */ 166 */
260struct GNUNET_SERVICE_Handle * 167struct GNUNET_SERVICE_Handle *
261GNUNET_SERVICE_starT (const char *service_name, 168GNUNET_SERVICE_start (const char *service_name,
262 const struct GNUNET_CONFIGURATION_Handle *cfg, 169 const struct GNUNET_CONFIGURATION_Handle *cfg,
263 GNUNET_SERVICE_ConnectHandler connect_cb, 170 GNUNET_SERVICE_ConnectHandler connect_cb,
264 GNUNET_SERVICE_DisconnectHandler disconnect_cb, 171 GNUNET_SERVICE_DisconnectHandler disconnect_cb,
@@ -267,12 +174,12 @@ GNUNET_SERVICE_starT (const char *service_name,
267 174
268 175
269/** 176/**
270 * Stops a service that was started with #GNUNET_SERVICE_starT(). 177 * Stops a service that was started with #GNUNET_SERVICE_start().
271 * 178 *
272 * @param srv service to stop 179 * @param srv service to stop
273 */ 180 */
274void 181void
275GNUNET_SERVICE_stoP (struct GNUNET_SERVICE_Handle *srv); 182GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv);
276 183
277 184
278/** 185/**
@@ -317,7 +224,7 @@ GNUNET_SERVICE_stoP (struct GNUNET_SERVICE_Handle *srv);
317 * @return 0 on success, non-zero on error 224 * @return 0 on success, non-zero on error
318 */ 225 */
319int 226int
320GNUNET_SERVICE_ruN_ (int argc, 227GNUNET_SERVICE_run_ (int argc,
321 char *const *argv, 228 char *const *argv,
322 const char *service_name, 229 const char *service_name,
323 enum GNUNET_SERVICE_Options options, 230 enum GNUNET_SERVICE_Options options,
@@ -393,7 +300,7 @@ GNUNET_SERVICE_ruN_ (int argc,
393 struct GNUNET_MQ_MessageHandler mh[] = { \ 300 struct GNUNET_MQ_MessageHandler mh[] = { \
394 __VA_ARGS__ \ 301 __VA_ARGS__ \
395 }; \ 302 }; \
396 return GNUNET_SERVICE_ruN_ (argc, \ 303 return GNUNET_SERVICE_run_ (argc, \
397 argv, \ 304 argv, \
398 service_name, \ 305 service_name, \
399 service_options, \ 306 service_options, \
diff --git a/src/include/gnunet_sq_lib.h b/src/include/gnunet_sq_lib.h
index c03f83e07..c196d7767 100644
--- a/src/include/gnunet_sq_lib.h
+++ b/src/include/gnunet_sq_lib.h
@@ -182,6 +182,29 @@ GNUNET_SQ_query_param_uint64 (const uint64_t *x);
182 182
183 183
184/** 184/**
185 * Execute binding operations for a prepared statement.
186 *
187 * @param db_conn database connection
188 * @param params parameters to the statement
189 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
190 */
191int
192GNUNET_SQ_bind (sqlite3_stmt *stmt,
193 const struct GNUNET_SQ_QueryParam *params);
194
195
196/**
197 * Reset @a stmt and log error.
198 *
199 * @param dbh database handle
200 * @param stmt statement to reset
201 */
202void
203GNUNET_SQ_reset (sqlite3 *dbh,
204 sqlite3_stmt *stmt);
205
206
207/**
185 * Extract data from a Postgres database @a result at row @a row. 208 * Extract data from a Postgres database @a result at row @a row.
186 * 209 *
187 * @param cls closure 210 * @param cls closure
@@ -400,18 +423,6 @@ GNUNET_SQ_result_spec_uint64 (uint64_t *u64);
400 423
401 424
402/** 425/**
403 * Execute a prepared statement.
404 *
405 * @param db_conn database connection
406 * @param params parameters to the statement
407 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
408 */
409int
410GNUNET_SQ_bind (sqlite3_stmt *stmt,
411 const struct GNUNET_SQ_QueryParam *params);
412
413
414/**
415 * Extract results from a query result according to the given specification. 426 * Extract results from a query result according to the given specification.
416 * 427 *
417 * @param result result to process 428 * @param result result to process
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h
index 52f5d8ab2..a9bd6c33f 100644
--- a/src/include/gnunet_util_lib.h
+++ b/src/include/gnunet_util_lib.h
@@ -38,10 +38,24 @@ extern "C"
38#endif 38#endif
39#endif 39#endif
40 40
41
42/**
43 * Largest supported message (to be precise, one byte more
44 * than the largest possible message, so tests involving
45 * this value should check for messages being smaller than
46 * this value).
47 */
48#define GNUNET_MAX_MESSAGE_SIZE 65536
49
50/**
51 * Smallest supported message.
52 */
53#define GNUNET_MIN_MESSAGE_SIZE sizeof (struct GNUNET_MessageHeader)
54
55
41#include "gnunet_crypto_lib.h" 56#include "gnunet_crypto_lib.h"
42#include "gnunet_bandwidth_lib.h" 57#include "gnunet_bandwidth_lib.h"
43#include "gnunet_bio_lib.h" 58#include "gnunet_bio_lib.h"
44#include "gnunet_connection_lib.h"
45#include "gnunet_client_lib.h" 59#include "gnunet_client_lib.h"
46#include "gnunet_container_lib.h" 60#include "gnunet_container_lib.h"
47#include "gnunet_getopt_lib.h" 61#include "gnunet_getopt_lib.h"
@@ -55,7 +69,6 @@ extern "C"
55#include "gnunet_plugin_lib.h" 69#include "gnunet_plugin_lib.h"
56#include "gnunet_program_lib.h" 70#include "gnunet_program_lib.h"
57#include "gnunet_protocols.h" 71#include "gnunet_protocols.h"
58#include "gnunet_server_lib.h"
59#include "gnunet_service_lib.h" 72#include "gnunet_service_lib.h"
60#include "gnunet_signal_lib.h" 73#include "gnunet_signal_lib.h"
61#include "gnunet_strings_lib.h" 74#include "gnunet_strings_lib.h"
diff --git a/src/include/platform.h b/src/include/platform.h
index add58821f..6095d0258 100644
--- a/src/include/platform.h
+++ b/src/include/platform.h
@@ -110,6 +110,7 @@
110#include <stdlib.h> 110#include <stdlib.h>
111#include <stdint.h> 111#include <stdint.h>
112#include <stdarg.h> 112#include <stdarg.h>
113#include <stdbool.h>
113#include <errno.h> 114#include <errno.h>
114#include <signal.h> 115#include <signal.h>
115#include <libgen.h> 116#include <libgen.h>