From: Christian Grothoff Date: Sat, 16 Jan 2010 20:44:56 +0000 (+0000) Subject: further simplify transport API X-Git-Tag: initial-import-from-subversion-38251~22958 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dfb4dfbde04e233b5ab0c489aa3aacacd8a696ba;p=oweals%2Fgnunet.git further simplify transport API --- diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf index 9b47c7681..844e1ded5 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf +++ b/src/hostlist/test_gnunet_daemon_hostlist_peer1.conf @@ -27,7 +27,7 @@ PORT = 12969 [core] PORT = 12970 DEBUG = YES -#PREFIX = xterm -e xterm -e valgrind --tool=memcheck +PREFIX = valgrind --tool=memcheck [testing] WEAKRANDOM = YES diff --git a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf index 167d3acbd..dd5a599b8 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf +++ b/src/hostlist/test_gnunet_daemon_hostlist_peer2.conf @@ -27,7 +27,7 @@ PORT = 22969 [core] PORT = 22970 DEBUG = YES -#PREFIX = xterm -e xterm -e valgrind --tool=memcheck +PREFIX = valgrind --tool=memcheck [testing] WEAKRANDOM = YES diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 6f3bc6e94..8196dd45a 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -850,11 +850,11 @@ try_transmission_to_peer (struct NeighbourList *neighbour); */ static void transmit_send_continuation (void *cls, - struct ReadyList *rl, const struct GNUNET_PeerIdentity *target, int result) { struct MessageQueue *mq = cls; + struct ReadyList *rl; struct SendOkMessage send_ok_msg; struct NeighbourList *n; @@ -864,13 +864,10 @@ transmit_send_continuation (void *cls, GNUNET_assert (0 == memcmp (&n->id, target, sizeof (struct GNUNET_PeerIdentity))); - if (rl == NULL) - { - rl = n->plugins; - while ((rl != NULL) && (rl->plugin != mq->plugin)) - rl = rl->next; - GNUNET_assert (rl != NULL); - } + rl = n->plugins; + while ((rl != NULL) && (rl->plugin != mq->plugin)) + rl = rl->next; + GNUNET_assert (rl != NULL); if (result == GNUNET_OK) { rl->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); @@ -980,7 +977,6 @@ try_transmission_to_peer (struct NeighbourList *neighbour) GNUNET_i2s (&neighbour->id), rl->plugin->short_name); #endif rl->plugin->api->send (rl->plugin->api->cls, - rl, &neighbour->id, mq->priority, mq->message, @@ -1859,9 +1855,8 @@ disconnect_neighbour (struct NeighbourList *n, n->plugins = rpos->next; GNUNET_assert (rpos->neighbour == n); if (GNUNET_YES == rpos->connected) - rpos->plugin->api->cancel (rpos->plugin->api->cls, - rpos, - &n->id); + rpos->plugin->api->disconnect (rpos->plugin->api->cls, + &n->id); GNUNET_free (rpos); } @@ -1974,9 +1969,6 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) * and generally forward to our receive callback. * * @param cls the "struct TransportPlugin *" we gave to the plugin - * @param service_context value passed to the transport-service - * to identify the neighbour; will be NULL on the first - * call for a given peer * @param latency estimated latency for communicating with the * given peer * @param peer (claimed) identity of the other peer @@ -1985,9 +1977,8 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer) * for future receive calls for messages from this * particular peer */ -static struct ReadyList * +static void plugin_env_receive (void *cls, - struct ReadyList *service_context, struct GNUNET_TIME_Relative latency, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message) @@ -1996,32 +1987,26 @@ plugin_env_receive (void *cls, htons (sizeof (struct GNUNET_MessageHeader)), htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ACK) }; + struct ReadyList *service_context; struct TransportPlugin *plugin = cls; struct TransportClient *cpos; struct InboundMessage *im; uint16_t msize; struct NeighbourList *n; - if (service_context != NULL) - { - n = service_context->neighbour; - GNUNET_assert (n != NULL); - } - else + n = find_neighbour (peer); + if (n == NULL) { - n = find_neighbour (peer); - if (n == NULL) - { - if (message == NULL) - return NULL; /* disconnect of peer already marked down */ - n = setup_new_neighbour (peer); - } - service_context = n->plugins; - while ((service_context != NULL) && (plugin != service_context->plugin)) - service_context = service_context->next; - GNUNET_assert ((plugin->api->send == NULL) || - (service_context != NULL)); + if (message == NULL) + return; /* disconnect of peer already marked down */ + n = setup_new_neighbour (peer); } + service_context = n->plugins; + while ( (service_context != NULL) && + (plugin != service_context->plugin) ) + service_context = service_context->next; + GNUNET_assert ((plugin->api->send == NULL) || + (service_context != NULL)); if (message == NULL) { #if DEBUG_TRANSPORT @@ -2033,7 +2018,7 @@ plugin_env_receive (void *cls, if (service_context != NULL) service_context->connected = GNUNET_NO; disconnect_neighbour (n, GNUNET_YES); - return NULL; + return; } #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, @@ -2073,7 +2058,7 @@ plugin_env_receive (void *cls, /* TODO: call stats */ GNUNET_assert ( (service_context == NULL) || (NULL != service_context->neighbour) ); - return service_context; + return; } switch (ntohs (message->type)) { @@ -2119,7 +2104,6 @@ plugin_env_receive (void *cls, } GNUNET_assert ( (service_context == NULL) || (NULL != service_context->neighbour) ); - return service_context; } diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h index 93564f8e2..4cbf5e2e6 100644 --- a/src/transport/plugin_transport.h +++ b/src/transport/plugin_transport.h @@ -43,24 +43,12 @@ #include "gnunet_scheduler_lib.h" #include "gnunet_transport_service.h" -/** - * Opaque internal context for a particular peer of the transport - * service. Plugins will be given a pointer to this type and, if - * cheaply possible, should pass this pointer back to the transport - * service whenever additional messages from the same peer are - * received. - */ -struct ReadyList; - /** * Function called by the transport for each received message. * This function should also be called with "NULL" for the * message to signal that the other peer disconnected. * * @param cls closure - * @param service_context value passed to the transport-service - * to identify the neighbour; will be NULL on the first - * call for a given peer * @param latency estimated latency for communicating with the * given peer; should be set to GNUNET_TIME_UNIT_FOREVER_REL * until the transport has seen messages transmitted in @@ -70,20 +58,14 @@ struct ReadyList; * using this one plugin actually works * @param peer (claimed) identity of the other peer * @param message the message, NULL if peer was disconnected - * @return the new service_context that the plugin should use - * for future receive calls for messages from this - * particular peer */ -typedef struct ReadyList * - (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, - struct ReadyList * - service_context, - struct GNUNET_TIME_Relative - latency, - const struct GNUNET_PeerIdentity - * peer, - const struct GNUNET_MessageHeader - * message); +typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls, + struct GNUNET_TIME_Relative + latency, + const struct GNUNET_PeerIdentity + * peer, + const struct GNUNET_MessageHeader + * message); /** @@ -247,8 +229,6 @@ typedef int * upon "completion". * * @param cls closure - * @param service_context value passed to the transport-service - * to identify the neighbour * @param target who was the recipient of the message? * @param result GNUNET_OK on success * GNUNET_SYSERR if the target disconnected; @@ -257,11 +237,10 @@ typedef int */ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, - struct ReadyList * - service_context, const struct GNUNET_PeerIdentity * target, int result); + /** * Function that can be used by the transport service to transmit * a message using the plugin. Note that in the case of a @@ -271,11 +250,6 @@ typedef void * a fresh connection to another peer. * * @param cls closure - * @param service_context value passed to the transport-service - * to identify the neighbour; NULL is used to indicate - * an urgent message. If the urgent message can not be - * scheduled for immediate transmission, the plugin is to - * call the continuation with failure immediately * @param target who should receive this message * @param priority how important is the message? * @param msg the message to transmit @@ -288,7 +262,6 @@ typedef void */ typedef void (*GNUNET_TRANSPORT_TransmitFunction) (void *cls, - struct ReadyList * service_context, const struct GNUNET_PeerIdentity * target, unsigned int priority, @@ -312,18 +285,13 @@ typedef void * closed after a getting this call. * * @param cls closure - * @param service_context must correspond to the service context - * of the corresponding Transmit call; the plugin should - * not cancel a send call made with a different service - * context pointer! Never NULL. * @param target peer for which the last transmission is * to be cancelled */ typedef void - (*GNUNET_TRANSPORT_CancelFunction) (void *cls, - struct ReadyList * service_context, - const struct GNUNET_PeerIdentity * - target); + (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls, + const struct GNUNET_PeerIdentity * + target); /** @@ -423,11 +391,13 @@ struct GNUNET_TRANSPORT_PluginFunctions GNUNET_TRANSPORT_TransmitFunction send; /** - * Function that can be used to force the plugin to disconnect - * from the given peer and cancel all previous transmissions - * (and their continuationc). + * Function that can be used to force the plugin to disconnect from + * the given peer and cancel all previous transmissions (and their + * continuations). Note that if the transport does not have + * sessions / persistent connections (for example, UDP), this + * function may very well do nothing. */ - GNUNET_TRANSPORT_CancelFunction cancel; + GNUNET_TRANSPORT_DisconnectFunction disconnect; /** * Function to pretty-print addresses. NOTE: this function is not diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 9fc33cbfa..8c5f79fd3 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -263,11 +263,6 @@ struct Session */ struct GNUNET_SERVER_Client *client; - /** - * gnunet-service-transport context for this connection. - */ - struct ReadyList *service_context; - /** * Messages currently pending for transmission * to this peer, if any. @@ -560,7 +555,6 @@ do_transmit (void *cls, size_t size, void *buf) #endif if (pm->transmit_cont != NULL) pm->transmit_cont (pm->transmit_cont_cls, - session->service_context, &session->target, GNUNET_SYSERR); GNUNET_free (pm); } @@ -600,7 +594,6 @@ do_transmit (void *cls, size_t size, void *buf) session->pending_messages = pm->next; if (pm->transmit_cont != NULL) pm->transmit_cont (pm->transmit_cont_cls, - session->service_context, &session->target, GNUNET_OK); GNUNET_free (pm); session->gen_time[session->out_msg_counter % ACK_LOG_SIZE] @@ -829,7 +822,6 @@ disconnect_session (struct Session *session) session->pending_messages = pm->next; if (NULL != pm->transmit_cont) pm->transmit_cont (pm->transmit_cont_cls, - session->service_context, &session->target, GNUNET_SYSERR); GNUNET_free (pm); } @@ -846,7 +838,6 @@ disconnect_session (struct Session *session) know about this one, so we need to notify transport service about disconnect */ session->plugin->env->receive (session->plugin->env->cls, - session->service_context, GNUNET_TIME_UNIT_ZERO, &session->target, NULL); } @@ -1081,7 +1072,6 @@ session_try_connect (void *cls, */ static void tcp_plugin_send (void *cls, - struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target, unsigned int priority, const struct GNUNET_MessageHeader *msg, @@ -1117,7 +1107,6 @@ tcp_plugin_send (void *cls, session->quota_in = plugin->env->default_quota_in; session->expecting_welcome = GNUNET_YES; session->pending_messages = pm; - session->service_context = service_context; session->ic = GNUNET_PEERINFO_iterate (plugin->env->cfg, plugin->env->sched, target, @@ -1126,7 +1115,6 @@ tcp_plugin_send (void *cls, } GNUNET_assert (session != NULL); GNUNET_assert (session->client != NULL); - session->service_context = service_context; /* append pm to pending_messages list */ pme = session->pending_messages; if (pme == NULL) @@ -1161,17 +1149,12 @@ tcp_plugin_send (void *cls, * closed after a getting this call. * * @param cls closure - * @param service_context must correspond to the service context - * of the corresponding Transmit call; the plugin should - * not cancel a send call made with a different service - * context pointer! Never NULL. * @param target peer for which the last transmission is * to be cancelled */ static void -tcp_plugin_cancel (void *cls, - struct ReadyList *service_context, - const struct GNUNET_PeerIdentity *target) +tcp_plugin_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { struct Plugin *plugin = cls; struct Session *session; @@ -1196,7 +1179,6 @@ tcp_plugin_cancel (void *cls, pm->transmit_cont_cls = NULL; pm = pm->next; } - session->service_context = NULL; if (session->client != NULL) { GNUNET_SERVER_client_drop (session->client); @@ -1866,10 +1848,8 @@ handle_tcp_data (void *cls, "Forwarding data of type %u to transport service.\n", ntohs (msg->type)); #endif - session->service_context - = plugin->env->receive (plugin->env->cls, - session->service_context, - latency, &session->target, msg); + plugin->env->receive (plugin->env->cls, + latency, &session->target, msg); /* update bandwidth used */ session->last_received += msize; update_quota (session, GNUNET_NO); @@ -2062,7 +2042,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) api->cls = plugin; api->validate = &tcp_plugin_validate; api->send = &tcp_plugin_send; - api->cancel = &tcp_plugin_cancel; + api->disconnect = &tcp_plugin_disconnect; api->address_pretty_printer = &tcp_plugin_address_pretty_printer; api->set_receive_quota = &tcp_plugin_set_receive_quota; api->address_suggested = &tcp_plugin_address_suggested; diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c index 1d949f345..69c27b923 100644 --- a/src/transport/plugin_transport_template.c +++ b/src/transport/plugin_transport_template.c @@ -163,8 +163,6 @@ template_plugin_validate (void *cls, * a message using the plugin. * * @param cls closure - * @param service_context value passed to the transport-service - * to identify the neighbour * @param target who should receive this message * @param priority how important is the message * @param msg the message to transmit @@ -177,7 +175,6 @@ template_plugin_validate (void *cls, */ static void template_plugin_send (void *cls, - struct ReadyList *service_context, const struct GNUNET_PeerIdentity *target, unsigned int priority, const struct GNUNET_MessageHeader *msg, @@ -196,17 +193,11 @@ template_plugin_send (void *cls, * (and their continuationc). * * @param cls closure - * @param service_context must correspond to the service context - * of the corresponding Transmit call; the plugin should - * not cancel a send call made with a different service - * context pointer! Never NULL. - * @param target peer for which the last transmission is - * to be cancelled + * @param target peer from which to disconnect */ static void -template_plugin_cancel (void *cls, - struct ReadyList *service_context, - const struct GNUNET_PeerIdentity *target) +template_plugin_disconnect (void *cls, + const struct GNUNET_PeerIdentity *target) { // struct Plugin *plugin = cls; // FIXME @@ -301,7 +292,7 @@ gnunet_plugin_transport_template_init (void *cls) api->cls = plugin; api->validate = &template_plugin_validate; api->send = &template_plugin_send; - api->cancel = &template_plugin_cancel; + api->disconnect = &template_plugin_disconnect; api->address_pretty_printer = &template_plugin_address_pretty_printer; api->set_receive_quota = &template_plugin_set_receive_quota; api->address_suggested = &template_plugin_address_suggested; diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index 283312bfe..d4183fc27 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c @@ -92,10 +92,8 @@ static int ok; /** * Initialize Environment for this plugin */ -struct ReadyList * +static void receive(void *cls, - struct ReadyList * - service_context, struct GNUNET_TIME_Relative latency, const struct GNUNET_PeerIdentity @@ -103,7 +101,7 @@ receive(void *cls, const struct GNUNET_MessageHeader * message) { - return NULL; + /* do nothing */ } void notify_address(void *cls,