diff options
author | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-05 16:15:22 +0000 |
---|---|---|
committer | Christian Fuchs <christian.fuchs@cfuchs.net> | 2013-09-05 16:15:22 +0000 |
commit | b93fbce0667741a36f60b046d3983d41c33dab8a (patch) | |
tree | 578d017d3e913a3a698aa247d8527f5879959d6f /src/scalarproduct | |
parent | 9a1ff3ca18fa008ca7f707a09af792d97fcec489 (diff) | |
download | gnunet-b93fbce0667741a36f60b046d3983d41c33dab8a.tar.gz gnunet-b93fbce0667741a36f60b046d3983d41c33dab8a.zip |
more work on the state machine.
transmit handles are now reset in do_transmit_msg
session remain active/present until the client disconnects or if a client sends a new message from the same connection
Diffstat (limited to 'src/scalarproduct')
-rw-r--r-- | src/scalarproduct/gnunet-service-scalarproduct.c | 85 |
1 files changed, 32 insertions, 53 deletions
diff --git a/src/scalarproduct/gnunet-service-scalarproduct.c b/src/scalarproduct/gnunet-service-scalarproduct.c index dd0c1f29d..1e92074e3 100644 --- a/src/scalarproduct/gnunet-service-scalarproduct.c +++ b/src/scalarproduct/gnunet-service-scalarproduct.c | |||
@@ -106,6 +106,11 @@ struct ServiceSession | |||
106 | struct GNUNET_SERVER_Client * client; | 106 | struct GNUNET_SERVER_Client * client; |
107 | 107 | ||
108 | /** | 108 | /** |
109 | * The message to send | ||
110 | */ | ||
111 | struct GNUNET_MessageHeader * msg; | ||
112 | |||
113 | /** | ||
109 | * how many elements we were supplied with from the client | 114 | * how many elements we were supplied with from the client |
110 | */ | 115 | */ |
111 | uint16_t element_count; | 116 | uint16_t element_count; |
@@ -166,23 +171,6 @@ struct ServiceSession | |||
166 | GNUNET_SCHEDULER_TaskIdentifier service_request_task; | 171 | GNUNET_SCHEDULER_TaskIdentifier service_request_task; |
167 | }; | 172 | }; |
168 | 173 | ||
169 | /** | ||
170 | * We need to do a minimum of bookkeeping to maintain track of our transmit handles. | ||
171 | * each msg is associated with a session and handle. using this information we can determine which msg was sent. | ||
172 | */ | ||
173 | struct MessageObject | ||
174 | { | ||
175 | /** | ||
176 | * The handle used to transmit with this request | ||
177 | */ | ||
178 | void ** transmit_handle; | ||
179 | |||
180 | /** | ||
181 | * The message to send | ||
182 | */ | ||
183 | struct GNUNET_MessageHeader * msg; | ||
184 | }; | ||
185 | |||
186 | /////////////////////////////////////////////////////////////////////////////// | 174 | /////////////////////////////////////////////////////////////////////////////// |
187 | // Global Variables | 175 | // Global Variables |
188 | /////////////////////////////////////////////////////////////////////////////// | 176 | /////////////////////////////////////////////////////////////////////////////// |
@@ -502,30 +490,30 @@ compute_square_sum (gcry_mpi_t * vector, uint16_t length) | |||
502 | static size_t | 490 | static size_t |
503 | do_send_message (void *cls, size_t size, void *buf) | 491 | do_send_message (void *cls, size_t size, void *buf) |
504 | { | 492 | { |
505 | struct MessageObject * info = cls; | 493 | struct ServiceSession * session = cls; |
506 | struct GNUNET_MessageHeader * msg; | ||
507 | size_t written = 0; | 494 | size_t written = 0; |
508 | 495 | ||
509 | GNUNET_assert (info); | ||
510 | msg = info->msg; | ||
511 | GNUNET_assert (msg); | ||
512 | GNUNET_assert (buf); | 496 | GNUNET_assert (buf); |
513 | 497 | ||
514 | if (ntohs (msg->size) == size) | 498 | if (ntohs (session->msg->size) == size) |
515 | { | 499 | { |
516 | memcpy (buf, msg, size); | 500 | memcpy (buf, session->msg, size); |
517 | written = size; | 501 | written = size; |
518 | } | 502 | } |
519 | 503 | ||
520 | // reset the transmit handle, if necessary | 504 | if (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_SERVICE_TO_CLIENT == ntohs(session->msg->type)){ |
521 | if (info->transmit_handle) | 505 | session->state = FINALIZED; |
522 | *info->transmit_handle = NULL; | 506 | session->client_transmit_handle = NULL; |
523 | 507 | } | |
508 | else | ||
509 | session->service_transmit_handle = NULL; | ||
510 | |||
524 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 511 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
525 | "Sent a message of type %hu.\n", | 512 | "Sent a message of type %hu.\n", |
526 | ntohs (msg->type)); | 513 | ntohs (session->msg->type)); |
527 | GNUNET_free(msg); | 514 | GNUNET_free(session->msg); |
528 | GNUNET_free(info); | 515 | session->msg = NULL; |
516 | |||
529 | return written; | 517 | return written; |
530 | } | 518 | } |
531 | 519 | ||
@@ -653,23 +641,20 @@ free_session (struct ServiceSession * session) | |||
653 | { | 641 | { |
654 | unsigned int i; | 642 | unsigned int i; |
655 | 643 | ||
656 | if (FINALIZED != session->state) | 644 | if (session->a) |
657 | { | 645 | { |
658 | if (session->a) | 646 | for (i = 0; i < session->used_element_count; i++) |
659 | { | 647 | gcry_mpi_release (session->a[i]); |
660 | for (i = 0; i < session->used_element_count; i++) | ||
661 | gcry_mpi_release (session->a[i]); | ||
662 | 648 | ||
663 | GNUNET_free (session->a); | 649 | GNUNET_free (session->a); |
664 | } | 650 | } |
665 | if (session->product) | 651 | if (session->product) |
666 | gcry_mpi_release (session->product); | 652 | gcry_mpi_release (session->product); |
667 | 653 | ||
668 | if (session->remote_pubkey) | 654 | if (session->remote_pubkey) |
669 | gcry_sexp_release (session->remote_pubkey); | 655 | gcry_sexp_release (session->remote_pubkey); |
670 | 656 | ||
671 | GNUNET_free_non_null (session->vector); | 657 | GNUNET_free_non_null (session->vector); |
672 | } | ||
673 | GNUNET_free (session); | 658 | GNUNET_free (session); |
674 | } | 659 | } |
675 | /////////////////////////////////////////////////////////////////////////////// | 660 | /////////////////////////////////////////////////////////////////////////////// |
@@ -742,7 +727,6 @@ prepare_client_end_notification (void * cls, | |||
742 | { | 727 | { |
743 | struct ServiceSession * session = cls; | 728 | struct ServiceSession * session = cls; |
744 | struct GNUNET_SCALARPRODUCT_client_response * msg; | 729 | struct GNUNET_SCALARPRODUCT_client_response * msg; |
745 | struct MessageObject * msg_obj; | ||
746 | 730 | ||
747 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; | 731 | session->client_notification_task = GNUNET_SCHEDULER_NO_TASK; |
748 | 732 | ||
@@ -755,9 +739,7 @@ prepare_client_end_notification (void * cls, | |||
755 | msg->product_length = htonl (0); | 739 | msg->product_length = htonl (0); |
756 | msg->range = 1; | 740 | msg->range = 1; |
757 | 741 | ||
758 | msg_obj = GNUNET_new (struct MessageObject); | 742 | session->msg = &msg->header; |
759 | msg_obj->msg = &msg->header; | ||
760 | msg_obj->transmit_handle = NULL; // do not reset the transmit handle, please | ||
761 | 743 | ||
762 | //transmit this message to our client | 744 | //transmit this message to our client |
763 | session->client_transmit_handle = | 745 | session->client_transmit_handle = |
@@ -765,7 +747,7 @@ prepare_client_end_notification (void * cls, | |||
765 | sizeof (struct GNUNET_SCALARPRODUCT_client_response), | 747 | sizeof (struct GNUNET_SCALARPRODUCT_client_response), |
766 | GNUNET_TIME_UNIT_FOREVER_REL, | 748 | GNUNET_TIME_UNIT_FOREVER_REL, |
767 | &do_send_message, | 749 | &do_send_message, |
768 | msg_obj); | 750 | session); |
769 | 751 | ||
770 | // if we could not even queue our request, something is wrong | 752 | // if we could not even queue our request, something is wrong |
771 | if ( ! session->client_transmit_handle) | 753 | if ( ! session->client_transmit_handle) |
@@ -1549,9 +1531,6 @@ tunnel_destruction_handler (void *cls, | |||
1549 | // or if it was a responder, no point in adding more statefulness | 1531 | // or if it was a responder, no point in adding more statefulness |
1550 | if (client_session && (!do_shutdown)) | 1532 | if (client_session && (!do_shutdown)) |
1551 | { | 1533 | { |
1552 | // remove the session, we just found it in the queue, so it must be there | ||
1553 | GNUNET_CONTAINER_DLL_remove (from_client_head, from_client_tail, client_session); | ||
1554 | |||
1555 | client_session->client_notification_task = | 1534 | client_session->client_notification_task = |
1556 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, | 1535 | GNUNET_SCHEDULER_add_now (&prepare_client_end_notification, |
1557 | client_session); | 1536 | client_session); |