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