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