diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-06-11 09:32:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-06-11 09:32:07 +0000 |
commit | c2ca3523b0035829489f2a97d58ea2f5e9f2c1ed (patch) | |
tree | 99b14a083eb67f642520e3992056823eca527939 /src/include/gnunet_multicast_service.h | |
parent | 9627b28239e88073beb0b254f1f6e022c12302d9 (diff) | |
download | gnunet-c2ca3523b0035829489f2a97d58ea2f5e9f2c1ed.tar.gz gnunet-c2ca3523b0035829489f2a97d58ea2f5e9f2c1ed.zip |
-more work on multicast/psyc API designs
Diffstat (limited to 'src/include/gnunet_multicast_service.h')
-rw-r--r-- | src/include/gnunet_multicast_service.h | 159 |
1 files changed, 127 insertions, 32 deletions
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h index 2a53cb66f..f8d37fc54 100644 --- a/src/include/gnunet_multicast_service.h +++ b/src/include/gnunet_multicast_service.h | |||
@@ -22,11 +22,6 @@ | |||
22 | * @file include/gnunet_multicast_service.h | 22 | * @file include/gnunet_multicast_service.h |
23 | * @brief multicast service; establish tunnels to distant peers | 23 | * @brief multicast service; establish tunnels to distant peers |
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | * | ||
26 | * TODO: | ||
27 | * - need to support async message transmission, etc. | ||
28 | * - need to do sanity check that this is consistent | ||
29 | * with current ideas for the PSYC layer's needs | ||
30 | */ | 25 | */ |
31 | 26 | ||
32 | #ifndef GNUNET_MULTICAST_SERVICE_H | 27 | #ifndef GNUNET_MULTICAST_SERVICE_H |
@@ -147,9 +142,13 @@ enum GNUNET_MULTICAST_ReplayErrorCode | |||
147 | }; | 142 | }; |
148 | 143 | ||
149 | 144 | ||
145 | GNUNET_NETWORK_STRUCT_BEGIN | ||
146 | |||
150 | /** | 147 | /** |
151 | * Header of a multicast message. This format is public as the replay | 148 | * Header of a multicast message. This format is public as the replay |
152 | * mechanism must replay messages using the same format. | 149 | * mechanism must replay messages using the same format. This is |
150 | * needed as we want to integrity-check messages within the multicast | ||
151 | * layer to avoid multicasting mal-formed messages. | ||
153 | */ | 152 | */ |
154 | struct GNUNET_MULTICAST_MessageHeader | 153 | struct GNUNET_MULTICAST_MessageHeader |
155 | { | 154 | { |
@@ -165,10 +164,11 @@ struct GNUNET_MULTICAST_MessageHeader | |||
165 | * among honest peers; updated at each hop and thus not signed | 164 | * among honest peers; updated at each hop and thus not signed |
166 | * and not secure) | 165 | * and not secure) |
167 | */ | 166 | */ |
168 | uint32_t hop_counter; | 167 | uint32_t hop_counter GNUNET_PACKED; |
169 | 168 | ||
170 | /** | 169 | /** |
171 | * ECC signature of the message. | 170 | * ECC signature of the message. Signature must match the public |
171 | * key of the multicast group. | ||
172 | */ | 172 | */ |
173 | struct GNUNET_CRYPTO_EccSignature signature; | 173 | struct GNUNET_CRYPTO_EccSignature signature; |
174 | 174 | ||
@@ -180,13 +180,13 @@ struct GNUNET_MULTICAST_MessageHeader | |||
180 | /** | 180 | /** |
181 | * Number of the message, monotonically increasing. | 181 | * Number of the message, monotonically increasing. |
182 | */ | 182 | */ |
183 | uint64_t message_id; | 183 | uint64_t message_id GNUNET_PACKED; |
184 | 184 | ||
185 | /** | 185 | /** |
186 | * Counter that monotonically increases whenever a member | 186 | * Counter that monotonically increases whenever a member |
187 | * leaves the group. | 187 | * leaves the group. |
188 | */ | 188 | */ |
189 | uint64_t group_generation; | 189 | uint64_t group_generation GNUNET_PACKED; |
190 | 190 | ||
191 | /** | 191 | /** |
192 | * Difference between the current message_id and the message_id of | 192 | * Difference between the current message_id and the message_id of |
@@ -206,7 +206,7 @@ struct GNUNET_MULTICAST_MessageHeader | |||
206 | * re-create the full state with state update messages following the | 206 | * re-create the full state with state update messages following the |
207 | * state reset message. | 207 | * state reset message. |
208 | */ | 208 | */ |
209 | uint64_t state_delta; | 209 | uint64_t state_delta GNUNET_PACKED; |
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Header for the message body. Three message types are | 212 | * Header for the message body. Three message types are |
@@ -220,6 +220,8 @@ struct GNUNET_MULTICAST_MessageHeader | |||
220 | /* followed by message body */ | 220 | /* followed by message body */ |
221 | }; | 221 | }; |
222 | 222 | ||
223 | GNUNET_NETWORK_STRUCT_END | ||
224 | |||
223 | 225 | ||
224 | /** | 226 | /** |
225 | * Replay a message from the multicast group. | 227 | * Replay a message from the multicast group. |
@@ -235,8 +237,46 @@ GNUNET_MULTICAST_replay (struct GNUNET_MULTICAST_ReplayHandle *rh, | |||
235 | 237 | ||
236 | 238 | ||
237 | /** | 239 | /** |
240 | * Handle that identifies a join request (to match calls to the | ||
241 | * 'GNUNET_MULTICAST_MembershipChangeCallback' to the corresponding | ||
242 | * calls to 'GNUNET_MULTICAST_join_decision'). | ||
243 | */ | ||
244 | struct GNUNET_MULTICAST_JoinHande; | ||
245 | |||
246 | |||
247 | /** | ||
248 | * Function to call with the decision made for a membership change | ||
249 | * request. Must be called once and only once in response to an | ||
250 | * invocation of the 'GNUNET_MULTICAST_MembershipChangeCallback'. | ||
251 | * | ||
252 | * @param jh join request handle | ||
253 | * @param join_response message to send in response to the joining peer; | ||
254 | * can also be used to redirect the peer to a different group at the | ||
255 | * application layer; this response is to be transmitted to the | ||
256 | * peer that issued the request even if admission is denied. | ||
257 | * @param is_admitted GNUNET_OK if joining is approved, GNUNET_SYSERR if it is disapproved; | ||
258 | * GNUNET_NO for peers leaving | ||
259 | * @param relay_count number of relays given | ||
260 | * @param relays array of suggested peers that might be useful relays to use | ||
261 | * when joining the multicast group (essentially a list of peers that | ||
262 | * are already part of the multicast group and might thus be willing | ||
263 | * to help with routing). If empty, only this local peer (which must | ||
264 | * be the multicast origin) is a good candidate for building the | ||
265 | * multicast tree. Note that it is unnecessary to specify our own | ||
266 | * peer identity in this array. | ||
267 | */ | ||
268 | void | ||
269 | GNUNET_MULTICAST_join_decision (struct GNUNET_MULTICAST_JoinHandle *jh, | ||
270 | const struct GNUNET_MessageHeader *join_response, | ||
271 | int is_admitted, | ||
272 | unsigned int relay_count, | ||
273 | const struct GNUNET_PeerIdentity *relays); | ||
274 | |||
275 | |||
276 | /** | ||
238 | * Method called whenever another peer wants to join or has left a | 277 | * Method called whenever another peer wants to join or has left a |
239 | * multicast group. | 278 | * multicast group. Implementations of this function must call |
279 | * 'GNUNET_MULTICAST_join_decision' with the decision. | ||
240 | * | 280 | * |
241 | * @param cls closure | 281 | * @param cls closure |
242 | * @param peer identity of the peer that wants to join or leave | 282 | * @param peer identity of the peer that wants to join or leave |
@@ -245,13 +285,13 @@ GNUNET_MULTICAST_replay (struct GNUNET_MULTICAST_ReplayHandle *rh, | |||
245 | * bind user identity/pseudonym to peer identity, application-level | 285 | * bind user identity/pseudonym to peer identity, application-level |
246 | * message to origin, etc.) | 286 | * message to origin, etc.) |
247 | * @param is_joining GNUNET_YES if the peer wants to join, GNUNET_NO if the peer left | 287 | * @param is_joining GNUNET_YES if the peer wants to join, GNUNET_NO if the peer left |
248 | * @return GNUNET_OK if joining is approved, GNUNET_SYSERR if it is disapproved; | 288 | * @param jh join handle to pass to 'GNUNET_MULTICAST_join_decison' |
249 | * GNUNET_NO should be returned for peers leaving | ||
250 | */ | 289 | */ |
251 | typedef int (*GNUNET_MULTICAST_MembershipChangeCallback)(void *cls, | 290 | typedef int (*GNUNET_MULTICAST_MembershipChangeCallback)(void *cls, |
252 | const struct GNUNET_PeerIdentity *peer, | 291 | const struct GNUNET_PeerIdentity *peer, |
253 | const struct GNUNET_MessageHeader *join_req, | 292 | const struct GNUNET_MessageHeader *join_req, |
254 | int is_joining); | 293 | int is_joining, |
294 | struct GNUNET_MULTICAST_JoinHandle *jh); | ||
255 | 295 | ||
256 | 296 | ||
257 | /** | 297 | /** |
@@ -287,18 +327,32 @@ typedef void (*GNUNET_MULTICAST_ResponseCallback) (void *cls, | |||
287 | 327 | ||
288 | /** | 328 | /** |
289 | * Function called whenever a group member is receiving a message from | 329 | * Function called whenever a group member is receiving a message from |
290 | * the origin. | 330 | * the origin. If admission to the group is denied, this function is |
331 | * called once with the response of the 'origin' (as given to | ||
332 | * 'GNUNET_MULTICAST_join_decision') and then a second time with "NULL" | ||
333 | * to indicate that the connection failed for good. | ||
291 | * | 334 | * |
292 | * @param cls closure (set from GNUNET_MULTICAST_member_join) | 335 | * @param cls closure (set from GNUNET_MULTICAST_member_join) |
336 | * @param message_id unique number of the message | ||
293 | * @param msg message from the origin, NULL if the origin shut down | 337 | * @param msg message from the origin, NULL if the origin shut down |
294 | * (or we were kicked out, and we should thus call GNUNET_MULTICAST_member_leave next) | 338 | * (or we were kicked out, and we should thus call GNUNET_MULTICAST_member_leave next) |
295 | */ | 339 | */ |
296 | typedef void (*GNUNET_MULTICAST_MessageCallback) (void *cls, | 340 | typedef void (*GNUNET_MULTICAST_MessageCallback) (void *cls, |
341 | uint64_t message_id, | ||
297 | const struct GNUNET_MULTICAST_MessageHeader *msg); | 342 | const struct GNUNET_MULTICAST_MessageHeader *msg); |
298 | 343 | ||
299 | 344 | ||
300 | /** | 345 | /** |
301 | * Start a multicast group. | 346 | * Start a multicast group. Will advertise the origin in the P2P |
347 | * overlay network under the respective public key so that other peer | ||
348 | * can find this peer to join it. Peers that issue | ||
349 | * 'GNUNET_MULTICAST_member_join' can then transmit a join request to | ||
350 | * either an existing group member (if the 'join_policy' is | ||
351 | * permissive) or to the origin. If the joining is approved, the | ||
352 | * member is cleared for 'replay' and will begin to receive messages | ||
353 | * transmitted to the group. If joining is disapproved, the failed | ||
354 | * candidate will be given a response. Members in the group can send | ||
355 | * messages to the origin (one at a time). | ||
302 | * | 356 | * |
303 | * @param cfg configuration to use | 357 | * @param cfg configuration to use |
304 | * @param cls closure for the various callbacks that follow | 358 | * @param cls closure for the various callbacks that follow |
@@ -325,15 +379,35 @@ GNUNET_MULTICAST_origin_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
325 | 379 | ||
326 | 380 | ||
327 | /** | 381 | /** |
382 | * Handle for a request to send a message to all multicast group members | ||
383 | * (from the origin). | ||
384 | */ | ||
385 | struct GNUNET_MULTICAST_MulticastRequest; | ||
386 | |||
387 | |||
388 | /** | ||
328 | * Send a message to the multicast group. | 389 | * Send a message to the multicast group. |
329 | * | 390 | * |
330 | * @param origin handle to the multicast group | 391 | * @param origin handle to the multicast group |
331 | * @param msg_body body of the message to transmit | 392 | * @param size number of bytes to transmit |
332 | * FIXME: change to notify_transmit_ready-style to wait for ACKs? | 393 | * @param cb function to call to get the message |
394 | * @param cb_cls closure for 'cb' | ||
395 | * @return NULL on error (i.e. request already pending) | ||
333 | */ | 396 | */ |
334 | void | 397 | struct GNUNET_MULTICAST_MulticastRequest * |
335 | GNUNET_MULTICAST_origin_send_to_all (struct GNUNET_MULTICAST_Origin *origin, | 398 | GNUNET_MULTICAST_origin_send_to_all (struct GNUNET_MULTICAST_Origin *origin, |
336 | const struct GNUNET_MessageHeader *msg_body); | 399 | size_t size, |
400 | GNUNET_CONNECTION_TransmitReadyNotify cb, | ||
401 | void *cb_cls); | ||
402 | |||
403 | |||
404 | /** | ||
405 | * Cancel request for message transmission to multicast group. | ||
406 | * | ||
407 | * @param mr request to cancel | ||
408 | */ | ||
409 | void | ||
410 | GNUNET_MULTICAST_origin_send_to_all_cancel (struct GNUNET_MULTICAST_MulticastRequest *mr); | ||
337 | 411 | ||
338 | 412 | ||
339 | /** | 413 | /** |
@@ -346,7 +420,15 @@ GNUNET_MULTICAST_origin_end (struct GNUNET_MULTICAST_Origin *origin); | |||
346 | 420 | ||
347 | 421 | ||
348 | /** | 422 | /** |
349 | * Join a multicast group. The entity joining is always the local peer. | 423 | * Join a multicast group. The entity joining is always the local |
424 | * peer. Further information about the candidate can be provided in | ||
425 | * the 'join_req' message. If the join fails, the 'message_cb' is | ||
426 | * invoked with a (failure) response and then with 'NULL'. If the | ||
427 | * join succeeds, outstanding (state) messages and ongoing multicast | ||
428 | * messages will be given to the 'message_cb' until the member decides | ||
429 | * to leave the group. The 'test_cb' and 'replay_cb' functions may be | ||
430 | * called at anytime by the multicast service to support relaying | ||
431 | * messages to other members of the group. | ||
350 | * | 432 | * |
351 | * @param cfg configuration to use | 433 | * @param cfg configuration to use |
352 | * @param cls closure for callbacks | 434 | * @param cls closure for callbacks |
@@ -396,16 +478,17 @@ struct GNUNET_MULTICAST_ReplayRequest; | |||
396 | * the 'max_known_*_id's given when joining are needed and not | 478 | * the 'max_known_*_id's given when joining are needed and not |
397 | * known to the client. | 479 | * known to the client. |
398 | * | 480 | * |
399 | * FIXME: we currently use the 'replay_cb' from the member_join call; | ||
400 | * we might alternatively add a different cb here. | ||
401 | * | ||
402 | * @param member membership handle | 481 | * @param member membership handle |
403 | * @param message_id ID of a message that this client would like to see replayed | 482 | * @param message_id ID of a message that this client would like to see replayed |
483 | * @param message_cb function to be called for the replayed message | ||
484 | * @param message_cb_cls closure for 'message_cb' | ||
404 | * @return replay request handle, NULL on error | 485 | * @return replay request handle, NULL on error |
405 | */ | 486 | */ |
406 | struct GNUNET_MULTICAST_ReplayRequest * | 487 | struct GNUNET_MULTICAST_ReplayRequest * |
407 | GNUNET_MULTICAST_member_request_replay (struct GNUNET_MULTICAST_Member *member, | 488 | GNUNET_MULTICAST_member_request_replay (struct GNUNET_MULTICAST_Member *member, |
408 | uint64_t message_id); | 489 | uint64_t message_id, |
490 | GNUNET_MULTICAST_MessageCallback message_cb, | ||
491 | void *message_cb_cls); | ||
409 | 492 | ||
410 | 493 | ||
411 | /** | 494 | /** |
@@ -433,16 +516,28 @@ struct GNUNET_MULTICAST_ResponseRequest; | |||
433 | 516 | ||
434 | 517 | ||
435 | /** | 518 | /** |
436 | * Send a message to the origin of the multicast group. FIXME: how | 519 | * Send a message to the origin of the multicast group. |
437 | * will we do routing/flow-control of responses? | ||
438 | * | 520 | * |
439 | * @param member membership handle | 521 | * @param member membership handle |
440 | * @param msg message to send to the origin | 522 | * @param size number of bytes we want to send to origin |
441 | * FIXME: change to notify_transmit_ready-style to wait for ACKs... | 523 | * @param cb callback to call to get the message |
524 | * @param cb_cls closure for 'cb' | ||
525 | * @return handle to cancel request, NULL on error (i.e. request already pending) | ||
442 | */ | 526 | */ |
443 | void | 527 | struct GNUNET_MULTICAST_ResponseRequest * |
444 | GNUNET_MULTICAST_member_message_to_origin (struct GNUNET_MULTICAST_Member *member, | 528 | GNUNET_MULTICAST_member_message_to_origin (struct GNUNET_MULTICAST_Member *member, |
445 | const struct GNUNET_MessageHeader *msg); | 529 | size_t size, |
530 | GNUNET_CONNECTION_TransmitReadyNotify cb, | ||
531 | void *cb_cls); | ||
532 | |||
533 | |||
534 | /** | ||
535 | * Cancel request for message transmission to origin. | ||
536 | * | ||
537 | * @param rr request to cancel | ||
538 | */ | ||
539 | void | ||
540 | GNUNET_MULTICAST_member_message_to_origin_cancel (struct GNUNET_MULTICAST_ResponseRequest *rr); | ||
446 | 541 | ||
447 | 542 | ||
448 | 543 | ||