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