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