aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-tng.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-22 01:02:10 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-22 01:02:10 +0200
commitcd58bcd814dde6c2b6269bb93c4e6232ddb5e2a6 (patch)
tree9107db1e64b82a1fed895ab29cba1b7120657683 /src/transport/gnunet-service-tng.c
parentf679160f2a6689ace17e2624405148da03c795bf (diff)
downloadgnunet-cd58bcd814dde6c2b6269bb93c4e6232ddb5e2a6.tar.gz
gnunet-cd58bcd814dde6c2b6269bb93c4e6232ddb5e2a6.zip
improve types
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r--src/transport/gnunet-service-tng.c120
1 files changed, 83 insertions, 37 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 7683ed016..2b512555c 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -25,8 +25,15 @@
25 * TODO: 25 * TODO:
26 * Implement next: 26 * Implement next:
27 * - track RTT, distance, loss, etc. => requires extra data structures! 27 * - track RTT, distance, loss, etc. => requires extra data structures!
28 * - consider replacing random `struct GNUNET_ShortHashCode` message UUIDs
29 * with (incrementing) 64-bit numbers (compacting both
30 * `struct TransportReliabilityBox` and `struct
31 * TransportReliabilityAckMessage`), and using *different* UUIDs for each
32 * transmission (even of the same message!)
28 * - proper use/initialization of timestamps in messages exchanged 33 * - proper use/initialization of timestamps in messages exchanged
29 * during DV learning 34 * during DV learning
35 * - persistence of monotonic time from DVInit to prevent
36 * replay attacks using DVInit messages
30 * - persistence of monotonic time obtained from other peers 37 * - persistence of monotonic time obtained from other peers
31 * in PEERSTORE (by message type) -- done for backchannel, needed elsewhere? 38 * in PEERSTORE (by message type) -- done for backchannel, needed elsewhere?
32 * - change transport-core API to provide proper flow control in both 39 * - change transport-core API to provide proper flow control in both
@@ -248,6 +255,42 @@
248GNUNET_NETWORK_STRUCT_BEGIN 255GNUNET_NETWORK_STRUCT_BEGIN
249 256
250/** 257/**
258 * Unique identifier we attach to a message.
259 */
260struct MessageUUID
261{
262 /**
263 * Unique value.
264 */
265 struct GNUNET_ShortHashCode uuid;
266};
267
268
269/**
270 * Unique identifier we attach to a message.
271 */
272struct FragmentUUIDP
273{
274 /**
275 * Unique value identifying a fragment, in NBO.
276 */
277 uint32_t uuid GNUNET_PACKED;
278};
279
280
281/**
282 * Type of a nonce used for challenges.
283 */
284struct ChallengeNonce
285{
286 /**
287 * The value of the nonce. Note that this is NOT a hash.
288 */
289 struct GNUNET_ShortHashCode value;
290};
291
292
293/**
251 * Outer layer of an encapsulated backchannel message. 294 * Outer layer of an encapsulated backchannel message.
252 */ 295 */
253struct TransportBackchannelEncapsulationMessage 296struct TransportBackchannelEncapsulationMessage
@@ -409,7 +452,7 @@ struct TransportReliabilityBox
409 * messages sent over possibly unreliable channels. Should 452 * messages sent over possibly unreliable channels. Should
410 * be a random. 453 * be a random.
411 */ 454 */
412 struct GNUNET_ShortHashCode msg_uuid; 455 struct MessageUUID msg_uuid;
413}; 456};
414 457
415 458
@@ -440,7 +483,7 @@ struct TransportReliabilityAckMessage
440 */ 483 */
441 struct GNUNET_TIME_RelativeNBO avg_ack_delay; 484 struct GNUNET_TIME_RelativeNBO avg_ack_delay;
442 485
443 /* followed by any number of `struct GNUNET_ShortHashCode` 486 /* followed by any number of `struct MessageUUID`
444 messages providing ACKs */ 487 messages providing ACKs */
445}; 488};
446 489
@@ -463,13 +506,13 @@ struct TransportFragmentBox
463 * fragment (same @e frag_off), it must send 506 * fragment (same @e frag_off), it must send
464 * #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK immediately. 507 * #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK immediately.
465 */ 508 */
466 uint32_t frag_uuid GNUNET_PACKED; 509 struct FragmentUUIDP frag_uuid;
467 510
468 /** 511 /**
469 * Original message ID for of the message that all the1 512 * Original message ID for of the message that all the
470 * fragments belong to. Must be the same for all fragments. 513 * fragments belong to. Must be the same for all fragments.
471 */ 514 */
472 struct GNUNET_ShortHashCode msg_uuid; 515 struct MessageUUID msg_uuid;
473 516
474 /** 517 /**
475 * Offset of this fragment in the overall message. 518 * Offset of this fragment in the overall message.
@@ -501,7 +544,7 @@ struct TransportFragmentAckMessage
501 /** 544 /**
502 * Unique ID of the lowest fragment UUID being acknowledged. 545 * Unique ID of the lowest fragment UUID being acknowledged.
503 */ 546 */
504 uint32_t frag_uuid GNUNET_PACKED; 547 struct FragmentUUIDP frag_uuid;
505 548
506 /** 549 /**
507 * Bitfield of up to 64 additional fragments following the 550 * Bitfield of up to 64 additional fragments following the
@@ -513,7 +556,7 @@ struct TransportFragmentAckMessage
513 * Original message ID for of the message that all the 556 * Original message ID for of the message that all the
514 * fragments belong to. 557 * fragments belong to.
515 */ 558 */
516 struct GNUNET_ShortHashCode msg_uuid; 559 struct MessageUUID msg_uuid;
517 560
518 /** 561 /**
519 * How long was the ACK delayed relative to the average time of 562 * How long was the ACK delayed relative to the average time of
@@ -572,7 +615,7 @@ struct DvInitPS
572 /** 615 /**
573 * Challenge value used by the initiator to re-identify the path. 616 * Challenge value used by the initiator to re-identify the path.
574 */ 617 */
575 struct GNUNET_ShortHashCode challenge; 618 struct ChallengeNonce challenge;
576}; 619};
577 620
578 621
@@ -612,7 +655,7 @@ struct DvHopPS
612 /** 655 /**
613 * Challenge value used by the initiator to re-identify the path. 656 * Challenge value used by the initiator to re-identify the path.
614 */ 657 */
615 struct GNUNET_ShortHashCode challenge; 658 struct ChallengeNonce challenge;
616}; 659};
617 660
618 661
@@ -692,7 +735,7 @@ struct TransportDVLearn
692 /** 735 /**
693 * Challenge value used by the initiator to re-identify the path. 736 * Challenge value used by the initiator to re-identify the path.
694 */ 737 */
695 struct GNUNET_ShortHashCode challenge; 738 struct ChallengeNonce challenge;
696 739
697 /* Followed by @e num_hops `struct DVPathEntryP` values, 740 /* Followed by @e num_hops `struct DVPathEntryP` values,
698 excluding the initiator of the DV trace; the last entry is the 741 excluding the initiator of the DV trace; the last entry is the
@@ -769,7 +812,7 @@ struct TransportValidationChallenge
769 /** 812 /**
770 * Challenge to be signed by the receiving peer. 813 * Challenge to be signed by the receiving peer.
771 */ 814 */
772 struct GNUNET_ShortHashCode challenge; 815 struct ChallengeNonce challenge;
773 816
774 /** 817 /**
775 * Timestamp of the sender, to be copied into the reply 818 * Timestamp of the sender, to be copied into the reply
@@ -800,7 +843,7 @@ struct TransportValidationPS
800 /** 843 /**
801 * Challenge signed by the receiving peer. 844 * Challenge signed by the receiving peer.
802 */ 845 */
803 struct GNUNET_ShortHashCode challenge; 846 struct ChallengeNonce challenge;
804}; 847};
805 848
806 849
@@ -830,7 +873,7 @@ struct TransportValidationResponse
830 /** 873 /**
831 * The challenge that was signed by the receiving peer. 874 * The challenge that was signed by the receiving peer.
832 */ 875 */
833 struct GNUNET_ShortHashCode challenge; 876 struct ChallengeNonce challenge;
834 877
835 /** 878 /**
836 * Original timestamp of the sender (was @code{sender_time}), 879 * Original timestamp of the sender (was @code{sender_time}),
@@ -900,7 +943,7 @@ struct LearnLaunchEntry
900 /** 943 /**
901 * Challenge that uniquely identifies this activity. 944 * Challenge that uniquely identifies this activity.
902 */ 945 */
903 struct GNUNET_ShortHashCode challenge; 946 struct ChallengeNonce challenge;
904 947
905 /** 948 /**
906 * When did we transmit the DV learn message (used to calculate RTT) and 949 * When did we transmit the DV learn message (used to calculate RTT) and
@@ -1285,7 +1328,7 @@ struct ReassemblyContext
1285 * Original message ID for of the message that all the 1328 * Original message ID for of the message that all the
1286 * fragments belong to. 1329 * fragments belong to.
1287 */ 1330 */
1288 struct GNUNET_ShortHashCode msg_uuid; 1331 struct MessageUUID msg_uuid;
1289 1332
1290 /** 1333 /**
1291 * Which neighbour is this context for? 1334 * Which neighbour is this context for?
@@ -1642,7 +1685,7 @@ struct PendingMessage
1642 * UUID to use for this message (used for reassembly of fragments, only 1685 * UUID to use for this message (used for reassembly of fragments, only
1643 * initialized if @e msg_uuid_set is #GNUNET_YES). 1686 * initialized if @e msg_uuid_set is #GNUNET_YES).
1644 */ 1687 */
1645 struct GNUNET_ShortHashCode msg_uuid; 1688 struct MessageUUID msg_uuid;
1646 1689
1647 /** 1690 /**
1648 * Counter incremented per generated fragment. 1691 * Counter incremented per generated fragment.
@@ -1941,7 +1984,7 @@ struct ValidationState
1941 * (We must not rotate more often as otherwise we may discard valid answers 1984 * (We must not rotate more often as otherwise we may discard valid answers
1942 * due to packet losses, latency and reorderings on the network). 1985 * due to packet losses, latency and reorderings on the network).
1943 */ 1986 */
1944 struct GNUNET_ShortHashCode challenge; 1987 struct ChallengeNonce challenge;
1945 1988
1946 /** 1989 /**
1947 * Claimed address of the peer. 1990 * Claimed address of the peer.
@@ -2378,7 +2421,7 @@ free_reassembly_context (struct ReassemblyContext *rc)
2378 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); 2421 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn));
2379 GNUNET_assert (GNUNET_OK == 2422 GNUNET_assert (GNUNET_OK ==
2380 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map, 2423 GNUNET_CONTAINER_multishortmap_remove (n->reassembly_map,
2381 &rc->msg_uuid, 2424 &rc->msg_uuid.uuid,
2382 rc)); 2425 rc));
2383 GNUNET_free (rc); 2426 GNUNET_free (rc);
2384} 2427}
@@ -3659,6 +3702,9 @@ struct BackchannelKeyState
3659}; 3702};
3660 3703
3661 3704
3705/**
3706 * FIXME: comment!
3707 */
3662static void 3708static void
3663bc_setup_key_state_from_km (const struct GNUNET_HashCode *km, 3709bc_setup_key_state_from_km (const struct GNUNET_HashCode *km,
3664 const struct GNUNET_ShortHashCode *iv, 3710 const struct GNUNET_ShortHashCode *iv,
@@ -4177,7 +4223,7 @@ send_fragment_ack (struct ReassemblyContext *rc)
4177 ack = GNUNET_new (struct TransportFragmentAckMessage); 4223 ack = GNUNET_new (struct TransportFragmentAckMessage);
4178 ack->header.size = htons (sizeof (struct TransportFragmentAckMessage)); 4224 ack->header.size = htons (sizeof (struct TransportFragmentAckMessage));
4179 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK); 4225 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT_ACK);
4180 ack->frag_uuid = htonl (rc->frag_uuid); 4226 ack->frag_uuid.uuid = htonl (rc->frag_uuid);
4181 ack->extra_acks = GNUNET_htonll (rc->extra_acks); 4227 ack->extra_acks = GNUNET_htonll (rc->extra_acks);
4182 ack->msg_uuid = rc->msg_uuid; 4228 ack->msg_uuid = rc->msg_uuid;
4183 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay); 4229 ack->avg_ack_delay = GNUNET_TIME_relative_hton (rc->avg_ack_delay);
@@ -4237,7 +4283,8 @@ handle_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4237 n); 4283 n);
4238 } 4284 }
4239 msize = ntohs (fb->msg_size); 4285 msize = ntohs (fb->msg_size);
4240 rc = GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, &fb->msg_uuid); 4286 rc =
4287 GNUNET_CONTAINER_multishortmap_get (n->reassembly_map, &fb->msg_uuid.uuid);
4241 if (NULL == rc) 4288 if (NULL == rc)
4242 { 4289 {
4243 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ 4290 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */
@@ -4254,7 +4301,7 @@ handle_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4254 GNUNET_assert (GNUNET_OK == 4301 GNUNET_assert (GNUNET_OK ==
4255 GNUNET_CONTAINER_multishortmap_put ( 4302 GNUNET_CONTAINER_multishortmap_put (
4256 n->reassembly_map, 4303 n->reassembly_map,
4257 &rc->msg_uuid, 4304 &rc->msg_uuid.uuid,
4258 rc, 4305 rc,
4259 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 4306 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
4260 target = (char *) &rc[1]; 4307 target = (char *) &rc[1];
@@ -4287,7 +4334,7 @@ handle_fragment_box (void *cls, const struct TransportFragmentBox *fb)
4287 } 4334 }
4288 4335
4289 /* Compute cummulative ACK */ 4336 /* Compute cummulative ACK */
4290 frag_uuid = ntohl (fb->frag_uuid); 4337 frag_uuid = ntohl (fb->frag_uuid.uuid);
4291 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); 4338 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag);
4292 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->num_acks); 4339 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->num_acks);
4293 rc->last_frag = GNUNET_TIME_absolute_get (); 4340 rc->last_frag = GNUNET_TIME_absolute_get ();
@@ -4379,7 +4426,7 @@ check_ack_against_pm (struct PendingMessage *pm,
4379{ 4426{
4380 int match; 4427 int match;
4381 struct PendingMessage *nxt; 4428 struct PendingMessage *nxt;
4382 uint32_t fs = ntohl (fa->frag_uuid); 4429 uint32_t fs = ntohl (fa->frag_uuid.uuid);
4383 uint64_t xtra = GNUNET_ntohll (fa->extra_acks); 4430 uint64_t xtra = GNUNET_ntohll (fa->extra_acks);
4384 4431
4385 match = GNUNET_NO; 4432 match = GNUNET_NO;
@@ -4387,7 +4434,7 @@ check_ack_against_pm (struct PendingMessage *pm,
4387 { 4434 {
4388 const struct TransportFragmentBox *tfb = 4435 const struct TransportFragmentBox *tfb =
4389 (const struct TransportFragmentBox *) &pm[1]; 4436 (const struct TransportFragmentBox *) &pm[1];
4390 uint32_t fu = ntohl (tfb->frag_uuid); 4437 uint32_t fu = ntohl (tfb->frag_uuid.uuid);
4391 4438
4392 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt); 4439 GNUNET_assert (PMT_FRAGMENT_BOX == frag->pmt);
4393 nxt = frag->next_frag; 4440 nxt = frag->next_frag;
@@ -4521,11 +4568,10 @@ handle_reliability_box (void *cls, const struct TransportReliabilityBox *rb)
4521 4568
4522 /* FIXME-OPTIMIZE: implement cummulative ACKs and ack_countdown, 4569 /* FIXME-OPTIMIZE: implement cummulative ACKs and ack_countdown,
4523 then setting the avg_ack_delay field below: */ 4570 then setting the avg_ack_delay field below: */
4524 ack = GNUNET_malloc (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode)); 4571 ack = GNUNET_malloc (sizeof (*ack) + sizeof (struct MessageUUID));
4525 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 4572 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
4526 ack->header.size = 4573 ack->header.size = htons (sizeof (*ack) + sizeof (struct MessageUUID));
4527 htons (sizeof (*ack) + sizeof (struct GNUNET_ShortHashCode)); 4574 memcpy (&ack[1], &rb->msg_uuid, sizeof (struct MessageUUID));
4528 memcpy (&ack[1], &rb->msg_uuid, sizeof (struct GNUNET_ShortHashCode));
4529 route_message (&cmc->im.sender, &ack->header, RMO_DV_ALLOWED); 4575 route_message (&cmc->im.sender, &ack->header, RMO_DV_ALLOWED);
4530 } 4576 }
4531 /* continue with inner message */ 4577 /* continue with inner message */
@@ -4547,7 +4593,7 @@ handle_reliability_ack (void *cls,
4547 struct CommunicatorMessageContext *cmc = cls; 4593 struct CommunicatorMessageContext *cmc = cls;
4548 struct Neighbour *n; 4594 struct Neighbour *n;
4549 unsigned int n_acks; 4595 unsigned int n_acks;
4550 const struct GNUNET_ShortHashCode *msg_uuids; 4596 const struct MessageUUID *msg_uuids;
4551 struct PendingMessage *nxt; 4597 struct PendingMessage *nxt;
4552 int matched; 4598 int matched;
4553 4599
@@ -4561,9 +4607,9 @@ handle_reliability_ack (void *cls,
4561 GNUNET_SERVICE_client_drop (client); 4607 GNUNET_SERVICE_client_drop (client);
4562 return; 4608 return;
4563 } 4609 }
4564 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / 4610 n_acks =
4565 sizeof (struct GNUNET_ShortHashCode); 4611 (ntohs (ra->header.size) - sizeof (*ra)) / sizeof (struct MessageUUID);
4566 msg_uuids = (const struct GNUNET_ShortHashCode *) &ra[1]; 4612 msg_uuids = (const struct MessageUUID *) &ra[1];
4567 4613
4568 /* FIXME-OPTIMIZE: maybe use another hash map here? */ 4614 /* FIXME-OPTIMIZE: maybe use another hash map here? */
4569 matched = GNUNET_NO; 4615 matched = GNUNET_NO;
@@ -5383,7 +5429,7 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
5383static int 5429static int
5384validate_dv_initiator_signature ( 5430validate_dv_initiator_signature (
5385 const struct GNUNET_PeerIdentity *init, 5431 const struct GNUNET_PeerIdentity *init,
5386 const struct GNUNET_ShortHashCode *challenge, 5432 const struct ChallengeNonce *challenge,
5387 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 5433 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
5388{ 5434{
5389 struct DvInitPS ip = {.purpose.purpose = htonl ( 5435 struct DvInitPS ip = {.purpose.purpose = htonl (
@@ -5835,7 +5881,7 @@ struct CheckKnownChallengeContext
5835 /** 5881 /**
5836 * Set to the challenge we are looking for. 5882 * Set to the challenge we are looking for.
5837 */ 5883 */
5838 const struct GNUNET_ShortHashCode *challenge; 5884 const struct ChallengeNonce *challenge;
5839 5885
5840 /** 5886 /**
5841 * Set to a matching validation state, if one was found. 5887 * Set to a matching validation state, if one was found.
@@ -6379,7 +6425,7 @@ fragment_message (struct PendingMessage *pm, uint16_t mtu)
6379 msg = (char *) &frag[1]; 6425 msg = (char *) &frag[1];
6380 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 6426 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
6381 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + fragsize); 6427 tfb.header.size = htons (sizeof (struct TransportFragmentBox) + fragsize);
6382 tfb.frag_uuid = htonl (pm->frag_uuidgen++); 6428 tfb.frag_uuid.uuid = htonl (pm->frag_uuidgen++);
6383 tfb.msg_uuid = pm->msg_uuid; 6429 tfb.msg_uuid = pm->msg_uuid;
6384 tfb.frag_off = htons (ff->frag_off + xoff); 6430 tfb.frag_off = htons (ff->frag_off + xoff);
6385 tfb.msg_size = htons (pm->bytes_msg); 6431 tfb.msg_size = htons (pm->bytes_msg);
@@ -7153,7 +7199,7 @@ start_dv_learn (void *cls)
7153 lle = lle_tail; 7199 lle = lle_tail;
7154 GNUNET_assert (GNUNET_YES == 7200 GNUNET_assert (GNUNET_YES ==
7155 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, 7201 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map,
7156 &lle->challenge, 7202 &lle->challenge.value,
7157 lle)); 7203 lle));
7158 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); 7204 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle);
7159 GNUNET_free (lle); 7205 GNUNET_free (lle);
@@ -7167,7 +7213,7 @@ start_dv_learn (void *cls)
7167 GNUNET_break (GNUNET_YES == 7213 GNUNET_break (GNUNET_YES ==
7168 GNUNET_CONTAINER_multishortmap_put ( 7214 GNUNET_CONTAINER_multishortmap_put (
7169 dvlearn_map, 7215 dvlearn_map,
7170 &lle->challenge, 7216 &lle->challenge.value,
7171 lle, 7217 lle,
7172 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7218 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7173 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 7219 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);