2 * This file is part of GNUnet
3 * (C) 2013 Christian Grothoff (and other contributing authors)
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * @file 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
36 #include "gnunet_util_lib.h"
37 #include "gnunet_env_lib.h"
38 #include "gnunet_multicast_service.h"
39 #include "gnunet_psyc_service.h"
40 #include "gnunet_psyc_util_lib.h"
43 #define LOG(kind,...) GNUNET_log_from (kind, "psyc-api",__VA_ARGS__)
47 * Handle to access PSYC channel operations for both the master and slaves.
49 struct GNUNET_PSYC_Channel
52 * Configuration to use.
54 const struct GNUNET_CONFIGURATION_Handle *cfg;
57 * Client connection to the service.
59 struct GNUNET_CLIENT_MANAGER_Connection *client;
62 * Transmission handle;
64 struct GNUNET_PSYC_TransmitHandle *tmit;
69 struct GNUNET_PSYC_ReceiveHandle *recv;
72 * Message to send on reconnect.
74 struct GNUNET_MessageHeader *connect_msg;
77 * Are we polling for incoming messages right now?
82 * Is this a master or slave channel?
89 * Handle for the master of a PSYC channel.
91 struct GNUNET_PSYC_Master
93 struct GNUNET_PSYC_Channel chn;
95 GNUNET_PSYC_MasterStartCallback start_cb;
98 * Join request callback.
100 GNUNET_PSYC_JoinRequestCallback join_req_cb;
103 * Closure for the callbacks.
110 * Handle for a PSYC channel slave.
112 struct GNUNET_PSYC_Slave
114 struct GNUNET_PSYC_Channel chn;
116 GNUNET_PSYC_SlaveConnectCallback connect_cb;
118 GNUNET_PSYC_JoinDecisionCallback join_dcsn_cb;
121 * Closure for the callbacks.
128 * Handle that identifies a join request.
130 * Used to match calls to #GNUNET_PSYC_JoinRequestCallback to the
131 * corresponding calls to GNUNET_PSYC_join_decision().
133 struct GNUNET_PSYC_JoinHandle
135 struct GNUNET_PSYC_Master *mst;
136 struct GNUNET_CRYPTO_EddsaPublicKey slave_key;
141 * Handle for a pending PSYC transmission operation.
143 struct GNUNET_PSYC_SlaveTransmitHandle
150 * Handle to a story telling operation.
152 struct GNUNET_PSYC_Story
159 * Handle for a state query operation.
161 struct GNUNET_PSYC_StateQuery
168 channel_send_connect_msg (struct GNUNET_PSYC_Channel *chn)
170 uint16_t cmsg_size = ntohs (chn->connect_msg->size);
171 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size);
172 memcpy (cmsg, chn->connect_msg, cmsg_size);
173 GNUNET_CLIENT_MANAGER_transmit_now (chn->client, cmsg);
178 channel_recv_disconnect (void *cls,
179 struct GNUNET_CLIENT_MANAGER_Connection *client,
180 const struct GNUNET_MessageHeader *msg)
182 struct GNUNET_PSYC_Channel *
183 chn = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*chn));
184 GNUNET_CLIENT_MANAGER_reconnect (client);
185 channel_send_connect_msg (chn);
190 channel_recv_message (void *cls,
191 struct GNUNET_CLIENT_MANAGER_Connection *client,
192 const struct GNUNET_MessageHeader *msg)
194 struct GNUNET_PSYC_Channel *
195 chn = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*chn));
196 GNUNET_PSYC_receive_message (chn->recv,
197 (const struct GNUNET_PSYC_MessageHeader *) msg);
202 channel_recv_message_ack (void *cls,
203 struct GNUNET_CLIENT_MANAGER_Connection *client,
204 const struct GNUNET_MessageHeader *msg)
206 struct GNUNET_PSYC_Channel *
207 chn = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*chn));
208 GNUNET_PSYC_transmit_got_ack (chn->tmit);
213 master_recv_start_ack (void *cls,
214 struct GNUNET_CLIENT_MANAGER_Connection *client,
215 const struct GNUNET_MessageHeader *msg)
217 struct GNUNET_PSYC_Master *
218 mst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
219 sizeof (struct GNUNET_PSYC_Channel));
221 struct CountersResult *cres = (struct CountersResult *) msg;
222 if (NULL != mst->start_cb)
223 mst->start_cb (mst->cb_cls, GNUNET_ntohll (cres->max_message_id));
228 master_recv_join_request (void *cls,
229 struct GNUNET_CLIENT_MANAGER_Connection *client,
230 const struct GNUNET_MessageHeader *msg)
232 struct GNUNET_PSYC_Master *
233 mst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
234 sizeof (struct GNUNET_PSYC_Channel));
236 const struct MasterJoinRequest *req = (const struct MasterJoinRequest *) msg;
238 struct GNUNET_PSYC_MessageHeader *pmsg = NULL;
239 if (ntohs (req->header.size) <= sizeof (*req) + sizeof (*pmsg))
240 pmsg = (struct GNUNET_PSYC_MessageHeader *) &req[1];
242 struct GNUNET_PSYC_JoinHandle *jh = GNUNET_malloc (sizeof (*jh));
244 jh->slave_key = req->slave_key;
246 if (NULL != mst->join_req_cb)
247 mst->join_req_cb (mst->cb_cls, &req->slave_key, pmsg, jh);
252 slave_recv_join_ack (void *cls,
253 struct GNUNET_CLIENT_MANAGER_Connection *client,
254 const struct GNUNET_MessageHeader *msg)
256 struct GNUNET_PSYC_Slave *
257 slv = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
258 sizeof (struct GNUNET_PSYC_Channel));
259 struct CountersResult *cres = (struct CountersResult *) msg;
260 if (NULL != slv->connect_cb)
261 slv->connect_cb (slv->cb_cls, GNUNET_ntohll (cres->max_message_id));
266 slave_recv_join_decision (void *cls,
267 struct GNUNET_CLIENT_MANAGER_Connection *client,
268 const struct GNUNET_MessageHeader *msg)
270 struct GNUNET_PSYC_Slave *
271 slv = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
272 sizeof (struct GNUNET_PSYC_Channel));
273 const struct SlaveJoinDecision *
274 dcsn = (const struct SlaveJoinDecision *) msg;
276 struct GNUNET_PSYC_MessageHeader *pmsg = NULL;
277 if (ntohs (dcsn->header.size) <= sizeof (*dcsn) + sizeof (*pmsg))
278 pmsg = (struct GNUNET_PSYC_MessageHeader *) &dcsn[1];
280 struct GNUNET_PSYC_JoinHandle *jh = GNUNET_malloc (sizeof (*jh));
281 if (NULL != slv->join_dcsn_cb)
282 slv->join_dcsn_cb (slv->cb_cls, ntohl (dcsn->is_admitted), pmsg);
286 static struct GNUNET_CLIENT_MANAGER_MessageHandler master_handlers[] =
288 { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
290 { &channel_recv_message, NULL,
291 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
292 sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
294 { &channel_recv_message_ack, NULL,
295 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
296 sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
298 { &master_recv_start_ack, NULL,
299 GNUNET_MESSAGE_TYPE_PSYC_MASTER_START_ACK,
300 sizeof (struct CountersResult), GNUNET_NO },
302 { &master_recv_join_request, NULL,
303 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
304 sizeof (struct MasterJoinRequest), GNUNET_YES },
306 { NULL, NULL, 0, 0, GNUNET_NO }
310 static struct GNUNET_CLIENT_MANAGER_MessageHandler slave_handlers[] =
312 { &channel_recv_disconnect, NULL, 0, 0, GNUNET_NO },
314 { &channel_recv_message, NULL,
315 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
316 sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
318 { &channel_recv_message_ack, NULL,
319 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
320 sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
322 { &slave_recv_join_ack, NULL,
323 GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN_ACK,
324 sizeof (struct CountersResult), GNUNET_NO },
326 { &slave_recv_join_decision, NULL,
327 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
328 sizeof (struct SlaveJoinDecision), GNUNET_YES },
330 { NULL, NULL, 0, 0, GNUNET_NO }
335 * Start a PSYC master channel.
337 * Will start a multicast group identified by the given ECC key. Messages
338 * received from group members will be given to the respective handler methods.
339 * If a new member wants to join a group, the "join" method handler will be
340 * invoked; the join handler must then generate a "join" message to approve the
341 * joining of the new member. The channel can also change group membership
342 * without explicit requests. Note that PSYC doesn't itself "understand" join
343 * or part messages, the respective methods must call other PSYC functions to
344 * inform PSYC about the meaning of the respective events.
346 * @param cfg Configuration to use (to connect to PSYC service).
347 * @param channel_key ECC key that will be used to sign messages for this
348 * PSYC session. The public key is used to identify the PSYC channel.
349 * Note that end-users will usually not use the private key directly, but
350 * rather look it up in GNS for places managed by other users, or select
351 * a file with the private key(s) when setting up their own channels
352 * FIXME: we'll likely want to use NOT the p521 curve here, but a cheaper
354 * @param policy Channel policy specifying join and history restrictions.
355 * Used to automate join decisions.
356 * @param message_cb Function to invoke on message parts received from slaves.
357 * @param join_request_cb Function to invoke when a slave wants to join.
358 * @param master_start_cb Function to invoke after the channel master started.
359 * @param cls Closure for @a method and @a join_cb.
361 * @return Handle for the channel master, NULL on error.
363 struct GNUNET_PSYC_Master *
364 GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
365 const struct GNUNET_CRYPTO_EddsaPrivateKey *channel_key,
366 enum GNUNET_PSYC_Policy policy,
367 GNUNET_PSYC_MasterStartCallback start_cb,
368 GNUNET_PSYC_JoinRequestCallback join_request_cb,
369 GNUNET_PSYC_MessageCallback message_cb,
372 struct GNUNET_PSYC_Master *mst = GNUNET_malloc (sizeof (*mst));
373 struct GNUNET_PSYC_Channel *chn = &mst->chn;
375 struct MasterStartRequest *req = GNUNET_malloc (sizeof (*req));
376 req->header.size = htons (sizeof (*req));
377 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MASTER_START);
378 req->channel_key = *channel_key;
379 req->policy = policy;
381 chn->connect_msg = (struct GNUNET_MessageHeader *) req;
383 chn->is_master = GNUNET_YES;
385 mst->start_cb = start_cb;
386 mst->join_req_cb = join_request_cb;
389 chn->client = GNUNET_CLIENT_MANAGER_connect (cfg, "psyc", master_handlers);
390 GNUNET_CLIENT_MANAGER_set_user_context_ (chn->client, mst, sizeof (*chn));
392 chn->tmit = GNUNET_PSYC_transmit_create (chn->client);
393 chn->recv = GNUNET_PSYC_receive_create (message_cb, message_cb, cls);
395 channel_send_connect_msg (chn);
401 * Stop a PSYC master channel.
403 * @param master PSYC channel master to stop.
404 * @param keep_active FIXME
407 GNUNET_PSYC_master_stop (struct GNUNET_PSYC_Master *mst)
409 GNUNET_CLIENT_MANAGER_disconnect (mst->chn.client, GNUNET_YES);
415 * Function to call with the decision made for a join request.
417 * Must be called once and only once in response to an invocation of the
418 * #GNUNET_PSYC_JoinCallback.
420 * @param jh Join request handle.
421 * @param is_admitted #GNUNET_YES if the join is approved,
422 * #GNUNET_NO if it is disapproved,
423 * #GNUNET_SYSERR if we cannot answer the request.
424 * @param relay_count Number of relays given.
425 * @param relays Array of suggested peers that might be useful relays to use
426 * when joining the multicast group (essentially a list of peers that
427 * are already part of the multicast group and might thus be willing
428 * to help with routing). If empty, only this local peer (which must
429 * be the multicast origin) is a good candidate for building the
430 * multicast tree. Note that it is unnecessary to specify our own
431 * peer identity in this array.
432 * @param join_resp Application-dependent join response message.
434 * @return #GNUNET_OK on success,
435 * #GNUNET_SYSERR if the message is too large.
438 GNUNET_PSYC_join_decision (struct GNUNET_PSYC_JoinHandle *jh,
440 uint32_t relay_count,
441 const struct GNUNET_PeerIdentity *relays,
442 const struct GNUNET_PSYC_MessageHeader *join_resp)
444 struct GNUNET_PSYC_Channel *chn = &jh->mst->chn;
445 struct MasterJoinDecision *dcsn;
446 uint16_t join_resp_size
447 = (NULL != join_resp) ? ntohs (join_resp->header.size) : 0;
448 uint16_t relay_size = relay_count * sizeof (*relays);
450 if (GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD
451 < sizeof (*dcsn) + relay_size + join_resp_size)
452 return GNUNET_SYSERR;
454 dcsn = GNUNET_malloc (sizeof (*dcsn) + relay_size + join_resp_size);
455 dcsn->header.size = htons (sizeof (*dcsn) + relay_size + join_resp_size);
456 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION);
457 dcsn->is_admitted = htonl (is_admitted);
458 dcsn->slave_key = jh->slave_key;
460 if (0 < join_resp_size)
461 memcpy (&dcsn[1], join_resp, join_resp_size);
463 GNUNET_CLIENT_MANAGER_transmit (chn->client, &dcsn->header);
469 * Send a message to call a method to all members in the PSYC channel.
471 * @param master Handle to the PSYC channel.
472 * @param method_name Which method should be invoked.
473 * @param notify_mod Function to call to obtain modifiers.
474 * @param notify_data Function to call to obtain fragments of the data.
475 * @param notify_cls Closure for @a notify_mod and @a notify_data.
476 * @param flags Flags for the message being transmitted.
478 * @return Transmission handle, NULL on error (i.e. more than one request queued).
480 struct GNUNET_PSYC_MasterTransmitHandle *
481 GNUNET_PSYC_master_transmit (struct GNUNET_PSYC_Master *mst,
482 const char *method_name,
483 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
484 GNUNET_PSYC_TransmitNotifyData notify_data,
486 enum GNUNET_PSYC_MasterTransmitFlags flags)
489 == GNUNET_PSYC_transmit_message (mst->chn.tmit, method_name, NULL,
490 notify_mod, notify_data, notify_cls,
492 return (struct GNUNET_PSYC_MasterTransmitHandle *) mst->chn.tmit;
499 * Resume transmission to the channel.
501 * @param tmit Handle of the request that is being resumed.
504 GNUNET_PSYC_master_transmit_resume (struct GNUNET_PSYC_MasterTransmitHandle *tmit)
506 GNUNET_PSYC_transmit_resume ((struct GNUNET_PSYC_TransmitHandle *) tmit);
511 * Abort transmission request to the channel.
513 * @param tmit Handle of the request that is being aborted.
516 GNUNET_PSYC_master_transmit_cancel (struct GNUNET_PSYC_MasterTransmitHandle *tmit)
518 GNUNET_PSYC_transmit_cancel ((struct GNUNET_PSYC_TransmitHandle *) tmit);
523 * Convert a channel @a master to a @e channel handle to access the @e channel
526 * @param master Channel master handle.
528 * @return Channel handle, valid for as long as @a master is valid.
530 struct GNUNET_PSYC_Channel *
531 GNUNET_PSYC_master_get_channel (struct GNUNET_PSYC_Master *master)
538 * Join a PSYC channel.
540 * The entity joining is always the local peer. The user must immediately use
541 * the GNUNET_PSYC_slave_transmit() functions to transmit a @e join_msg to the
542 * channel; if the join request succeeds, the channel state (and @e recent
543 * method calls) will be replayed to the joining member. There is no explicit
544 * notification on failure (as the channel may simply take days to approve,
545 * and disapproval is simply being ignored).
547 * @param cfg Configuration to use.
548 * @param channel_key ECC public key that identifies the channel we wish to join.
549 * @param slave_key ECC private-public key pair that identifies the slave, and
550 * used by multicast to sign the join request and subsequent unicast
551 * requests sent to the master.
552 * @param origin Peer identity of the origin.
553 * @param relay_count Number of peers in the @a relays array.
554 * @param relays Peer identities of members of the multicast group, which serve
555 * as relays and used to join the group at.
556 * @param message_cb Function to invoke on message parts received from the
557 * channel, typically at least contains method handlers for @e join and
559 * @param slave_connect_cb Function invoked once we have connected to the
561 * @param join_decision_cb Function invoked once we have received a join
563 * @param cls Closure for @a message_cb and @a slave_joined_cb.
564 * @param method_name Method name for the join request.
565 * @param env Environment containing transient variables for the request, or NULL.
566 * @param data Payload for the join message.
567 * @param data_size Number of bytes in @a data.
569 * @return Handle for the slave, NULL on error.
571 struct GNUNET_PSYC_Slave *
572 GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
573 const struct GNUNET_CRYPTO_EddsaPublicKey *channel_key,
574 const struct GNUNET_CRYPTO_EddsaPrivateKey *slave_key,
575 const struct GNUNET_PeerIdentity *origin,
576 uint32_t relay_count,
577 const struct GNUNET_PeerIdentity *relays,
578 GNUNET_PSYC_MessageCallback message_cb,
579 GNUNET_PSYC_SlaveConnectCallback connect_cb,
580 GNUNET_PSYC_JoinDecisionCallback join_decision_cb,
582 const char *method_name,
583 const struct GNUNET_ENV_Environment *env,
587 struct GNUNET_PSYC_Slave *slv = GNUNET_malloc (sizeof (*slv));
588 struct GNUNET_PSYC_Channel *chn = &slv->chn;
589 struct SlaveJoinRequest *req
590 = GNUNET_malloc (sizeof (*req) + relay_count * sizeof (*relays));
591 req->header.size = htons (sizeof (*req)
592 + relay_count * sizeof (*relays));
593 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN);
594 req->channel_key = *channel_key;
595 req->slave_key = *slave_key;
596 req->origin = *origin;
597 req->relay_count = htonl (relay_count);
598 memcpy (&req[1], relays, relay_count * sizeof (*relays));
600 chn->connect_msg = (struct GNUNET_MessageHeader *) req;
602 chn->is_master = GNUNET_NO;
604 slv->connect_cb = connect_cb;
605 slv->join_dcsn_cb = join_decision_cb;
608 chn->client = GNUNET_CLIENT_MANAGER_connect (cfg, "psyc", slave_handlers);
609 GNUNET_CLIENT_MANAGER_set_user_context_ (chn->client, slv, sizeof (*chn));
611 chn->recv = GNUNET_PSYC_receive_create (message_cb, message_cb, cls);
612 chn->tmit = GNUNET_PSYC_transmit_create (chn->client);
614 channel_send_connect_msg (chn);
620 * Part a PSYC channel.
622 * Will terminate the connection to the PSYC service. Polite clients should
623 * first explicitly send a part request (via GNUNET_PSYC_slave_transmit()).
625 * @param slave Slave handle.
628 GNUNET_PSYC_slave_part (struct GNUNET_PSYC_Slave *slv)
630 GNUNET_CLIENT_MANAGER_disconnect (slv->chn.client, GNUNET_YES);
636 * Request a message to be sent to the channel master.
638 * @param slave Slave handle.
639 * @param method_name Which (PSYC) method should be invoked (on host).
640 * @param notify_mod Function to call to obtain modifiers.
641 * @param notify_data Function to call to obtain fragments of the data.
642 * @param notify_cls Closure for @a notify.
643 * @param flags Flags for the message being transmitted.
645 * @return Transmission handle, NULL on error (i.e. more than one request
648 struct GNUNET_PSYC_SlaveTransmitHandle *
649 GNUNET_PSYC_slave_transmit (struct GNUNET_PSYC_Slave *slv,
650 const char *method_name,
651 GNUNET_PSYC_TransmitNotifyModifier notify_mod,
652 GNUNET_PSYC_TransmitNotifyData notify_data,
654 enum GNUNET_PSYC_SlaveTransmitFlags flags)
658 == GNUNET_PSYC_transmit_message (slv->chn.tmit, method_name, NULL,
659 notify_mod, notify_data, notify_cls,
661 return (struct GNUNET_PSYC_SlaveTransmitHandle *) slv->chn.tmit;
668 * Resume transmission to the master.
670 * @param tmit Handle of the request that is being resumed.
673 GNUNET_PSYC_slave_transmit_resume (struct GNUNET_PSYC_SlaveTransmitHandle *tmit)
675 GNUNET_PSYC_transmit_resume ((struct GNUNET_PSYC_TransmitHandle *) tmit);
680 * Abort transmission request to master.
682 * @param tmit Handle of the request that is being aborted.
685 GNUNET_PSYC_slave_transmit_cancel (struct GNUNET_PSYC_SlaveTransmitHandle *tmit)
687 GNUNET_PSYC_transmit_cancel ((struct GNUNET_PSYC_TransmitHandle *) tmit);
692 * Convert @a slave to a @e channel handle to access the @e channel APIs.
694 * @param slv Slave handle.
696 * @return Channel handle, valid for as long as @a slave is valid.
698 struct GNUNET_PSYC_Channel *
699 GNUNET_PSYC_slave_get_channel (struct GNUNET_PSYC_Slave *slv)
706 * Add a slave to the channel's membership list.
708 * Note that this will NOT generate any PSYC traffic, it will merely update the
709 * local database to modify how we react to <em>membership test</em> queries.
710 * The channel master still needs to explicitly transmit a @e join message to
711 * notify other channel members and they then also must still call this function
712 * in their respective methods handling the @e join message. This way, how @e
713 * join and @e part operations are exactly implemented is still up to the
714 * application; for example, there might be a @e part_all method to kick out
717 * Note that channel slaves are explicitly trusted to execute such methods
718 * correctly; not doing so correctly will result in either denying other slaves
719 * access or offering access to channel data to non-members.
721 * @param channel Channel handle.
722 * @param slave_key Identity of channel slave to add.
723 * @param announced_at ID of the message that announced the membership change.
724 * @param effective_since Addition of slave is in effect since this message ID.
727 GNUNET_PSYC_channel_slave_add (struct GNUNET_PSYC_Channel *chn,
728 const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
729 uint64_t announced_at,
730 uint64_t effective_since)
732 struct ChannelSlaveAdd *add = GNUNET_malloc (sizeof (*add));
733 add->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_ADD);
734 add->header.size = htons (sizeof (*add));
735 add->announced_at = GNUNET_htonll (announced_at);
736 add->effective_since = GNUNET_htonll (effective_since);
737 GNUNET_CLIENT_MANAGER_transmit (chn->client, &add->header);
742 * Remove a slave from the channel's membership list.
744 * Note that this will NOT generate any PSYC traffic, it will merely update the
745 * local database to modify how we react to <em>membership test</em> queries.
746 * The channel master still needs to explicitly transmit a @e part message to
747 * notify other channel members and they then also must still call this function
748 * in their respective methods handling the @e part message. This way, how
749 * @e join and @e part operations are exactly implemented is still up to the
750 * application; for example, there might be a @e part_all message to kick out
753 * Note that channel members are explicitly trusted to perform these
754 * operations correctly; not doing so correctly will result in either
755 * denying members access or offering access to channel data to
758 * @param channel Channel handle.
759 * @param slave_key Identity of channel slave to remove.
760 * @param announced_at ID of the message that announced the membership change.
763 GNUNET_PSYC_channel_slave_remove (struct GNUNET_PSYC_Channel *chn,
764 const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key,
765 uint64_t announced_at)
767 struct ChannelSlaveRemove *rm = GNUNET_malloc (sizeof (*rm));
768 rm->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_CHANNEL_SLAVE_RM);
769 rm->header.size = htons (sizeof (*rm));
770 rm->announced_at = GNUNET_htonll (announced_at);
771 GNUNET_CLIENT_MANAGER_transmit (chn->client, &rm->header);
776 * Request to be told the message history of the channel.
778 * Historic messages (but NOT the state at the time) will be replayed (given to
779 * the normal method handlers) if available and if access is permitted.
781 * To get the latest message, use 0 for both the start and end message ID.
783 * @param channel Which channel should be replayed?
784 * @param start_message_id Earliest interesting point in history.
785 * @param end_message_id Last (exclusive) interesting point in history.
786 * @param message_cb Function to invoke on message parts received from the story.
787 * @param finish_cb Function to call when the requested story has been fully
788 * told (counting message IDs might not suffice, as some messages
789 * might be secret and thus the listener would not know the story is
790 * finished without being told explicitly) once this function
791 * has been called, the client must not call
792 * GNUNET_PSYC_channel_story_tell_cancel() anymore.
793 * @param cls Closure for the callbacks.
795 * @return Handle to cancel story telling operation.
797 struct GNUNET_PSYC_Story *
798 GNUNET_PSYC_channel_story_tell (struct GNUNET_PSYC_Channel *channel,
799 uint64_t start_message_id,
800 uint64_t end_message_id,
801 GNUNET_PSYC_MessageCallback message_cb,
802 GNUNET_PSYC_FinishCallback finish_cb,
810 * Abort story telling.
812 * This function must not be called from within method handlers (as given to
813 * GNUNET_PSYC_slave_join()) of the slave.
815 * @param story Story telling operation to stop.
818 GNUNET_PSYC_channel_story_tell_cancel (struct GNUNET_PSYC_Story *story)
825 * Retrieve the best matching channel state variable.
827 * If the requested variable name is not present in the state, the nearest
828 * less-specific name is matched; for example, requesting "_a_b" will match "_a"
829 * if "_a_b" does not exist.
831 * @param channel Channel handle.
832 * @param full_name Full name of the requested variable, the actual variable
833 * returned might have a shorter name..
834 * @param cb Function called once when a matching state variable is found.
835 * Not called if there's no matching state variable.
836 * @param cb_cls Closure for the callbacks.
838 * @return Handle that can be used to cancel the query operation.
840 struct GNUNET_PSYC_StateQuery *
841 GNUNET_PSYC_channel_state_get (struct GNUNET_PSYC_Channel *channel,
842 const char *full_name,
843 GNUNET_PSYC_StateCallback cb,
851 * Return all channel state variables whose name matches a given prefix.
853 * A name matches if it starts with the given @a name_prefix, thus requesting
854 * the empty prefix ("") will match all values; requesting "_a_b" will also
855 * return values stored under "_a_b_c".
857 * The @a state_cb is invoked on all matching state variables asynchronously, as
858 * the state is stored in and retrieved from the PSYCstore,
860 * @param channel Channel handle.
861 * @param name_prefix Prefix of the state variable name to match.
862 * @param cb Function to call with the matching state variables.
863 * @param cb_cls Closure for the callbacks.
865 * @return Handle that can be used to cancel the query operation.
867 struct GNUNET_PSYC_StateQuery *
868 GNUNET_PSYC_channel_state_get_prefix (struct GNUNET_PSYC_Channel *channel,
869 const char *name_prefix,
870 GNUNET_PSYC_StateCallback cb,
878 * Cancel a state query operation.
880 * @param query Handle for the operation to cancel.
883 GNUNET_PSYC_channel_state_get_cancel (struct GNUNET_PSYC_StateQuery *query)
889 /* end of psyc_api.c */