aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-18 18:49:13 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-18 18:49:13 +0000
commit710e8923105dfcc38d8aefed19e6da670db9c440 (patch)
treec6e46d41beedcf3ac2b13a1e040a790db8aa794a /src/util
parent5dfc382a9f8467cd15b6a0c3a6e022fca9fc4a30 (diff)
downloadgnunet-710e8923105dfcc38d8aefed19e6da670db9c440.tar.gz
gnunet-710e8923105dfcc38d8aefed19e6da670db9c440.zip
partial refactoring, will cause FTBFS, to be completed ASAP
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mq.c107
-rw-r--r--src/util/perf_crypto_asymmetric.c2
2 files changed, 67 insertions, 42 deletions
diff --git a/src/util/mq.c b/src/util/mq.c
index 6f8c04224..4170338ad 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -74,13 +74,7 @@ struct GNUNET_MQ_Handle
74 /** 74 /**
75 * Handlers array, or NULL if the queue should not receive messages 75 * Handlers array, or NULL if the queue should not receive messages
76 */ 76 */
77 const struct GNUNET_MQ_MessageHandler *handlers; 77 struct GNUNET_MQ_MessageHandler *handlers;
78
79 /**
80 * Closure for the handler callbacks,
81 * as well as for the error handler.
82 */
83 void *handlers_cls;
84 78
85 /** 79 /**
86 * Actual implementation of message sending, 80 * Actual implementation of message sending,
@@ -109,6 +103,11 @@ struct GNUNET_MQ_Handle
109 GNUNET_MQ_ErrorHandler error_handler; 103 GNUNET_MQ_ErrorHandler error_handler;
110 104
111 /** 105 /**
106 * Closure for the error handler.
107 */
108 void *error_handler_cls;
109
110 /**
112 * Linked list of messages pending to be sent 111 * Linked list of messages pending to be sent
113 */ 112 */
114 struct GNUNET_MQ_Envelope *envelope_head; 113 struct GNUNET_MQ_Envelope *envelope_head;
@@ -133,7 +132,7 @@ struct GNUNET_MQ_Handle
133 /** 132 /**
134 * Task scheduled during #GNUNET_MQ_impl_send_continue. 133 * Task scheduled during #GNUNET_MQ_impl_send_continue.
135 */ 134 */
136 struct GNUNET_SCHEDULER_Task * continue_task; 135 struct GNUNET_SCHEDULER_Task *continue_task;
137 136
138 /** 137 /**
139 * Next id that should be used for the @e assoc_map, 138 * Next id that should be used for the @e assoc_map,
@@ -206,23 +205,42 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
206{ 205{
207 const struct GNUNET_MQ_MessageHandler *handler; 206 const struct GNUNET_MQ_MessageHandler *handler;
208 int handled = GNUNET_NO; 207 int handled = GNUNET_NO;
209 208 uint16_t ms = ntohs (mh->size);
209
210 if (NULL == mq->handlers) 210 if (NULL == mq->handlers)
211 { 211 goto done;
212 LOG (GNUNET_ERROR_TYPE_WARNING,
213 "No handler for message of type %d\n",
214 ntohs (mh->type));
215 return;
216 }
217 for (handler = mq->handlers; NULL != handler->cb; handler++) 212 for (handler = mq->handlers; NULL != handler->cb; handler++)
218 { 213 {
219 if (handler->type == ntohs (mh->type)) 214 if (handler->type == ntohs (mh->type))
220 { 215 {
221 handler->cb (mq->handlers_cls, mh);
222 handled = GNUNET_YES; 216 handled = GNUNET_YES;
217 if ( (handler->expected_size > ms) ||
218 ( (handler->expected_size != ms) &&
219 (NULL == handler->mv) ) )
220 {
221 /* Too small, or not an exact size and
222 no 'mv' handler to check rest */
223 GNUNET_MQ_inject_error (mq,
224 GNUNET_MQ_ERROR_MALFORMED);
225 break;
226 }
227 if ( (NULL == handler->mv) ||
228 (GNUNET_OK ==
229 handler->mv (handler->cls, mh)) )
230 {
231 /* message well-formed, pass to handler */
232 handler->cb (handler->cls, mh);
233 }
234 else
235 {
236 /* Message rejected by check routine */
237 GNUNET_MQ_inject_error (mq,
238 GNUNET_MQ_ERROR_MALFORMED);
239 }
223 break; 240 break;
224 } 241 }
225 } 242 }
243 done:
226 if (GNUNET_NO == handled) 244 if (GNUNET_NO == handled)
227 LOG (GNUNET_ERROR_TYPE_WARNING, 245 LOG (GNUNET_ERROR_TYPE_WARNING,
228 "No handler for message of type %d\n", 246 "No handler for message of type %d\n",
@@ -251,7 +269,7 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
251 (int) error); 269 (int) error);
252 return; 270 return;
253 } 271 }
254 mq->error_handler (mq->handlers_cls, error); 272 mq->error_handler (mq->error_handler_cls, error);
255} 273}
256 274
257 275
@@ -355,7 +373,7 @@ GNUNET_MQ_impl_send_continue (struct GNUNET_MQ_Handle *mq)
355 * @param impl_state for the queue, passed to 'send' and 'destroy' 373 * @param impl_state for the queue, passed to 'send' and 'destroy'
356 * @param handlers array of message handlers 374 * @param handlers array of message handlers
357 * @param error_handler handler for read and write errors 375 * @param error_handler handler for read and write errors
358 * @param cls closure for message handlers and error handler 376 * @param error_handler_cls closure for @a error_handler
359 * @return a new message queue 377 * @return a new message queue
360 */ 378 */
361struct GNUNET_MQ_Handle * 379struct GNUNET_MQ_Handle *
@@ -365,16 +383,26 @@ GNUNET_MQ_queue_for_callbacks (GNUNET_MQ_SendImpl send,
365 void *impl_state, 383 void *impl_state,
366 const struct GNUNET_MQ_MessageHandler *handlers, 384 const struct GNUNET_MQ_MessageHandler *handlers,
367 GNUNET_MQ_ErrorHandler error_handler, 385 GNUNET_MQ_ErrorHandler error_handler,
368 void *cls) 386 void *error_handler_cls)
369{ 387{
370 struct GNUNET_MQ_Handle *mq; 388 struct GNUNET_MQ_Handle *mq;
389 unsigned int i;
371 390
372 mq = GNUNET_new (struct GNUNET_MQ_Handle); 391 mq = GNUNET_new (struct GNUNET_MQ_Handle);
373 mq->send_impl = send; 392 mq->send_impl = send;
374 mq->destroy_impl = destroy; 393 mq->destroy_impl = destroy;
375 mq->cancel_impl = cancel; 394 mq->cancel_impl = cancel;
376 mq->handlers = handlers; 395 if (NULL != handlers)
377 mq->handlers_cls = cls; 396 {
397 for (i=0;NULL != handlers[i].cb; i++) ;
398 mq->handlers = GNUNET_new_array (i,
399 struct GNUNET_MQ_MessageHandler);
400 memcpy (mq->handlers,
401 handlers,
402 i * sizeof (struct GNUNET_MQ_MessageHandler));
403 }
404 mq->error_handler = error_handler;
405 mq->error_handler_cls = error_handler_cls;
378 mq->impl_state = impl_state; 406 mq->impl_state = impl_state;
379 407
380 return mq; 408 return mq;
@@ -572,7 +600,6 @@ handle_client_message (void *cls,
572 struct ClientConnectionState *state; 600 struct ClientConnectionState *state;
573 601
574 state = mq->impl_state; 602 state = mq->impl_state;
575
576 if (NULL == msg) 603 if (NULL == msg)
577 { 604 {
578 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ); 605 GNUNET_MQ_inject_error (mq, GNUNET_MQ_ERROR_READ);
@@ -617,7 +644,9 @@ connection_client_transmit_queued (void *cls,
617 (GNUNET_NO == state->receive_active) ) 644 (GNUNET_NO == state->receive_active) )
618 { 645 {
619 state->receive_active = GNUNET_YES; 646 state->receive_active = GNUNET_YES;
620 GNUNET_CLIENT_receive (state->connection, handle_client_message, mq, 647 GNUNET_CLIENT_receive (state->connection,
648 &handle_client_message,
649 mq,
621 GNUNET_TIME_UNIT_FOREVER_REL); 650 GNUNET_TIME_UNIT_FOREVER_REL);
622 } 651 }
623 652
@@ -673,17 +702,24 @@ struct GNUNET_MQ_Handle *
673GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection, 702GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection,
674 const struct GNUNET_MQ_MessageHandler *handlers, 703 const struct GNUNET_MQ_MessageHandler *handlers,
675 GNUNET_MQ_ErrorHandler error_handler, 704 GNUNET_MQ_ErrorHandler error_handler,
676 void *cls) 705 void *error_handler_cls)
677{ 706{
678 struct GNUNET_MQ_Handle *mq; 707 struct GNUNET_MQ_Handle *mq;
679 struct ClientConnectionState *state; 708 struct ClientConnectionState *state;
680 709 unsigned int i;
681 GNUNET_assert (NULL != connection);
682 710
683 mq = GNUNET_new (struct GNUNET_MQ_Handle); 711 mq = GNUNET_new (struct GNUNET_MQ_Handle);
684 mq->handlers = handlers; 712 if (NULL != handlers)
713 {
714 for (i=0;NULL != handlers[i].cb; i++) ;
715 mq->handlers = GNUNET_new_array (i,
716 struct GNUNET_MQ_MessageHandler);
717 memcpy (mq->handlers,
718 handlers,
719 i * sizeof (struct GNUNET_MQ_MessageHandler));
720 }
685 mq->error_handler = error_handler; 721 mq->error_handler = error_handler;
686 mq->handlers_cls = cls; 722 mq->error_handler_cls = error_handler_cls;
687 state = GNUNET_new (struct ClientConnectionState); 723 state = GNUNET_new (struct ClientConnectionState);
688 state->connection = connection; 724 state->connection = connection;
689 mq->impl_state = state; 725 mq->impl_state = state;
@@ -697,18 +733,6 @@ GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connecti
697} 733}
698 734
699 735
700void
701GNUNET_MQ_replace_handlers (struct GNUNET_MQ_Handle *mq,
702 const struct GNUNET_MQ_MessageHandler *new_handlers,
703 void *cls)
704{
705 /* FIXME: notify implementation? */
706 /* FIXME: what about NULL handlers? abort receive? */
707 mq->handlers = new_handlers;
708 mq->handlers_cls = cls;
709}
710
711
712/** 736/**
713 * Associate the assoc_data in mq with a unique request id. 737 * Associate the assoc_data in mq with a unique request id.
714 * 738 *
@@ -784,6 +808,7 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
784 while (NULL != mq->envelope_head) 808 while (NULL != mq->envelope_head)
785 { 809 {
786 struct GNUNET_MQ_Envelope *ev; 810 struct GNUNET_MQ_Envelope *ev;
811
787 ev = mq->envelope_head; 812 ev = mq->envelope_head;
788 ev->parent_queue = NULL; 813 ev->parent_queue = NULL;
789 GNUNET_CONTAINER_DLL_remove (mq->envelope_head, 814 GNUNET_CONTAINER_DLL_remove (mq->envelope_head,
@@ -804,7 +829,7 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
804 GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map); 829 GNUNET_CONTAINER_multihashmap32_destroy (mq->assoc_map);
805 mq->assoc_map = NULL; 830 mq->assoc_map = NULL;
806 } 831 }
807 832 GNUNET_free_non_null (mq->handlers);
808 GNUNET_free (mq); 833 GNUNET_free (mq);
809} 834}
810 835
diff --git a/src/util/perf_crypto_asymmetric.c b/src/util/perf_crypto_asymmetric.c
index 6e9c40e02..418d6dab3 100644
--- a/src/util/perf_crypto_asymmetric.c
+++ b/src/util/perf_crypto_asymmetric.c
@@ -88,7 +88,7 @@ main (int argc, char *argv[])
88 start = GNUNET_TIME_absolute_get(); 88 start = GNUNET_TIME_absolute_get();
89 for (i = 0; i < l; i++) 89 for (i = 0; i < l; i++)
90 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]); 90 GNUNET_CRYPTO_eddsa_key_get_public (eddsa[i], &dspub[i]);
91 log_duration ("EdDSA", "get pubilc"); 91 log_duration ("EdDSA", "get public");
92 92
93 start = GNUNET_TIME_absolute_get(); 93 start = GNUNET_TIME_absolute_get();
94 for (i = 0; i < l; i++) 94 for (i = 0; i < l; i++)