From 1e620c9a829531da18fa309af050c26fddd34f1f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 5 Oct 2011 13:33:59 +0000 Subject: [PATCH] eliminate last calls to GNUNET_CORE_peer_request_connect --- src/core/core_api.c | 150 +++----------------------- src/core/test_core_api.c | 2 +- src/core/test_core_api_preferences.c | 2 +- src/core/test_core_api_reliability.c | 4 +- src/core/test_core_quota_compliance.c | 2 +- src/include/gnunet_core_service.h | 56 ---------- 6 files changed, 18 insertions(+), 198 deletions(-) diff --git a/src/core/core_api.c b/src/core/core_api.c index cdb050e8e..3624a6e7f 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -120,6 +120,19 @@ struct PeerRecord }; +/** + * Type of function called upon completion. + * + * @param cls closure + * @param success GNUNET_OK on success (which for request_connect + * ONLY means that we transmitted the connect request to CORE, + * it does not mean that we are actually now connected!); + * GNUNET_NO on timeout, + * GNUNET_SYSERR if core was shut down + */ +typedef void (*GNUNET_CORE_ControlContinuation) (void *cls, int success); + + /** * Entry in a doubly-linked list of control messages to be transmitted * to the core service. Control messages include traffic allocation, @@ -1623,143 +1636,6 @@ GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th) } -/* ****************** GNUNET_CORE_peer_request_connect ******************** */ - -/** - * Handle for a request to the core to connect to - * a particular peer. Can be used to cancel the request - * (before the 'cont'inuation is called). - */ -struct GNUNET_CORE_PeerRequestHandle -{ - - /** - * Link to control message. - */ - struct ControlMessage *cm; - - /** - * Core handle used. - */ - struct GNUNET_CORE_Handle *h; - - /** - * Continuation to run when done. - */ - GNUNET_CORE_ControlContinuation cont; - - /** - * Closure for 'cont'. - */ - void *cont_cls; - -}; - - -/** - * Continuation called when the control message was transmitted. - * Calls the original continuation and frees the remaining - * resources. - * - * @param cls the 'struct GNUNET_CORE_PeerRequestHandle' - * @param success was the request transmitted? - */ -static void -peer_request_connect_cont (void *cls, int success) -{ - struct GNUNET_CORE_PeerRequestHandle *ret = cls; - - if (ret->cont != NULL) - ret->cont (ret->cont_cls, success); - GNUNET_free (ret); -} - - -/** - * Request that the core should try to connect to a particular peer. - * Once the request has been transmitted to the core, the continuation - * function will be called. Note that this does NOT mean that a - * connection was successfully established -- it only means that the - * core will now try. Successful establishment of the connection - * will be signalled to the 'connects' callback argument of - * 'GNUNET_CORE_connect' only. If the core service does not respond - * to our connection attempt within the given time frame, 'cont' will - * be called with the TIMEOUT reason code. - * - * @param h core handle - * @param peer who should we connect to - * @param cont function to call once the request has been completed (or timed out) - * @param cont_cls closure for cont - * - * @return NULL on error or already connected, - * otherwise handle for cancellation - */ -struct GNUNET_CORE_PeerRequestHandle * -GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, - const struct GNUNET_PeerIdentity *peer, - GNUNET_CORE_ControlContinuation cont, - void *cont_cls) -{ - struct GNUNET_CORE_PeerRequestHandle *ret; - struct ControlMessage *cm; - struct ConnectMessage *msg; - - if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey)) - { -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n"); -#endif - return NULL; - } - - cm = GNUNET_malloc (sizeof (struct ControlMessage) + - sizeof (struct ConnectMessage)); - msg = (struct ConnectMessage *) &cm[1]; - msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT); - msg->header.size = htons (sizeof (struct ConnectMessage)); - msg->reserved = htonl (0); - msg->peer = *peer; - GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head, - h->control_pending_tail, cm); - ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle)); - ret->h = h; - ret->cm = cm; - ret->cont = cont; - ret->cont_cls = cont_cls; - cm->cont = &peer_request_connect_cont; - cm->cont_cls = ret; -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing REQUEST_CONNECT request\n"); -#endif - trigger_next_request (h, GNUNET_NO); - return ret; -} - - -/** - * Cancel a pending request to connect to a particular peer. Must not - * be called after the 'cont' function was invoked. - * - * @param req request handle that was returned for the original request - */ -void -GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle - *req) -{ - struct GNUNET_CORE_Handle *h = req->h; - struct ControlMessage *cm = req->cm; - -#if DEBUG_CORE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "A CHANGE PREFERENCE request was cancelled!\n"); -#endif - GNUNET_CONTAINER_DLL_remove (h->control_pending_head, h->control_pending_tail, - cm); - GNUNET_free (cm); - GNUNET_free (req); -} - - /* ****************** GNUNET_CORE_peer_change_preference ******************** */ diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c index 1566840e8..5779b969d 100644 --- a/src/core/test_core_api.c +++ b/src/core/test_core_api.c @@ -261,7 +261,7 @@ connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking core (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); - GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); + GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); } static void diff --git a/src/core/test_core_api_preferences.c b/src/core/test_core_api_preferences.c index 6730e3701..88aff2899 100644 --- a/src/core/test_core_api_preferences.c +++ b/src/core/test_core_api_preferences.c @@ -340,7 +340,7 @@ ask_connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking core (1) AGAIN to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); - GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); + GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); } diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c index 7224581d7..7627a32c0 100644 --- a/src/core/test_core_api_reliability.c +++ b/src/core/test_core_api_reliability.c @@ -391,9 +391,9 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, OKPP; GNUNET_assert (cls == &p2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Asking core (1) to connect to peer `%4s'\n", + "Asking transport (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); - GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); + GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); } } diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c index c909892e1..0f23e2b0b 100644 --- a/src/core/test_core_quota_compliance.c +++ b/src/core/test_core_quota_compliance.c @@ -534,7 +534,7 @@ init_notify (void *cls, struct GNUNET_CORE_Handle *server, "Asking core (1) to connect to peer `%4s'\n", GNUNET_i2s (&p2.id)); #endif - GNUNET_CORE_peer_request_connect (p1.ch, &p2.id, NULL, NULL); + GNUNET_TRANSPORT_try_connect (p1.ch, &p2.id); } } diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 0fcff6d6f..11514ae29 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -244,62 +244,6 @@ void GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle); -/** - * Handle for a request to the core to connect or disconnect - * from a particular peer. Can be used to cancel the request - * (before the 'cont'inuation is called). - */ -struct GNUNET_CORE_PeerRequestHandle; - - -/** - * Type of function called upon completion. - * - * @param cls closure - * @param success GNUNET_OK on success (which for request_connect - * ONLY means that we transmitted the connect request to CORE, - * it does not mean that we are actually now connected!); - * GNUNET_NO on timeout, - * GNUNET_SYSERR if core was shut down - */ -typedef void (*GNUNET_CORE_ControlContinuation) (void *cls, int success); - - -/** - * Request that the core should try to connect to a particular peer. - * Once the request has been transmitted to the core, the continuation - * function will be called. Note that this does NOT mean that a - * connection was successfully established -- it only means that the - * core will now try. Successful establishment of the connection - * will be signalled to the 'connects' callback argument of - * 'GNUNET_CORE_connect' only. If the core service does not respond - * to our connection attempt within the given time frame, 'cont' will - * be called with the TIMEOUT reason code. - * - * @param h core handle - * @param peer who should we connect to - * @param cont function to call once the request has been completed (or timed out) - * @param cont_cls closure for cont - * @return NULL on error (cont will not be called), otherwise handle for cancellation - */ -struct GNUNET_CORE_PeerRequestHandle * -GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h, - const struct GNUNET_PeerIdentity *peer, - GNUNET_CORE_ControlContinuation cont, - void *cont_cls); - - -/** - * Cancel a pending request to connect to a particular peer. Must not - * be called after the 'cont' function was invoked. - * - * @param req request handle that was returned for the original request - */ -void -GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle - *req); - - /** * Function called with perference change information about the given peer. * -- 2.25.1