diff options
-rw-r--r-- | src/ats/ats_api_connectivity.c | 24 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 26 | ||||
-rw-r--r-- | src/consensus/consensus_api.c | 35 | ||||
-rw-r--r-- | src/conversation/conversation_api.c | 25 | ||||
-rw-r--r-- | src/include/gnunet_client_lib.h | 19 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 37 | ||||
-rw-r--r-- | src/rps/rps_api.c | 43 | ||||
-rw-r--r-- | src/secretsharing/secretsharing_api.c | 29 | ||||
-rw-r--r-- | src/set/set_api.c | 49 | ||||
-rw-r--r-- | src/util/client.c | 30 | ||||
-rw-r--r-- | src/util/mq.c | 12 | ||||
-rw-r--r-- | src/util/test_mq_client.c | 27 |
12 files changed, 149 insertions, 207 deletions
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c index 1897e2783e..139f50a814 100644 --- a/src/ats/ats_api_connectivity.c +++ b/src/ats/ats_api_connectivity.c @@ -72,11 +72,6 @@ struct GNUNET_ATS_ConnectivityHandle struct GNUNET_CONTAINER_MultiPeerMap *sug_requests; /** - * Connection to ATS service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * Message queue for sending requests to the ATS service. */ struct GNUNET_MQ_Handle *mq; @@ -130,11 +125,6 @@ force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) GNUNET_MQ_destroy (ch->mq); ch->mq = NULL; } - if (NULL != ch->client) - { - GNUNET_CLIENT_disconnect (ch->client); - ch->client = NULL; - } ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, @@ -203,15 +193,16 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) { { NULL, 0, 0 } }; struct GNUNET_MQ_Envelope *ev; struct ClientStartMessage *init; + struct GNUNET_CLIENT_Connection *client; - GNUNET_assert (NULL == ch->client); - ch->client = GNUNET_CLIENT_connect ("ats", ch->cfg); - if (NULL == ch->client) + GNUNET_assert (NULL == ch->mq); + client = GNUNET_CLIENT_connect ("ats", ch->cfg); + if (NULL == client) { force_reconnect (ch); return; } - ch->mq = GNUNET_MQ_queue_for_connection_client (ch->client, + ch->mq = GNUNET_MQ_queue_for_connection_client (client, handlers, &error_handler, ch); @@ -281,11 +272,6 @@ GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch) GNUNET_MQ_destroy (ch->mq); ch->mq = NULL; } - if (NULL != ch->client) - { - GNUNET_CLIENT_disconnect (ch->client); - ch->client = NULL; - } if (NULL != ch->task) { GNUNET_SCHEDULER_cancel (ch->task); diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index bc730b2486..d7e305950f 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -118,11 +118,6 @@ struct GNUNET_ATS_SchedulingHandle void *suggest_cb_cls; /** - * Connection to ATS service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * Message queue for sending requests to the ATS service. */ struct GNUNET_MQ_Handle *mq; @@ -190,11 +185,6 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) GNUNET_MQ_destroy (sh->mq); sh->mq = NULL; } - if (NULL != sh->client) - { - GNUNET_CLIENT_disconnect (sh->client); - sh->client = NULL; - } sh->suggest_cb (sh->suggest_cb_cls, NULL, NULL, NULL, GNUNET_BANDWIDTH_ZERO, @@ -539,17 +529,18 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) struct ClientStartMessage *init; unsigned int i; struct GNUNET_ATS_AddressRecord *ar; + struct GNUNET_CLIENT_Connection *client; - GNUNET_assert (NULL == sh->client); - sh->client = GNUNET_CLIENT_connect ("ats", - sh->cfg); - if (NULL == sh->client) + GNUNET_assert (NULL == sh->mq); + client = GNUNET_CLIENT_connect ("ats", + sh->cfg); + if (NULL == client) { GNUNET_break (0); force_reconnect (sh); return; } - sh->mq = GNUNET_MQ_queue_for_connection_client (sh->client, + sh->mq = GNUNET_MQ_queue_for_connection_client (client, handlers, &error_handler, sh); @@ -614,11 +605,6 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) GNUNET_MQ_destroy (sh->mq); sh->mq = NULL; } - if (NULL != sh->client) - { - GNUNET_CLIENT_disconnect (sh->client); - sh->client = NULL; - } if (NULL != sh->task) { GNUNET_SCHEDULER_cancel (sh->task); diff --git a/src/consensus/consensus_api.c b/src/consensus/consensus_api.c index 16096c28c8..8653621ecd 100644 --- a/src/consensus/consensus_api.c +++ b/src/consensus/consensus_api.c @@ -45,17 +45,12 @@ struct GNUNET_CONSENSUS_Handle const struct GNUNET_CONFIGURATION_Handle *cfg; /** - * Client connected to the consensus service, may be NULL if not connected. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * Callback for new elements. Not called for elements added locally. */ GNUNET_CONSENSUS_ElementCallback new_element_cb; /** - * Closure for new_element_cb + * Closure for @e new_element_cb */ void *new_element_cls; @@ -75,7 +70,7 @@ struct GNUNET_CONSENSUS_Handle GNUNET_CONSENSUS_ConcludeCallback conclude_cb; /** - * Closure for the conclude callback. + * Closure for the @e conclude_cb callback. */ void *conclude_cls; @@ -156,8 +151,6 @@ handle_conclude_done (void *cls, GNUNET_MQ_destroy (consensus->mq); consensus->mq = NULL; - GNUNET_CLIENT_disconnect (consensus->client); - consensus->client = NULL; GNUNET_assert (NULL != (cc = consensus->conclude_cb)); consensus->conclude_cb = NULL; cc (consensus->conclude_cls); @@ -224,17 +217,22 @@ GNUNET_CONSENSUS_create (const struct GNUNET_CONFIGURATION_Handle *cfg, }; struct GNUNET_CONSENSUS_JoinMessage *join_msg; struct GNUNET_MQ_Envelope *ev; + struct GNUNET_CLIENT_Connection *client; consensus->cfg = cfg; consensus->new_element_cb = new_element_cb; consensus->new_element_cls = new_element_cls; consensus->session_id = *session_id; - consensus->client = GNUNET_CLIENT_connect ("consensus", cfg); - consensus->mq = GNUNET_MQ_queue_for_connection_client (consensus->client, - mq_handlers, mq_error_handler, consensus); - - GNUNET_assert (consensus->client != NULL); - + client = GNUNET_CLIENT_connect ("consensus", cfg); + if (NULL == client) + { + GNUNET_free (consensus); + return NULL; + } + consensus->mq = GNUNET_MQ_queue_for_connection_client (client, + mq_handlers, + &mq_error_handler, + consensus); ev = GNUNET_MQ_msg_extra (join_msg, (num_peers * sizeof (struct GNUNET_PeerIdentity)), GNUNET_MESSAGE_TYPE_CONSENSUS_CLIENT_JOIN); @@ -342,10 +340,7 @@ GNUNET_CONSENSUS_destroy (struct GNUNET_CONSENSUS_Handle *consensus) GNUNET_MQ_destroy (consensus->mq); consensus->mq = NULL; } - if (NULL != consensus->client) - { - GNUNET_CLIENT_disconnect (consensus->client); - consensus->client = NULL; - } GNUNET_free (consensus); } + +/* end of consensus_api.c */ diff --git a/src/conversation/conversation_api.c b/src/conversation/conversation_api.c index a9dc1f27f3..3e0db67ea2 100644 --- a/src/conversation/conversation_api.c +++ b/src/conversation/conversation_api.c @@ -161,11 +161,6 @@ struct GNUNET_CONVERSATION_Phone const struct GNUNET_CONFIGURATION_Handle *cfg; /** - * Handle to talk with CONVERSATION service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * We keep all callers in a DLL. */ struct GNUNET_CONVERSATION_Caller *caller_head; @@ -562,6 +557,7 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) }; struct GNUNET_MQ_Envelope *e; struct ClientPhoneRegisterMessage *reg; + struct GNUNET_CLIENT_Connection *client; clean_up_callers (phone); if (NULL != phone->mq) @@ -569,16 +565,12 @@ reconnect_phone (struct GNUNET_CONVERSATION_Phone *phone) GNUNET_MQ_destroy (phone->mq); phone->mq = NULL; } - if (NULL != phone->client) - { - GNUNET_CLIENT_disconnect (phone->client); - phone->client = NULL; - } phone->state = PS_REGISTER; - phone->client = GNUNET_CLIENT_connect ("conversation", phone->cfg); - if (NULL == phone->client) + client = GNUNET_CLIENT_connect ("conversation", + phone->cfg); + if (NULL == client) return; - phone->mq = GNUNET_MQ_queue_for_connection_client (phone->client, + phone->mq = GNUNET_MQ_queue_for_connection_client (client, handlers, &phone_error_handler, phone); @@ -644,7 +636,7 @@ GNUNET_CONVERSATION_phone_create (const struct GNUNET_CONFIGURATION_Handle *cfg, phone->my_record.line = htonl ((uint32_t) line); phone->my_record.version = htonl (0); reconnect_phone (phone); - if ( (NULL == phone->client) || + if ( (NULL == phone->mq) || (NULL == phone->ns) ) { GNUNET_break (0); @@ -764,11 +756,6 @@ GNUNET_CONVERSATION_phone_destroy (struct GNUNET_CONVERSATION_Phone *phone) GNUNET_MQ_destroy (phone->mq); phone->mq = NULL; } - if (NULL != phone->client) - { - GNUNET_CLIENT_disconnect (phone->client); - phone->client = NULL; - } GNUNET_free (phone); } diff --git a/src/include/gnunet_client_lib.h b/src/include/gnunet_client_lib.h index 4bac4d5f36..aa32b55adc 100644 --- a/src/include/gnunet_client_lib.h +++ b/src/include/gnunet_client_lib.h @@ -59,26 +59,26 @@ struct GNUNET_CLIENT_Connection; * @param handlers handlers for receiving messages, can be NULL * @param error_handler error handler * @param error_handler_cls closure for the @a error_handler - * @return the message queue + * @return the message queue, NULL on error */ struct GNUNET_MQ_Handle * -GNUNET_CLIENT_connect2 (const char *service_name, - const struct GNUNET_CONFIGURATION_Handle *cfg, - const struct GNUNET_MQ_MessageHandler *handlers, - GNUNET_MQ_ErrorHandler error_handler, - void *error_handler_cls); +GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *service_name, + const struct GNUNET_MQ_MessageHandler *handlers, + GNUNET_MQ_ErrorHandler error_handler, + void *error_handler_cls); /** * Create a message queue for a GNUNET_CLIENT_Connection. * If handlers are specfied, receive messages from the connection. * - * @param connection the client connection + * @param connection the client connection, taken over and freed by the MQ * @param handlers handlers for receiving messages * @param error_handler error handler * @param error_handler_cls closure for the @a error_handler * @return the message queue - * @deprecated use #GNUNET_CLIENT_connect2 + * @deprecated use #GNUNET_CLIENT_connecT */ struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connection, @@ -189,8 +189,7 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *client, * @deprecated */ void -GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle - *th); +GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th); /** diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index b1f4695ec0..b08de82297 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - Copyright (C) 2013-2014 GNUnet e.V. + Copyright (C) 2013-2016 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -46,11 +46,6 @@ struct GNUNET_PEERSTORE_Handle const struct GNUNET_CONFIGURATION_Handle *cfg; /** - * Connection to the service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * Message queue */ struct GNUNET_MQ_Handle *mq; @@ -385,11 +380,6 @@ do_disconnect (struct GNUNET_PEERSTORE_Handle *h) GNUNET_MQ_destroy (h->mq); h->mq = NULL; } - if (NULL != h->client) - { - GNUNET_CLIENT_disconnect (h->client); - h->client = NULL; - } GNUNET_free (h); } @@ -406,16 +396,14 @@ GNUNET_PEERSTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) struct GNUNET_PEERSTORE_Handle *h; h = GNUNET_new (struct GNUNET_PEERSTORE_Handle); - - h->client = GNUNET_CLIENT_connect ("peerstore", cfg); - if (NULL == h->client) + h->cfg = cfg; + h->disconnecting = GNUNET_NO; + reconnect (h); + if (NULL == h->mq) { GNUNET_free (h); return NULL; } - h->cfg = cfg; - h->disconnecting = GNUNET_NO; - reconnect (h); return h; } @@ -819,6 +807,7 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) void *icb_cls; struct GNUNET_PEERSTORE_StoreContext *sc; struct GNUNET_MQ_Envelope *ev; + struct GNUNET_CLIENT_Connection *client; LOG (GNUNET_ERROR_TYPE_DEBUG, "Reconnecting...\n"); @@ -841,15 +830,11 @@ reconnect (struct GNUNET_PEERSTORE_Handle *h) GNUNET_MQ_destroy (h->mq); h->mq = NULL; } - if (NULL != h->client) - { - GNUNET_CLIENT_disconnect (h->client); - h->client = NULL; - } - h->client = GNUNET_CLIENT_connect ("peerstore", - h->cfg); - GNUNET_assert (NULL != h->client); - h->mq = GNUNET_MQ_queue_for_connection_client (h->client, + client = GNUNET_CLIENT_connect ("peerstore", + h->cfg); + if (NULL == client) + return; + h->mq = GNUNET_MQ_queue_for_connection_client (client, mq_handlers, &handle_client_error, h); LOG (GNUNET_ERROR_TYPE_DEBUG, diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index b055f62653..b52e9da51b 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c @@ -40,12 +40,7 @@ struct GNUNET_RPS_Handle /** * The handle to the client configuration. */ - struct GNUNET_CONFIGURATION_Handle *cfg; - - /** - * The connection to the client. - */ - struct GNUNET_CLIENT_Connection *conn; + const struct GNUNET_CONFIGURATION_Handle *cfg; /** * The message queue to the client. @@ -214,6 +209,8 @@ mq_error_handler (void *cls, static void reconnect (struct GNUNET_RPS_Handle *h) { + struct GNUNET_CLIENT_Connection *conn; + GNUNET_MQ_hd_var_size (reply, GNUNET_MESSAGE_TYPE_RPS_CS_REPLY, struct GNUNET_RPS_CS_ReplyMessage); @@ -224,11 +221,10 @@ reconnect (struct GNUNET_RPS_Handle *h) if (NULL != h->mq) GNUNET_MQ_destroy (h->mq); - if (NULL != h->conn) - GNUNET_CLIENT_disconnect (h->conn); - h->conn = GNUNET_CLIENT_connect ("rps", h->cfg); - GNUNET_assert (NULL != h->conn); - h->mq = GNUNET_MQ_queue_for_connection_client (h->conn, + conn = GNUNET_CLIENT_connect ("rps", h->cfg); + if (NULL == conn) + return; + h->mq = GNUNET_MQ_queue_for_connection_client (conn, mq_handlers, &mq_error_handler, h); @@ -241,15 +237,19 @@ reconnect (struct GNUNET_RPS_Handle *h) * @param cfg configuration to use * @return a handle to the service */ - struct GNUNET_RPS_Handle * +struct GNUNET_RPS_Handle * GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_RPS_Handle *h; - //struct GNUNET_RPS_Request_Handle *rh; - h = GNUNET_new(struct GNUNET_RPS_Handle); - h->cfg = GNUNET_CONFIGURATION_dup (cfg); + h = GNUNET_new (struct GNUNET_RPS_Handle); + h->cfg = cfg; reconnect (h); + if (NULL == h->mq) + { + GNUNET_free (h); + return NULL; + } h->req_handlers = GNUNET_CONTAINER_multihashmap32_create (4); return h; } @@ -264,7 +264,7 @@ GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) * @param cls closure given to the callback * @return a handle to cancel this request */ - struct GNUNET_RPS_Request_Handle * +struct GNUNET_RPS_Request_Handle * GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, uint32_t num_req_peers, GNUNET_RPS_NotifyReadyCB ready_cb, @@ -304,7 +304,7 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *rps_handle, * @param n number of peers to seed * @param ids the ids of the peers seeded */ - void +void GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n, const struct GNUNET_PeerIdentity *ids) @@ -375,7 +375,7 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, * if @type is 2 the last id is the id of the * peer to be isolated from the rest */ - void +void GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, uint32_t type, uint32_t num_peers, @@ -456,7 +456,7 @@ GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h, * * @param rh request handle of request to cancle */ - void +void GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) { struct GNUNET_RPS_Handle *h; @@ -482,12 +482,9 @@ GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh) * * @param h the handle to the rps service */ - void +void GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h) { - if (NULL != h->conn) - GNUNET_CLIENT_disconnect (h->conn); - GNUNET_CONFIGURATION_destroy (h->cfg); GNUNET_MQ_destroy (h->mq); if (0 < GNUNET_CONTAINER_multihashmap32_size (h->req_handlers)) LOG (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/secretsharing/secretsharing_api.c b/src/secretsharing/secretsharing_api.c index 4411648500..e268fc56f0 100644 --- a/src/secretsharing/secretsharing_api.c +++ b/src/secretsharing/secretsharing_api.c @@ -38,10 +38,6 @@ */ struct GNUNET_SECRETSHARING_Session { - /** - * Client connected to the secretsharing service. - */ - struct GNUNET_CLIENT_Connection *client; /** * Message queue for @e client. @@ -65,10 +61,6 @@ struct GNUNET_SECRETSHARING_Session */ struct GNUNET_SECRETSHARING_DecryptionHandle { - /** - * Client connected to the secretsharing service. - */ - struct GNUNET_CLIENT_Connection *client; /** * Message queue for @e client. @@ -226,8 +218,6 @@ GNUNET_SECRETSHARING_session_destroy (struct GNUNET_SECRETSHARING_Session *s) { GNUNET_MQ_destroy (s->mq); s->mq = NULL; - GNUNET_CLIENT_disconnect (s->client); - s->client = NULL; GNUNET_free (s); } @@ -270,9 +260,10 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c }; struct GNUNET_MQ_Envelope *ev; struct GNUNET_SECRETSHARING_CreateMessage *msg; + struct GNUNET_CLIENT_Connection *client; - s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); - if (NULL == s->client) + client = GNUNET_CLIENT_connect ("secretsharing", cfg); + if (NULL == client) { /* secretsharing not configured correctly */ GNUNET_break (0); @@ -281,7 +272,8 @@ GNUNET_SECRETSHARING_create_session (const struct GNUNET_CONFIGURATION_Handle *c } s->secret_ready_cb = cb; s->secret_ready_cls = cls; - s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, + s->mq = GNUNET_MQ_queue_for_connection_client (client, + mq_handlers, &handle_session_client_error, s); GNUNET_assert (NULL != s->mq); @@ -356,13 +348,16 @@ GNUNET_SECRETSHARING_decrypt (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_MQ_Envelope *ev; struct GNUNET_SECRETSHARING_DecryptRequestMessage *msg; size_t share_size; + struct GNUNET_CLIENT_Connection *client; - s->client = GNUNET_CLIENT_connect ("secretsharing", cfg); + client = GNUNET_CLIENT_connect ("secretsharing", cfg); + if (NULL == client) + return NULL; s->decrypt_cb = decrypt_cb; s->decrypt_cls = decrypt_cb_cls; - GNUNET_assert (NULL != s->client); - s->mq = GNUNET_MQ_queue_for_connection_client (s->client, mq_handlers, + s->mq = GNUNET_MQ_queue_for_connection_client (client, + mq_handlers, &handle_decrypt_client_error, s); GNUNET_assert (NULL != s->mq); @@ -505,8 +500,6 @@ GNUNET_SECRETSHARING_decrypt_cancel (struct GNUNET_SECRETSHARING_DecryptionHandl { GNUNET_MQ_destroy (dh->mq); dh->mq = NULL; - GNUNET_CLIENT_disconnect (dh->client); - dh->client = NULL; GNUNET_free (dh); } diff --git a/src/set/set_api.c b/src/set/set_api.c index 343b5f8812..826b6a63c8 100644 --- a/src/set/set_api.c +++ b/src/set/set_api.c @@ -26,7 +26,6 @@ #include "platform.h" #include "gnunet_util_lib.h" #include "gnunet_protocols.h" -#include "gnunet_client_lib.h" #include "gnunet_set_service.h" #include "set.h" @@ -50,11 +49,6 @@ struct SetCopyRequest struct GNUNET_SET_Handle { /** - * Client connected to the set service. - */ - struct GNUNET_CLIENT_Connection *client; - - /** * Message queue for @e client. */ struct GNUNET_MQ_Handle *mq; @@ -189,10 +183,6 @@ struct GNUNET_SET_OperationHandle */ struct GNUNET_SET_ListenHandle { - /** - * Connection to the service. - */ - struct GNUNET_CLIENT_Connection *client; /** * Message queue for the client. @@ -298,7 +288,7 @@ check_iter_element (void *cls, /* minimum size was already checked, everything else is OK! */ return GNUNET_OK; } - + /** * Handle element for iteration over the set. Notifies the @@ -313,7 +303,7 @@ check_iter_element (void *cls, { struct GNUNET_SET_Handle *set = cls; GNUNET_SET_ElementIterator iter = set->iterator; - struct GNUNET_SET_Element element; + struct GNUNET_SET_Element element; struct GNUNET_SET_IterAckMessage *ack_msg; struct GNUNET_MQ_Envelope *ev; uint16_t msize; @@ -534,7 +524,7 @@ handle_client_set_error (void *cls, { struct GNUNET_SET_Handle *set = cls; GNUNET_SET_ElementIterator iter = set->iterator; - + LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling client set error %d\n", error); @@ -589,15 +579,16 @@ create_internal (const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_CreateMessage *create_msg; struct GNUNET_SET_CopyLazyConnectMessage *copy_msg; + struct GNUNET_CLIENT_Connection *client; set->cfg = cfg; - set->client = GNUNET_CLIENT_connect ("set", cfg); - if (NULL == set->client) + client = GNUNET_CLIENT_connect ("set", cfg); + if (NULL == client) { GNUNET_free (set); return NULL; } - set->mq = GNUNET_MQ_queue_for_connection_client (set->client, + set->mq = GNUNET_MQ_queue_for_connection_client (client, mq_handlers, &handle_client_set_error, set); @@ -750,11 +741,6 @@ GNUNET_SET_destroy (struct GNUNET_SET_Handle *set) } LOG (GNUNET_ERROR_TYPE_DEBUG, "Really destroying set\n"); - if (NULL != set->client) - { - GNUNET_CLIENT_disconnect (set->client); - set->client = NULL; - } if (NULL != set->mq) { GNUNET_MQ_destroy (set->mq); @@ -893,8 +879,6 @@ handle_client_listener_error (void *cls, LOG (GNUNET_ERROR_TYPE_DEBUG, "Listener broke down (%d), re-connecting\n", (int) error); - GNUNET_CLIENT_disconnect (lh->client); - lh->client = NULL; GNUNET_MQ_destroy (lh->mq); lh->mq = NULL; lh->reconnect_task = GNUNET_SCHEDULER_add_delayed (lh->reconnect_backoff, @@ -911,7 +895,7 @@ handle_client_listener_error (void *cls, */ static void listen_connect (void *cls) -{ +{ GNUNET_MQ_hd_var_size (request, GNUNET_MESSAGE_TYPE_SET_REQUEST, struct GNUNET_SET_RequestMessage); @@ -922,14 +906,14 @@ listen_connect (void *cls) }; struct GNUNET_MQ_Envelope *mqm; struct GNUNET_SET_ListenMessage *msg; + struct GNUNET_CLIENT_Connection *client; lh->reconnect_task = NULL; - GNUNET_assert (NULL == lh->client); - lh->client = GNUNET_CLIENT_connect ("set", lh->cfg); - if (NULL == lh->client) - return; GNUNET_assert (NULL == lh->mq); - lh->mq = GNUNET_MQ_queue_for_connection_client (lh->client, + client = GNUNET_CLIENT_connect ("set", lh->cfg); + if (NULL == client) + return; + lh->mq = GNUNET_MQ_queue_for_connection_client (client, mq_handlers, &handle_client_listener_error, lh); @@ -969,7 +953,7 @@ GNUNET_SET_listen (const struct GNUNET_CONFIGURATION_Handle *cfg, lh->app_id = *app_id; lh->reconnect_backoff = GNUNET_TIME_UNIT_MILLISECONDS; listen_connect (lh); - if (NULL == lh->client) + if (NULL == lh->mq) { GNUNET_free (lh); return NULL; @@ -993,11 +977,6 @@ GNUNET_SET_listen_cancel (struct GNUNET_SET_ListenHandle *lh) GNUNET_MQ_destroy (lh->mq); lh->mq = NULL; } - if (NULL != lh->client) - { - GNUNET_CLIENT_disconnect (lh->client); - lh->client = NULL; - } if (NULL != lh->reconnect_task) { GNUNET_SCHEDULER_cancel (lh->reconnect_task); diff --git a/src/util/client.c b/src/util/client.c index d00e8bbd06..e30ce65896 100644 --- a/src/util/client.c +++ b/src/util/client.c @@ -404,6 +404,36 @@ do_connect (const char *service_name, /** + * Create a message queue to connect to a GNUnet service. + * If handlers are specfied, receive messages from the connection. + * + * @param connection the client connection + * @param handlers handlers for receiving messages, can be NULL + * @param error_handler error handler + * @param error_handler_cls closure for the @a error_handler + * @return the message queue, NULL on error + */ +struct GNUNET_MQ_Handle * +GNUNET_CLIENT_connecT (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *service_name, + const struct GNUNET_MQ_MessageHandler *handlers, + GNUNET_MQ_ErrorHandler error_handler, + void *error_handler_cls) +{ + struct GNUNET_CLIENT_Connection *c; + + c = GNUNET_CLIENT_connect (service_name, + cfg); + if (NULL == c) + return NULL; + return GNUNET_MQ_queue_for_connection_client (c, + handlers, + error_handler, + error_handler_cls); +} + + +/** * Get a connection with a service. * * @param service_name name of the service diff --git a/src/util/mq.c b/src/util/mq.c index 4170338add..c14b4b91dc 100644 --- a/src/util/mq.c +++ b/src/util/mq.c @@ -206,7 +206,7 @@ GNUNET_MQ_inject_message (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_MessageHandler *handler; int handled = GNUNET_NO; uint16_t ms = ntohs (mh->size); - + if (NULL == mq->handlers) goto done; for (handler = mq->handlers; NULL != handler->cb; handler++) @@ -665,6 +665,9 @@ static void connection_client_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { + struct ClientConnectionState *state = impl_state; + + GNUNET_CLIENT_disconnect (state->connection); GNUNET_free (impl_state); } @@ -692,6 +695,7 @@ connection_client_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) { struct ClientConnectionState *state = impl_state; + GNUNET_assert (NULL != state->th); GNUNET_CLIENT_notify_transmit_ready_cancel (state->th); state->th = NULL; @@ -723,9 +727,9 @@ GNUNET_MQ_queue_for_connection_client (struct GNUNET_CLIENT_Connection *connecti state = GNUNET_new (struct ClientConnectionState); state->connection = connection; mq->impl_state = state; - mq->send_impl = connection_client_send_impl; - mq->destroy_impl = connection_client_destroy_impl; - mq->cancel_impl = connection_client_cancel_impl; + mq->send_impl = &connection_client_send_impl; + mq->destroy_impl = &connection_client_destroy_impl; + mq->cancel_impl = &connection_client_cancel_impl; if (NULL != handlers) state->receive_requested = GNUNET_YES; diff --git a/src/util/test_mq_client.c b/src/util/test_mq_client.c index f894c39124..27458ec0a0 100644 --- a/src/util/test_mq_client.c +++ b/src/util/test_mq_client.c @@ -32,8 +32,6 @@ static struct GNUNET_SERVER_Handle *server; -static struct GNUNET_CLIENT_Connection *client; - static struct GNUNET_CONFIGURATION_Handle *cfg; static int ok; @@ -44,13 +42,15 @@ static int received = 0; static void -recv_cb (void *cls, struct GNUNET_SERVER_Client *argclient, +recv_cb (void *cls, + struct GNUNET_SERVER_Client *argclient, const struct GNUNET_MessageHeader *message) { received++; if (received == 2) { - GNUNET_SERVER_receive_done (argclient, GNUNET_NO); + GNUNET_SERVER_receive_done (argclient, + GNUNET_NO); return; } @@ -79,7 +79,8 @@ clean_up (void *cls) * @param client identification of the client */ static void -notify_disconnect (void *cls, struct GNUNET_SERVER_Client *client) +notify_disconnect (void *cls, + struct GNUNET_SERVER_Client *client) { if (client == NULL) return; @@ -110,11 +111,15 @@ send_trap_cb (void *cls) static void -test_mq (struct GNUNET_CLIENT_Connection *client) +test_mq () { + struct GNUNET_CLIENT_Connection *client; struct GNUNET_MQ_Handle *mq; struct GNUNET_MQ_Envelope *mqm; + client = GNUNET_CLIENT_connect ("test", cfg); + GNUNET_assert (client != NULL); + /* FIXME: test handling responses */ mq = GNUNET_MQ_queue_for_connection_client (client, NULL, NULL, NULL); @@ -122,14 +127,13 @@ test_mq (struct GNUNET_CLIENT_Connection *client) GNUNET_MQ_send (mq, mqm); mqm = GNUNET_MQ_msg_header (MY_TYPE); - GNUNET_MQ_notify_sent (mqm, send_trap_cb, NULL); + GNUNET_MQ_notify_sent (mqm, &send_trap_cb, NULL); GNUNET_MQ_send (mq, mqm); GNUNET_MQ_send_cancel (mqm); mqm = GNUNET_MQ_msg_header (MY_TYPE); - GNUNET_MQ_notify_sent (mqm, send_cb, NULL); + GNUNET_MQ_notify_sent (mqm, &send_cb, NULL); GNUNET_MQ_send (mq, mqm); - } @@ -163,10 +167,7 @@ task (void *cls) GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", "localhost"); - client = GNUNET_CLIENT_connect ("test", cfg); - GNUNET_assert (client != NULL); - - test_mq (client); + test_mq (); } |