aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-04 11:36:38 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-04 11:36:38 +0000
commit8cdcce63c7a938409dee4a745a891c4df7dbc349 (patch)
tree7685c3dd1a8572ffe033bc4e1bfcb93e002cb814 /src/util
parente1f074d4692f807c00902b415c0b139b16ea0b76 (diff)
downloadgnunet-8cdcce63c7a938409dee4a745a891c4df7dbc349.tar.gz
gnunet-8cdcce63c7a938409dee4a745a891c4df7dbc349.zip
-better logging, doxygen, indentation
Diffstat (limited to 'src/util')
-rw-r--r--src/util/mq.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/src/util/mq.c b/src/util/mq.c
index 941a5c43e..5e40059c2 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors) 3 (C) 2012-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -144,15 +144,28 @@ struct GNUNET_MQ_Handle
144}; 144};
145 145
146 146
147 147/**
148 148 * Implementation-specific state for connection to
149 * client (MQ for server).
150 */
149struct ServerClientSocketState 151struct ServerClientSocketState
150{ 152{
153 /**
154 * Handle of the client that connected to the server.
155 */
151 struct GNUNET_SERVER_Client *client; 156 struct GNUNET_SERVER_Client *client;
157
158 /**
159 * Active transmission request to the client.
160 */
152 struct GNUNET_SERVER_TransmitHandle* th; 161 struct GNUNET_SERVER_TransmitHandle* th;
153}; 162};
154 163
155 164
165/**
166 * Implementation-specific state for connection to
167 * service (MQ for clients).
168 */
156struct ClientConnectionState 169struct ClientConnectionState
157{ 170{
158 /** 171 /**
@@ -164,7 +177,15 @@ struct ClientConnectionState
164 * Do we also want to receive? 177 * Do we also want to receive?
165 */ 178 */
166 int receive_requested; 179 int receive_requested;
180
181 /**
182 * Connection to the service.
183 */
167 struct GNUNET_CLIENT_Connection *connection; 184 struct GNUNET_CLIENT_Connection *connection;
185
186 /**
187 * Active transmission request (or NULL).
188 */
168 struct GNUNET_CLIENT_TransmitHandle *th; 189 struct GNUNET_CLIENT_TransmitHandle *th;
169}; 190};
170 191
@@ -180,14 +201,20 @@ struct ClientConnectionState
180 * @param mh message to dispatch 201 * @param mh message to dispatch
181 */ 202 */
182void 203void
183GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh) 204GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
205 const struct GNUNET_MessageHeader *mh)
184{ 206{
185 const struct GNUNET_MQ_MessageHandler *handler; 207 const struct GNUNET_MQ_MessageHandler *handler;
186 int handled = GNUNET_NO; 208 int handled = GNUNET_NO;
187 209
188 handler = mq->handlers; 210 handler = mq->handlers;
189 if (NULL == handler) 211 if (NULL == handler)
212 {
213 LOG (GNUNET_ERROR_TYPE_WARNING,
214 "No handler for message of type %d\n",
215 ntohs (mh->type));
190 return; 216 return;
217 }
191 for (; NULL != handler->cb; handler++) 218 for (; NULL != handler->cb; handler++)
192 { 219 {
193 if (handler->type == ntohs (mh->type)) 220 if (handler->type == ntohs (mh->type))
@@ -198,7 +225,9 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, const struct GNUNET_Messa
198 } 225 }
199 226
200 if (GNUNET_NO == handled) 227 if (GNUNET_NO == handled)
201 LOG (GNUNET_ERROR_TYPE_WARNING, "no handler for message of type %d\n", ntohs (mh->type)); 228 LOG (GNUNET_ERROR_TYPE_WARNING,
229 "No handler for message of type %d\n",
230 ntohs (mh->type));
202} 231}
203 232
204 233
@@ -218,8 +247,9 @@ GNUNET_MQ_inject_error (struct GNUNET_MQ_Handle *mq,
218{ 247{
219 if (NULL == mq->error_handler) 248 if (NULL == mq->error_handler)
220 { 249 {
221 /* FIXME: log what kind of error occured */ 250 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
222 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "mq: got error, but no handler installed\n"); 251 "mq: got error %d, but no handler installed\n",
252 (int) error);
223 return; 253 return;
224 } 254 }
225 mq->error_handler (mq->handlers_cls, error); 255 mq->error_handler (mq->handlers_cls, error);
@@ -242,17 +272,19 @@ GNUNET_MQ_discard (struct GNUNET_MQ_Envelope *mqm)
242 * @param ev the envelope with the message to send. 272 * @param ev the envelope with the message to send.
243 */ 273 */
244void 274void
245GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev) 275GNUNET_MQ_send (struct GNUNET_MQ_Handle *mq,
276 struct GNUNET_MQ_Envelope *ev)
246{ 277{
247 GNUNET_assert (NULL != mq); 278 GNUNET_assert (NULL != mq);
248 GNUNET_assert (NULL == ev->parent_queue); 279 GNUNET_assert (NULL == ev->parent_queue);
249 280
250 ev->parent_queue = mq; 281 ev->parent_queue = mq;
251
252 /* is the implementation busy? queue it! */ 282 /* is the implementation busy? queue it! */
253 if (NULL != mq->current_envelope) 283 if (NULL != mq->current_envelope)
254 { 284 {
255 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head, mq->envelope_tail, ev); 285 GNUNET_CONTAINER_DLL_insert_tail (mq->envelope_head,
286 mq->envelope_tail,
287 ev);
256 return; 288 return;
257 } 289 }
258 mq->current_envelope = ev; 290 mq->current_envelope = ev;
@@ -396,7 +428,9 @@ GNUNET_MQ_impl_state (struct GNUNET_MQ_Handle *mq)
396 428
397 429
398struct GNUNET_MQ_Envelope * 430struct GNUNET_MQ_Envelope *
399GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type) 431GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp,
432 uint16_t size,
433 uint16_t type)
400{ 434{
401 struct GNUNET_MQ_Envelope *mqm; 435 struct GNUNET_MQ_Envelope *mqm;
402 436
@@ -420,7 +454,9 @@ GNUNET_MQ_msg_ (struct GNUNET_MessageHeader **mhp, uint16_t size, uint16_t type)
420 * @param nested_mh the message to append to the message after base_size 454 * @param nested_mh the message to append to the message after base_size
421 */ 455 */
422struct GNUNET_MQ_Envelope * 456struct GNUNET_MQ_Envelope *
423GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, uint16_t base_size, uint16_t type, 457GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp,
458 uint16_t base_size,
459 uint16_t type,
424 const struct GNUNET_MessageHeader *nested_mh) 460 const struct GNUNET_MessageHeader *nested_mh)
425{ 461{
426 struct GNUNET_MQ_Envelope *mqm; 462 struct GNUNET_MQ_Envelope *mqm;
@@ -493,7 +529,8 @@ server_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
493 529
494static void 530static void
495server_client_send_impl (struct GNUNET_MQ_Handle *mq, 531server_client_send_impl (struct GNUNET_MQ_Handle *mq,
496 const struct GNUNET_MessageHeader *msg, void *impl_state) 532 const struct GNUNET_MessageHeader *msg,
533 void *impl_state)
497{ 534{
498 struct ServerClientSocketState *state = impl_state; 535 struct ServerClientSocketState *state = impl_state;
499 536
@@ -587,7 +624,6 @@ connection_client_transmit_queued (void *cls,
587 GNUNET_TIME_UNIT_FOREVER_REL); 624 GNUNET_TIME_UNIT_FOREVER_REL);
588 } 625 }
589 626
590
591 msg_size = ntohs (msg->size); 627 msg_size = ntohs (msg->size);
592 GNUNET_assert (size >= msg_size); 628 GNUNET_assert (size >= msg_size);
593 memcpy (buf, msg, msg_size); 629 memcpy (buf, msg, msg_size);
@@ -600,7 +636,8 @@ connection_client_transmit_queued (void *cls,
600 636
601 637
602static void 638static void
603connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 639connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
640 void *impl_state)
604{ 641{
605 GNUNET_free (impl_state); 642 GNUNET_free (impl_state);
606} 643}
@@ -608,7 +645,8 @@ connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
608 645
609static void 646static void
610connection_client_send_impl (struct GNUNET_MQ_Handle *mq, 647connection_client_send_impl (struct GNUNET_MQ_Handle *mq,
611 const struct GNUNET_MessageHeader *msg, void *impl_state) 648 const struct GNUNET_MessageHeader *msg,
649 void *impl_state)
612{ 650{
613 struct ClientConnectionState *state = impl_state; 651 struct ClientConnectionState *state = impl_state;
614 652
@@ -698,7 +736,8 @@ GNUNET_MQ_assoc_add (struct GNUNET_MQ_Handle *mq,
698 736
699 737
700void * 738void *
701GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id) 739GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq,
740 uint32_t request_id)
702{ 741{
703 if (NULL == mq->assoc_map) 742 if (NULL == mq->assoc_map)
704 return NULL; 743 return NULL;
@@ -707,7 +746,8 @@ GNUNET_MQ_assoc_get (struct GNUNET_MQ_Handle *mq, uint32_t request_id)
707 746
708 747
709void * 748void *
710GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq, uint32_t request_id) 749GNUNET_MQ_assoc_remove (struct GNUNET_MQ_Handle *mq,
750 uint32_t request_id)
711{ 751{
712 void *val; 752 void *val;
713 753
@@ -766,7 +806,8 @@ GNUNET_MQ_destroy (struct GNUNET_MQ_Handle *mq)
766 806
767 807
768struct GNUNET_MessageHeader * 808struct GNUNET_MessageHeader *
769GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh, uint16_t base_size) 809GNUNET_MQ_extract_nested_mh_ (const struct GNUNET_MessageHeader *mh,
810 uint16_t base_size)
770{ 811{
771 uint16_t whole_size; 812 uint16_t whole_size;
772 uint16_t nested_size; 813 uint16_t nested_size;
@@ -840,3 +881,4 @@ GNUNET_MQ_send_cancel (struct GNUNET_MQ_Envelope *ev)
840 GNUNET_free (ev); 881 GNUNET_free (ev);
841} 882}
842 883
884/* end of mq.c */