b05d2d99c3236ead3bf87d36ad20693376672947
[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  *        FIXME: we'll likely want to use NOT the p521 curve here, but a cheaper
276  *        one in the future.
277  * @param last_fragment_id Last fragment ID to continue counting fragments from
278  *        when restarting the origin.  0 for a new group.
279  * @param join_cb Function called to approve / disapprove joining of a peer.
280  * @param test_cb Function multicast can use to test group membership.
281  * @param replay_frag_cb Function that can be called to replay a message fragment.
282  * @param replay_msg_cb Function that can be called to replay a message.
283  * @param request_cb Function called with message fragments from group members.
284  * @param message_cb Function called with the message fragments sent to the
285  *        network by GNUNET_MULTICAST_origin_to_all().  These message fragments
286  *        should be stored for answering replay requests later.
287  * @param cls Closure for the various callbacks that follow.
288  * @return Handle for the origin, NULL on error.
289  */
290 struct GNUNET_MULTICAST_Origin *
291 GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
292                                const struct GNUNET_CRYPTO_EccPrivateKey *priv_key,
293                                uint64_t last_fragment_id,
294                                GNUNET_MULTICAST_JoinCallback join_cb,
295                                GNUNET_MULTICAST_MembershipTestCallback test_cb,
296                                GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
297                                GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
298                                GNUNET_MULTICAST_RequestCallback request_cb,
299                                GNUNET_MULTICAST_MessageCallback message_cb,
300                                void *cls)
301 {
302   return NULL;
303 }
304
305
306 /** 
307  * Handle for a request to send a message to all multicast group members
308  * (from the origin).
309  */
310 struct GNUNET_MULTICAST_OriginMessageHandle
311 {
312 };
313
314
315 /** 
316  * Send a message to the multicast group.
317  *
318  * @param origin Handle to the multicast group.
319  * @param message_id Application layer ID for the message.  Opaque to multicast.
320  * @param group_generation Group generation of the message.  Documented in
321  *             GNUNET_MULTICAST_MessageHeader.
322  * @param size Number of bytes to transmit.
323  *        FIXME: Needed? The end of the message can be flagged with a last fragment flag.
324  * @param notify Function to call to get the message.
325  * @param notify_cls Closure for @a notify.
326  * @return NULL on error (i.e. request already pending).
327  */
328 struct GNUNET_MULTICAST_OriginMessageHandle *
329 GNUNET_MULTICAST_origin_to_all (struct GNUNET_MULTICAST_Origin *origin,
330                                 uint64_t message_id,
331                                 uint64_t group_generation,
332                                 size_t size,
333                                 GNUNET_MULTICAST_OriginTransmitNotify notify,
334                                 void *notify_cls)
335 {
336   return NULL;
337 }
338
339
340 /** 
341  * Cancel request for message transmission to multicast group.
342  *
343  * @param mh Request to cancel.
344  */
345 void
346 GNUNET_MULTICAST_origin_to_all_cancel (struct GNUNET_MULTICAST_OriginMessageHandle *mh)
347 {
348 }
349
350
351 /** 
352  * Stop a multicast group.
353  *
354  * @param origin Multicast group to stop.
355  */
356 void
357 GNUNET_MULTICAST_origin_stop (struct GNUNET_MULTICAST_Origin *origin)
358 {
359 }
360
361
362 /** 
363  * Join a multicast group.
364  *
365  * The entity joining is always the local peer.  Further information about the
366  * candidate can be provided in the @a join_request message.  If the join fails, the
367  * @a message_cb is invoked with a (failure) response and then with NULL.  If
368  * the join succeeds, outstanding (state) messages and ongoing multicast
369  * messages will be given to the @a message_cb until the member decides to part
370  * the group.  The @a test_cb and @a replay_cb functions may be called at
371  * anytime by the multicast service to support relaying messages to other
372  * members of the group.
373  *
374  * @param cfg Configuration to use.
375  * @param group_key ECC public key that identifies the group to join.
376  * @param member_key ECC key that identifies the member and used to sign
377  *        requests sent to the origin.
378  * @param origin Peer ID of the origin to send unicast requsets to.  If NULL,
379  *        unicast requests are sent back via multiple hops on the reverse path
380  *        of multicast messages.
381  * @param relay_count Number of peers in the @a relays array.
382  * @param relays Peer identities of members of the group, which serve as relays
383  *        and can be used to join the group at. and send the @a join_request to.
384  *        If empty, the @a join_request is sent directly to the @a origin.
385  * @param join_request  Application-dependent join request to be passed to the peer
386  *        @a relay (might, for example, contain a user, bind user
387  *        identity/pseudonym to peer identity, application-level message to
388  *        origin, etc.).
389  * @param join_cb Function called to approve / disapprove joining of a peer.
390  * @param test_cb Function multicast can use to test group membership.
391  * @param replay_frag_cb Function that can be called to replay message fragments
392  *        this peer already knows from this group. NULL if this
393  *        client is unable to support replay.
394  * @param replay_msg_cb Function that can be called to replay message fragments
395  *        this peer already knows from this group. NULL if this
396  *        client is unable to support replay.
397  * @param message_cb Function to be called for all message fragments we
398  *        receive from the group, excluding those our @a replay_cb
399  *        already has.
400  * @param cls Closure for callbacks.
401  * @return Handle for the member, NULL on error.
402  */
403 struct GNUNET_MULTICAST_Member *
404 GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
405                               const struct GNUNET_CRYPTO_EccPublicSignKey *group_key,
406                               const struct GNUNET_CRYPTO_EccPrivateKey *member_key,
407                               const struct GNUNET_PeerIdentity *origin,
408                               size_t relay_count,
409                               const struct GNUNET_PeerIdentity *relays,
410                               const struct GNUNET_MessageHeader *join_request,
411                               GNUNET_MULTICAST_JoinCallback join_cb,
412                               GNUNET_MULTICAST_MembershipTestCallback test_cb,
413                               GNUNET_MULTICAST_ReplayFragmentCallback replay_frag_cb,
414                               GNUNET_MULTICAST_ReplayMessageCallback replay_msg_cb,
415                               GNUNET_MULTICAST_MessageCallback message_cb,
416                               void *cls)
417 {
418   return NULL;
419 }
420
421
422 /** 
423  * Handle for a replay request.
424  */
425 struct GNUNET_MULTICAST_MemberReplayHandle
426 {
427 };
428
429
430 /** 
431  * Request a fragment to be replayed by fragment ID.
432  *
433  * Useful if messages below the @e max_known_fragment_id given when joining are
434  * needed and not known to the client.
435  *
436  * @param member Membership handle.
437  * @param fragment_id ID of a message fragment that this client would like to
438           see replayed.
439  * @param flags Additional flags for the replay request.  It is used and defined
440  *        by the replay callback.  FIXME: which replay callback? FIXME: use enum?
441  *        FIXME: why not pass reply cb here?
442  * @return Replay request handle, NULL on error.
443  */
444 struct GNUNET_MULTICAST_MemberReplayHandle *
445 GNUNET_MULTICAST_member_replay_fragment (struct GNUNET_MULTICAST_Member *member,
446                                          uint64_t fragment_id,
447                                          uint64_t flags)
448 {
449   return NULL;
450 }
451
452
453 /** 
454  * Request a message fr to be replayed.
455  *
456  * Useful if messages below the @e max_known_fragment_id given when joining are
457  * needed and not known to the client.
458  *
459  * @param member Membership handle.
460  * @param message_id ID of the message this client would like to see replayed.
461  * @param fragment_offset Offset of the fragment within the message to replay.
462  * @param flags Additional flags for the replay request.  It is used & defined
463  *        by the replay callback.
464  * @param result_cb Function to be called for the replayed message.
465  * @param result_cb_cls Closure for @a result_cb.
466  * @return Replay request handle, NULL on error.
467  */
468 struct GNUNET_MULTICAST_MemberReplayHandle *
469 GNUNET_MULTICAST_member_replay_message (struct GNUNET_MULTICAST_Member *member,
470                                         uint64_t message_id,
471                                         uint64_t fragment_offset,
472                                         uint64_t flags,
473                                         GNUNET_MULTICAST_ResultCallback result_cb,
474                                         void *result_cb_cls)
475 {
476   return NULL;
477 }
478
479
480 /** 
481  * Cancel a replay request.
482  *
483  * @param rh Request to cancel.
484  */
485 void
486 GNUNET_MULTICAST_member_replay_cancel (struct GNUNET_MULTICAST_MemberReplayHandle *rh)
487 {
488 }
489
490
491 /** 
492  * Part a multicast group.
493  *
494  * Disconnects from all group members and invalidates the @a member handle.
495  *
496  * An application-dependent part message can be transmitted beforehand using
497  * #GNUNET_MULTICAST_member_to_origin())
498  *
499  * @param member Membership handle.
500  */
501 void
502 GNUNET_MULTICAST_member_part (struct GNUNET_MULTICAST_Member *member)
503 {
504 }
505
506
507 /** 
508  * Handle for a message to be delivered from a member to the origin.
509  */
510 struct GNUNET_MULTICAST_MemberRequestHandle
511 {
512 };
513
514
515 /** 
516  * Send a message to the origin of the multicast group.
517  * 
518  * @param member Membership handle.
519  * @param message_id Application layer ID for the message.  Opaque to multicast.
520  * @param size Number of bytes we want to send to origin.
521  * @param notify Callback to call to get the message.
522  * @param notify_cls Closure for @a notify.
523  * @return Handle to cancel request, NULL on error (i.e. request already pending).
524  */
525 struct GNUNET_MULTICAST_MemberRequestHandle *
526 GNUNET_MULTICAST_member_to_origin (struct GNUNET_MULTICAST_Member *member,
527                                    uint64_t message_id,
528                                    size_t size,
529                                    GNUNET_MULTICAST_MemberTransmitNotify notify,
530                                    void *notify_cls)
531 {
532   return NULL;
533 }
534
535
536 /** 
537  * Cancel request for message transmission to origin.
538  *
539  * @param rh Request to cancel.
540  */
541 void
542 GNUNET_MULTICAST_member_to_origin_cancel (struct GNUNET_MULTICAST_MemberRequestHandle *rh)
543 {
544 }
545
546
547 /* end of multicast_api.c */