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