fix bad free
[oweals/gnunet.git] / src / include / gnunet_multicast_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2012, 2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Gabor X Toth
21  * @author Christian Grothoff
22  *
23  * @file
24  * Multicast service; multicast messaging via CADET
25  *
26  * @defgroup multicast  Multicast service
27  * Multicast messaging via CADET.
28  * @{
29  */
30
31 #ifndef GNUNET_MULTICAST_SERVICE_H
32 #define GNUNET_MULTICAST_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_util_lib.h"
43 #include "gnunet_transport_service.h"
44
45 /**
46  * Version number of GNUnet-multicast API.
47  */
48 #define GNUNET_MULTICAST_VERSION 0x00000000
49
50 /**
51  * Opaque handle for a multicast group member.
52  */
53 struct GNUNET_MULTICAST_Member;
54
55 /**
56  * Handle for the origin of a multicast group.
57  */
58 struct GNUNET_MULTICAST_Origin;
59
60
61 enum GNUNET_MULTICAST_MessageFlags
62 {
63   /**
64    * First fragment of a message.
65    */
66   GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT = 1 << 0,
67
68   /**
69    * Last fragment of a message.
70    */
71   GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT = 1 << 1,
72
73   /**
74    * OR'ed flags if message is not fragmented.
75    */
76   GNUNET_MULTICAST_MESSAGE_NOT_FRAGMENTED
77     = GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT
78   | GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT,
79
80   /**
81    * Historic message, used only locally when replaying messages from local
82    * storage.
83    */
84   GNUNET_MULTICAST_MESSAGE_HISTORIC = 1 << 30
85
86 };
87
88
89 GNUNET_NETWORK_STRUCT_BEGIN
90
91 /**
92  * Header of a multicast message fragment.
93  *
94  * This format is public as the replay mechanism must replay message fragments using the
95  * same format.  This is needed as we want to integrity-check message fragments within
96  * the multicast layer to avoid multicasting mal-formed messages.
97  */
98 struct GNUNET_MULTICAST_MessageHeader
99 {
100
101   /**
102    * Header for all multicast message fragments from the origin.
103    */
104   struct GNUNET_MessageHeader header;
105
106   /**
107    * Number of hops this message fragment has taken since the origin.
108    *
109    * Helpful to determine shortest paths to the origin among honest peers for
110    * unicast requests from members.  Updated at each hop and thus not signed and
111    * not secure.
112    */
113   uint32_t hop_counter GNUNET_PACKED;
114
115   /**
116    * ECC signature of the message fragment.
117    *
118    * Signature must match the public key of the multicast group.
119    */
120   struct GNUNET_CRYPTO_EddsaSignature signature;
121
122   /**
123    * Purpose for the signature and size of the signed data.
124    */
125   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
126
127   /**
128    * Number of the message fragment, monotonically increasing starting from 1.
129    */
130   uint64_t fragment_id GNUNET_PACKED;
131
132   /**
133    * Byte offset of this @e fragment of the @e message.
134    */
135   uint64_t fragment_offset GNUNET_PACKED;
136
137   /**
138    * Number of the message this fragment belongs to.
139    *
140    * Set in GNUNET_MULTICAST_origin_to_all().
141    */
142   uint64_t message_id GNUNET_PACKED;
143
144   /**
145    * Counter that monotonically increases whenever a member parts the group.
146    *
147    * Set in GNUNET_MULTICAST_origin_to_all().
148    *
149    * It has significance in case of replay requests: when a member has missed
150    * messages and gets a replay request: in this case if the @a group_generation
151    * is still the same before and after the missed messages, it means that no
152    * @e join or @e part operations happened during the missed messages.
153    */
154   uint64_t group_generation GNUNET_PACKED;
155
156   /**
157    * Flags for this message fragment.
158    *
159    * @see enum GNUNET_MULTICAST_MessageFlags
160    */
161   uint32_t flags GNUNET_PACKED;
162
163   /* Followed by message body. */
164 };
165
166
167 /**
168  * Header of a request from a member to the origin.
169  */
170 struct GNUNET_MULTICAST_RequestHeader
171 {
172   /**
173    * Header for all requests from a member to the origin.
174    */
175   struct GNUNET_MessageHeader header;
176
177   /**
178    * Public key of the sending member.
179    */
180   struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
181
182   /**
183    * ECC signature of the request fragment.
184    *
185    * Signature must match the public key of the multicast group.
186    */
187   struct GNUNET_CRYPTO_EcdsaSignature signature;
188
189   /**
190    * Purpose for the signature and size of the signed data.
191    */
192   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
193
194   /**
195    * Number of the request fragment.
196    * Monotonically increasing from 1.
197    */
198   uint64_t fragment_id GNUNET_PACKED;
199
200   /**
201    * Byte offset of this @e fragment of the @e request.
202    */
203   uint64_t fragment_offset GNUNET_PACKED;
204
205   /**
206    * Number of the request this fragment belongs to.
207    *
208    * Set in GNUNET_MULTICAST_origin_to_all().
209    */
210   uint64_t request_id GNUNET_PACKED;
211
212   /**
213    * Flags for this request.
214    */
215   enum GNUNET_MULTICAST_MessageFlags flags GNUNET_PACKED;
216
217   /* Followed by request body. */
218 };
219
220 GNUNET_NETWORK_STRUCT_END
221
222
223 /**
224  * Maximum size of a multicast message fragment.
225  */
226 #define GNUNET_MULTICAST_FRAGMENT_MAX_SIZE (63 * 1024)
227
228 #define GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD           \
229   (GNUNET_MULTICAST_FRAGMENT_MAX_SIZE                   \
230    - sizeof (struct GNUNET_MULTICAST_MessageHeader))
231
232
233 /**
234  * Handle that identifies a join request.
235  *
236  * Used to match calls to #GNUNET_MULTICAST_JoinRequestCallback to the
237  * corresponding calls to #GNUNET_MULTICAST_join_decision().
238  */
239 struct GNUNET_MULTICAST_JoinHandle;
240
241
242 /**
243  * Function to call with the decision made for a join request.
244  *
245  * Must be called once and only once in response to an invocation of the
246  * #GNUNET_MULTICAST_JoinRequestCallback.
247  *
248  * @param jh
249  *        Join request handle.
250  * @param is_admitted
251  *        #GNUNET_YES    if the join is approved,
252  *        #GNUNET_NO     if it is disapproved,
253  *        #GNUNET_SYSERR if we cannot answer the request.
254  * @param relay_count
255  *        Number of relays given.
256  * @param relays
257  *        Array of suggested peers that might be useful relays to use
258  *        when joining the multicast group (essentially a list of peers that
259  *        are already part of the multicast group and might thus be willing
260  *        to help with routing).  If empty, only this local peer (which must
261  *        be the multicast origin) is a good candidate for building the
262  *        multicast tree.  Note that it is unnecessary to specify our own
263  *        peer identity in this array.
264  * @param join_resp
265  *        Message to send in response to the joining peer;
266  *        can also be used to redirect the peer to a different group at the
267  *        application layer; this response is to be transmitted to the
268  *        peer that issued the request even if admission is denied.
269  */
270 struct GNUNET_MULTICAST_ReplayHandle *
271 GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh,
272                                 int is_admitted,
273                                 uint16_t relay_count,
274                                 const struct GNUNET_PeerIdentity *relays,
275                                 const struct GNUNET_MessageHeader *join_resp);
276
277
278 /**
279  * Method called whenever another peer wants to join the multicast group.
280  *
281  * Implementations of this function must call GNUNET_MULTICAST_join_decision()
282  * with the decision.
283  *
284  * @param cls
285  *        Closure.
286  * @param member_pub_key
287  *        Public key of the member requesting join.
288  * @param join_msg
289  *        Application-dependent join message from the new member.
290  * @param jh
291  *        Join handle to pass to GNUNET_MULTICAST_join_decison().
292  */
293 typedef void
294 (*GNUNET_MULTICAST_JoinRequestCallback) (void *cls,
295                                          const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
296                                          const struct GNUNET_MessageHeader *join_msg,
297                                          struct GNUNET_MULTICAST_JoinHandle *jh);
298
299
300 /**
301  * Method called to inform about the decision in response to a join request.
302  *
303  * If @a is_admitted is not #GNUNET_YES, then the multicast service disconnects
304  * the client and the multicast member handle returned by
305  * GNUNET_MULTICAST_member_join() is invalidated.
306  *
307  * @param cls
308  *         Closure.
309  * @param is_admitted
310  *         #GNUNET_YES or #GNUNET_NO or #GNUNET_SYSERR
311  * @param peer
312  *        The peer we are connected to and the join decision is from.
313  * @param relay_count
314  *        Number of peers in the @a relays array.
315  * @param relays
316  *        Peer identities of members of the group, which serve as relays
317  *        and can be used to join the group at.  If empty, only the origin can
318  *        be used to connect to the group.
319  * @param join_msg
320  *        Application-dependent join message from the origin.
321  */
322 typedef void
323 (*GNUNET_MULTICAST_JoinDecisionCallback) (void *cls,
324                                           int is_admitted,
325                                           const struct GNUNET_PeerIdentity *peer,
326                                           uint16_t relay_count,
327                                           const struct GNUNET_PeerIdentity *relays,
328                                           const struct GNUNET_MessageHeader *join_msg);
329
330
331 /**
332  * Function called whenever a group member has transmitted a request
333  * to the origin (other than joining or leaving).
334  *
335  * FIXME: need to distinguish between origin cancelling a message (some fragments
336  * were sent, then the rest 'discarded') and the case where we got disconnected;
337  * right now, both would mean 'msg' is NULL, but they could be quite different...
338  * So the semantics from the receiver side of
339  * GNUNET_MULTICAST_member_to_origin_cancel() are not clear here.   Maybe we
340  * should do something with the flags in this case?
341  *
342  * @param cls
343  *        Closure (set from GNUNET_MULTICAST_origin_start).
344  * @param sender
345  *        Identity of the sender.
346  * @param req
347  *        Request to the origin.
348  * @param flags
349  *        Flags for the request.
350  */
351 typedef void
352 (*GNUNET_MULTICAST_RequestCallback) (void *cls,
353                                      const struct GNUNET_MULTICAST_RequestHeader *req);
354
355
356 /**
357  * Function called whenever a group member is receiving a message fragment from
358  * the origin.
359  *
360  * If admission to the group is denied, this function is called once with the
361  * response of the @e origin (as given to GNUNET_MULTICAST_join_decision()) and
362  * then a second time with NULL to indicate that the connection failed for good.
363  *
364  * FIXME: need to distinguish between origin cancelling a message (some fragments
365  * were sent, then the rest 'discarded') and the case where we got disconnected;
366  * right now, both would mean 'msg' is NULL, but they could be quite different...
367  * So the semantics from the receiver side of
368  * GNUNET_MULTICAST_origin_to_all_cancel() are not clear here.
369  *
370  * @param cls
371  *        Closure (set from GNUNET_MULTICAST_member_join())
372  * @param msg
373  *        Message from the origin, NULL if the origin shut down
374  *        (or we were kicked out, and we should thus call
375  *        GNUNET_MULTICAST_member_part() next)
376  */
377 typedef void
378 (*GNUNET_MULTICAST_MessageCallback) (void *cls,
379                                      const struct GNUNET_MULTICAST_MessageHeader *msg);
380
381
382 /**
383  * Opaque handle to a replay request from the multicast service.
384  */
385 struct GNUNET_MULTICAST_ReplayHandle;
386
387
388 /**
389  * Functions with this signature are called whenever the multicast service needs
390  * a message fragment to be replayed by fragment_id.
391  *
392  * Implementations of this function MUST call GNUNET_MULTICAST_replay() ONCE
393  * (with a message or an error); however, if the origin is destroyed or the
394  * group is left, the replay handle must no longer be used.
395  *
396  * @param cls
397  *        Closure (set from GNUNET_MULTICAST_origin_start()
398  *        or GNUNET_MULTICAST_member_join()).
399  * @param member_pub_key
400  *        The member requesting replay.
401  * @param fragment_id
402  *        Which message fragment should be replayed.
403  * @param flags
404  *        Flags for the replay.
405  * @param rh
406  *        Handle to pass to message transmit function.
407  */
408 typedef void
409 (*GNUNET_MULTICAST_ReplayFragmentCallback) (void *cls,
410                                             const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
411                                             uint64_t fragment_id,
412                                             uint64_t flags,
413                                             struct GNUNET_MULTICAST_ReplayHandle *rh);
414
415 /**
416  * Functions with this signature are called whenever the multicast service needs
417  * a message fragment to be replayed by message_id and fragment_offset.
418  *
419  * Implementations of this function MUST call GNUNET_MULTICAST_replay() ONCE
420  * (with a message or an error); however, if the origin is destroyed or the
421  * group is left, the replay handle must no longer be used.
422  *
423  * @param cls
424  *        Closure (set from GNUNET_MULTICAST_origin_start()
425  *        or GNUNET_MULTICAST_member_join()).
426  * @param member_pub_key
427  *        The member requesting replay.
428  * @param message_id
429  *        Which message should be replayed.
430  * @param fragment_offset
431  *        Offset of the fragment within of @a message_id to be replayed.
432  * @param flags
433  *        Flags for the replay.
434  * @param rh
435  *        Handle to pass to message transmit function.
436  */
437 typedef void
438 (*GNUNET_MULTICAST_ReplayMessageCallback) (void *cls,
439                                            const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
440                                            uint64_t message_id,
441                                            uint64_t fragment_offset,
442                                            uint64_t flags,
443                                            struct GNUNET_MULTICAST_ReplayHandle *rh);
444
445
446 /**
447  * Possible error codes during replay.
448  */
449 enum GNUNET_MULTICAST_ReplayErrorCode
450 {
451
452   /**
453    * Everything is fine.
454    */
455   GNUNET_MULTICAST_REC_OK = 0,
456
457   /**
458    * Message fragment not found in the message store.
459    *
460    * Either discarded if it is too old, or not arrived yet if this member has
461    * missed some messages.
462    */
463   GNUNET_MULTICAST_REC_NOT_FOUND = 1,
464
465   /**
466    * Fragment ID counter was larger than the highest counter this
467    * replay function has ever encountered; thus it is likely the
468    * origin never sent it and we're at the HEAD of the multicast
469    * stream as far as this node is concerned.
470    *
471    * FIXME: needed?
472    */
473   GNUNET_MULTICAST_REC_PAST_HEAD = 2,
474
475   /**
476    * Access is denied to the requested fragment, membership test did not pass.
477    */
478   GNUNET_MULTICAST_REC_ACCESS_DENIED = 3,
479
480   /**
481    * Internal error (i.e. database error).  Try some other peer.
482    */
483   GNUNET_MULTICAST_REC_INTERNAL_ERROR = 4
484
485 };
486
487
488 /**
489  * Replay a message fragment for the multicast group.
490  *
491  * @param rh
492  *        Replay handle identifying which replay operation was requested.
493  * @param msg
494  *        Replayed message fragment, NULL if not found / an error occurred.
495  * @param ec
496  *        Error code.  See enum GNUNET_MULTICAST_ReplayErrorCode
497  *        If not #GNUNET_MULTICAST_REC_OK, the replay handle is invalidated.
498  */
499 void
500 GNUNET_MULTICAST_replay_response (struct GNUNET_MULTICAST_ReplayHandle *rh,
501                                   const struct GNUNET_MessageHeader *msg,
502                                   enum GNUNET_MULTICAST_ReplayErrorCode ec);
503
504
505 /**
506  * Indicate the end of the replay session.
507  *
508  * Invalidates the replay handle.
509  *
510  * @param rh Replay session to end.
511  */
512 void
513 GNUNET_MULTICAST_replay_response_end (struct GNUNET_MULTICAST_ReplayHandle *rh);
514
515
516 /**
517  * Function called to provide data for a transmission for a replay.
518  *
519  * @see GNUNET_MULTICAST_replay2()
520  */
521 typedef int
522 (*GNUNET_MULTICAST_ReplayTransmitNotify) (void *cls,
523                                           size_t *data_size,
524                                           void *data);
525
526
527 /**
528  * Replay a message for the multicast group.
529  *
530  * @param rh
531  *        Replay handle identifying which replay operation was requested.
532  * @param notify
533  *        Function to call to get the message.
534  * @param notify_cls
535  *        Closure for @a notify.
536  */
537 void
538 GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
539                                    GNUNET_MULTICAST_ReplayTransmitNotify notify,
540                                    void *notify_cls);
541
542
543 /**
544  * Start a multicast group.
545  *
546  * Peers that issue GNUNET_MULTICAST_member_join() can transmit a join request
547  * to either an existing group member or to the origin.  If the joining is
548  * approved, the member is cleared for @e replay and will begin to receive
549  * messages transmitted to the group.  If joining is disapproved, the failed
550  * candidate will be given a response.  Members in the group can send messages
551  * to the origin.
552  *
553  * TODO: This function could optionally offer to advertise the origin in the
554  * P2P overlay network(where?) under the respective public key so that other
555  * peers can find an alternate PeerId to join it. Higher level protocols may
556  * however provide other means of solving the problem of the offline host
557  * (see secushare specs about that) and therefore merely need a way to provide
558  * a list of possible PeerIds.
559  *
560  * @param cfg
561  *        Configuration to use.
562  * @param priv_key
563  *        ECC key that will be used to sign messages for this
564  *        multicast session; public key is used to identify the multicast group;
565  * @param max_fragment_id
566  *        Maximum fragment ID already sent to the group.
567  *        0 for a new group.
568  * @param join_request_cb
569  *        Function called to approve / disapprove joining of a peer.
570  * @param replay_frag_cb
571  *        Function that can be called to replay a message fragment.
572  * @param replay_msg_cb
573  *        Function that can be called to replay a message.
574  * @param request_cb
575  *        Function called with message fragments from group members.
576  * @param message_cb
577  *        Function called with the message fragments sent to the
578  *        network by GNUNET_MULTICAST_origin_to_all().  These message fragments
579  *        should be stored for answering replay requests later.
580  * @param cls
581  *        Closure for the various callbacks that follow.
582  *
583  * @return Handle for the origin, NULL on error.
584  */
585 struct GNUNET_MULTICAST_Origin *
586 GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
587                                const struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key,
588                                uint64_t max_fragment_id,
589                                GNUNET_MULTICAST_JoinRequestCallback join_request_cb,
590                                GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
591                                GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
592                                GNUNET_MULTICAST_RequestCallback request_cb,
593                                GNUNET_MULTICAST_MessageCallback message_cb,
594                                void *cls);
595
596 /**
597  * Function called to provide data for a transmission from the origin to all
598  * members.
599  *
600  * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
601  * invalidates the respective transmission handle.
602  *
603  * @param cls
604  *        Closure.
605  * @param[in,out] data_size
606  *        Initially set to the number of bytes available in
607  *        @a data, should be set to the number of bytes written to data.
608  * @param[out] data
609  *        Where to write the body of the message to give to the
610  *         method. The function must copy at most @a data_size bytes to @a data.
611  *
612  * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
613  *         #GNUNET_NO on success, if more data is to be transmitted later.
614  *         Should be used if @a data_size was not big enough to take all the
615  *         data.  If 0 is returned in @a data_size the transmission is paused,
616  *         and can be resumed with GNUNET_MULTICAST_origin_to_all_resume().
617  *         #GNUNET_YES if this completes the transmission (all data supplied)
618  * @deprecated should move to MQ-style API!
619  */
620 typedef int
621 (*GNUNET_MULTICAST_OriginTransmitNotify) (void *cls,
622                                           size_t *data_size,
623                                           void *data);
624
625
626 /**
627  * Handle for a request to send a message to all multicast group members
628  * (from the origin).
629  */
630 struct GNUNET_MULTICAST_OriginTransmitHandle;
631
632
633 /**
634  * Send a message to the multicast group.
635  *
636  * @param origin
637  *        Handle to the multicast group.
638  * @param message_id
639  *        Application layer ID for the message.  Opaque to multicast.
640  * @param group_generation
641  *        Group generation of the message.  Documented in
642  *        struct GNUNET_MULTICAST_MessageHeader.
643  * @param notify
644  *        Function to call to get the message.
645  * @param notify_cls
646  *        Closure for @a notify.
647  *
648  * @return NULL on error (i.e. request already pending).
649  * @deprecated should move to MQ-style API!
650  */
651 struct GNUNET_MULTICAST_OriginTransmitHandle *
652 GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
653                                 uint64_t message_id,
654                                 uint64_t group_generation,
655                                 GNUNET_MULTICAST_OriginTransmitNotify notify,
656                                 void *notify_cls);
657
658
659
660 /**
661  * Resume message transmission to multicast group.
662  *
663  * @param th  Transmission to cancel.
664  */
665 void
666 GNUNET_MULTICAST_origin_to_all_resume (struct GNUNET_MULTICAST_OriginTransmitHandle *th);
667
668
669 /**
670  * Cancel request for message transmission to multicast group.
671  *
672  * @param th  Transmission to cancel.
673  */
674 void
675 GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginTransmitHandle *th);
676
677
678 /**
679  * Stop a multicast group.
680  *
681  * @param origin Multicast group to stop.
682  */
683 void
684 GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin,
685                               GNUNET_ContinuationCallback stop_cb,
686                               void *stop_cls);
687
688
689 /**
690  * Join a multicast group.
691  *
692  * The entity joining is always the local peer.  Further information about the
693  * candidate can be provided in @a join_msg.  If the join fails, the
694  * @a message_cb is invoked with a (failure) response and then with NULL.  If
695  * the join succeeds, outstanding (state) messages and ongoing multicast
696  * messages will be given to the @a message_cb until the member decides to part
697  * the group.  The @a mem_test_cb and @a replay_cb functions may be called at
698  * anytime by the multicast service to support relaying messages to other
699  * members of the group.
700  *
701  * @param cfg
702  *        Configuration to use.
703  * @param group_key
704  *        ECC public key that identifies the group to join.
705  * @param member_pub_key
706  *        ECC key that identifies the member
707  *        and used to sign requests sent to the origin.
708  * @param origin
709  *        Peer ID of the origin to send unicast requsets to.  If NULL,
710  *        unicast requests are sent back via multiple hops on the reverse path
711  *        of multicast messages.
712  * @param relay_count
713  *        Number of peers in the @a relays array.
714  * @param relays
715  *        Peer identities of members of the group, which serve as relays
716  *        and can be used to join the group at. and send the @a join_request to.
717  *        If empty, the @a join_request is sent directly to the @a origin.
718  * @param join_msg
719  *        Application-dependent join message to be passed to the peer @a origin.
720  * @param join_request_cb
721  *        Function called to approve / disapprove joining of a peer.
722  * @param join_decision_cb
723  *        Function called to inform about the join decision.
724  * @param replay_frag_cb
725  *        Function that can be called to replay message fragments
726  *        this peer already knows from this group. NULL if this
727  *        client is unable to support replay.
728  * @param replay_msg_cb
729  *        Function that can be called to replay message fragments
730  *        this peer already knows from this group. NULL if this
731  *        client is unable to support replay.
732  * @param message_cb
733  *        Function to be called for all message fragments we
734  *        receive from the group, excluding those our @a replay_cb
735  *        already has.
736  * @param cls
737  *        Closure for callbacks.
738  *
739  * @return Handle for the member, NULL on error.
740  */
741 struct GNUNET_MULTICAST_Member *
742 GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
743                               const struct GNUNET_CRYPTO_EddsaPublicKey *group_key,
744                               const struct GNUNET_CRYPTO_EcdsaPrivateKey *member_pub_key,
745                               const struct GNUNET_PeerIdentity *origin,
746                               uint16_t relay_count,
747                               const struct GNUNET_PeerIdentity *relays,
748                               const struct GNUNET_MessageHeader *join_request,
749                               GNUNET_MULTICAST_JoinRequestCallback join_request_cb,
750                               GNUNET_MULTICAST_JoinDecisionCallback join_decision_cb,
751                               GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
752                               GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
753                               GNUNET_MULTICAST_MessageCallback message_cb,
754                               void *cls);
755
756 /**
757  * Handle for a replay request.
758  */
759 struct GNUNET_MULTICAST_MemberReplayHandle;
760
761
762 /**
763  * Request a fragment to be replayed by fragment ID.
764  *
765  * Useful if messages below the @e max_known_fragment_id given when joining are
766  * needed and not known to the client.
767  *
768  * @param member
769  *        Membership handle.
770  * @param fragment_id
771  *        ID of a message fragment that this client would like to see replayed.
772  * @param flags
773  *        Additional flags for the replay request.
774  *        It is used and defined by GNUNET_MULTICAST_ReplayFragmentCallback
775  *
776  * @return Replay request handle, NULL on error.
777  */
778 struct GNUNET_MULTICAST_MemberReplayHandle *
779 GNUNET_MULTICAST_member_replay_fragment (struct GNUNET_MULTICAST_Member *member,
780                                          uint64_t fragment_id,
781                                          uint64_t flags);
782
783
784 /**
785  * Request a message fr to be replayed.
786  *
787  * Useful if messages below the @e max_known_fragment_id given when joining are
788  * needed and not known to the client.
789  *
790  * @param member
791  *        Membership handle.
792  * @param message_id
793  *        ID of the message this client would like to see replayed.
794  * @param fragment_offset
795  *        Offset of the fragment within the message to replay.
796  * @param flags
797  *        Additional flags for the replay request.
798  *        It is used & defined by GNUNET_MULTICAST_ReplayMessageCallback
799  *
800  * @return Replay request handle, NULL on error.
801  */
802 struct GNUNET_MULTICAST_MemberReplayHandle *
803 GNUNET_MULTICAST_member_replay_message (struct GNUNET_MULTICAST_Member *member,
804                                         uint64_t message_id,
805                                         uint64_t fragment_offset,
806                                         uint64_t flags);
807
808
809 /**
810  * Cancel a replay request.
811  *
812  * @param rh
813  *        Request to cancel.
814  */
815 void
816 GNUNET_MULTICAST_member_replay_cancel (struct GNUNET_MULTICAST_MemberReplayHandle *rh);
817
818
819 /**
820  * Part a multicast group.
821  *
822  * Disconnects from all group members and invalidates the @a member handle.
823  *
824  * An application-dependent part message can be transmitted beforehand using
825  * #GNUNET_MULTICAST_member_to_origin())
826  *
827  * @param member
828  *        Membership handle.
829  */
830 void
831 GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member,
832                               GNUNET_ContinuationCallback part_cb,
833                               void *part_cls);
834
835
836 /**
837  * Function called to provide data for a transmission from a member to the origin.
838  *
839  * Note that returning #GNUNET_OK or #GNUNET_SYSERR (but not #GNUNET_NO)
840  * invalidates the respective transmission handle.
841  *
842  * @param cls
843  *        Closure.
844  * @param[in,out] data_size
845  *        Initially set to the number of bytes available in
846  *        @a data, should be set to the number of bytes written to data.
847  * @param[out] data
848  *        Where to write the body of the message to give to the
849  *        method. The function must copy at most @a data_size bytes to @a data.
850  *
851  * @return #GNUNET_SYSERR on error (fatal, aborts transmission)
852  *         #GNUNET_NO on success, if more data is to be transmitted later.
853  *         Should be used if @a data_size was not big enough to take all the
854  *         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().
856  *         #GNUNET_YES if this completes the transmission (all data supplied)
857  * @deprecated should move to MQ-style API!
858  */
859 typedef int
860 (*GNUNET_MULTICAST_MemberTransmitNotify) (void *cls,
861                                           size_t *data_size,
862                                           void *data);
863
864
865 /**
866  * Handle for a message to be delivered from a member to the origin.
867  */
868 struct GNUNET_MULTICAST_MemberTransmitHandle;
869
870
871 /**
872  * Send a message to the origin of the multicast group.
873  *
874  * @param member
875  *        Membership handle.
876  * @param request_id
877  *        Application layer ID for the request.  Opaque to multicast.
878  * @param notify
879  *        Callback to call to get the message.
880  * @param notify_cls
881  *        Closure for @a notify.
882  *
883  * @return Handle to cancel request, NULL on error (i.e. request already pending).
884  * @deprecated should move to MQ-style API!
885  */
886 struct GNUNET_MULTICAST_MemberTransmitHandle *
887 GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
888                                    uint64_t request_id,
889                                    GNUNET_MULTICAST_MemberTransmitNotify notify,
890                                    void *notify_cls);
891
892
893 /**
894  * Resume message transmission to origin.
895  *
896  * @param th
897  *        Transmission to cancel.
898  */
899 void
900 GNUNET_MULTICAST_member_to_origin_resume (struct GNUNET_MULTICAST_MemberTransmitHandle *th);
901
902
903 /**
904  * Cancel request for message transmission to origin.
905  *
906  * @param th
907  *        Transmission to cancel.
908  */
909 void
910 GNUNET_MULTICAST_member_to_origin_cancel (struct GNUNET_MULTICAST_MemberTransmitHandle *th);
911
912
913 #if 0                           /* keep Emacsens' auto-indent happy */
914 {
915 #endif
916 #ifdef __cplusplus
917 }
918 #endif
919
920 /* ifndef GNUNET_MULTICAST_SERVICE_H */
921 #endif
922
923 /** @} */  /* end of group */