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