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