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