aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_multicast_service.h
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2013-07-15 07:25:09 +0000
committerGabor X Toth <*@tg-x.net>2013-07-15 07:25:09 +0000
commit00c2318820ac3ee2ea06c173c3fce994bc29eb4e (patch)
treed825e66cde2d0efdc4491033c32e096937bd9d58 /src/include/gnunet_multicast_service.h
parentb6791ebdaa0d5299be3cc9fb5fbdcd5356ededf0 (diff)
downloadgnunet-00c2318820ac3ee2ea06c173c3fce994bc29eb4e.tar.gz
gnunet-00c2318820ac3ee2ea06c173c3fce994bc29eb4e.zip
multicast: message fragmentation
Diffstat (limited to 'src/include/gnunet_multicast_service.h')
-rw-r--r--src/include/gnunet_multicast_service.h143
1 files changed, 105 insertions, 38 deletions
diff --git a/src/include/gnunet_multicast_service.h b/src/include/gnunet_multicast_service.h
index df677784a..5803f551e 100644
--- a/src/include/gnunet_multicast_service.h
+++ b/src/include/gnunet_multicast_service.h
@@ -94,26 +94,46 @@ enum GNUNET_MULTICAST_JoinPolicy
94 94
95}; 95};
96 96
97enum GNUNET_MULTICAST_MessageFlags
98{
99 /**
100 * First fragment of a message.
101 */
102 GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT = 1 << 0,
103
104 /**
105 * Last fragment of a message.
106 */
107 GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT = 1 << 1,
108
109 /**
110 * OR'ed flags if message is not fragmented.
111 */
112 GNUNET_MULTICAST_MESSAGE_NOT_FRAGMENTED
113 = GNUNET_MULTICAST_MESSAGE_FIRST_FRAGMENT
114 | GNUNET_MULTICAST_MESSAGE_LAST_FRAGMENT
115};
116
97 117
98GNUNET_NETWORK_STRUCT_BEGIN 118GNUNET_NETWORK_STRUCT_BEGIN
99 119
100/** 120/**
101 * Header of a multicast message. 121 * Header of a multicast message fragment.
102 * 122 *
103 * This format is public as the replay mechanism must replay messages using the 123 * This format is public as the replay mechanism must replay message fragments using the
104 * same format. This is needed as we want to integrity-check messages within 124 * same format. This is needed as we want to integrity-check message fragments within
105 * the multicast layer to avoid multicasting mal-formed messages. 125 * the multicast layer to avoid multicasting mal-formed messages.
106 */ 126 */
107struct GNUNET_MULTICAST_MessageHeader 127struct GNUNET_MULTICAST_MessageHeader
108{ 128{
109 129
110 /** 130 /**
111 * Header for all multicast messages from the origin. 131 * Header for all multicast message fragments from the origin.
112 */ 132 */
113 struct GNUNET_MessageHeader header; 133 struct GNUNET_MessageHeader header;
114 134
115 /** 135 /**
116 * Number of hops this message has taken since the origin. 136 * Number of hops this message fragment has taken since the origin.
117 * 137 *
118 * Helpful to determine shortest paths to the origin for responses among 138 * Helpful to determine shortest paths to the origin for responses among
119 * honest peers; updated at each hop and thus not signed and not secure. 139 * honest peers; updated at each hop and thus not signed and not secure.
@@ -121,23 +141,33 @@ struct GNUNET_MULTICAST_MessageHeader
121 uint32_t hop_counter GNUNET_PACKED; 141 uint32_t hop_counter GNUNET_PACKED;
122 142
123 /** 143 /**
124 * ECC signature of the message. 144 * ECC signature of the message fragment.
125 * 145 *
126 * Signature must match the public key of the multicast group. 146 * Signature must match the public key of the multicast group.
127 */ 147 */
128 struct GNUNET_CRYPTO_EccSignature signature; 148 struct GNUNET_CRYPTO_EccSignature signature;
129 149
130 /** 150 /**
131 * Signature of the multicast message. 151 * Signature of the multicast message fragment.
132 */ 152 */
133 struct GNUNET_CRYPTO_EccSignaturePurpose purpose; 153 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
134 154
135 /** 155 /**
136 * Number of the message, monotonically increasing. 156 * Number of the message fragment, monotonically increasing.
157 */
158 uint64_t fragment_id GNUNET_PACKED;
159
160 /**
161 * Number of the message this fragment belongs to.
137 */ 162 */
138 uint64_t message_id GNUNET_PACKED; 163 uint64_t message_id GNUNET_PACKED;
139 164
140 /** 165 /**
166 * Byte offset of this @e fragment of the @e message.
167 */
168 uint64_t fragment_offset GNUNET_PACKED;
169
170 /**
141 * Counter that monotonically increases whenever a member parts the group. 171 * Counter that monotonically increases whenever a member parts the group.
142 * 172 *
143 * It has significance in case of replay requests: when a member has missed 173 * It has significance in case of replay requests: when a member has missed
@@ -148,12 +178,12 @@ struct GNUNET_MULTICAST_MessageHeader
148 uint64_t group_generation GNUNET_PACKED; 178 uint64_t group_generation GNUNET_PACKED;
149 179
150 /** 180 /**
151 * Difference between the current @a message_id and the @a message_id of the 181 * Difference between the current @a fragment_id and the @a fragment_id of the
152 * preceeding non-transient message. 182 * preceeding non-transient message.
153 * 183 *
154 * Zero for transient messages, @c UINT64_MAX for the first message, or any 184 * Zero for transient messages, @c UINT64_MAX for the first message, or any
155 * other message creating a full state reset by the origin. By subtracting 185 * other message creating a full state reset by the origin. By subtracting
156 * @a state_delta from @a message_id, it is possible to calculate the message 186 * @a state_delta from @a fragment_id, it is possible to calculate the message
157 * ID of the preceeding non-transient message and thus quickly traverse all 187 * ID of the preceeding non-transient message and thus quickly traverse all
158 * state changes up to the last full state reset by the origin. This is 188 * state changes up to the last full state reset by the origin. This is
159 * useful as it allows joining clients to quickly reassemble the state while 189 * useful as it allows joining clients to quickly reassemble the state while
@@ -170,6 +200,11 @@ struct GNUNET_MULTICAST_MessageHeader
170 */ 200 */
171 uint64_t state_delta GNUNET_PACKED; 201 uint64_t state_delta GNUNET_PACKED;
172 202
203 /**
204 * Flags for this message.
205 */
206 enum GNUNET_MULTICAST_MessageFlags flags GNUNET_PACKED;
207
173 /** 208 /**
174 * Header for the message body. 209 * Header for the message body.
175 * 210 *
@@ -180,7 +215,44 @@ struct GNUNET_MULTICAST_MessageHeader
180 */ 215 */
181 struct GNUNET_MessageHeader body; 216 struct GNUNET_MessageHeader body;
182 217
183 /* followed by message body */ 218 /* Followed by message body. */
219};
220
221GNUNET_NETWORK_STRUCT_END
222
223GNUNET_NETWORK_STRUCT_BEGIN
224
225/**
226 * Header of a request from a member to the origin.
227 *
228 * This format is public as the replay mechanism must replay message fragments using the
229 * same format. This is needed as we want to integrity-check message fragments within
230 * the multicast layer to avoid multicasting mal-formed messages.
231 */
232struct GNUNET_MULTICAST_RequestHeader
233{
234
235 /**
236 * Header for all requests from a member to the origin.
237 */
238 struct GNUNET_MessageHeader header;
239
240 /**
241 * Flags for this request.
242 */
243 enum GNUNET_MULTICAST_MessageFlags flags GNUNET_PACKED;
244
245 /**
246 * Header for the request body.
247 *
248 * Two request types are specifically understood by multicast, namely "peer
249 * join", "peer part". Multicast will use those messages to update its list
250 * of candidates for content distribution. All other message types are
251 * application-specific.
252 */
253 struct GNUNET_MessageHeader body;
254
255 /* Followed by request body. */
184}; 256};
185 257
186GNUNET_NETWORK_STRUCT_END 258GNUNET_NETWORK_STRUCT_END
@@ -304,32 +376,30 @@ GNUNET_MULTICAST_membership_test_answer (struct GNUNET_MULTICAST_MembershipTestH
304 * 376 *
305 * @param cls Closure. 377 * @param cls Closure.
306 * @param peer Identity of the peer that we want to test. 378 * @param peer Identity of the peer that we want to test.
307 * @param message_id Message ID for which we want to do the test. 379 * @param fragment_id Message fragment ID for which we want to do the test.
308 * @param mth Handle to give to GNUNET_MULTICAST_membership_test_answer(). 380 * @param mth Handle to give to GNUNET_MULTICAST_membership_test_answer().
309 */ 381 */
310typedef void (*GNUNET_MULTICAST_MembershipTestCallback)(void *cls, 382typedef void (*GNUNET_MULTICAST_MembershipTestCallback)(void *cls,
311 const struct GNUNET_PeerIdentity *peer, 383 const struct GNUNET_PeerIdentity *peer,
312 uint64_t message_id, 384 uint64_t fragment_id,
313 struct GNUNET_MULTICAST_MembershipTestHandle *mth); 385 struct GNUNET_MULTICAST_MembershipTestHandle *mth);
314 386
315 387
316/** 388/**
317 * Function called whenever a group member has transmitted a message 389 * Function called whenever a group member has transmitted a request
318 * to the origin (other than joining or leaving). 390 * to the origin (other than joining or leaving).
319 * 391 *
320 * @param cls Closure (set from GNUNET_MULTICAST_origin_start). 392 * @param cls Closure (set from GNUNET_MULTICAST_origin_start).
321 * @param sender Identity of the sender. 393 * @param sender Identity of the sender.
322 * @param request_id Unique counter for the request from this sender to this origin. FIXME: needed? 394 * @param req Request to the origin.
323 * @param msg Message to the origin.
324 */ 395 */
325typedef void (*GNUNET_MULTICAST_RequestCallback) (void *cls, 396typedef void (*GNUNET_MULTICAST_RequestCallback) (void *cls,
326 const struct GNUNET_PeerIdentity *sender, 397 const struct GNUNET_PeerIdentity *sender,
327 uint64_t request_id, 398 const struct GNUNET_MULTICAST_RequestHeader *req);
328 const struct GNUNET_MessageHeader *msg);
329 399
330 400
331/** 401/**
332 * Function called whenever a group member is receiving a message from 402 * Function called whenever a group member is receiving a message fragment from
333 * the origin. 403 * the origin.
334 * 404 *
335 * If admission to the group is denied, this function is called once with the 405 * If admission to the group is denied, this function is called once with the
@@ -337,14 +407,11 @@ typedef void (*GNUNET_MULTICAST_RequestCallback) (void *cls,
337 * then a second time with NULL to indicate that the connection failed for good. 407 * then a second time with NULL to indicate that the connection failed for good.
338 * 408 *
339 * @param cls Closure (set from GNUNET_MULTICAST_member_join()) 409 * @param cls Closure (set from GNUNET_MULTICAST_member_join())
340 * @param message_id Unique number of the message, 0 for response to join request,
341 * normal message IDs in either direction start at 1.
342 * @param msg Message from the origin, NULL if the origin shut down 410 * @param msg Message from the origin, NULL if the origin shut down
343 * (or we were kicked out, and we should thus call 411 * (or we were kicked out, and we should thus call
344 * GNUNET_MULTICAST_member_part() next) 412 * GNUNET_MULTICAST_member_part() next)
345 */ 413 */
346typedef void (*GNUNET_MULTICAST_MessageCallback) (void *cls, 414typedef void (*GNUNET_MULTICAST_MessageCallback) (void *cls,
347 uint64_t message_id,
348 const struct GNUNET_MULTICAST_MessageHeader *msg); 415 const struct GNUNET_MULTICAST_MessageHeader *msg);
349 416
350 417
@@ -364,11 +431,11 @@ struct GNUNET_MULTICAST_ReplayHandle;
364 * 431 *
365 * @param cls Closure (set from GNUNET_MULTICAST_origin_start() 432 * @param cls Closure (set from GNUNET_MULTICAST_origin_start()
366 * or GNUNET_MULTICAST_member_join()). 433 * or GNUNET_MULTICAST_member_join()).
367 * @param message_id Which message should be replayed. 434 * @param fragment_id Which message fragment should be replayed.
368 * @param rh Handle to pass to message transmit function. 435 * @param rh Handle to pass to message transmit function.
369 */ 436 */
370typedef void (*GNUNET_MULTICAST_ReplayCallback) (void *cls, 437typedef void (*GNUNET_MULTICAST_ReplayCallback) (void *cls,
371 uint64_t message_id, 438 uint64_t fragment_id,
372 struct GNUNET_MULTICAST_ReplayHandle *rh); 439 struct GNUNET_MULTICAST_ReplayHandle *rh);
373 440
374 441
@@ -384,12 +451,12 @@ enum GNUNET_MULTICAST_ReplayErrorCode
384 GNUNET_MULTICAST_REC_OK = 0, 451 GNUNET_MULTICAST_REC_OK = 0,
385 452
386 /** 453 /**
387 * Message has been discarded (likely transient message that was too old). 454 * Message fragment has been discarded (likely transient message that was too old).
388 */ 455 */
389 GNUNET_MULTICAST_REC_TRANSIENT_LOST = 1, 456 GNUNET_MULTICAST_REC_TRANSIENT_LOST = 1,
390 457
391 /** 458 /**
392 * Message ID counter was larger than the highest counter this 459 * Fragment ID counter was larger than the highest counter this
393 * replay function has ever encountered; thus it is likely the 460 * replay function has ever encountered; thus it is likely the
394 * origin never sent it and we're at the HEAD of the multicast 461 * origin never sent it and we're at the HEAD of the multicast
395 * stream as far as this node is concerned. 462 * stream as far as this node is concerned.
@@ -408,7 +475,7 @@ enum GNUNET_MULTICAST_ReplayErrorCode
408 * Replay a message from the multicast group. 475 * Replay a message from the multicast group.
409 * 476 *
410 * @param rh Replay handle identifying which replay operation was requested. 477 * @param rh Replay handle identifying which replay operation was requested.
411 * @param msg Replayed message, NULL if unknown/error. 478 * @param msg Replayed message fragment, NULL if unknown/error.
412 * @param ec Error code. 479 * @param ec Error code.
413 */ 480 */
414void 481void
@@ -509,15 +576,14 @@ GNUNET_MULTICAST_origin_end (struct GNUNET_MULTICAST_Origin *origin);
509 * members of the group. 576 * members of the group.
510 * 577 *
511 * @param cfg Configuration to use. 578 * @param cfg Configuration to use.
512 * @param cls Closure for callbacks.
513 * @param pub_key ECC key that identifies the group. 579 * @param pub_key ECC key that identifies the group.
514 * @param origin Peer identity of the origin. 580 * @param origin Peer identity of the origin.
515 * @param max_known_message_id Largest known message ID to the replay service; 581 * @param max_known_fragment_id Largest known message fragment ID to the replay
516 * all messages with IDs larger than this ID will be replayed if 582 service; all messages with IDs larger than this ID will be replayed if
517 * possible (lower IDs will be considered known and thus only 583 * possible (lower IDs will be considered known and thus only
518 * be replayed upon explicit request). 584 * be replayed upon explicit request).
519 * @param max_known_state_message_id Largest known message ID with a non-zero 585 * @param max_known_state_fragment_id Largest known message fragment ID with a
520 * value for the @e state_delta; state messages with 586 non-zero value for the @e state_delta; state messages with
521 * larger IDs than this value will be replayed with high priority 587 * larger IDs than this value will be replayed with high priority
522 * (lower IDs will be considered known and thus only 588 * (lower IDs will be considered known and thus only
523 * be replayed upon explicit request). 589 * be replayed upon explicit request).
@@ -525,9 +591,10 @@ GNUNET_MULTICAST_origin_end (struct GNUNET_MULTICAST_Origin *origin);
525 * this peer already knows from this group; NULL if this 591 * this peer already knows from this group; NULL if this
526 * client is unable to support replay. 592 * client is unable to support replay.
527 * @param test_cb Function multicast can use to test group membership. 593 * @param test_cb Function multicast can use to test group membership.
528 * @param message_cb Function to be called for all messages we 594 * @param message_cb Function to be called for all message fragments we
529 * receive from the group, excluding those our @a replay_cb 595 * receive from the group, excluding those our @a replay_cb
530 * already has. 596 * already has.
597 * @param cls Closure for callbacks.
531 * @param join_req Application-dependent join message to be passed to origin 598 * @param join_req Application-dependent join message to be passed to origin
532 * (might, for example, contain a user 599 * (might, for example, contain a user
533 * bind user identity/pseudonym to peer identity, application-level 600 * bind user identity/pseudonym to peer identity, application-level
@@ -536,14 +603,14 @@ GNUNET_MULTICAST_origin_end (struct GNUNET_MULTICAST_Origin *origin);
536 */ 603 */
537struct GNUNET_MULTICAST_Member * 604struct GNUNET_MULTICAST_Member *
538GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg, 605GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
539 void *cls,
540 const struct GNUNET_CRYPTO_EccPublicKey *pub_key, 606 const struct GNUNET_CRYPTO_EccPublicKey *pub_key,
541 const struct GNUNET_PeerIdentity *origin, 607 const struct GNUNET_PeerIdentity *origin,
542 uint64_t max_known_message_id, 608 uint64_t max_known_fragment_id,
543 uint64_t max_known_state_message_id, 609 uint64_t max_known_state_fragment_id,
544 GNUNET_MULTICAST_ReplayCallback replay_cb, 610 GNUNET_MULTICAST_ReplayCallback replay_cb,
545 GNUNET_MULITCAST_MembershipTestCallback test_cb, 611 GNUNET_MULITCAST_MembershipTestCallback test_cb,
546 GNUNET_MULTICAST_MessageCallback message_cb, 612 GNUNET_MULTICAST_MessageCallback message_cb,
613 void *cls,
547 const struct GNUNET_MessageHeader *join_req); 614 const struct GNUNET_MessageHeader *join_req);
548 615
549 616
@@ -560,14 +627,14 @@ struct GNUNET_MULTICAST_MemberReplayHandle;
560 * needed and not known to the client. 627 * needed and not known to the client.
561 * 628 *
562 * @param member Membership handle. 629 * @param member Membership handle.
563 * @param message_id ID of a message that this client would like to see replayed. 630 * @param fragment_id ID of a message fragment that this client would like to see replayed.
564 * @param message_cb Function to be called for the replayed message. 631 * @param message_cb Function to be called for the replayed message.
565 * @param message_cb_cls Closure for @a message_cb. 632 * @param message_cb_cls Closure for @a message_cb.
566 * @return Replay request handle, NULL on error. 633 * @return Replay request handle, NULL on error.
567 */ 634 */
568struct GNUNET_MULTICAST_MemberReplayHandle * 635struct GNUNET_MULTICAST_MemberReplayHandle *
569GNUNET_MULTICAST_member_request_replay (struct GNUNET_MULTICAST_Member *member, 636GNUNET_MULTICAST_member_request_replay (struct GNUNET_MULTICAST_Member *member,
570 uint64_t message_id, 637 uint64_t fragment_id,
571 GNUNET_MULTICAST_MessageCallback message_cb, 638 GNUNET_MULTICAST_MessageCallback message_cb,
572 void *message_cb_cls); 639 void *message_cb_cls);
573 640