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