b8ee42cb36d85dd660a9f741d316943e3a418a31
[oweals/gnunet.git] / src / multicast / multicast_api.c
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 multicast/multicast_api.c
23  * @brief multicast service; establish tunnels to distant peers
24  * @author Christian Grothoff
25  * @author Gabor X Toth
26  */
27 #include "platform.h"
28 #include "gnunet_multicast_service.h"
29
30 /** 
31  * Opaque handle for a multicast group member.
32  */
33 struct GNUNET_MULTICAST_Member
34 {
35 };
36
37
38 /** 
39  * Handle for the origin of a multicast group.
40  */
41 struct GNUNET_MULTICAST_Origin
42 {
43 };
44
45
46 GNUNET_NETWORK_STRUCT_BEGIN
47
48 /** 
49  * Header of a request from a member to the origin.
50  */
51 struct GNUNET_MULTICAST_RequestHeader
52 {
53   /** 
54    * Header for all requests from a member to the origin.
55    */
56   struct GNUNET_MessageHeader header;
57
58   /**
59    * Public key of the sending member.
60    */
61   struct GNUNET_CRYPTO_EccPublicSignKey member_key;
62
63   /** 
64    * ECC signature of the request fragment.
65    *
66    * Signature must match the public key of the multicast group.
67    */
68   struct GNUNET_CRYPTO_EccSignature signature;
69
70   /** 
71    * Purpose for the signature and size of the signed data.
72    */
73   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
74
75   /** 
76    * Number of the request fragment, monotonically increasing.
77    */
78   uint64_t fragment_id GNUNET_PACKED;
79
80   /** 
81    * Byte offset of this @e fragment of the @e request.
82    */
83   uint64_t fragment_offset GNUNET_PACKED;
84
85   /** 
86    * Number of the request this fragment belongs to.
87    *
88    * Set in GNUNET_MULTICAST_origin_to_all().
89    */
90   uint64_t request_id GNUNET_PACKED;
91
92   /**
93    * Flags for this request.
94    */
95   enum GNUNET_MULTICAST_MessageFlags flags GNUNET_PACKED;
96
97   /* Followed by request body. */
98 };
99
100 /** 
101  * Header of a join request sent to the origin or another member.
102  */
103 struct GNUNET_MULTICAST_JoinRequest
104 {
105   /** 
106    * Header for the join request.
107    */
108   struct GNUNET_MessageHeader header;
109
110   /** 
111    * ECC signature of the rest of the fields of the join request.
112    *
113    * Signature must match the public key of the joining member.
114    */
115   struct GNUNET_CRYPTO_EccSignature signature;
116
117   /** 
118    * Purpose for the signature and size of the signed data.
119    */
120   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
121
122   /**
123    * Public key of the target group.
124    */
125   struct GNUNET_CRYPTO_EccPublicSignKey group_key;
126
127   /**
128    * Public key of the joining member.
129    */
130   struct GNUNET_CRYPTO_EccPublicSignKey member_key;
131
132   /**
133    * Peer identity of the joining member.
134    */
135   struct GNUNET_PeerIdentity member_peer;
136
137   /* Followed by request body. */
138 };
139
140 GNUNET_NETWORK_STRUCT_END
141
142
143 /** 
144  * Handle that identifies a join request.
145  *
146  * Used to match calls to #GNUNET_MULTICAST_JoinCallback to the
147  * corresponding calls to #GNUNET_MULTICAST_join_decision().
148  */
149 struct GNUNET_MULTICAST_JoinHandle
150 {
151 };
152
153
154 /** 
155  * Function to call with the decision made for a join request.
156  *
157  * Must be called once and only once in response to an invocation of the
158  * #GNUNET_MULTICAST_JoinCallback.
159  *
160  * @param jh Join request handle.
161  * @param is_admitted #GNUNET_YES if joining is approved,
162  *        #GNUNET_NO if it is disapproved
163  * @param relay_count Number of relays given.
164  * @param relays Array of suggested peers that might be useful relays to use
165  *        when joining the multicast group (essentially a list of peers that
166  *        are already part of the multicast group and might thus be willing
167  *        to help with routing).  If empty, only this local peer (which must
168  *        be the multicast origin) is a good candidate for building the
169  *        multicast tree.  Note that it is unnecessary to specify our own
170  *        peer identity in this array.
171  * @param join_response Message to send in response to the joining peer;
172  *        can also be used to redirect the peer to a different group at the
173  *        application layer; this response is to be transmitted to the
174  *        peer that issued the request even if admission is denied.
175  */
176 struct GNUNET_MULTICAST_ReplayHandle *
177 GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh,
178                                 int is_admitted,
179                                 unsigned int relay_count,
180                                 const struct GNUNET_PeerIdentity *relays,
181                                 const struct GNUNET_MessageHeader *join_response)
182 {
183   return NULL;
184 }
185
186
187 /** 
188  * Handle to pass back for the answer of a membership test.
189  */
190 struct GNUNET_MULTICAST_MembershipTestHandle
191 {
192 };
193
194
195 /** 
196  * Call informing multicast about the decision taken for a membership test.
197  *
198  * @param mth Handle that was given for the query.
199  * @param result #GNUNET_YES if peer was a member, #GNUNET_NO if peer was not a member,
200  *        #GNUNET_SYSERR if we cannot answer the membership test.
201  */
202 void
203 GNUNET_MULTICAST_membership_test_result (struct GNUNET_MULTICAST_MembershipTestHandle *mth,
204                                          int result)
205 {
206 }
207
208
209 /** 
210  * Opaque handle to a replay request from the multicast service.
211  */
212 struct GNUNET_MULTICAST_ReplayHandle
213 {
214 };
215
216
217 /** 
218  * Replay a message fragment for the multicast group.
219  *
220  * @param rh Replay handle identifying which replay operation was requested.
221  * @param msg Replayed message fragment, NULL if unknown/error.
222  * @param ec Error code.
223  */
224 void
225 GNUNET_MULTICAST_replay_response (struct GNUNET_MULTICAST_ReplayHandle *rh,
226                                   const struct GNUNET_MessageHeader *msg,
227                                   enum GNUNET_MULTICAST_ReplayErrorCode ec)
228 {
229 }
230
231
232 /** 
233  * Indicate the end of the replay session.
234  *
235  * Invalidates the replay handle.
236  *
237  * @param rh Replay session to end.
238  */
239 void
240 GNUNET_MULTICAST_replay_response_end (struct GNUNET_MULTICAST_ReplayHandle *rh)
241 {
242 }
243
244
245 /** 
246  * Replay a message for the multicast group.
247  *
248  * @param rh Replay handle identifying which replay operation was requested.
249  * @param notify Function to call to get the message.
250  * @param notify_cls Closure for @a notify.
251  */
252 void
253 GNUNET_MULTICAST_replay_response2 (struct GNUNET_MULTICAST_ReplayHandle *rh,
254                                    GNUNET_MULTICAST_ReplayTransmitNotify notify,
255                                    void *notify_cls)
256 {
257 }
258
259
260 /** 
261  * Start a multicast group.
262  *
263  * Will advertise the origin in the P2P overlay network under the respective
264  * public key so that other peer can find this peer to join it.  Peers that
265  * issue GNUNET_MULTICAST_member_join() can then transmit a join request to
266  * either an existing group member or to the origin.  If the joining is
267  * approved, the member is cleared for @e replay and will begin to receive
268  * messages transmitted to the group.  If joining is disapproved, the failed
269  * candidate will be given a response.  Members in the group can send messages
270  * to the origin (one at a time).
271  *
272  * @param cfg Configuration to use.
273  * @param priv_key ECC key that will be used to sign messages for this
274  *        multicast session; public key is used to identify the multicast group;
275  * @param last_fragment_id Last fragment ID to continue counting fragments from
276  *        when restarting the origin.  0 for a new group.
277  * @param join_cb Function called to approve / disapprove joining of a peer.
278  * @param test_cb Function multicast can use to test group membership.
279  * @param replay_frag_cb Function that can be called to replay a message fragment.
280  * @param replay_msg_cb Function that can be called to replay a message.
281  * @param request_cb Function called with message fragments from group members.
282  * @param message_cb Function called with the message fragments sent to the
283  *        network by GNUNET_MULTICAST_origin_to_all().  These message fragments
284  *        should be stored for answering replay requests later.
285  * @param cls Closure for the various callbacks that follow.
286  * @return Handle for the origin, NULL on error.
287  */
288 struct GNUNET_MULTICAST_Origin *
289 GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
290                                const struct GNUNET_CRYPTO_EccPrivateKey *priv_key,
291                                uint64_t last_fragment_id,
292                                GNUNET_MULTICAST_JoinCallback join_cb,
293                                GNUNET_MULTICAST_MembershipTestCallback test_cb,
294                                GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
295                                GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
296                                GNUNET_MULTICAST_RequestCallback request_cb,
297                                GNUNET_MULTICAST_MessageCallback message_cb,
298                                void *cls)
299 {
300   return NULL;
301 }
302
303
304 /** 
305  * Handle for a request to send a message to all multicast group members
306  * (from the origin).
307  */
308 struct GNUNET_MULTICAST_OriginMessageHandle
309 {
310 };
311
312
313 /** 
314  * Send a message to the multicast group.
315  *
316  * @param origin Handle to the multicast group.
317  * @param message_id Application layer ID for the message.  Opaque to multicast.
318  * @param group_generation Group generation of the message.  Documented in
319  *             `struct GNUNET_MULTICAST_MessageHeader`.
320  * @param size Number of bytes to transmit.
321  *        FIXME: Needed? The end of the message can be flagged with a last fragment flag.
322  * @param notify Function to call to get the message.
323  * @param notify_cls Closure for @a notify.
324  * @return NULL on error (i.e. request already pending).
325  */
326 struct GNUNET_MULTICAST_OriginMessageHandle *
327 GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
328                                 uint64_t message_id,
329                                 uint64_t group_generation,
330                                 size_t size,
331                                 GNUNET_MULTICAST_OriginTransmitNotify notify,
332                                 void *notify_cls)
333 {
334   return NULL;
335 }
336
337
338 /** 
339  * Cancel request for message transmission to multicast group.
340  *
341  * @param mh Request to cancel.
342  */
343 void
344 GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginMessageHandle *mh)
345 {
346 }
347
348
349 /** 
350  * Stop a multicast group.
351  *
352  * @param origin Multicast group to stop.
353  */
354 void
355 GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin)
356 {
357 }
358
359
360 /** 
361  * Join a multicast group.
362  *
363  * The entity joining is always the local peer.  Further information about the
364  * candidate can be provided in the @a join_request message.  If the join fails, the
365  * @a message_cb is invoked with a (failure) response and then with NULL.  If
366  * the join succeeds, outstanding (state) messages and ongoing multicast
367  * messages will be given to the @a message_cb until the member decides to part
368  * the group.  The @a test_cb and @a replay_cb functions may be called at
369  * anytime by the multicast service to support relaying messages to other
370  * members of the group.
371  *
372  * @param cfg Configuration to use.
373  * @param group_key ECC public key that identifies the group to join.
374  * @param member_key ECC key that identifies the member and used to sign
375  *        requests sent to the origin.
376  * @param origin Peer ID of the origin to send unicast requsets to.  If NULL,
377  *        unicast requests are sent back via multiple hops on the reverse path
378  *        of multicast messages.
379  * @param relay_count Number of peers in the @a relays array.
380  * @param relays Peer identities of members of the group, which serve as relays
381  *        and can be used to join the group at. and send the @a join_request to.
382  *        If empty, the @a join_request is sent directly to the @a origin.
383  * @param join_request  Application-dependent join request to be passed to the peer
384  *        @a relay (might, for example, contain a user, bind user
385  *        identity/pseudonym to peer identity, application-level message to
386  *        origin, etc.).
387  * @param join_cb Function called to approve / disapprove joining of a peer.
388  * @param test_cb Function multicast can use to test group membership.
389  * @param replay_frag_cb Function that can be called to replay message fragments
390  *        this peer already knows from this group. NULL if this
391  *        client is unable to support replay.
392  * @param replay_msg_cb Function that can be called to replay message fragments
393  *        this peer already knows from this group. NULL if this
394  *        client is unable to support replay.
395  * @param message_cb Function to be called for all message fragments we
396  *        receive from the group, excluding those our @a replay_cb
397  *        already has.
398  * @param cls Closure for callbacks.
399  * @return Handle for the member, NULL on error.
400  */
401 struct GNUNET_MULTICAST_Member *
402 GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
403                               const struct GNUNET_CRYPTO_EccPublicSignKey *group_key,
404                               const struct GNUNET_CRYPTO_EccPrivateKey *member_key,
405                               const struct GNUNET_PeerIdentity *origin,
406                               uint32_t relay_count,
407                               const struct GNUNET_PeerIdentity *relays,
408                               const struct GNUNET_MessageHeader *join_request,
409                               GNUNET_MULTICAST_JoinCallback join_cb,
410                               GNUNET_MULTICAST_MembershipTestCallback test_cb,
411                               GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
412                               GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
413                               GNUNET_MULTICAST_MessageCallback message_cb,
414                               void *cls)
415 {
416   return NULL;
417 }
418
419
420 /** 
421  * Handle for a replay request.
422  */
423 struct GNUNET_MULTICAST_MemberReplayHandle
424 {
425 };
426
427
428 /** 
429  * Request a fragment to be replayed by fragment ID.
430  *
431  * Useful if messages below the @e max_known_fragment_id given when joining are
432  * needed and not known to the client.
433  *
434  * @param member Membership handle.
435  * @param fragment_id ID of a message fragment that this client would like to
436           see replayed.
437  * @param flags Additional flags for the replay request.  It is used and defined
438  *        by the replay callback.  FIXME: which replay callback? FIXME: use enum?
439  *        FIXME: why not pass reply cb here?
440  * @return Replay request handle, NULL on error.
441  */
442 struct GNUNET_MULTICAST_MemberReplayHandle *
443 GNUNET_MULTICAST_member_replay_fragment (struct GNUNET_MULTICAST_Member *member,
444                                          uint64_t fragment_id,
445                                          uint64_t flags)
446 {
447   return NULL;
448 }
449
450
451 /** 
452  * Request a message fragment to be replayed.
453  *
454  * Useful if messages below the @e max_known_fragment_id given when joining are
455  * needed and not known to the client.
456  *
457  * @param member Membership handle.
458  * @param message_id ID of the message this client would like to see replayed.
459  * @param fragment_offset Offset of the fragment within the message to replay.
460  * @param flags Additional flags for the replay request.  It is used & defined
461  *        by the replay callback.
462  * @param result_cb Function to be called for the replayed message.
463  * @param result_cb_cls Closure for @a result_cb.
464  * @return Replay request handle, NULL on error.
465  */
466 struct GNUNET_MULTICAST_MemberReplayHandle *
467 GNUNET_MULTICAST_member_replay_message (struct GNUNET_MULTICAST_Member *member,
468                                         uint64_t message_id,
469                                         uint64_t fragment_offset,
470                                         uint64_t flags,
471                                         GNUNET_MULTICAST_ResultCallback result_cb,
472                                         void *result_cb_cls)
473 {
474   return NULL;
475 }
476
477
478 /** 
479  * Cancel a replay request.
480  *
481  * @param rh Request to cancel.
482  */
483 void
484 GNUNET_MULTICAST_member_replay_cancel (struct GNUNET_MULTICAST_MemberReplayHandle *rh)
485 {
486 }
487
488
489 /** 
490  * Part a multicast group.
491  *
492  * Disconnects from all group members and invalidates the @a member handle.
493  *
494  * An application-dependent part message can be transmitted beforehand using
495  * #GNUNET_MULTICAST_member_to_origin())
496  *
497  * @param member Membership handle.
498  */
499 void
500 GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member)
501 {
502 }
503
504
505 /** 
506  * Handle for a message to be delivered from a member to the origin.
507  */
508 struct GNUNET_MULTICAST_MemberRequestHandle
509 {
510 };
511
512
513 /** 
514  * Send a message to the origin of the multicast group.
515  * 
516  * @param member Membership handle.
517  * @param message_id Application layer ID for the message.  Opaque to multicast.
518  * @param size Number of bytes we want to send to origin.
519  * @param notify Callback to call to get the message.
520  * @param notify_cls Closure for @a notify.
521  * @return Handle to cancel request, NULL on error (i.e. request already pending).
522  */
523 struct GNUNET_MULTICAST_MemberRequestHandle *
524 GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
525                                    uint64_t message_id,
526                                    size_t size,
527                                    GNUNET_MULTICAST_MemberTransmitNotify notify,
528                                    void *notify_cls)
529 {
530   return NULL;
531 }
532
533
534 /** 
535  * Cancel request for message transmission to origin.
536  *
537  * @param rh Request to cancel.
538  */
539 void
540 GNUNET_MULTICAST_member_to_origin_cancel (struct GNUNET_MULTICAST_MemberRequestHandle *rh)
541 {
542 }
543
544
545 /* end of multicast_api.c */