From 07632b2d9509b0e425967cbc80d2abd6ffc81c9d Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 22 Jan 2010 17:27:16 +0000 Subject: [PATCH] use new APIs for connect/disconnect --- src/core/core_api_peer_request.c | 64 +++----------------------- src/core/gnunet-service-core.c | 27 ----------- src/include/gnunet_core_service.h | 36 ++------------- src/include/gnunet_protocols.h | 5 -- src/include/gnunet_transport_service.h | 7 +++ src/topology/gnunet-daemon-topology.c | 62 ++++++++----------------- 6 files changed, 36 insertions(+), 165 deletions(-) diff --git a/src/core/core_api_peer_request.c b/src/core/core_api_peer_request.c index 58837c773..7a76a91df 100644 --- a/src/core/core_api_peer_request.c +++ b/src/core/core_api_peer_request.c @@ -29,8 +29,8 @@ /** - * Handle for a request to the core to connect or disconnect - * from a particular peer. Can be used to cancel the request + * 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 @@ -57,7 +57,7 @@ struct GNUNET_CORE_PeerRequestHandle void *cont_cls; /** - * Identity of the peer to connect/disconnect. + * Identity of the peer to connect to. */ struct GNUNET_PeerIdentity peer; @@ -160,65 +160,13 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_SCHEDULER_Handle *sched, /** - * Request that the core should try to disconnect from 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 cut -- it only means that the - * core will now try. Typically this will work pretty much - * immediately, but it is at least in theory also possible that a - * reconnect is also triggered rather quickly. Successful creation - * and destruction of connections will be signalled to the 'connects' - * and 'disconnects' callback arguments 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 sched scheduler to use - * @param cfg configuration to use - * @param timeout how long to try to talk to core - * @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_disconnect (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_PeerIdentity * peer, - GNUNET_SCHEDULER_Task cont, - void *cont_cls) -{ - struct GNUNET_CORE_PeerRequestHandle *ret; - struct GNUNET_CLIENT_Connection *client; - - client = GNUNET_CLIENT_connect (sched, "core", cfg); - if (client == NULL) - return NULL; - ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle)); - ret->client = client; - ret->sched = sched; - ret->cont = cont; - ret->cont_cls = cont_cls; - ret->peer = *peer; - ret->type = GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT; - GNUNET_CLIENT_notify_transmit_ready (client, - sizeof (struct ConnectMessage), - timeout, - GNUNET_YES, - &send_request, - ret); - return ret; -} - - -/** - * Cancel a pending request to connect or disconnect from/to a particular - * peer. Must not be called after the 'cont' function was invoked. + * 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_cancel (struct GNUNET_CORE_PeerRequestHandle *req) +GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req) { GNUNET_CLIENT_disconnect (req->client); GNUNET_free (req); diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index a3694e582..cb74fc8c2 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -1861,30 +1861,6 @@ handle_client_request_connect (void *cls, } -/** - * Handle CORE_REQUEST_DISCONNECT request. - * - * @param cls unused - * @param client the client issuing the request - * @param message the "struct ConnectMessage" - */ -static void -handle_client_request_disconnect (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) -{ - const struct ConnectMessage *cm = (const struct ConnectMessage*) message; - struct Neighbour *n; - - GNUNET_SERVER_receive_done (client, GNUNET_OK); - n = find_neighbour (&cm->peer); - if (n == NULL) - return; /* done */ - /* FIXME: implement disconnect! */ -} - - - /** * List of handlers for the messages understood by this * service. @@ -1900,9 +1876,6 @@ static struct GNUNET_SERVER_MessageHandler handlers[] = { {&handle_client_request_connect, NULL, GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT, sizeof (struct ConnectMessage)}, - {&handle_client_request_disconnect, NULL, - GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT, - sizeof (struct ConnectMessage)}, {NULL, NULL, 0, 0} }; diff --git a/src/include/gnunet_core_service.h b/src/include/gnunet_core_service.h index 3ba4ef137..6f49dc71a 100644 --- a/src/include/gnunet_core_service.h +++ b/src/include/gnunet_core_service.h @@ -232,43 +232,13 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_SCHEDULER_Handle *sched, /** - * Request that the core should try to disconnect from 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 cut -- it only means that the - * core will now try. Typically this will work pretty much - * immediately, but it is at least in theory also possible that a - * reconnect is also triggered rather quickly. Successful creation - * and destruction of connections will be signalled to the 'connects' - * and 'disconnects' callback arguments 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 sched scheduler to use - * @param cfg configuration to use - * @param timeout how long to try to talk to core - * @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_disconnect (struct GNUNET_SCHEDULER_Handle *sched, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_TIME_Relative timeout, - const struct GNUNET_PeerIdentity * peer, - GNUNET_SCHEDULER_Task cont, - void *cont_cls); - - -/** - * Cancel a pending request to connect or disconnect from/to a particular - * peer. Must not be called after the 'cont' function was invoked. + * 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_cancel (struct GNUNET_CORE_PeerRequestHandle *req); +GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle *req); /** diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 85553bff0..779c16f73 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -307,11 +307,6 @@ extern "C" */ #define GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT 74 -/** - * Request from client asking to disconnect from a peer. - */ -#define GNUNET_MESSAGE_TYPE_CORE_REQUEST_DISCONNECT 75 - /** * Session key exchange between peers. diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index b86bb1663..650dd2e68 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -223,6 +223,13 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct +/** + * Function called whenever there is an update to the + * HELLO of this peer. + * + * @param cls closure + * @param hello our updated HELLO + */ typedef void (*GNUNET_TRANSPORT_HelloUpdateCallback)(void *cls, const struct GNUNET_MessageHeader *hello); diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index a636360d6..3bcc29704 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -87,7 +87,7 @@ struct PeerList * Our handle for the request to connect to this peer; NULL if no * such request is pending. */ - struct GNUNET_CORE_TransmitHandle *connect_req; + struct GNUNET_CORE_PeerRequestHandle *connect_req; /** * Pointer to the HELLO message of this peer; can be NULL. @@ -158,8 +158,8 @@ struct DisconnectList /** * Our request handle. */ - struct GNUNET_CORE_PeerRequestHandle *rh; - + struct GNUNET_TRANSPORT_BlacklistRequest *rh; + /** * Peer we tried to disconnect. */ @@ -268,9 +268,7 @@ disconnect_done (void *cls, /** - * Force a disconnect from the specified peer. This is currently done by - * changing the bandwidth policy to 0 bytes per second. - * FIXME: maybe we want a nicer CORE API for both connect and disconnect... + * Force a disconnect from the specified peer. * FIXME: this policy change is never undone; how do we reconnect ever? */ static void @@ -283,43 +281,25 @@ force_disconnect (const struct GNUNET_PeerIdentity *peer) GNUNET_CONTAINER_DLL_insert (disconnect_head, disconnect_tail, dl); - dl->rh = GNUNET_CORE_peer_request_disconnect (sched, cfg, - GNUNET_TIME_UNIT_FOREVER_REL, - peer, - &disconnect_done, - dl); + dl->rh = GNUNET_TRANSPORT_blacklist (sched, cfg, + peer, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_TIME_UNIT_FOREVER_REL, + &disconnect_done, + dl); } /** * Function called by core when our attempt to connect succeeded. - * Transmits a 'DUMMY' message to trigger the session key exchange. - * FIXME: this is an issue with the current CORE API. */ -static size_t -ready_callback (void *cls, - size_t size, void *buf) +static void +connect_completed_callback (void *cls, + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct PeerList *pos = cls; - struct GNUNET_MessageHeader hdr; pos->connect_req = NULL; - if (buf == NULL) - { -#if DEBUG_TOPOLOGY - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Core told us that our attempt to connect failed.\n"); -#endif - return 0; - } -#if DEBUG_TOPOLOGY - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending dummy message to establish connection.\n"); -#endif - hdr.size = htons (sizeof (struct GNUNET_MessageHeader)); - hdr.type = htons (GNUNET_MESSAGE_TYPE_TOPOLOGY_DUMMY); - memcpy (buf, &hdr, sizeof (struct GNUNET_MessageHeader)); - return sizeof (struct GNUNET_MessageHeader); } @@ -340,13 +320,11 @@ attempt_connect (struct PeerList *pos) "Asking core to connect to `%s'\n", GNUNET_i2s (&pos->id)); #endif - pos->connect_req = GNUNET_CORE_notify_transmit_ready (handle, - 0 /* priority */, - GNUNET_TIME_UNIT_MINUTES, - &pos->id, - sizeof(struct GNUNET_MessageHeader), - &ready_callback, - pos); + pos->connect_req = GNUNET_CORE_peer_request_connect (sched, cfg, + GNUNET_TIME_UNIT_MINUTES, + &pos->id, + &connect_completed_callback, + pos); } @@ -457,7 +435,7 @@ free_peer (struct PeerList *peer) if (pos->hello_req != NULL) GNUNET_CORE_notify_transmit_ready_cancel (pos->hello_req); if (pos->connect_req != NULL) - GNUNET_CORE_notify_transmit_ready_cancel (pos->connect_req); + GNUNET_CORE_peer_request_connect_cancel (pos->connect_req); if (pos->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (sched, pos->hello_delay_task); @@ -1203,7 +1181,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONTAINER_DLL_remove (disconnect_head, disconnect_tail, dl); - GNUNET_CORE_peer_request_cancel (dl->rh); + GNUNET_TRANSPORT_blacklist_cancel (dl->rh); GNUNET_free (dl); } } -- 2.25.1