aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-19 18:50:00 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-19 18:50:00 +0000
commit2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd (patch)
tree58be8b2e7321a91015df8ab3281a9f89a26cec1f /src
parentd8d3021ad9af2abe551fd6cd0fe2529a99d3683c (diff)
downloadgnunet-2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd.tar.gz
gnunet-2042d867f71e3cb1d7ade6b3d474ce0c1f5f87bd.zip
redefine GNUNET_MQ_queue_for_connection_client to capture client handle
Diffstat (limited to 'src')
-rw-r--r--src/ats/ats_api_connectivity.c24
-rw-r--r--src/ats/ats_api_scheduling.c26
-rw-r--r--src/consensus/consensus_api.c35
-rw-r--r--src/conversation/conversation_api.c25
-rw-r--r--src/include/gnunet_client_lib.h19
-rw-r--r--src/peerstore/peerstore_api.c37
-rw-r--r--src/rps/rps_api.c43
-rw-r--r--src/secretsharing/secretsharing_api.c29
-rw-r--r--src/set/set_api.c49
-rw-r--r--src/util/client.c30
-rw-r--r--src/util/mq.c12
-rw-r--r--src/util/test_mq_client.c27
12 files changed, 149 insertions, 207 deletions
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c
index 1897e2783..139f50a81 100644
--- a/src/ats/ats_api_connectivity.c
+++ b/src/ats/ats_api_connectivity.c
@@ -72,11 +72,6 @@ struct GNUNET_ATS_ConnectivityHandle
72 struct GNUNET_CONTAINER_MultiPeerMap *sug_requests; 72 struct GNUNET_CONTAINER_MultiPeerMap *sug_requests;
73 73
74 /** 74 /**
75 * Connection to ATS service.
76 */
77 struct GNUNET_CLIENT_Connection *client;
78
79 /**
80 * Message queue for sending requests to the ATS service. 75 * Message queue for sending requests to the ATS service.
81 */ 76 */
82 struct GNUNET_MQ_Handle *mq; 77 struct GNUNET_MQ_Handle *mq;
@@ -130,11 +125,6 @@ force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
130 GNUNET_MQ_destroy (ch->mq); 125 GNUNET_MQ_destroy (ch->mq);
131 ch->mq = NULL; 126 ch->mq = NULL;
132 } 127 }
133 if (NULL != ch->client)
134 {
135 GNUNET_CLIENT_disconnect (ch->client);
136 ch->client = NULL;
137 }
138 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); 128 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
139 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, 129 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
140 &reconnect_task, 130 &reconnect_task,
@@ -203,15 +193,16 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
203 { { NULL, 0, 0 } }; 193 { { NULL, 0, 0 } };
204 struct GNUNET_MQ_Envelope *ev; 194 struct GNUNET_MQ_Envelope *ev;
205 struct ClientStartMessage *init; 195 struct ClientStartMessage *init;
196 struct GNUNET_CLIENT_Connection *client;
206 197
207 GNUNET_assert (NULL == ch->client); 198 GNUNET_assert (NULL == ch->mq);
208 ch->client = GNUNET_CLIENT_connect ("ats", ch->cfg); 199 client = GNUNET_CLIENT_connect ("ats", ch->cfg);
209 if (NULL == ch->client) 200 if (NULL == client)
210 { 201 {
211 force_reconnect (ch); 202 force_reconnect (ch);
212 return; 203 return;
213 } 204 }
214 ch->mq = GNUNET_MQ_queue_for_connection_client (ch->client, 205 ch->mq = GNUNET_MQ_queue_for_connection_client (client,
215 handlers, 206 handlers,
216 &error_handler, 207 &error_handler,
217 ch); 208 ch);
@@ -281,11 +272,6 @@ GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch)
281 GNUNET_MQ_destroy (ch->mq); 272 GNUNET_MQ_destroy (ch->mq);
282 ch->mq = NULL; 273 ch->mq = NULL;
283 } 274 }
284 if (NULL != ch->client)
285 {
286 GNUNET_CLIENT_disconnect (ch->client);
287 ch->client = NULL;
288 }
289 if (NULL != ch->task) 275 if (NULL != ch->task)
290 { 276 {
291 GNUNET_SCHEDULER_cancel (ch->task); 277 GNUNET_SCHEDULER_cancel (ch->task);
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c
index bc730b248..d7e305950 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -118,11 +118,6 @@ struct GNUNET_ATS_SchedulingHandle
118 void *suggest_cb_cls; 118 void *suggest_cb_cls;
119 119
120 /** 120 /**
121 * Connection to ATS service.
122 */
123 struct GNUNET_CLIENT_Connection *client;
124
125 /**
126 * Message queue for sending requests to the ATS service. 121 * Message queue for sending requests to the ATS service.
127 */ 122 */
128 struct GNUNET_MQ_Handle *mq; 123 struct GNUNET_MQ_Handle *mq;
@@ -190,11 +185,6 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
190 GNUNET_MQ_destroy (sh->mq); 185 GNUNET_MQ_destroy (sh->mq);
191 sh->mq = NULL; 186 sh->mq = NULL;
192 } 187 }
193 if (NULL != sh->client)
194 {
195 GNUNET_CLIENT_disconnect (sh->client);
196 sh->client = NULL;
197 }
198 sh->suggest_cb (sh->suggest_cb_cls, 188 sh->suggest_cb (sh->suggest_cb_cls,
199 NULL, NULL, NULL, 189 NULL, NULL, NULL,
200 GNUNET_BANDWIDTH_ZERO, 190 GNUNET_BANDWIDTH_ZERO,
@@ -539,17 +529,18 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
539 struct ClientStartMessage *init; 529 struct ClientStartMessage *init;
540 unsigned int i; 530 unsigned int i;
541 struct GNUNET_ATS_AddressRecord *ar; 531 struct GNUNET_ATS_AddressRecord *ar;
532 struct GNUNET_CLIENT_Connection *client;
542 533
543 GNUNET_assert (NULL == sh->client); 534 GNUNET_assert (NULL == sh->mq);
544 sh->client = GNUNET_CLIENT_connect ("ats", 535 client = GNUNET_CLIENT_connect ("ats",
545 sh->cfg); 536 sh->cfg);
546 if (NULL == sh->client) 537 if (NULL == client)
547 { 538 {
548 GNUNET_break (0); 539 GNUNET_break (0);
549 force_reconnect (sh); 540 force_reconnect (sh);
550 return; 541 return;
551 } 542 }
552 sh->mq = GNUNET_MQ_queue_for_connection_client (sh->client, 543 sh->mq = GNUNET_MQ_queue_for_connection_client (client,
553 handlers, 544 handlers,
554 &error_handler, 545 &error_handler,
555 sh); 546 sh);
@@ -614,11 +605,6 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
614 GNUNET_MQ_destroy (sh->mq); 605 GNUNET_MQ_destroy (sh->mq);
615 sh->mq = NULL; 606 sh->mq = NULL;
616 } 607 }
617 if (NULL != sh->client)
618 {
619 GNUNET_CLIENT_disconnect (sh->client);
620 sh->client = NULL;
621 }
622 if (NULL != sh->task) 608 if (NULL != sh->task)
623 { 609 {
624 GNUNET_SCHEDULER_cancel (sh->task); 610 GNUNET_SCHEDULER_cancel (sh->task);
diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c
index 16096c28c..8653621ec 100644
--- a/src/consensus/consensus_api.c
+++ b/src/consensus/consensus_api.c
@@ -45,17 +45,12 @@ struct GNUNET_CONSENSUS_Handle
45 const struct GNUNET_CONFIGURATION_Handle *cfg; 45 const struct GNUNET_CONFIGURATION_Handle *cfg;
46 46
47 /** 47 /**
48 * Client connected to the consensus service, may be NULL if not connected.
49 */
50 struct GNUNET_CLIENT_Connection *client;
51
52 /**
53 * Callback for new elements. Not called for elements added locally. 48 * Callback for new elements. Not called for elements added locally.
54 */ 49 */
55 GNUNET_CONSENSUS_ElementCallback new_element_cb; 50 GNUNET_CONSENSUS_ElementCallback new_element_cb;
56 51
57 /** 52 /**
58 * Closure for new_element_cb 53 * Closure for @e new_element_cb
59 */ 54 */
60 void *new_element_cls; 55 void *new_element_cls;
61 56
@@ -75,7 +70,7 @@ struct GNUNET_CONSENSUS_Handle
75 GNUNET_CONSENSUS_ConcludeCallback conclude_cb; 70 GNUNET_CONSENSUS_ConcludeCallback conclude_cb;
76 71
77 /** 72 /**
78 * Closure for the conclude callback. 73 * Closure for the @e conclude_cb callback.
79 */ 74 */
80 void *conclude_cls; 75 void *conclude_cls;
81 76
@@ -156,8 +151,6 @@ handle_conclude_done (void *cls,
156 151
157 GNUNET_MQ_destroy (consensus->mq); 152 GNUNET_MQ_destroy (consensus->mq);
158 consensus->mq = NULL; 153 consensus->mq = NULL;
159 GNUNET_CLIENT_disconnect (consensus->client);
160 consensus->client = NULL;
161 GNUNET_assert (NULL != (cc = consensus->conclude_cb)); 154 GNUNET_assert (NULL != (cc = consensus->conclude_cb));
162 consensus->conclude_cb = NULL; 155 consensus->conclude_cb = NULL;
163 cc (consensus->conclude_cls); 156 cc (consensus->conclude_cls);
@@ -224,17 +217,22 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
224 }; 217 };
225 struct GNUNET_CONSENSUS_JoinMessage *join_msg; 218 struct GNUNET_CONSENSUS_JoinMessage *join_msg;
226 struct GNUNET_MQ_Envelope *ev; 219 struct GNUNET_MQ_Envelope *ev;
220 struct GNUNET_CLIENT_Connection *client;
227 221
228 consensus->cfg = cfg; 222 consensus->cfg = cfg;
229 consensus->new_element_cb = new_element_cb; 223 consensus->new_element_cb = new_element_cb;
230 consensus->new_element_cls = new_element_cls; 224 consensus->new_element_cls = new_element_cls;
231 consensus->session_id = *session_id; 225 consensus->session_id = *session_id;
232 consensus->client = GNUNET_CLIENT_connect ("consensus", cfg); 226 client = GNUNET_CLIENT_connect ("consensus", cfg);
233 consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client, 227 if (NULL == client)
234 mq_handlers, mq_error_handler, consensus); 228 {
235 229 GNUNET_free (consensus);
236 GNUNET_assert (consensus->client != NULL); 230 return NULL;
237 231 }
232 consensus->mq = GNUNET_MQ_queue_for_connection_client (client,
233 mq_handlers,
234 &mq_error_handler,
235 consensus);
238 ev = GNUNET_MQ_msg_extra (join_msg, 236 ev = GNUNET_MQ_msg_extra (join_msg,
239 (num_peers * sizeof (struct GNUNET_PeerIdentity)), 237 (num_peers * sizeof (struct GNUNET_PeerIdentity)),
240 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN); 238 GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN);
@@ -342,10 +340,7 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus)
342 GNUNET_MQ_destroy (consensus->mq); 340 GNUNET_MQ_destroy (consensus->mq);
343 consensus->mq = NULL; 341 consensus->mq = NULL;
344 } 342 }
345 if (NULL != consensus->client)
346 {
347 GNUNET_CLIENT_disconnect (consensus->client);
348 consensus->client = NULL;
349 }
350 GNUNET_free (consensus); 343 GNUNET_free (consensus);
351} 344}
345
346/* end of consensus_api.c */
diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c
index a9dc1f27f..3e0db67ea 100644
--- a/src/conversation/conversation_api.c
+++ b/src/conversation/conversation_api.c
@@ -161,11 +161,6 @@ struct GNUNET_CONVERSATION_Phone
161 const struct GNUNET_CONFIGURATION_Handle *cfg; 161 const struct GNUNET_CONFIGURATION_Handle *cfg;
162 162
163 /** 163 /**
164 * Handle to talk with CONVERSATION service.
165 */
166 struct GNUNET_CLIENT_Connection *client;
167
168 /**
169 * We keep all callers in a DLL. 164 * We keep all callers in a DLL.
170 */ 165 */
171 struct GNUNET_CONVERSATION_Caller *caller_head; 166 struct GNUNET_CONVERSATION_Caller *caller_head;
@@ -562,6 +557,7 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
562 }; 557 };
563 struct GNUNET_MQ_Envelope *e; 558 struct GNUNET_MQ_Envelope *e;
564 struct ClientPhoneRegisterMessage *reg; 559 struct ClientPhoneRegisterMessage *reg;
560 struct GNUNET_CLIENT_Connection *client;
565 561
566 clean_up_callers (phone); 562 clean_up_callers (phone);
567 if (NULL != phone->mq) 563 if (NULL != phone->mq)
@@ -569,16 +565,12 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone)
569 GNUNET_MQ_destroy (phone->mq); 565 GNUNET_MQ_destroy (phone->mq);
570 phone->mq = NULL; 566 phone->mq = NULL;
571 } 567 }
572 if (NULL != phone->client)
573 {
574 GNUNET_CLIENT_disconnect (phone->client);
575 phone->client = NULL;
576 }
577 phone->state = PS_REGISTER; 568 phone->state = PS_REGISTER;
578 phone->client = GNUNET_CLIENT_connect ("conversation", phone->cfg); 569 client = GNUNET_CLIENT_connect ("conversation",
579 if (NULL == phone->client) 570 phone->cfg);
571 if (NULL == client)
580 return; 572 return;
581 phone->mq = GNUNET_MQ_queue_for_connection_client (phone->client, 573 phone->mq = GNUNET_MQ_queue_for_connection_client (client,
582 handlers, 574 handlers,
583 &phone_error_handler, 575 &phone_error_handler,
584 phone); 576 phone);
@@ -644,7 +636,7 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
644 phone->my_record.line = htonl ((uint32_t) line); 636 phone->my_record.line = htonl ((uint32_t) line);
645 phone->my_record.version = htonl (0); 637 phone->my_record.version = htonl (0);
646 reconnect_phone (phone); 638 reconnect_phone (phone);
647 if ( (NULL == phone->client) || 639 if ( (NULL == phone->mq) ||
648 (NULL == phone->ns) ) 640 (NULL == phone->ns) )
649 { 641 {
650 GNUNET_break (0); 642 GNUNET_break (0);
@@ -764,11 +756,6 @@ GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone)
764 GNUNET_MQ_destroy (phone->mq); 756 GNUNET_MQ_destroy (phone->mq);
765 phone->mq = NULL; 757 phone->mq = NULL;
766 } 758 }
767 if (NULL != phone->client)
768 {
769 GNUNET_CLIENT_disconnect (phone->client);
770 phone->client = NULL;
771 }
772 GNUNET_free (phone); 759 GNUNET_free (phone);
773} 760}
774 761
diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h
index 4bac4d5f3..aa32b55ad 100644
--- a/src/include/gnunet_client_lib.h
+++ b/src/include/gnunet_client_lib.h
@@ -59,26 +59,26 @@ struct GNUNET_CLIENT_Connection;
59 * @param handlers handlers for receiving messages, can be NULL 59 * @param handlers handlers for receiving messages, can be NULL
60 * @param error_handler error handler 60 * @param error_handler error handler
61 * @param error_handler_cls closure for the @a error_handler 61 * @param error_handler_cls closure for the @a error_handler
62 * @return the message queue 62 * @return the message queue, NULL on error
63 */ 63 */
64struct GNUNET_MQ_Handle * 64struct GNUNET_MQ_Handle *
65GNUNET_CLIENT_connect2 (const char *service_name, 65GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
66 const struct GNUNET_CONFIGURATION_Handle *cfg, 66 const char *service_name,
67 const struct GNUNET_MQ_MessageHandler *handlers, 67 const struct GNUNET_MQ_MessageHandler *handlers,
68 GNUNET_MQ_ErrorHandler error_handler, 68 GNUNET_MQ_ErrorHandler error_handler,
69 void *error_handler_cls); 69 void *error_handler_cls);
70 70
71 71
72/** 72/**
73 * Create a message queue for a GNUNET_CLIENT_Connection. 73 * Create a message queue for a GNUNET_CLIENT_Connection.
74 * If handlers are specfied, receive messages from the connection. 74 * If handlers are specfied, receive messages from the connection.
75 * 75 *
76 * @param connection the client connection 76 * @param connection the client connection, taken over and freed by the MQ
77 * @param handlers handlers for receiving messages 77 * @param handlers handlers for receiving messages
78 * @param error_handler error handler 78 * @param error_handler error handler
79 * @param error_handler_cls closure for the @a error_handler 79 * @param error_handler_cls closure for the @a error_handler
80 * @return the message queue 80 * @return the message queue
81 * @deprecated use #GNUNET_CLIENT_connect2 81 * @deprecated use #GNUNET_CLIENT_connecT
82 */ 82 */
83struct GNUNET_MQ_Handle * 83struct GNUNET_MQ_Handle *
84GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection, 84GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection,
@@ -189,8 +189,7 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client,
189 * @deprecated 189 * @deprecated
190 */ 190 */
191void 191void
192GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle 192GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th);
193 *th);
194 193
195 194
196/** 195/**
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c
index b1f4695ec..b08de8229 100644
--- a/src/peerstore/peerstore_api.c
+++ b/src/peerstore/peerstore_api.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2013-2014 GNUnet e.V. 3 Copyright (C) 2013-2016 GNUnet e.V.
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
@@ -46,11 +46,6 @@ struct GNUNET_PEERSTORE_Handle
46 const struct GNUNET_CONFIGURATION_Handle *cfg; 46 const struct GNUNET_CONFIGURATION_Handle *cfg;
47 47
48 /** 48 /**
49 * Connection to the service.
50 */
51 struct GNUNET_CLIENT_Connection *client;
52
53 /**
54 * Message queue 49 * Message queue
55 */ 50 */
56 struct GNUNET_MQ_Handle *mq; 51 struct GNUNET_MQ_Handle *mq;
@@ -385,11 +380,6 @@ do_disconnect (struct GNUNET_PEERSTORE_Handle *h)
385 GNUNET_MQ_destroy (h->mq); 380 GNUNET_MQ_destroy (h->mq);
386 h->mq = NULL; 381 h->mq = NULL;
387 } 382 }
388 if (NULL != h->client)
389 {
390 GNUNET_CLIENT_disconnect (h->client);
391 h->client = NULL;
392 }
393 GNUNET_free (h); 383 GNUNET_free (h);
394} 384}
395 385
@@ -406,16 +396,14 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
406 struct GNUNET_PEERSTORE_Handle *h; 396 struct GNUNET_PEERSTORE_Handle *h;
407 397
408 h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); 398 h = GNUNET_new (struct GNUNET_PEERSTORE_Handle);
409 399 h->cfg = cfg;
410 h->client = GNUNET_CLIENT_connect ("peerstore", cfg); 400 h->disconnecting = GNUNET_NO;
411 if (NULL == h->client) 401 reconnect (h);
402 if (NULL == h->mq)
412 { 403 {
413 GNUNET_free (h); 404 GNUNET_free (h);
414 return NULL; 405 return NULL;
415 } 406 }
416 h->cfg = cfg;
417 h->disconnecting = GNUNET_NO;
418 reconnect (h);
419 return h; 407 return h;
420} 408}
421 409
@@ -819,6 +807,7 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h)
819 void *icb_cls; 807 void *icb_cls;
820 struct GNUNET_PEERSTORE_StoreContext *sc; 808 struct GNUNET_PEERSTORE_StoreContext *sc;
821 struct GNUNET_MQ_Envelope *ev; 809 struct GNUNET_MQ_Envelope *ev;
810 struct GNUNET_CLIENT_Connection *client;
822 811
823 LOG (GNUNET_ERROR_TYPE_DEBUG, 812 LOG (GNUNET_ERROR_TYPE_DEBUG,
824 "Reconnecting...\n"); 813 "Reconnecting...\n");
@@ -841,15 +830,11 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h)
841 GNUNET_MQ_destroy (h->mq); 830 GNUNET_MQ_destroy (h->mq);
842 h->mq = NULL; 831 h->mq = NULL;
843 } 832 }
844 if (NULL != h->client) 833 client = GNUNET_CLIENT_connect ("peerstore",
845 { 834 h->cfg);
846 GNUNET_CLIENT_disconnect (h->client); 835 if (NULL == client)
847 h->client = NULL; 836 return;
848 } 837 h->mq = GNUNET_MQ_queue_for_connection_client (client,
849 h->client = GNUNET_CLIENT_connect ("peerstore",
850 h->cfg);
851 GNUNET_assert (NULL != h->client);
852 h->mq = GNUNET_MQ_queue_for_connection_client (h->client,
853 mq_handlers, 838 mq_handlers,
854 &handle_client_error, h); 839 &handle_client_error, h);
855 LOG (GNUNET_ERROR_TYPE_DEBUG, 840 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index b055f6265..b52e9da51 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -40,12 +40,7 @@ struct GNUNET_RPS_Handle
40 /** 40 /**
41 * The handle to the client configuration. 41 * The handle to the client configuration.
42 */ 42 */
43 struct GNUNET_CONFIGURATION_Handle *cfg; 43 const struct GNUNET_CONFIGURATION_Handle *cfg;
44
45 /**
46 * The connection to the client.
47 */
48 struct GNUNET_CLIENT_Connection *conn;
49 44
50 /** 45 /**
51 * The message queue to the client. 46 * The message queue to the client.
@@ -214,6 +209,8 @@ mq_error_handler (void *cls,
214static void 209static void
215reconnect (struct GNUNET_RPS_Handle *h) 210reconnect (struct GNUNET_RPS_Handle *h)
216{ 211{
212 struct GNUNET_CLIENT_Connection *conn;
213
217 GNUNET_MQ_hd_var_size (reply, 214 GNUNET_MQ_hd_var_size (reply,
218 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, 215 GNUNET_MESSAGE_TYPE_RPS_CS_REPLY,
219 struct GNUNET_RPS_CS_ReplyMessage); 216 struct GNUNET_RPS_CS_ReplyMessage);
@@ -224,11 +221,10 @@ reconnect (struct GNUNET_RPS_Handle *h)
224 221
225 if (NULL != h->mq) 222 if (NULL != h->mq)
226 GNUNET_MQ_destroy (h->mq); 223 GNUNET_MQ_destroy (h->mq);
227 if (NULL != h->conn) 224 conn = GNUNET_CLIENT_connect ("rps", h->cfg);
228 GNUNET_CLIENT_disconnect (h->conn); 225 if (NULL == conn)
229 h->conn = GNUNET_CLIENT_connect ("rps", h->cfg); 226 return;
230 GNUNET_assert (NULL != h->conn); 227 h->mq = GNUNET_MQ_queue_for_connection_client (conn,
231 h->mq = GNUNET_MQ_queue_for_connection_client (h->conn,
232 mq_handlers, 228 mq_handlers,
233 &mq_error_handler, 229 &mq_error_handler,
234 h); 230 h);
@@ -241,15 +237,19 @@ reconnect (struct GNUNET_RPS_Handle *h)
241 * @param cfg configuration to use 237 * @param cfg configuration to use
242 * @return a handle to the service 238 * @return a handle to the service
243 */ 239 */
244 struct GNUNET_RPS_Handle * 240struct GNUNET_RPS_Handle *
245GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 241GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
246{ 242{
247 struct GNUNET_RPS_Handle *h; 243 struct GNUNET_RPS_Handle *h;
248 //struct GNUNET_RPS_Request_Handle *rh;
249 244
250 h = GNUNET_new(struct GNUNET_RPS_Handle); 245 h = GNUNET_new (struct GNUNET_RPS_Handle);
251 h->cfg = GNUNET_CONFIGURATION_dup (cfg); 246 h->cfg = cfg;
252 reconnect (h); 247 reconnect (h);
248 if (NULL == h->mq)
249 {
250 GNUNET_free (h);
251 return NULL;
252 }
253 h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4); 253 h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4);
254 return h; 254 return h;
255} 255}
@@ -264,7 +264,7 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
264 * @param cls closure given to the callback 264 * @param cls closure given to the callback
265 * @return a handle to cancel this request 265 * @return a handle to cancel this request
266 */ 266 */
267 struct GNUNET_RPS_Request_Handle * 267struct GNUNET_RPS_Request_Handle *
268GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, 268GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
269 uint32_t num_req_peers, 269 uint32_t num_req_peers,
270 GNUNET_RPS_NotifyReadyCB ready_cb, 270 GNUNET_RPS_NotifyReadyCB ready_cb,
@@ -304,7 +304,7 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle,
304 * @param n number of peers to seed 304 * @param n number of peers to seed
305 * @param ids the ids of the peers seeded 305 * @param ids the ids of the peers seeded
306 */ 306 */
307 void 307void
308GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, 308GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
309 uint32_t n, 309 uint32_t n,
310 const struct GNUNET_PeerIdentity *ids) 310 const struct GNUNET_PeerIdentity *ids)
@@ -375,7 +375,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
375 * if @type is 2 the last id is the id of the 375 * if @type is 2 the last id is the id of the
376 * peer to be isolated from the rest 376 * peer to be isolated from the rest
377 */ 377 */
378 void 378void
379GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, 379GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
380 uint32_t type, 380 uint32_t type,
381 uint32_t num_peers, 381 uint32_t num_peers,
@@ -456,7 +456,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
456 * 456 *
457 * @param rh request handle of request to cancle 457 * @param rh request handle of request to cancle
458 */ 458 */
459 void 459void
460GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) 460GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
461{ 461{
462 struct GNUNET_RPS_Handle *h; 462 struct GNUNET_RPS_Handle *h;
@@ -482,12 +482,9 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh)
482 * 482 *
483 * @param h the handle to the rps service 483 * @param h the handle to the rps service
484 */ 484 */
485 void 485void
486GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) 486GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
487{ 487{
488 if (NULL != h->conn)
489 GNUNET_CLIENT_disconnect (h->conn);
490 GNUNET_CONFIGURATION_destroy (h->cfg);
491 GNUNET_MQ_destroy (h->mq); 488 GNUNET_MQ_destroy (h->mq);
492 if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers)) 489 if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers))
493 LOG (GNUNET_ERROR_TYPE_WARNING, 490 LOG (GNUNET_ERROR_TYPE_WARNING,
diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c
index 441164850..e268fc56f 100644
--- a/src/secretsharing/secretsharing_api.c
+++ b/src/secretsharing/secretsharing_api.c
@@ -38,10 +38,6 @@
38 */ 38 */
39struct GNUNET_SECRETSHARING_Session 39struct GNUNET_SECRETSHARING_Session
40{ 40{
41 /**
42 * Client connected to the secretsharing service.
43 */
44 struct GNUNET_CLIENT_Connection *client;
45 41
46 /** 42 /**
47 * Message queue for @e client. 43 * Message queue for @e client.
@@ -65,10 +61,6 @@ struct GNUNET_SECRETSHARING_Session
65 */ 61 */
66struct GNUNET_SECRETSHARING_DecryptionHandle 62struct GNUNET_SECRETSHARING_DecryptionHandle
67{ 63{
68 /**
69 * Client connected to the secretsharing service.
70 */
71 struct GNUNET_CLIENT_Connection *client;
72 64
73 /** 65 /**
74 * Message queue for @e client. 66 * Message queue for @e client.
@@ -226,8 +218,6 @@ GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s)
226{ 218{
227 GNUNET_MQ_destroy (s->mq); 219 GNUNET_MQ_destroy (s->mq);
228 s->mq = NULL; 220 s->mq = NULL;
229 GNUNET_CLIENT_disconnect (s->client);
230 s->client = NULL;
231 GNUNET_free (s); 221 GNUNET_free (s);
232} 222}
233 223
@@ -270,9 +260,10 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
270 }; 260 };
271 struct GNUNET_MQ_Envelope *ev; 261 struct GNUNET_MQ_Envelope *ev;
272 struct GNUNET_SECRETSHARING_CreateMessage *msg; 262 struct GNUNET_SECRETSHARING_CreateMessage *msg;
263 struct GNUNET_CLIENT_Connection *client;
273 264
274 s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); 265 client = GNUNET_CLIENT_connect ("secretsharing", cfg);
275 if (NULL == s->client) 266 if (NULL == client)
276 { 267 {
277 /* secretsharing not configured correctly */ 268 /* secretsharing not configured correctly */
278 GNUNET_break (0); 269 GNUNET_break (0);
@@ -281,7 +272,8 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c
281 } 272 }
282 s->secret_ready_cb = cb; 273 s->secret_ready_cb = cb;
283 s->secret_ready_cls = cls; 274 s->secret_ready_cls = cls;
284 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, 275 s->mq = GNUNET_MQ_queue_for_connection_client (client,
276 mq_handlers,
285 &handle_session_client_error, 277 &handle_session_client_error,
286 s); 278 s);
287 GNUNET_assert (NULL != s->mq); 279 GNUNET_assert (NULL != s->mq);
@@ -356,13 +348,16 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg,
356 struct GNUNET_MQ_Envelope *ev; 348 struct GNUNET_MQ_Envelope *ev;
357 struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg; 349 struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg;
358 size_t share_size; 350 size_t share_size;
351 struct GNUNET_CLIENT_Connection *client;
359 352
360 s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); 353 client = GNUNET_CLIENT_connect ("secretsharing", cfg);
354 if (NULL == client)
355 return NULL;
361 s->decrypt_cb = decrypt_cb; 356 s->decrypt_cb = decrypt_cb;
362 s->decrypt_cls = decrypt_cb_cls; 357 s->decrypt_cls = decrypt_cb_cls;
363 GNUNET_assert (NULL != s->client);
364 358
365 s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, 359 s->mq = GNUNET_MQ_queue_for_connection_client (client,
360 mq_handlers,
366 &handle_decrypt_client_error, 361 &handle_decrypt_client_error,
367 s); 362 s);
368 GNUNET_assert (NULL != s->mq); 363 GNUNET_assert (NULL != s->mq);
@@ -505,8 +500,6 @@ GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandl
505{ 500{
506 GNUNET_MQ_destroy (dh->mq); 501 GNUNET_MQ_destroy (dh->mq);
507 dh->mq = NULL; 502 dh->mq = NULL;
508 GNUNET_CLIENT_disconnect (dh->client);
509 dh->client = NULL;
510 GNUNET_free (dh); 503 GNUNET_free (dh);
511} 504}
512 505
diff --git a/src/set/set_api.c b/src/set/set_api.c
index 343b5f881..826b6a63c 100644
--- a/src/set/set_api.c
+++ b/src/set/set_api.c
@@ -26,7 +26,6 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h" 28#include "gnunet_protocols.h"
29#include "gnunet_client_lib.h"
30#include "gnunet_set_service.h" 29#include "gnunet_set_service.h"
31#include "set.h" 30#include "set.h"
32 31
@@ -50,11 +49,6 @@ struct SetCopyRequest
50struct GNUNET_SET_Handle 49struct GNUNET_SET_Handle
51{ 50{
52 /** 51 /**
53 * Client connected to the set service.
54 */
55 struct GNUNET_CLIENT_Connection *client;
56
57 /**
58 * Message queue for @e client. 52 * Message queue for @e client.
59 */ 53 */
60 struct GNUNET_MQ_Handle *mq; 54 struct GNUNET_MQ_Handle *mq;
@@ -189,10 +183,6 @@ struct GNUNET_SET_OperationHandle
189 */ 183 */
190struct GNUNET_SET_ListenHandle 184struct GNUNET_SET_ListenHandle
191{ 185{
192 /**
193 * Connection to the service.
194 */
195 struct GNUNET_CLIENT_Connection *client;
196 186
197 /** 187 /**
198 * Message queue for the client. 188 * Message queue for the client.
@@ -298,7 +288,7 @@ check_iter_element (void *cls,
298 /* minimum size was already checked, everything else is OK! */ 288 /* minimum size was already checked, everything else is OK! */
299 return GNUNET_OK; 289 return GNUNET_OK;
300} 290}
301 291
302 292
303/** 293/**
304 * Handle element for iteration over the set. Notifies the 294 * Handle element for iteration over the set. Notifies the
@@ -313,7 +303,7 @@ check_iter_element (void *cls,
313{ 303{
314 struct GNUNET_SET_Handle *set = cls; 304 struct GNUNET_SET_Handle *set = cls;
315 GNUNET_SET_ElementIterator iter = set->iterator; 305 GNUNET_SET_ElementIterator iter = set->iterator;
316 struct GNUNET_SET_Element element; 306 struct GNUNET_SET_Element element;
317 struct GNUNET_SET_IterAckMessage *ack_msg; 307 struct GNUNET_SET_IterAckMessage *ack_msg;
318 struct GNUNET_MQ_Envelope *ev; 308 struct GNUNET_MQ_Envelope *ev;
319 uint16_t msize; 309 uint16_t msize;
@@ -534,7 +524,7 @@ handle_client_set_error (void *cls,
534{ 524{
535 struct GNUNET_SET_Handle *set = cls; 525 struct GNUNET_SET_Handle *set = cls;
536 GNUNET_SET_ElementIterator iter = set->iterator; 526 GNUNET_SET_ElementIterator iter = set->iterator;
537 527
538 LOG (GNUNET_ERROR_TYPE_DEBUG, 528 LOG (GNUNET_ERROR_TYPE_DEBUG,
539 "Handling client set error %d\n", 529 "Handling client set error %d\n",
540 error); 530 error);
@@ -589,15 +579,16 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg,
589 struct GNUNET_MQ_Envelope *mqm; 579 struct GNUNET_MQ_Envelope *mqm;
590 struct GNUNET_SET_CreateMessage *create_msg; 580 struct GNUNET_SET_CreateMessage *create_msg;
591 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; 581 struct GNUNET_SET_CopyLazyConnectMessage *copy_msg;
582 struct GNUNET_CLIENT_Connection *client;
592 583
593 set->cfg = cfg; 584 set->cfg = cfg;
594 set->client = GNUNET_CLIENT_connect ("set", cfg); 585 client = GNUNET_CLIENT_connect ("set", cfg);
595 if (NULL == set->client) 586 if (NULL == client)
596 { 587 {
597 GNUNET_free (set); 588 GNUNET_free (set);
598 return NULL; 589 return NULL;
599 } 590 }
600 set->mq = GNUNET_MQ_queue_for_connection_client (set->client, 591 set->mq = GNUNET_MQ_queue_for_connection_client (client,
601 mq_handlers, 592 mq_handlers,
602 &handle_client_set_error, 593 &handle_client_set_error,
603 set); 594 set);
@@ -750,11 +741,6 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set)
750 } 741 }
751 LOG (GNUNET_ERROR_TYPE_DEBUG, 742 LOG (GNUNET_ERROR_TYPE_DEBUG,
752 "Really destroying set\n"); 743 "Really destroying set\n");
753 if (NULL != set->client)
754 {
755 GNUNET_CLIENT_disconnect (set->client);
756 set->client = NULL;
757 }
758 if (NULL != set->mq) 744 if (NULL != set->mq)
759 { 745 {
760 GNUNET_MQ_destroy (set->mq); 746 GNUNET_MQ_destroy (set->mq);
@@ -893,8 +879,6 @@ handle_client_listener_error (void *cls,
893 LOG (GNUNET_ERROR_TYPE_DEBUG, 879 LOG (GNUNET_ERROR_TYPE_DEBUG,
894 "Listener broke down (%d), re-connecting\n", 880 "Listener broke down (%d), re-connecting\n",
895 (int) error); 881 (int) error);
896 GNUNET_CLIENT_disconnect (lh->client);
897 lh->client = NULL;
898 GNUNET_MQ_destroy (lh->mq); 882 GNUNET_MQ_destroy (lh->mq);
899 lh->mq = NULL; 883 lh->mq = NULL;
900 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, 884 lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff,
@@ -911,7 +895,7 @@ handle_client_listener_error (void *cls,
911 */ 895 */
912static void 896static void
913listen_connect (void *cls) 897listen_connect (void *cls)
914{ 898{
915 GNUNET_MQ_hd_var_size (request, 899 GNUNET_MQ_hd_var_size (request,
916 GNUNET_MESSAGE_TYPE_SET_REQUEST, 900 GNUNET_MESSAGE_TYPE_SET_REQUEST,
917 struct GNUNET_SET_RequestMessage); 901 struct GNUNET_SET_RequestMessage);
@@ -922,14 +906,14 @@ listen_connect (void *cls)
922 }; 906 };
923 struct GNUNET_MQ_Envelope *mqm; 907 struct GNUNET_MQ_Envelope *mqm;
924 struct GNUNET_SET_ListenMessage *msg; 908 struct GNUNET_SET_ListenMessage *msg;
909 struct GNUNET_CLIENT_Connection *client;
925 910
926 lh->reconnect_task = NULL; 911 lh->reconnect_task = NULL;
927 GNUNET_assert (NULL == lh->client);
928 lh->client = GNUNET_CLIENT_connect ("set", lh->cfg);
929 if (NULL == lh->client)
930 return;
931 GNUNET_assert (NULL == lh->mq); 912 GNUNET_assert (NULL == lh->mq);
932 lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client, 913 client = GNUNET_CLIENT_connect ("set", lh->cfg);
914 if (NULL == client)
915 return;
916 lh->mq = GNUNET_MQ_queue_for_connection_client (client,
933 mq_handlers, 917 mq_handlers,
934 &handle_client_listener_error, 918 &handle_client_listener_error,
935 lh); 919 lh);
@@ -969,7 +953,7 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg,
969 lh->app_id = *app_id; 953 lh->app_id = *app_id;
970 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 954 lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
971 listen_connect (lh); 955 listen_connect (lh);
972 if (NULL == lh->client) 956 if (NULL == lh->mq)
973 { 957 {
974 GNUNET_free (lh); 958 GNUNET_free (lh);
975 return NULL; 959 return NULL;
@@ -993,11 +977,6 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh)
993 GNUNET_MQ_destroy (lh->mq); 977 GNUNET_MQ_destroy (lh->mq);
994 lh->mq = NULL; 978 lh->mq = NULL;
995 } 979 }
996 if (NULL != lh->client)
997 {
998 GNUNET_CLIENT_disconnect (lh->client);
999 lh->client = NULL;
1000 }
1001 if (NULL != lh->reconnect_task) 980 if (NULL != lh->reconnect_task)
1002 { 981 {
1003 GNUNET_SCHEDULER_cancel (lh->reconnect_task); 982 GNUNET_SCHEDULER_cancel (lh->reconnect_task);
diff --git a/src/util/client.c b/src/util/client.c
index d00e8bbd0..e30ce6589 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -404,6 +404,36 @@ do_connect (const char *service_name,
404 404
405 405
406/** 406/**
407 * Create a message queue to connect to a GNUnet service.
408 * If handlers are specfied, receive messages from the connection.
409 *
410 * @param connection the client connection
411 * @param handlers handlers for receiving messages, can be NULL
412 * @param error_handler error handler
413 * @param error_handler_cls closure for the @a error_handler
414 * @return the message queue, NULL on error
415 */
416struct GNUNET_MQ_Handle *
417GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg,
418 const char *service_name,
419 const struct GNUNET_MQ_MessageHandler *handlers,
420 GNUNET_MQ_ErrorHandler error_handler,
421 void *error_handler_cls)
422{
423 struct GNUNET_CLIENT_Connection *c;
424
425 c = GNUNET_CLIENT_connect (service_name,
426 cfg);
427 if (NULL == c)
428 return NULL;
429 return GNUNET_MQ_queue_for_connection_client (c,
430 handlers,
431 error_handler,
432 error_handler_cls);
433}
434
435
436/**
407 * Get a connection with a service. 437 * Get a connection with a service.
408 * 438 *
409 * @param service_name name of the service 439 * @param service_name name of the service
diff --git a/src/util/mq.c b/src/util/mq.c
index 4170338ad..c14b4b91d 100644
--- a/src/util/mq.c
+++ b/src/util/mq.c
@@ -206,7 +206,7 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq,
206 const struct GNUNET_MQ_MessageHandler *handler; 206 const struct GNUNET_MQ_MessageHandler *handler;
207 int handled = GNUNET_NO; 207 int handled = GNUNET_NO;
208 uint16_t ms = ntohs (mh->size); 208 uint16_t ms = ntohs (mh->size);
209 209
210 if (NULL == mq->handlers) 210 if (NULL == mq->handlers)
211 goto done; 211 goto done;
212 for (handler = mq->handlers; NULL != handler->cb; handler++) 212 for (handler = mq->handlers; NULL != handler->cb; handler++)
@@ -665,6 +665,9 @@ static void
665connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, 665connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq,
666 void *impl_state) 666 void *impl_state)
667{ 667{
668 struct ClientConnectionState *state = impl_state;
669
670 GNUNET_CLIENT_disconnect (state->connection);
668 GNUNET_free (impl_state); 671 GNUNET_free (impl_state);
669} 672}
670 673
@@ -692,6 +695,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq,
692 void *impl_state) 695 void *impl_state)
693{ 696{
694 struct ClientConnectionState *state = impl_state; 697 struct ClientConnectionState *state = impl_state;
698
695 GNUNET_assert (NULL != state->th); 699 GNUNET_assert (NULL != state->th);
696 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); 700 GNUNET_CLIENT_notify_transmit_ready_cancel (state->th);
697 state->th = NULL; 701 state->th = NULL;
@@ -723,9 +727,9 @@ GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connecti
723 state = GNUNET_new (struct ClientConnectionState); 727 state = GNUNET_new (struct ClientConnectionState);
724 state->connection = connection; 728 state->connection = connection;
725 mq->impl_state = state; 729 mq->impl_state = state;
726 mq->send_impl = connection_client_send_impl; 730 mq->send_impl = &connection_client_send_impl;
727 mq->destroy_impl = connection_client_destroy_impl; 731 mq->destroy_impl = &connection_client_destroy_impl;
728 mq->cancel_impl = connection_client_cancel_impl; 732 mq->cancel_impl = &connection_client_cancel_impl;
729 if (NULL != handlers) 733 if (NULL != handlers)
730 state->receive_requested = GNUNET_YES; 734 state->receive_requested = GNUNET_YES;
731 735
diff --git a/src/util/test_mq_client.c b/src/util/test_mq_client.c
index f894c3912..27458ec0a 100644
--- a/src/util/test_mq_client.c
+++ b/src/util/test_mq_client.c
@@ -32,8 +32,6 @@
32 32
33static struct GNUNET_SERVER_Handle *server; 33static struct GNUNET_SERVER_Handle *server;
34 34
35static struct GNUNET_CLIENT_Connection *client;
36
37static struct GNUNET_CONFIGURATION_Handle *cfg; 35static struct GNUNET_CONFIGURATION_Handle *cfg;
38 36
39static int ok; 37static int ok;
@@ -44,13 +42,15 @@ static int received = 0;
44 42
45 43
46static void 44static void
47recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, 45recv_cb (void *cls,
46 struct GNUNET_SERVER_Client *argclient,
48 const struct GNUNET_MessageHeader *message) 47 const struct GNUNET_MessageHeader *message)
49{ 48{
50 received++; 49 received++;
51 if (received == 2) 50 if (received == 2)
52 { 51 {
53 GNUNET_SERVER_receive_done (argclient, GNUNET_NO); 52 GNUNET_SERVER_receive_done (argclient,
53 GNUNET_NO);
54 return; 54 return;
55 } 55 }
56 56
@@ -79,7 +79,8 @@ clean_up (void *cls)
79 * @param client identification of the client 79 * @param client identification of the client
80 */ 80 */
81static void 81static void
82notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 82notify_disconnect (void *cls,
83 struct GNUNET_SERVER_Client *client)
83{ 84{
84 if (client == NULL) 85 if (client == NULL)
85 return; 86 return;
@@ -110,11 +111,15 @@ send_trap_cb (void *cls)
110 111
111 112
112static void 113static void
113test_mq (struct GNUNET_CLIENT_Connection *client) 114test_mq ()
114{ 115{
116 struct GNUNET_CLIENT_Connection *client;
115 struct GNUNET_MQ_Handle *mq; 117 struct GNUNET_MQ_Handle *mq;
116 struct GNUNET_MQ_Envelope *mqm; 118 struct GNUNET_MQ_Envelope *mqm;
117 119
120 client = GNUNET_CLIENT_connect ("test", cfg);
121 GNUNET_assert (client != NULL);
122
118 /* FIXME: test handling responses */ 123 /* FIXME: test handling responses */
119 mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL); 124 mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL);
120 125
@@ -122,14 +127,13 @@ test_mq (struct GNUNET_CLIENT_Connection *client)
122 GNUNET_MQ_send (mq, mqm); 127 GNUNET_MQ_send (mq, mqm);
123 128
124 mqm = GNUNET_MQ_msg_header (MY_TYPE); 129 mqm = GNUNET_MQ_msg_header (MY_TYPE);
125 GNUNET_MQ_notify_sent (mqm, send_trap_cb, NULL); 130 GNUNET_MQ_notify_sent (mqm, &send_trap_cb, NULL);
126 GNUNET_MQ_send (mq, mqm); 131 GNUNET_MQ_send (mq, mqm);
127 GNUNET_MQ_send_cancel (mqm); 132 GNUNET_MQ_send_cancel (mqm);
128 133
129 mqm = GNUNET_MQ_msg_header (MY_TYPE); 134 mqm = GNUNET_MQ_msg_header (MY_TYPE);
130 GNUNET_MQ_notify_sent (mqm, send_cb, NULL); 135 GNUNET_MQ_notify_sent (mqm, &send_cb, NULL);
131 GNUNET_MQ_send (mq, mqm); 136 GNUNET_MQ_send (mq, mqm);
132
133} 137}
134 138
135 139
@@ -163,10 +167,7 @@ task (void *cls)
163 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); 167 GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost");
164 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", 168 GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME",
165 "localhost"); 169 "localhost");
166 client = GNUNET_CLIENT_connect ("test", cfg); 170 test_mq ();
167 GNUNET_assert (client != NULL);
168
169 test_mq (client);
170} 171}
171 172
172 173