aboutsummaryrefslogtreecommitdiff
path: root/src/psyc/psyc_api.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-09-16 16:46:43 +0000
committerGabor X Toth <*@tg-x.net>2013-09-16 16:46:43 +0000
commit4839fff11f31cac9af0cfbe1d67b6961d5f1b88f (patch)
tree2ccae35bf637e1bec185656f8c25b2693d0a29d4 /src/psyc/psyc_api.c
parent2745a5145a07c6effa7075391fb9ea74288ec83a (diff)
downloadgnunet-4839fff11f31cac9af0cfbe1d67b6961d5f1b88f.tar.gz
gnunet-4839fff11f31cac9af0cfbe1d67b6961d5f1b88f.zip
psyc service skeleton
Diffstat (limited to 'src/psyc/psyc_api.c')
-rw-r--r--src/psyc/psyc_api.c452
1 files changed, 452 insertions, 0 deletions
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
new file mode 100644
index 000000000..8d07f5f79
--- /dev/null
+++ b/src/psyc/psyc_api.c
@@ -0,0 +1,452 @@
1/*
2 * This file is part of GNUnet
3 * (C) 2013 Christian Grothoff (and other contributing authors)
4 *
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 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., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file psyc/psyc_api.c
23 * @brief PSYC service; high-level access to the PSYC protocol
24 * note that clients of this API are NOT expected to
25 * understand the PSYC message format, only the semantics!
26 * Parsing (and serializing) the PSYC stream format is done
27 * within the implementation of the libgnunetpsyc library,
28 * and this API deliberately exposes as little as possible
29 * of the actual data stream format to the application!
30 * @author Gabor X Toth
31 */
32
33#include "platform.h"
34#include "gnunet_util_lib.h"
35#include "gnunet_env_lib.h"
36#include "gnunet_psyc_service.h"
37#include "psyc.h"
38
39/**
40 * Handle that identifies a join request.
41 *
42 * Used to match calls to #GNUNET_PSYC_JoinCallback to the
43 * corresponding calls to GNUNET_PSYC_join_decision().
44 */
45struct GNUNET_PSYC_JoinHandle;
46
47
48/**
49 * Handle for the master of a PSYC channel.
50 */
51struct GNUNET_PSYC_Master;
52
53
54/**
55 * Handle for a pending PSYC transmission operation.
56 */
57struct GNUNET_PSYC_MasterTransmitHandle;
58
59
60/**
61 * Handle for a PSYC channel slave.
62 */
63struct GNUNET_PSYC_Slave;
64
65
66/**
67 * Handle for a pending PSYC transmission operation.
68 */
69struct GNUNET_PSYC_SlaveTransmitHandle;
70
71
72/**
73 * Handle to access PSYC channel operations for both the master and slaves.
74 */
75struct GNUNET_PSYC_Channel;
76
77
78/**
79 * Handle to a story telling operation.
80 */
81struct GNUNET_PSYC_Story;
82
83
84struct GNUNET_PSYC_StateQuery;
85
86
87/**
88 * Function to call with the decision made for a join request.
89 *
90 * Must be called once and only once in response to an invocation of the
91 * #GNUNET_PSYC_JoinCallback.
92 *
93 * @param jh Join request handle.
94 * @param is_admitted #GNUNET_YES if joining is approved,
95 * #GNUNET_NO if it is disapproved.
96 * @param relay_count Number of relays given.
97 * @param relays Array of suggested peers that might be useful relays to use
98 * when joining the multicast group (essentially a list of peers that
99 * are already part of the multicast group and might thus be willing
100 * to help with routing). If empty, only this local peer (which must
101 * be the multicast origin) is a good candidate for building the
102 * multicast tree. Note that it is unnecessary to specify our own
103 * peer identity in this array.
104 * @param method_name Method name for the message transmitted with the response.
105 * @param env Environment containing transient variables for the message, or NULL.
106 * @param data Data of the message.
107 * @param data_size Size of @a data.
108 */
109void
110GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
111 int is_admitted,
112 unsigned int relay_count,
113 const struct GNUNET_PeerIdentity *relays,
114 const char *method_name,
115 const struct GNUNET_ENV_Environment *env,
116 const void *data,
117 size_t data_size);
118
119
120/**
121 * Start a PSYC master channel.
122 *
123 * Will start a multicast group identified by the given ECC key. Messages
124 * received from group members will be given to the respective handler methods.
125 * If a new member wants to join a group, the "join" method handler will be
126 * invoked; the join handler must then generate a "join" message to approve the
127 * joining of the new member. The channel can also change group membership
128 * without explicit requests. Note that PSYC doesn't itself "understand" join
129 * or part messages, the respective methods must call other PSYC functions to
130 * inform PSYC about the meaning of the respective events.
131 *
132 * @param cfg Configuration to use (to connect to PSYC service).
133 * @param channel_key ECC key that will be used to sign messages for this
134 * PSYC session. The public key is used to identify the PSYC channel.
135 * Note that end-users will usually not use the private key directly, but
136 * rather look it up in GADS for places managed by other users, or select
137 * a file with the private key(s) when setting up their own channels
138 * FIXME: we'll likely want to use NOT the p521 curve here, but a cheaper
139 * one in the future.
140 * @param policy Channel policy specifying join and history restrictions.
141 * Used to automate join decisions.
142 * @param method Function to invoke on messages received from slaves.
143 * @param join_cb Function to invoke when a peer wants to join.
144 * @param cls Closure for @a method and @a join_cb.
145 * @return Handle for the channel master, NULL on error.
146 */
147struct GNUNET_PSYC_Master *
148GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
149 const struct GNUNET_CRYPTO_EccPrivateKey *channel_key,
150 enum GNUNET_PSYC_Policy policy,
151 GNUNET_PSYC_Method method,
152 GNUNET_PSYC_JoinCallback join_cb,
153 void *cls);
154
155
156/**
157 * Send a message to call a method to all members in the PSYC channel.
158 *
159 * @param master Handle to the PSYC channel.
160 * @param method_name Which method should be invoked.
161 * @param env Environment containing state operations and transient variables
162 * for the message, or NULL.
163 * @param notify Function to call to obtain the arguments.
164 * @param notify_cls Closure for @a notify.
165 * @param flags Flags for the message being transmitted.
166 * @return Transmission handle, NULL on error (i.e. more than one request queued).
167 */
168struct GNUNET_PSYC_MasterTransmitHandle *
169GNUNET_PSYC_master_transmit (struct GNUNET_PSYC_Master *master,
170 const char *method_name,
171 const struct GNUNET_ENV_Environment *env,
172 GNUNET_PSYC_MasterTransmitNotify notify,
173 void *notify_cls,
174 enum GNUNET_PSYC_MasterTransmitFlags flags);
175
176
177/**
178 * Abort transmission request to channel.
179 *
180 * @param th Handle of the request that is being aborted.
181 */
182void
183GNUNET_PSYC_master_transmit_cancel (struct GNUNET_PSYC_MasterTransmitHandle *th);
184
185
186/**
187 * Stop a PSYC master channel.
188 *
189 * @param master PSYC channel master to stop.
190 */
191void
192GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *master);
193
194
195/**
196 * Join a PSYC channel.
197 *
198 * The entity joining is always the local peer. The user must immediately use
199 * the GNUNET_PSYC_slave_to_master() functions to transmit a @e join_msg to the
200 * channel; if the join request succeeds, the channel state (and @e recent
201 * method calls) will be replayed to the joining member. There is no explicit
202 * notification on failure (as the channel may simply take days to approve,
203 * and disapproval is simply being ignored).
204 *
205 * @param cfg Configuration to use.
206 * @param channel_key ECC public key that identifies the channel we wish to join.
207 * @param slave_key ECC private-public key pair that identifies the slave, and
208 * used by multicast to sign the join request and subsequent unicast
209 * requests sent to the master.
210 * @param origin Peer identity of the origin.
211 * @param relay_count Number of peers in the @a relays array.
212 * @param relays Peer identities of members of the multicast group, which serve
213 * as relays and used to join the group at.
214 * @param method Function to invoke on messages received from the channel,
215 * typically at least contains functions for @e join and @e part.
216 * @param join_cb Function to invoke when a peer wants to join.
217 * @param cls Closure for @a method_cb and @a join_cb.
218 * @param method_name Method name for the join request.
219 * @param env Environment containing transient variables for the request, or NULL.
220 * @param data Payload for the join message.
221 * @param data_size Number of bytes in @a data.
222 * @return Handle for the slave, NULL on error.
223 */
224struct GNUNET_PSYC_Slave *
225GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
226 const struct GNUNET_CRYPTO_EccPublicSignKey *channel_key,
227 const struct GNUNET_CRYPTO_EccPrivateKey *slave_key,
228 const struct GNUNET_PeerIdentity *origin,
229 size_t relay_count,
230 const struct GNUNET_PeerIdentity *relays,
231 GNUNET_PSYC_Method method,
232 GNUNET_PSYC_JoinCallback join_cb,
233 void *cls,
234 const char *method_name,
235 const struct GNUNET_ENV_Environment *env,
236 const void *data,
237 size_t data_size);
238
239
240/**
241 * Part a PSYC channel.
242 *
243 * Will terminate the connection to the PSYC service. Polite clients should
244 * first explicitly send a @e part request (via GNUNET_PSYC_slave_to_master()).
245 *
246 * @param slave Slave handle.
247 */
248void
249GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slave);
250
251
252/**
253 * Request a message to be sent to the channel master.
254 *
255 * @param slave Slave handle.
256 * @param method_name Which (PSYC) method should be invoked (on host).
257 * @param env Environment containing transient variables for the message, or NULL.
258 * @param notify Function to call when we are allowed to transmit (to get data).
259 * @param notify_cls Closure for @a notify.
260 * @param flags Flags for the message being transmitted.
261 * @return Transmission handle, NULL on error (i.e. more than one request queued).
262 */
263struct GNUNET_PSYC_SlaveTransmitHandle *
264GNUNET_PSYC_slave_transmit (struct GNUNET_PSYC_Slave *slave,
265 const char *method_name,
266 const struct GNUNET_ENV_Environment *env,
267 GNUNET_PSYC_SlaveTransmitNotify notify,
268 void *notify_cls,
269 enum GNUNET_PSYC_SlaveTransmitFlags flags);
270
271
272/**
273 * Abort transmission request to master.
274 *
275 * @param th Handle of the request that is being aborted.
276 */
277void
278GNUNET_PSYC_slave_transmit_cancel (struct GNUNET_PSYC_SlaveTransmitHandle *th);
279
280
281/**
282 * Convert a channel @a master to a @e channel handle to access the @e channel APIs.
283 *
284 * @param master Channel master handle.
285 * @return Channel handle, valid for as long as @a master is valid.
286 */
287struct GNUNET_PSYC_Channel *
288GNUNET_PSYC_master_get_channel (struct GNUNET_PSYC_Master *master);
289
290
291/**
292 * Convert @a slave to a @e channel handle to access the @e channel APIs.
293 *
294 * @param slave Slave handle.
295 * @return Channel handle, valid for as long as @a slave is valid.
296 */
297struct GNUNET_PSYC_Channel *
298GNUNET_PSYC_slave_get_channel (struct GNUNET_PSYC_Slave *slave);
299
300
301/**
302 * Add a slave to the channel's membership list.
303 *
304 * Note that this will NOT generate any PSYC traffic, it will merely update the
305 * local database to modify how we react to <em>membership test</em> queries.
306 * The channel master still needs to explicitly transmit a @e join message to
307 * notify other channel members and they then also must still call this function
308 * in their respective methods handling the @e join message. This way, how @e
309 * join and @e part operations are exactly implemented is still up to the
310 * application; for example, there might be a @e part_all method to kick out
311 * everyone.
312 *
313 * Note that channel slaves are explicitly trusted to execute such methods
314 * correctly; not doing so correctly will result in either denying other slaves
315 * access or offering access to channel data to non-members.
316 *
317 * @param channel Channel handle.
318 * @param slave_key Identity of channel slave to add.
319 * @param announced_at ID of the message that announced the membership change.
320 * @param effective_since Addition of slave is in effect since this message ID.
321 */
322void
323GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *channel,
324 const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
325 uint64_t announced_at,
326 uint64_t effective_since);
327
328
329/**
330 * Remove a slave from the channel's membership list.
331 *
332 * Note that this will NOT generate any PSYC traffic, it will merely update the
333 * local database to modify how we react to <em>membership test</em> queries.
334 * The channel master still needs to explicitly transmit a @e part message to
335 * notify other channel members and they then also must still call this function
336 * in their respective methods handling the @e part message. This way, how
337 * @e join and @e part operations are exactly implemented is still up to the
338 * application; for example, there might be a @e part_all message to kick out
339 * everyone.
340 *
341 * Note that channel members are explicitly trusted to perform these
342 * operations correctly; not doing so correctly will result in either
343 * denying members access or offering access to channel data to
344 * non-members.
345 *
346 * @param channel Channel handle.
347 * @param slave_key Identity of channel slave to remove.
348 * @param announced_at ID of the message that announced the membership change.
349 */
350void
351GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *channel,
352 const struct GNUNET_CRYPTO_EccPublicSignKey *slave_key,
353 uint64_t announced_at);
354
355
356/**
357 * Request to be told the message history of the channel.
358 *
359 * Historic messages (but NOT the state at the time) will be replayed (given to
360 * the normal method handlers) if available and if access is permitted.
361 *
362 * To get the latest message, use 0 for both the start and end message ID.
363 *
364 * @param channel Which channel should be replayed?
365 * @param start_message_id Earliest interesting point in history.
366 * @param end_message_id Last (exclusive) interesting point in history.
367 * @param method Function to invoke on messages received from the story.
368 * @param finish_cb Function to call when the requested story has been fully
369 * told (counting message IDs might not suffice, as some messages
370 * might be secret and thus the listener would not know the story is
371 * finished without being told explicitly); once this function
372 * has been called, the client must not call
373 * GNUNET_PSYC_channel_story_tell_cancel() anymore.
374 * @param cls Closure for the callbacks.
375 * @return Handle to cancel story telling operation.
376 */
377struct GNUNET_PSYC_Story *
378GNUNET_PSYC_channel_story_tell (struct GNUNET_PSYC_Channel *channel,
379 uint64_t start_message_id,
380 uint64_t end_message_id,
381 GNUNET_PSYC_Method method,
382 GNUNET_PSYC_FinishCallback *finish_cb,
383 void *cls);
384
385
386/**
387 * Abort story telling.
388 *
389 * This function must not be called from within method handlers (as given to
390 * GNUNET_PSYC_slave_join()) of the slave.
391 *
392 * @param story Story telling operation to stop.
393 */
394void
395GNUNET_PSYC_channel_story_tell_cancel (struct GNUNET_PSYC_Story *story);
396
397
398/**
399 * Retrieve the best matching channel state variable.
400 *
401 * If the requested variable name is not present in the state, the nearest
402 * less-specific name is matched; for example, requesting "_a_b" will match "_a"
403 * if "_a_b" does not exist.
404 *
405 * @param channel Channel handle.
406 * @param full_name Full name of the requested variable, the actual variable
407 * returned might have a shorter name..
408 * @param cb Function called once when a matching state variable is found.
409 * Not called if there's no matching state variable.
410 * @param cb_cls Closure for the callbacks.
411 * @return Handle that can be used to cancel the query operation.
412 */
413struct GNUNET_PSYC_StateQuery *
414GNUNET_PSYC_channel_state_get (struct GNUNET_PSYC_Channel *channel,
415 const char *full_name,
416 GNUNET_PSYC_StateCallback cb,
417 void *cb_cls);
418
419
420/**
421 * Return all channel state variables whose name matches a given prefix.
422 *
423 * A name matches if it starts with the given @a name_prefix, thus requesting the
424 * empty prefix ("") will match all values; requesting "_a_b" will also return
425 * values stored under "_a_b_c".
426 *
427 * The @a state_cb is invoked on all matching state variables asynchronously, as
428 * the state is stored in and retrieved from the PSYCstore,
429 *
430 * @param channel Channel handle.
431 * @param name_prefix Prefix of the state variable name to match.
432 * @param cb Function to call with the matching state variables.
433 * @param cb_cls Closure for the callbacks.
434 * @return Handle that can be used to cancel the query operation.
435 */
436struct GNUNET_PSYC_StateQuery *
437GNUNET_PSYC_channel_state_get_prefix (struct GNUNET_PSYC_Channel *channel,
438 const char *name_prefix,
439 GNUNET_PSYC_StateCallback cb,
440 void *cb_cls);
441
442
443/**
444 * Cancel a state query operation.
445 *
446 * @param query Handle for the operation to cancel.
447 */
448void
449GNUNET_PSYC_channel_state_get_cancel (struct GNUNET_PSYC_StateQuery *query);
450
451
452/* end of psyc_api.c */