aboutsummaryrefslogtreecommitdiff
path: root/src/scalarproduct
diff options
context:
space:
mode:
authorChristian Fuchs <christian.fuchs@cfuchs.net>2013-09-11 12:20:03 +0000
committerChristian Fuchs <christian.fuchs@cfuchs.net>2013-09-11 12:20:03 +0000
commit30b74c15b7f76b0371495f79447a8aaebcc71636 (patch)
treec3a346f2ee2b695f5c895d617fe05a3c71528747 /src/scalarproduct
parent70cb9504b1f82b0ee580a464ee1929cb0b314ff8 (diff)
downloadgnunet-30b74c15b7f76b0371495f79447a8aaebcc71636.tar.gz
gnunet-30b74c15b7f76b0371495f79447a8aaebcc71636.zip
added propper shutdown task to SP-client
fixed a logics mixup in the SP-API between alice's client and bob's client-function fixed a memory allocation bug in SP-API adjusted message formats to use uint32_t instead of 16 for all element counts and mask lengths
Diffstat (limited to 'src/scalarproduct')
-rw-r--r--src/scalarproduct/gnunet-scalarproduct.c16
-rw-r--r--src/scalarproduct/scalarproduct.h16
-rw-r--r--src/scalarproduct/scalarproduct_api.c18
3 files changed, 33 insertions, 17 deletions
diff --git a/src/scalarproduct/gnunet-scalarproduct.c b/src/scalarproduct/gnunet-scalarproduct.c
index f56fd7625..83c907b6c 100644
--- a/src/scalarproduct/gnunet-scalarproduct.c
+++ b/src/scalarproduct/gnunet-scalarproduct.c
@@ -151,6 +151,18 @@ requester_callback (void *cls,
151 } 151 }
152} 152}
153 153
154/**
155 * Task run during shutdown.
156 *
157 * @param cls unused
158 * @param tc unused
159 */
160static void
161shutdown_task (void *cls,
162 const struct GNUNET_SCHEDULER_TaskContext *tc)
163{
164 GNUNET_SCALARPRODUCT_disconnect ();
165}
154 166
155/** 167/**
156 * Main function that will be run by the scheduler. 168 * Main function that will be run by the scheduler.
@@ -310,6 +322,10 @@ run (void *cls,
310 (void *) &closure))) 322 (void *) &closure)))
311 return; 323 return;
312 324
325 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
326 &shutdown_task,
327 NULL);
328
313 ret = 0; 329 ret = 0;
314} 330}
315 331
diff --git a/src/scalarproduct/scalarproduct.h b/src/scalarproduct/scalarproduct.h
index 9304c0c7e..02c6d8b21 100644
--- a/src/scalarproduct/scalarproduct.h
+++ b/src/scalarproduct/scalarproduct.h
@@ -73,12 +73,12 @@ struct GNUNET_SCALARPRODUCT_client_request
73 /** 73 /**
74 * how many elements the vector in payload contains 74 * how many elements the vector in payload contains
75 */ 75 */
76 uint16_t element_count GNUNET_PACKED; 76 uint32_t element_count GNUNET_PACKED;
77 77
78 /** 78 /**
79 * how many bytes the mask has 79 * how many bytes the mask has
80 */ 80 */
81 uint16_t mask_length GNUNET_PACKED; 81 uint32_t mask_length GNUNET_PACKED;
82 82
83 /** 83 /**
84 * the transaction/session key used to identify a session 84 * the transaction/session key used to identify a session
@@ -108,12 +108,12 @@ struct GNUNET_SCALARPRODUCT_service_request {
108 /** 108 /**
109 * how many bytes the mask has 109 * how many bytes the mask has
110 */ 110 */
111 uint16_t mask_length GNUNET_PACKED; 111 uint32_t mask_length GNUNET_PACKED;
112 112
113 /** 113 /**
114 * the length of the publickey contained within this message 114 * the length of the publickey contained within this message
115 */ 115 */
116 uint16_t pk_length GNUNET_PACKED; 116 uint32_t pk_length GNUNET_PACKED;
117 117
118 /** 118 /**
119 * the transaction/session key used to identify a session 119 * the transaction/session key used to identify a session
@@ -123,12 +123,12 @@ struct GNUNET_SCALARPRODUCT_service_request {
123 /** 123 /**
124 * how many elements the vector in payload contains 124 * how many elements the vector in payload contains
125 */ 125 */
126 uint16_t element_count GNUNET_PACKED; 126 uint32_t element_count GNUNET_PACKED;
127 127
128 /** 128 /**
129 * how many elements are actually included after the mask was applied. 129 * how many elements are actually included after the mask was applied.
130 */ 130 */
131 uint16_t used_element_count GNUNET_PACKED; 131 uint32_t used_element_count GNUNET_PACKED;
132 132
133 /** 133 /**
134 * followed by mask | public_key | vector[used_element_count] 134 * followed by mask | public_key | vector[used_element_count]
@@ -148,12 +148,12 @@ struct GNUNET_SCALARPRODUCT_service_response {
148 /** 148 /**
149 * how many elements the vector in payload contains 149 * how many elements the vector in payload contains
150 */ 150 */
151 uint16_t element_count GNUNET_PACKED; 151 uint32_t element_count GNUNET_PACKED;
152 152
153 /** 153 /**
154 * how many elements are actually included after the mask was applied. 154 * how many elements are actually included after the mask was applied.
155 */ 155 */
156 uint16_t used_element_count GNUNET_PACKED; 156 uint32_t used_element_count GNUNET_PACKED;
157 157
158 /** 158 /**
159 * the transaction/session key used to identify a session 159 * the transaction/session key used to identify a session
diff --git a/src/scalarproduct/scalarproduct_api.c b/src/scalarproduct/scalarproduct_api.c
index bfdf04de4..91f1992f9 100644
--- a/src/scalarproduct/scalarproduct_api.c
+++ b/src/scalarproduct/scalarproduct_api.c
@@ -351,14 +351,14 @@ GNUNET_SCALARPRODUCT_response (const struct GNUNET_CONFIGURATION_Handle *cfg,
351 351
352 h->cont_status = cont; 352 h->cont_status = cont;
353 h->cont_cls = cont_cls; 353 h->cont_cls = cont_cls;
354 h->response_proc = &process_result_message; 354 h->response_proc = &process_status_message;
355 h->cfg = cfg; 355 h->cfg = cfg;
356 h->msg = GNUNET_malloc (size);
357 memcpy (&h->key, key, sizeof (struct GNUNET_HashCode)); 356 memcpy (&h->key, key, sizeof (struct GNUNET_HashCode));
358 357
359 msg = (struct GNUNET_SCALARPRODUCT_client_request*) h->msg; 358 msg = (struct GNUNET_SCALARPRODUCT_client_request*) GNUNET_malloc (size);
359 h->msg = msg;
360 msg->header.size = htons (size); 360 msg->header.size = htons (size);
361 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE); 361 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_BOB);
362 msg->element_count = htonl (element_count); 362 msg->element_count = htonl (element_count);
363 363
364 vector = (int32_t*) & msg[1]; 364 vector = (int32_t*) & msg[1];
@@ -444,16 +444,16 @@ GNUNET_SCALARPRODUCT_request (const struct GNUNET_CONFIGURATION_Handle *cfg,
444 444
445 h->cont_datum = cont; 445 h->cont_datum = cont;
446 h->cont_cls = cont_cls; 446 h->cont_cls = cont_cls;
447 h->response_proc = &process_status_message; 447 h->response_proc = &process_result_message;
448 h->cfg = cfg; 448 h->cfg = cfg;
449 memcpy (&h->key, key, sizeof (struct GNUNET_HashCode)); 449 memcpy (&h->key, key, sizeof (struct GNUNET_HashCode));
450 450
451 msg = (struct GNUNET_SCALARPRODUCT_client_request*) GNUNET_malloc (size); 451 msg = (struct GNUNET_SCALARPRODUCT_client_request*) GNUNET_malloc (size);
452 h->msg = msg; 452 h->msg = msg;
453 msg->header.size = htons (size); 453 msg->header.size = htons (size);
454 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE); 454 msg->header.type = htons (GNUNET_MESSAGE_TYPE_SCALARPRODUCT_CLIENT_TO_ALICE);
455 msg->element_count = htons (element_count); 455 msg->element_count = htonl (element_count);
456 msg->mask_length = htons (mask_bytes); 456 msg->mask_length = htonl (mask_bytes);
457 457
458 vector = (int32_t*) & msg[1]; 458 vector = (int32_t*) & msg[1];
459 // copy each element over to the message 459 // copy each element over to the message