diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-04-17 12:50:33 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-04-17 12:50:33 +0200 |
commit | 701ec37b6908b900fea2df9c746af8ca8aab284f (patch) | |
tree | f3e82557f6b165e868b52a6701f808a2ea90e2c3 /src/transport/gnunet-service-tng.c | |
parent | 9f0bad77828b5e449b77f67101bf3a5b3153a3fa (diff) | |
download | gnunet-701ec37b6908b900fea2df9c746af8ca8aab284f.tar.gz gnunet-701ec37b6908b900fea2df9c746af8ca8aab284f.zip |
implement proper SEND_MSG wrapping for control messages
Diffstat (limited to 'src/transport/gnunet-service-tng.c')
-rw-r--r-- | src/transport/gnunet-service-tng.c | 139 |
1 files changed, 82 insertions, 57 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 41aed9630..29bf3bf95 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -33,8 +33,6 @@ | |||
33 | * transport-to-transport traffic) | 33 | * transport-to-transport traffic) |
34 | * | 34 | * |
35 | * Implement next: | 35 | * Implement next: |
36 | * - FIXMEs: missing communicator-protocol wrappers around messages | ||
37 | * passed in MQ transmission requests on queues (see FIXME in code) | ||
38 | * - route_message() implementation, including using DV data structures | 36 | * - route_message() implementation, including using DV data structures |
39 | * (but not when routing certain message types, like DV learn, | 37 | * (but not when routing certain message types, like DV learn, |
40 | * MUST pay attention to content here -- or pass extra flags?) | 38 | * MUST pay attention to content here -- or pass extra flags?) |
@@ -1460,7 +1458,12 @@ enum PendingMessageType | |||
1460 | /** | 1458 | /** |
1461 | * Any type of acknowledgement. | 1459 | * Any type of acknowledgement. |
1462 | */ | 1460 | */ |
1463 | PMT_ACKNOWLEDGEMENT = 3 | 1461 | PMT_ACKNOWLEDGEMENT = 3, |
1462 | |||
1463 | /** | ||
1464 | * Control traffic generated by the TRANSPORT service itself. | ||
1465 | */ | ||
1466 | PMT_CONTROL = 4 | ||
1464 | 1467 | ||
1465 | }; | 1468 | }; |
1466 | 1469 | ||
@@ -5671,6 +5674,55 @@ reliability_box_message (struct PendingMessage *pm) | |||
5671 | 5674 | ||
5672 | 5675 | ||
5673 | /** | 5676 | /** |
5677 | * Send the control message @a payload on @a queue. | ||
5678 | * | ||
5679 | * @param queue the queue to use for transmission | ||
5680 | * @param pm pending message to update once transmission is done, may be NULL! | ||
5681 | * @param payload the payload to send (encapsulated in a | ||
5682 | * #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG). | ||
5683 | * @param payload_size number of bytes in @a payload | ||
5684 | */ | ||
5685 | static void | ||
5686 | queue_send_msg (struct Queue *queue, | ||
5687 | struct PendingMessage *pm, | ||
5688 | const void *payload, | ||
5689 | size_t payload_size) | ||
5690 | { | ||
5691 | struct Neighbour *n = queue->neighbour; | ||
5692 | struct GNUNET_TRANSPORT_SendMessageTo *smt; | ||
5693 | struct GNUNET_MQ_Envelope *env; | ||
5694 | |||
5695 | env = GNUNET_MQ_msg_extra (smt, | ||
5696 | payload_size, | ||
5697 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); | ||
5698 | smt->qid = queue->qid; | ||
5699 | smt->mid = queue->mid_gen; | ||
5700 | smt->receiver = n->pid; | ||
5701 | memcpy (&smt[1], | ||
5702 | payload, | ||
5703 | payload_size); | ||
5704 | { | ||
5705 | /* Pass the env to the communicator of queue for transmission. */ | ||
5706 | struct QueueEntry *qe; | ||
5707 | |||
5708 | qe = GNUNET_new (struct QueueEntry); | ||
5709 | qe->mid = queue->mid_gen++; | ||
5710 | qe->queue = queue; | ||
5711 | // qe->pm = pm; // FIXME: not so easy, reference management on 'free(s)'! | ||
5712 | // (also, note that pm may be NULL!) | ||
5713 | GNUNET_CONTAINER_DLL_insert (queue->queue_head, | ||
5714 | queue->queue_tail, | ||
5715 | qe); | ||
5716 | GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); | ||
5717 | queue->queue_length++; | ||
5718 | queue->tc->details.communicator.total_queue_length++; | ||
5719 | GNUNET_MQ_send (queue->tc->mq, | ||
5720 | env); | ||
5721 | } | ||
5722 | } | ||
5723 | |||
5724 | |||
5725 | /** | ||
5674 | * We believe we are ready to transmit a message on a queue. Double-checks | 5726 | * We believe we are ready to transmit a message on a queue. Double-checks |
5675 | * with the queue's "tracker_out" and then gives the message to the | 5727 | * with the queue's "tracker_out" and then gives the message to the |
5676 | * communicator for transmission (updating the tracker, and re-scheduling | 5728 | * communicator for transmission (updating the tracker, and re-scheduling |
@@ -5686,8 +5738,6 @@ transmit_on_queue (void *cls) | |||
5686 | struct PendingMessage *pm; | 5738 | struct PendingMessage *pm; |
5687 | struct PendingMessage *s; | 5739 | struct PendingMessage *s; |
5688 | uint32_t overhead; | 5740 | uint32_t overhead; |
5689 | struct GNUNET_TRANSPORT_SendMessageTo *smt; | ||
5690 | struct GNUNET_MQ_Envelope *env; | ||
5691 | 5741 | ||
5692 | queue->transmit_task = NULL; | 5742 | queue->transmit_task = NULL; |
5693 | if (NULL == (pm = n->pending_msg_head)) | 5743 | if (NULL == (pm = n->pending_msg_head)) |
@@ -5728,33 +5778,10 @@ transmit_on_queue (void *cls) | |||
5728 | } | 5778 | } |
5729 | 5779 | ||
5730 | /* Pass 's' for transission to the communicator */ | 5780 | /* Pass 's' for transission to the communicator */ |
5731 | env = GNUNET_MQ_msg_extra (smt, | 5781 | queue_send_msg (queue, |
5732 | s->bytes_msg, | 5782 | s, |
5733 | GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); | 5783 | &s[1], |
5734 | smt->qid = queue->qid; | 5784 | s->bytes_msg); |
5735 | smt->mid = queue->mid_gen; | ||
5736 | smt->receiver = n->pid; | ||
5737 | memcpy (&smt[1], | ||
5738 | &s[1], | ||
5739 | s->bytes_msg); | ||
5740 | { | ||
5741 | /* Pass the env to the communicator of queue for transmission. */ | ||
5742 | struct QueueEntry *qe; | ||
5743 | |||
5744 | qe = GNUNET_new (struct QueueEntry); | ||
5745 | qe->mid = queue->mid_gen++; | ||
5746 | qe->queue = queue; | ||
5747 | // qe->pm = s; // FIXME: not so easy, reference management on 'free(s)'! | ||
5748 | GNUNET_CONTAINER_DLL_insert (queue->queue_head, | ||
5749 | queue->queue_tail, | ||
5750 | qe); | ||
5751 | GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); | ||
5752 | queue->queue_length++; | ||
5753 | queue->tc->details.communicator.total_queue_length++; | ||
5754 | GNUNET_MQ_send (queue->tc->mq, | ||
5755 | env); | ||
5756 | } | ||
5757 | |||
5758 | // FIXME: do something similar to the logic below | 5785 | // FIXME: do something similar to the logic below |
5759 | // in defragmentation / reliability ACK handling! | 5786 | // in defragmentation / reliability ACK handling! |
5760 | 5787 | ||
@@ -6217,19 +6244,18 @@ static void | |||
6217 | validation_transmit_on_queue (struct Queue *q, | 6244 | validation_transmit_on_queue (struct Queue *q, |
6218 | struct ValidationState *vs) | 6245 | struct ValidationState *vs) |
6219 | { | 6246 | { |
6220 | struct GNUNET_MQ_Envelope *env; | 6247 | struct TransportValidationChallenge tvc; |
6221 | struct TransportValidationChallenge *tvc; | ||
6222 | 6248 | ||
6223 | vs->last_challenge_use = GNUNET_TIME_absolute_get (); | 6249 | vs->last_challenge_use = GNUNET_TIME_absolute_get (); |
6224 | env = GNUNET_MQ_msg (tvc, | 6250 | tvc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); |
6225 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); | 6251 | tvc.header.size = htons (sizeof (tvc)); |
6226 | tvc->reserved = htonl (0); | 6252 | tvc.reserved = htonl (0); |
6227 | tvc->challenge = vs->challenge; | 6253 | tvc.challenge = vs->challenge; |
6228 | tvc->sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); | 6254 | tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); |
6229 | // FIXME: not so easy, need to BOX this message | 6255 | queue_send_msg (q, |
6230 | // in a transmission request! (mistake also done elsewhere!) | 6256 | NULL, |
6231 | GNUNET_MQ_send (q->tc->mq, | 6257 | &tvc, |
6232 | env); | 6258 | sizeof (tvc)); |
6233 | } | 6259 | } |
6234 | 6260 | ||
6235 | 6261 | ||
@@ -6379,8 +6405,7 @@ start_dv_learn (void *cls) | |||
6379 | { | 6405 | { |
6380 | struct LearnLaunchEntry *lle; | 6406 | struct LearnLaunchEntry *lle; |
6381 | struct QueueQualityContext qqc; | 6407 | struct QueueQualityContext qqc; |
6382 | struct GNUNET_MQ_Envelope *env; | 6408 | struct TransportDVLearn dvl; |
6383 | struct TransportDVLearn *dvl; | ||
6384 | 6409 | ||
6385 | (void) cls; | 6410 | (void) cls; |
6386 | dvlearn_task = NULL; | 6411 | dvlearn_task = NULL; |
@@ -6433,11 +6458,11 @@ start_dv_learn (void *cls) | |||
6433 | &lle->challenge, | 6458 | &lle->challenge, |
6434 | lle, | 6459 | lle, |
6435 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 6460 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
6436 | env = GNUNET_MQ_msg (dvl, | 6461 | dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); |
6437 | GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); | 6462 | dvl.header.size = htons (sizeof (dvl)); |
6438 | dvl->num_hops = htons (0); | 6463 | dvl.num_hops = htons (0); |
6439 | dvl->bidirectional = htons (0); | 6464 | dvl.bidirectional = htons (0); |
6440 | dvl->non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); | 6465 | dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); |
6441 | { | 6466 | { |
6442 | struct DvInitPS dvip = { | 6467 | struct DvInitPS dvip = { |
6443 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), | 6468 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), |
@@ -6448,10 +6473,10 @@ start_dv_learn (void *cls) | |||
6448 | GNUNET_assert (GNUNET_OK == | 6473 | GNUNET_assert (GNUNET_OK == |
6449 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | 6474 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, |
6450 | &dvip.purpose, | 6475 | &dvip.purpose, |
6451 | &dvl->init_sig)); | 6476 | &dvl.init_sig)); |
6452 | } | 6477 | } |
6453 | dvl->initiator = GST_my_identity; | 6478 | dvl.initiator = GST_my_identity; |
6454 | dvl->challenge = lle->challenge; | 6479 | dvl.challenge = lle->challenge; |
6455 | 6480 | ||
6456 | qqc.quality_count = 0; | 6481 | qqc.quality_count = 0; |
6457 | qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 6482 | qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
@@ -6465,11 +6490,11 @@ start_dv_learn (void *cls) | |||
6465 | 6490 | ||
6466 | /* Do this as close to transmission time as possible! */ | 6491 | /* Do this as close to transmission time as possible! */ |
6467 | lle->launch_time = GNUNET_TIME_absolute_get (); | 6492 | lle->launch_time = GNUNET_TIME_absolute_get (); |
6468 | // FIXME: not so easy, need to BOX this message | ||
6469 | // in a transmission request! (mistake also done elsewhere!) | ||
6470 | GNUNET_MQ_send (qqc.q->tc->mq, | ||
6471 | env); | ||
6472 | 6493 | ||
6494 | queue_send_msg (qqc.q, | ||
6495 | NULL, | ||
6496 | &dvl, | ||
6497 | sizeof (dvl)); | ||
6473 | /* reschedule this job, randomizing the time it runs (but no | 6498 | /* reschedule this job, randomizing the time it runs (but no |
6474 | actual backoff!) */ | 6499 | actual backoff!) */ |
6475 | dvlearn_task | 6500 | dvlearn_task |